// Begin gotosite
function gotosite()
{
	var strUrlSrc = window.location.href;
	var strUrlCost = "";
	var strUrlUpdateType = "";
	
	if (strUrlSrc.match(/paid/)) strUrlCost = "/paid";
	if (strUrlSrc.match(/free/)) strUrlCost = "/free";
	
	if (strUrlSrc.match(/updates/)) strUrlUpdateType = "/updates";
	if (strUrlSrc.match(/(new\/)|(new$)/)) strUrlUpdateType = "/new";
	if (strUrlSrc.match(/prices/)) strUrlUpdateType = "/prices";
	
	var strUrlDest = document.gotoform.selectcategories.options[document.gotoform.selectcategories.selectedIndex].value;

	setFrontView(strUrlDest + strUrlUpdateType + strUrlCost);
	window.location.href = strUrlDest + strUrlUpdateType + strUrlCost;
} 
// End gotosite


function gotosite_bestsellers()
{
	var strUrlSrc = window.location.href;
	var strUrlCost = "";
	var strUrlUpdateType = "";
	
	if (strUrlSrc.match(/paid/)) strUrlCost = "/paid";
	if (strUrlSrc.match(/free/)) strUrlCost = "/free";
	if (strUrlSrc.match(/grossing/)) strUrlCost = "/grossing";
	
	var strUrlDest = document.gotoform.selectcategories.options[document.gotoform.selectcategories.selectedIndex].value;
	window.location.href = strUrlDest + strUrlCost;
} 

// Begin setCategory()
function setCategory(page,category)
{
	var expireDate = new Date();
	expireDate.setDate(expireDate.getDate() + 365);
	
	var value = "AS_" + page + "_category=" + category.replace(/\//,"") + "; expires=" + expireDate.toGMTString() + "; path=/";
	document.cookie = value;
};
// End setCategory()


// Begin clearCategory()
function clearCategory(page)
{
	var expireDate = new Date();
	expireDate.setDate(expireDate.getDate() - 1);
	
	var value = "AS_" + page + "_category=; expires=" + expireDate.toGMTString() + "; path=/";
	document.cookie = value;
};
// End clearCategory()


// Begin getXmlHttp()
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;
}
// End getXmlHttp

// Begin appStatusOwnIt
function appStatusOwnIt(userId, appleid, updateid)
{
	var elemButtonOwnIt = document.getElementById("app_" + appleid + "_button_ownit");
	var on = elemButtonOwnIt.className == "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","/includes/appStatusAjax.php?userId=" + userId + "&appleid=" + appleid + "&status=" + status + "&updateid=" + updateid,true);
	xmlHttp.send(null);
}
// End appStatusOwnIt

// Begin appStatusBoughtIt
function appStatusBoughtIt(userId, appleid, updateid)
{
	var elemButtonOwnIt = document.getElementById("app_" + appleid + "_button_boughtit");
	var on = elemButtonOwnIt.className == "boughtit" ? true : false;

	// toggle button
	elemButtonOwnIt.className = on ? "boughtit selected" : "boughtit";

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

// Begin appStatusDontShareIt
function appStatusDontShareIt(userId, appleid)
{
	var elemButtonDontShareIt = document.getElementById("app_" + appleid + "_button_dontshareit");
	var on = elemButtonDontShareIt.className == "dontshareit" ? true : false;

	// toggle button
	elemButtonDontShareIt.className = on ? "dontshareit selected" : "dontshareit";

	// record in database
	var xmlHttp = getXmlHttp();
	var dontshare = on ? "1" : "0";

	xmlHttp.open("GET","/includes/appDontShareAjax.php?userId=" + userId + "&appleid=" + appleid + "&dontshare=" + dontshare,true);
	xmlHttp.send(null);
}
// End appStatusDontShareIt

// Begin appStatusWantIt
function appStatusWantIt(userId, appleid, updateid)
{
	var elemButtonWantIt = document.getElementById("app_" + appleid + "_button_wantit");
	var on = elemButtonWantIt.className == "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","/includes/appStatusAjax.php?userId=" + userId + "&appleid=" + appleid + "&status=" + status + "&updateid=" + updateid, true);
	xmlHttp.send(null);
}
// End appStatusOwnIt

// Begin appStatusRemove
function appStatusRemove(userId, appleid)
{ 
	var status = "";
	var updateid = "";

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

// Begin appRate
function appRate(userId, appleid, rating)
{
	var elemButtonRate = document.getElementById("app_" + appleid + "_button_rating");
	elemButtonRate.originalClassName = "score s" + rating;
	
	// record in database
	var xmlHttp = getXmlHttp();
	xmlHttp.open("GET","/includes/appRateAjax.php?userId=" + userId + "&appleid=" + appleid + "&rating=" + rating, true);
	xmlHttp.send(null);
}
// End appRate

// Begin listSortBy
function listSortBy(page, fieldName, direction)
{
	var expireDate = new Date();
	expireDate.setDate(expireDate.getDate() + 365);

	document.cookie = "AS_" + page + "_sortBy=" + fieldName + "; expires=" + expireDate.toGMTString() + ";path=/";
	document.cookie = "AS_" + page + "_sortDir=" + direction + "; expires=" + expireDate.toGMTString() + ";path=/";

};
// End listSortBy

// Begin settingClickSearch
function settingClickSearch(page, setting)
{
	var expireDate = new Date();
	expireDate.setDate(expireDate.getDate() + 365);
	
	var elemSetting = document.getElementById("set");
	var elemMultiA = document.getElementById("search_setting_titleOnly");
	var elemMultiB = document.getElementById("search_setting_titleDesc");
	
	elemSetting.value = setting;
	elemMultiA.className = setting == "titleOnly" ? "multia selected" : "multia";
	elemMultiB.className = setting == "titleDesc" ? "multib selected" : "multib";
	
	var value = "AS_" + page + "_setting=" + setting + "; expires=" + expireDate.toGMTString() + "; path=/";
	document.cookie = value;
};
// End settingClick


// Begin settingClickBestsellers
function settingClickBestsellers(page, setting)
{
	var expireDate = new Date();
	expireDate.setDate(expireDate.getDate() + 365);
	
	var elem = document.getElementById("bestsellers_setting");
	
	elem.className = "selector2 " + setting;
	
	var value = "AS_" + page + "_setting=" + setting + "; expires=" + expireDate.toGMTString() + "; path=/";
	document.cookie = value;
};
// End settingClick

// Begin emailOptClick
function emailOptClick(userId, list)
{
	var elem = document.getElementById("emailopt_checkbox_" + list);
	var type = "";
	if (elem.checked) type = list;

	// record in database
	var xmlHttp = getXmlHttp();
	xmlHttp.open("GET","/includes/listEmailAjax.php?userId=" + userId + "&list=" + list + "&type=" + type, true);
	xmlHttp.send(null);	
};
// End emailOptClick

function toggleCustomFilters($on)
{
	$setting = $on ? "on" : "off";

	var expireDate = new Date();
	expireDate.setDate(expireDate.getDate() + 365);

	var value = "AS_customfilterson=" + $setting + "; expires=" + expireDate.toGMTString() + "; path=/";
	document.cookie = value;
	
};

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

function GotoAlphOffset(userid, page, alph)
{
	// get from database
	var xmlHttp = getXmlHttp();
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
			redirect(xmlHttp.responseText);
	}
	
	xmlHttp.open("GET","/includes/getAlphOffsetAjax.php?userId=" + userId + "&page=" + page + "&alph=" + alph, true);
	xmlHttp.send(null);
	
	
};

/*
function featured_click(checked)
{
	var elem = document.getElementById("modebutton");
	elem.className = "selected";

	var expireDate = new Date();
	expireDate.setDate(expireDate.getDate() + 365);

	var setting = checked ? "on" : "off";
	
	var value = "AS_featured=" + setting + "; expires=" + expireDate.toGMTString() + "; path=/";
	document.cookie = value;
};
*/

function hideMyApps(checked)
{
	var setting = checked ? "on" : "off";
	
	var expireDate = new Date();
	expireDate.setDate(expireDate.getDate() + 365);

	var value = "AS_hideMyApps=" + setting + "; expires=" + expireDate.toGMTString() + "; path=/";
	document.cookie = value;

}

function hideWishlist(checked)
{
	var setting = checked ? "on" : "off";
	
	var expireDate = new Date();
	expireDate.setDate(expireDate.getDate() + 365);

	var value = "AS_hideWishlist=" + setting + "; expires=" + expireDate.toGMTString() + "; path=/";
	document.cookie = value;

}

function profileShare(checked, record, list)
{
	var elem = document.getElementById("userProfileEnabled");
	elem.checked = checked;

	var elem = document.getElementById("userProfileTextLabel");
	if (elem) elem.style.color = (checked) ? "#0c2c5c" : "#A0A0A0";

	var elem = document.getElementById("userProfileUrlLabel");
	if (elem) elem.style.color = (checked) ? "#0c2c5c" : "#A0A0A0";

	var elem = document.getElementById("userProfileTagsLabel");
	if (elem) elem.style.color = (checked) ? "#0c2c5c" : "#A0A0A0";

	var elem = document.getElementById("userProfileText");
	if (elem)
	{
		elem.style.color = "#A0A0A0";
		elem.style.background = (checked) ? "transparent" : "#F0F0F0";
		elem.disabled = !checked;
	}

	var elem = document.getElementById("userProfileUrl");
	if (elem) 
	{
		elem.style.color = "#A0A0A0";
		elem.style.background = (checked) ? "#FFFFFF" : "#F0F0F0";
		elem.disabled = !checked;
	}

	var elem = document.getElementById("userProfileTags");
	if (elem) 
	{
		elem.style.color = "#A0A0A0";
		elem.style.background = (checked) ? "#FFFFFF" : "#F0F0F0";
		elem.disabled = !checked;
	}

	// shrink / hide
	var elem = document.getElementById("userProfileContents");
	if (elem) elem.style.display = (checked) ? "inline" : "none";

	var elem = document.getElementById("userProfile");
	if (elem) elem.style.height = (checked) ? "374px" : "0px";

	// don't share buttons
	var elems = document.getElementsByTagName("a");
	var i;
	for (i = 0; i < elems.length; i++)
	{
		var elem = elems[i];
		if (elem.id.substr(13,19) == "_button_dontshareit")
			elem.style.display =  (checked) ? "inline" : "none";

		if (elem.id.substr(13,19) == "_button_boughtit")
			elem.style.left =  (checked) ? "-20px" : "19px";
	}

	if (record)
	{
		var profileEnabled = checked ? "1" : "0";

		var xmlHttp = getXmlHttp();
		xmlHttp.open("GET","/includes/userProfileEnableAjax.php?list=" + list + "&profileEnable=" + profileEnabled);
		xmlHttp.send(null);
	}
}

function profileTextFocus()
{
	var elem = document.getElementById("userProfileText");
	elem.style.color = "#000000";
}


function profileUrlFocus()
{
	var elem = document.getElementById("userProfileUrl");
	elem.style.color = "#000000";
}

function profileTagsFocus()
{
	var elem = document.getElementById("userProfileTags");
	elem.style.color = "#000000";
}

function saveProfile()
{
	var elemText = document.getElementById("userProfileText");
	elemText.style.color = "#A0A0A0";

	var elemUrl = document.getElementById("userProfileUrl");
	elemUrl.style.color = "#A0A0A0";

	var elemTags = document.getElementById("userProfileTags");
	elemTags.style.color = "#A0A0A0";

	var xmlHttp = getXmlHttp();
	xmlHttp.open("GET","/includes/userProfileAjax.php?&profileText=" + escape(elemText.value) + "&profileUrl=" + escape(elemUrl.value) + "&profileTags=" + escape(elemTags.value));
	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;
}