
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+escape(value)+expires+"; path=/";
}

function readCookie(name)
{
	var cookies = document.cookie;
	if (cookies.indexOf(name) != -1)
	{
		var startpos = cookies.indexOf(name)+name.length+1;
		var endpos = cookies.indexOf(";",startpos)-1;
		if (endpos == -2) endpos = cookies.length;
		return unescape(cookies.substring(startpos,endpos));
	}
	else
	{
		return false; // the cookie couldn't be found! it was never set before, or it expired.
	}
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
function blank(field, val) {
	var c = document.getElementById(field);
	var s = val;

	if(c.value == s){
		c.value='';
	}
}
function fill(field, val) {
	var c = document.getElementById(field);
	var s = val;
	if(c.value==''){
		c.value=s;
	}
}

function showhideOOSOLD(){
	var resTable = document.getElementById("resultsTable");
	var allTrs = resTable.getElementsByTagName("tr");
	for(i=0; i<allTrs.length; i++) {
		var aTr = allTrs[i];
		var sID = aTr.id;
		if (sID.indexOf('OOS_') == 0) {
			if(readCookie('hideOOS')=='tru'){
				aTr.className="oosShow";			
			}
			else {
				aTr.className="oosHide";
			}
		}
	}
	if(readCookie('hideOOS')=='tru'){
		createCookie("hideOOS", "false", 365);
	} else {
		createCookie("hideOOS", "true", 365);
	}
}
function showhideOOS(){
	var allOOS = document.getElementsByTagName("div");
	var showHide = document.getElementById("showhideOOS").checked;
	var showHideVinyl = document.getElementById("showhideVinyl").checked;
	for(i=0; i<allOOS.length; i++) {
		var aTr = allOOS[i];
		var sID = aTr.id;
		if (sID.indexOf('OOS_') == 0) {
			if(!showHide){
				if(!showHideVinyl) {
					aTr.style.display='inline';	
				}
			}
			else {
				aTr.style.display='none';
			}
		}
	}
}
function showhideDigital(){
	var allOOS = document.getElementsByTagName("div");
	var showHide = document.getElementById("showhideDigital").checked;
	for(i=0; i<allOOS.length; i++) {
		var aTr = allOOS[i];
		var sID = aTr.id;
		if (sID.indexOf('DIG_') == 0) {
			if(!showHide){
				aTr.style.display='inline';			
			}
			else {
				aTr.style.display='none';
			}
		}
	}
}
function showhideVinyl(){
	var allOOS = $("div[title='V']");
	var showHide = document.getElementById("showhideVinyl").checked;
	for(i=0; i<allOOS.length; i++) {
		var aTr = allOOS[i];
		var sID = aTr.id;
			if(!showHide){
				aTr.style.display='inline';			
			}
			else {
				aTr.style.display='none';
			}
		}

}


function showRec(Id){
	a = document.getElementById(Id);
	if(a.className=='RecommendShow'){
		a.className='RecommendHide';
	}
	else {
		a.className="RecommendShow";
		a = document.getElementById('Rec'+Id);
		
		$.ajaxSetup ({cache: false});
		var ajax_load = "<center><img src='../images/LoadCircle.gif' alt='Loading Recommendations...' /></center>";
		var loadUrl = "AJAX-Recommend.asp?recID="+Id;
		$(a).html(ajax_load).load(loadUrl);
	}
}
function showRecFullInfo(Id){
		a = document.getElementById('fiRecommendationsContainer');
		
		$.ajaxSetup ({cache: false});
		var ajax_load = "<center><img src='../images/LoadCircle.gif' alt='Loading Recommendations...' /></center>";
		var loadUrl = "AJAX-RecommendFullInfo.asp?recID="+Id;
		$(a).html(ajax_load).load(loadUrl);
}
function changeMP(MPT) {
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	if(urlHalves[1]){
		//load all the name/value pairs into an array 
		var urlVars = urlHalves[1].split('&');
		//loop over the list, and find the specified url variable 
		for(i=0; i<=(urlVars.length); i++){
			if(urlVars[i]){
				//load the name/value pair into an array 
				var urlVarPair = urlVars[i].split('=');
				if (urlVarPair[0] && urlVarPair[0] != "MPT") {
					//I found a variable that matches, load it's value into the return variable 
					urlVarValue = urlVarValue + urlVarPair[0] + "=" + urlVarPair[1] + "&";
				}
			}
		}
	}
	urlVarValue= "?" + urlVarValue + "MPT="+MPT;   
	location.href = "http://" + window.location.host + window.location.pathname + urlVarValue;
}
function viewOption(view) {
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	if(urlHalves[1]){
		//load all the name/value pairs into an array 
		var urlVars = urlHalves[1].split('&');
		//loop over the list, and find the specified url variable 
		for(i=0; i<=(urlVars.length); i++){
			if(urlVars[i]){
				//load the name/value pair into an array 
				var urlVarPair = urlVars[i].split('=');
				if (urlVarPair[0] && urlVarPair[0] != "view") {
					//I found a variable that matches, load it's value into the return variable 
					urlVarValue = urlVarValue + urlVarPair[0] + "=" + urlVarPair[1] + "&";
				}
			}
		}
	}
	urlVarValue= "?" + urlVarValue + "view="+view;   
	location.href = "http://" + window.location.host + window.location.pathname + urlVarValue;
}
