// JavaScript Document

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/";
}

function toggleComp(comp_str, id,redirect){
	
	if(comp_str.indexOf("-"+id+"-")<0)
		comp_str = addtoCompareStr(comp_str, id);
	else
		comp_str = removefromCompareStr(comp_str, id);
	
	setCookie('comp_str',comp_str,1);
	
	if((comp_str=="-" || comp_str=="") && redirect==1){
		window.location = "index.html";
		return false;
	}
	
	return comp_str;
}

function addtoCompareStr(comp_str, id){
	comp_str = comp_str+id+"-";
	return comp_str;
}

function removefromCompareStr(comp_str, id){
	replace_str = "-"+id+"-";
	return comp_str.replace(replace_str,'-');;
}

function gotoComparison(pid){
	if(getCookie("comp_str")=="-" || getCookie("comp_str")==""){
		alert("Please select products to compare");
	}
	else{
		apistr = "http://api.shopping.com/scripts/GSIsapiExt.dll/linkin_id-8032974/sf-2/pid"+getCookie("comp_str");
		window.location="compare_"+pid+".html?ap="+Base64.encode(apistr);
	}
}