function hideAlert (){
	document.getElementById("alert").style.display = 'none';
	//document.getElementById("alert").style.marginTop = '0px';
	//	document.getElementById("alert").style.marginLeft = '';
}

function toppos() {
	if (document.documentElement && document.documentElement.scrollTop)
	theTop = document.documentElement.scrollTop;
	else if (document.body)
	theTop = document.body.scrollTop
	return theTop;
}

function showElement (element) {
	document.getElementById(element).style.display = 'block';
}

function hideElement (element) {
	document.getElementById(element).style.display = 'none';
}

function URLDecode(str)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = str;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
}

function viewAlert () {
	var dsoctop = toppos()+200;
	if (document.documentElement && document.documentElement.scrollTop) {
		w = screen.width-520;
	}
	else if (document.body) {
		w = window.innerWidth-20;
	}
	marginsx = (w/2)-380;
	var h = window.innerHeight;

	document.getElementById("alert").style.display = '';
	document.getElementById("alert").style.marginLeft = marginsx +'px';
	document.getElementById("alert").style.marginTop = dsoctop + 'px';

	setTimeout ('hideAlert()', '1500');
}

function addCart ( product_id ) {

	advAJAX.get({
		tag: "cartList",
		url: "./additional/cart.php?pid=" + product_id,
		timeout : 3000,
		onTimeout : function() { alert("Connection timed out."); },
		retry: 2,
		retryDelay: 2000,
		onRetry : function() { alert("Retry connection..."); },
		onRetryDelay : function() { alert("Awaiting retry..."); },
		onSuccess : function(obj) {
			if (document.getElementById(obj.tag))
			{
	        document.getElementById(obj.tag).innerHTML = URLDecode(obj.responseText);
			}
			viewAlert();
		},
		onError : function(obj) { alert("Error: " + obj.status); }
	});

}

function delCart ( product_id ) {

	advAJAX.get({
		tag: "cartList",
		url: "./additional/cart.php?a=d&pid=" + product_id,
		timeout : 3000,
		onTimeout : function() { alert("Connection timed out."); },
		retry: 2,
		retryDelay: 2000,
		onRetry : function() { alert("Retry connection..."); },
		onRetryDelay : function() { alert("Awaiting retry..."); },
		onSuccess : function(obj) {
			if (document.getElementById(obj.tag))
			{
				document.getElementById(obj.tag).innerHTML = URLDecode(obj.responseText);
			}
		},
		onError : function(obj) { alert("Error: " + obj.status); }
	});

}

function viewCart () {

	advAJAX.get({
		tag: "cartList",
		url: "./additional/cart.php",
		timeout : 3000,
		onTimeout : function() { alert("Connection timed out."); },
		retry: 2,
		retryDelay: 2000,
		onRetry : function() { alert("Retry connection..."); },
		onRetryDelay : function() { alert("Awaiting retry..."); },
		onSuccess : function(obj) {
	        document.getElementById(obj.tag).innerHTML = URLDecode(obj.responseText);
		},
		onError : function(obj) { alert("Error: " + obj.status); }
	});

}

function searchSuggest (string) {

	advAJAX.get({
		tag: "searchSuggest",
		url: "./additional/ssuggest.php?q=" + string,
		timeout : 3000,
		onTimeout : function() { alert("Connection timed out."); },
		retry: 2,
		retryDelay: 2000,
		onRetry : function() { alert("Retry connection..."); },
		onRetryDelay : function() { alert("Awaiting retry..."); },
		onSuccess : function(obj) {
			document.getElementById(obj.tag).style.display = 'block';
	        document.getElementById(obj.tag).innerHTML = obj.responseText;
			setTimeout('hideElement(\'' + obj.tag + '\')', 5000);
		},
		onError : function(obj) { alert("Error: " + obj.status); }
	});

}

function search (string) {
	document.getElementById('query_item').value = unescape(string);
}


function pop(element, width, height) {
	window.open(element.href,"hpop",'width=' + width + ',height=' + height + ',left=50,top=50,resizable=0,scrollbars=no,menubar=no' );
	element.href = '#';
}

function rollCat (cat, element) {
	var hand = document.getElementById("sub" + cat).style.display;

	if (hand == 'none')
	{
		document.getElementById("sub" + cat).style.display = 'block';
		element.href = '#';
	}
	else {
		document.getElementById("sub" + cat).style.display = 'none';
	}

}

function go(rollmenu, element) {
	element.href = element.href + "&roll=" + rollmenu;
}

function goSelect (element) {
	var gourl = element.options[element.selectedIndex].value;	
	window.top.location.href = gourl;
}