function DelayLoad(id,url,delay)
{
	setTimeout("LoadImage('"+id+"','"+url+"');",delay);
}
function LoadImage(id,url)
{
	var img = document.getElementById(id);
	img.src = url;
}
function GetWindowSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return {x:myWidth,y:myHeight};
}
//function SearchClick(search, searchFilterExists)
//{
//
//	if(!search.value && !searchFilterExists)
//	{
//		search.style.textAlign='center';
//		search.style.color = "#999999";
//		search.value += "keyword or product #";
//	}
//	else if(searchFilterExists && !search.value)
//	{
//		search.style.textAlign='center';
//		search.style.color = "#999999";
//		search.value = "search within";
//	}
//	else
//	{
//		search.style.textAlign='left';
//		search.style.color = "#000000";
//
//		if(
//			search.value == 'search within' ||
//			search.value == 'keyword or product #')
//			{
//			search.value = "";
//		}
//	}
//}
function CopyShippingToBilling()
{
	document.getElementById('billingAddress1').value = document.getElementById('shippingAddress1').value;
	document.getElementById('billingAddress2').value = document.getElementById('shippingAddress2').value;
	document.getElementById('billingCity').value = document.getElementById('shippingCity').value;
	document.getElementById('billingState').value = document.getElementById('shippingState').value;
	document.getElementById('billingZip').value = document.getElementById('shippingZip').value;
	document.getElementById('billingPhone').value = document.getElementById('shippingPhone').value;
	document.getElementById('billingEmail').value = document.getElementById('shippingEmail').value;
}
function AjaxForm(form)
{
	if(null==form)
	{
		return;
	}
	//alert(form.elements);
	var postFields = "";
	for(var i = 0 ; i < form.elements.length ; i++)
	{
		//alert(form.elements[i].name);
		if(form.elements[i].name)
		{
			if('checkbox'==form.elements[i].type && false==form.elements[i].checked)
			{
				continue;
			}
			postFields = postFields + 
			form.elements[i].name +
			"=" +
			encodeURIComponent( form.elements[i].value ) +
			"&";
		}
	}
	postFields = postFields.substring(0,postFields.length-1);//trim trailing &
	//alert(postFields);
	AjaxPost("ajax.php", postFields);

//	return false;
}
function AjaxPost(url, parameters)
{
	var http_request = false;
	if (window.XMLHttpRequest)
	{ // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType)
		{
			// set type accordingly to anticipated content type
			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');
		}
	}
	else if (window.ActiveXObject) // IE
	{
		try
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}
	if (!http_request)
	{
		alert('Cannot create XMLHTTP instance');
		return false;
	}

	http_request.open('POST', url, false);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
	//alert(url+"?"+parameters+"\n-------\n"+http_request.responseText);
}
function refreshCurrentWindow()
{
	window.location.reload( true );
}
function pop(url,width,height) {
	window.open(url,'_pop1','toolbar=no,menubar=no,location=no,height='+height+',width='+width+',scrollbars=yes').focus();
	return false;
}
function _blank(href) {
	window.open(href);
	return false;
}
function submit(form) {
	form = document.getElementById(form);
	form.submit();
}
function toggleMoreLess(elementID,parent) {
	var div = document.getElementById(elementID);
	div.style.display = ('none'==div.style.display) ? 'block' : 'none';
	parent.innerHTML = ('More �'==parent.innerHTML) ? 'Less �' : 'More �';
	return false;
}
function toggleDiv(elementId) {
	var div = document.getElementById(elementId);
	div.style.display = ('none'==div.style.display) ? 'block' : 'none';
	return false;
}
function showDiv(elementId,show) {
	var div = document.getElementById(elementId);

	if(show)
	{
		div.style.display = 'block';
	}
	else
	{
		div.style.display = 'none';
	}
	return false;
}
//item management functions
function removeItemFromList(cookieKey,id,name) {
	var path="/sys/bounceback.php5?removeItemFromList=true&cookieKey="+cookieKey+"&id="+id+"&name="+name;
	//alert(path);
	window.location=path;
	return false;
}
function copyToClipboard(s)
{
	if( window.clipboardData && clipboardData.setData )
	{
		clipboardData.setData("Text", s);
	}
	else
	{
		// You have to sign the code to enable this or allow the action in about:config by changing
		user_pref("signed.applets.codebase_principal_support", true);
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

		var clip = Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		// create a transferable
		var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		// specify the data we wish to handle. Plaintext in this case.
		trans.addDataFlavor('text/unicode');

		// To get the data from the transferable we need two new objects
		var str = new Object();
		var len = new Object();

		var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);

		var copytext=meintext;

		str.data=copytext;

		trans.setTransferData("text/unicode",str,copytext.length*[[[[2]]]]);

		var clipid=Components.interfaces.nsIClipboard;

		if (!clip) return false;

		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
}

//general functions
function ajaxUrl(url)
{
	var xmlHttp = null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.open("GET",url,false);//non async transfer
	xmlHttp.send(null);
}//general functions
function ajaxUrlReload(url)
{
	//alert("ajaxReload");
	var xmlHttp = null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			// Get the data from the server's response in xmlHttp.responseText;
			//1) For now, we'll always want to refresh the current window once the ajax call finishes.
			//could be a scope issue here...
			//alert("Ajax Done:"+xmlHttp.responseText);
			
			//alert("ready state 4");
			window.location.reload( true );
		}
	}
	xmlHttp.open("GET",url,true);//async transfer
	xmlHttp.send(null);
}
