String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function toolbarCatSelect(url)
{
	location.href = url;
};

function getXmlHttp()
{
	var xmlHttp;
	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;
   	 		}
   	 	}
   	 }
   	 
   	 return xmlHttp;
}

function appStatusOwnIt(userId, appleid, updateid)
{
	var elemButtonOwnIt = document.getElementById("app_" + appleid + "_button_ownit");
	var on = elemButtonOwnIt.className.trim() == "ownit" ? true : false;

	// toggle buttons
	elemButtonOwnIt.className = on ? "ownit selected" : "ownit";
	var elemButtonWantIt = document.getElementById("app_" + appleid + "_button_wantit");
	elemButtonWantIt.className = "wantit";

	// record in database
	var xmlHttp = getXmlHttp();
	var status = on ? "own" : "";
	xmlHttp.open("GET","/appStatusAjax.php?userId=" + userId + "&appleid=" + appleid + "&status=" + status + "&updateid=" + updateid,true);
	xmlHttp.send(null);
}

function appStatusWantIt(userId, appleid, updateid)
{
	var elemButtonWantIt = document.getElementById("app_" + appleid + "_button_wantit");
	var on = elemButtonWantIt.className.trim() == "wantit" ? true: false;

	// toggle buttons
	elemButtonWantIt.className = on ? "wantit selected" : "wantit";
	var elemButtonOwnIt = document.getElementById("app_" + appleid + "_button_ownit");
	elemButtonOwnIt.className = "ownit";

	// record in database
	var xmlHttp = getXmlHttp();
	var status = on ? "want" : "";
	xmlHttp.open("GET","/appStatusAjax.php?userId=" + userId + "&appleid=" + appleid + "&status=" + status + "&updateid=" + updateid, true);
	xmlHttp.send(null);
}

function setFrontView(view)
{
	var expireDate = new Date();
	expireDate.setDate(expireDate.getDate() + 365);

	var value = "AS_frontview=" + view + "; expires=" + expireDate.toGMTString() + "; path=/";
	document.cookie = value;
}


