function create_input(name){
	// creates an input element if it does not exist.
	// returns the input element.
	var elem = null;
	inputList = document.forms[0].getElementsByTagName('input');
	for(i=0; i<inputList.length; i++){
		if(name == inputList[i].name){
			elem = inputList[i];
			break;
		}	
	}
	if(null == elem){
		try {
			// this hokey method is for IE... for shame. Mozilla and other browsers will throw an exception.
			var new_input = document.createElement('<input name="'+name+'">');
		} catch(e){
				// Catch the exception and do it the right way.
				var new_input = document.createElement('input');
				new_input.setAttribute('name', name)
		}
		new_input.setAttribute('type','hidden');
		document.forms[0].appendChild(new_input);
		elem = document.forms[0].lastChild;
	} 
	return elem;		
}

function fts_search(){
	var i =0;
	while(i < document.forms[0].search_type.length){
		if(true == document.forms[0].search_type[i].checked){
			var search_type = document.forms[0].search_type[i].value;
		}
		i++;
	}
	switch(search_type){
		case "trk_track":
			document.forms[0].limit_offset.value = '';
			FuseAction('search.fts_track');
			break;
		case "ecom":
			document.forms[0].limit_offset.value = '';
			FuseAction('search.fts_ecom');
			break;
		case "cms":
			document.forms[0].limit_offset.value = '';
			FuseAction('search.fts_cms');
			break;
	}
}

function item_nav(_nav_id, xfa, super_item){
	if (undefined == super_item || 0 == super_item || '0' == super_item || 'false' == super_item) {
		super_item = false;	
	} else {
		super_item = true;
	}
	
	if (false == super_item) {
		if(!document.forms[0].item_id){
			try {
				// this hokey method is for IE... for shame. Mozilla and other browsers will throw an exception.
				var new_input = document.createElement('<input name="item_id">');
			} catch(e){
					// Catch the exception and do it the right way.
					var new_input = document.createElement('input');
					new_input.setAttribute('name', 'item_id')
			}
			new_input.setAttribute('type','hidden');
			document.forms[0].appendChild(new_input);
		}
		document.forms[0].item_id.value = _nav_id;
		FuseAction(xfa);
	} else {
		if(!document.forms[0].item_cat_id){
			try {
				// this hokey method is for IE... for shame. Mozilla and other browsers will throw an exception.
				var new_input = document.createElement('<input name="item_cat_id">');
			} catch(e){
					// Catch the exception and do it the right way.
					var new_input = document.createElement('input');
					new_input.setAttribute('name', 'item_cat_id')
			}
			new_input.setAttribute('type','hidden');
			document.forms[0].appendChild(new_input);
		}
		document.forms[0].item_cat_id.value = _nav_id;
		FuseAction(xfa);
	}
}

function cat_nav(item_cat_id, xfa){
	input = create_input('item_cat_id');
	input.value = item_cat_id;
	FuseAction(xfa);
}
function article_cat_nav(content_cat_id, xfa){
	input = create_input('content_cat_id');
	input.value = content_cat_id;
	FuseAction(xfa);
}

function fix_flash(){
	// <![CDATA[
	var tmp = new Date();
	unique = tmp.getTime();
	var so = new SWFObject("media/images/banner/banner.swf", "head_banner", "659", "158", "8", "#FFFFFF");
	so.addVariable("extImage", "media/images/banner/banner_custom.jpg?_unique="+unique);
	so.write("site_head_banner");
	// ]]>
}

function init_page(){
	foo = null;//	fix_flash();
}

if (window.addEventListener) { window.addEventListener("load", init_page, false);
}else if (window.attachEvent) { document.attachEvent("onreadystatechange", init_page); }

function newsletter_signup(subscribe_id, email){
	dojo.xhrGet({
		 url : '?fuseaction=subscribe.svc_subscribe_add_no_lay&subscribe_id='+subscribe_id+'&subscribe_email_add='+email,
		 handleAs : 'json',
		 load : handle_newsletter_signup
	});
}
function handle_newsletter_signup(response, ioArgs){
	msg = dojo.byId('newsletter_subscribe_msg');
	msg.innerHTML = response.message;
	dojo.style(msg, 'color', '#333333');
	dojo.style(msg, 'opacity', 1);
	fadeout = dojo.fadeOut({node: msg, duration:1000});
	window.setTimeout('fadeout.play()', 4000);
}
