// Sets a Cookie with the given name and value
function PlpSetCookie (piKey, piValue)
{
var sSubDomain;
var nPos;
 
	sSubDomain = location.hostname;
	nPos = sSubDomain.indexOf('.');
	if (nPos > 0)
	{
	 sSubDomain = sSubDomain.substring (nPos);
	 document.cookie= piKey + '=' + escape(piValue) + ';domain=' + sSubDomain + '; path=/';
	}
	else
	{
	 document.cookie= piKey + '=' + escape(piValue) + '; path=/';
	}

}

// Read the value of the specified cookie
function PlpReadCookie (piKey)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0)
           return null;
    }
    else
    {
        begin += 2;
    }
    
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    
    return unescape(dc.substring(begin + prefix.length, end));
}

// Remove the specified cookie
// It will damage IE cookie?
function PlpRemoveCookie (piKey)
{
 if (PlpReadCookie (piKey))
 {
  document.cookie = piKey + "=" + 
     ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
 }
}

function PlpDetectCookieForItemDetail()
{
 if (! window.navigator.cookieEnabled)
 {
// alert('cookie disabled');
   
   window.location.href = "/CookieHelp/";
   return false;
 }
 else
 {
   var sURl = new String(window.document.frmItemDetail.action);
   sURl = sURl.replace("&PDF=T","");
   window.document.frmItemDetail.action = sURl;
   return true;
 }
}

function PlpDetectCookie ()
{
 if (! window.navigator.cookieEnabled)
 {
// alert('cookie disabled');
   
   window.location.href = "/CookieHelp/";
   return false;
 }
 else
 {
   return true;
 }
}

function GotoReuiredCookieUrl(piUrl)
{
 if (! PlpDetectCookie())
    return false;
     
 window.location.href = piUrl;
 
 return true;
}

function GotoReuiredCookiePlpUrl(piUrl, piPlpUrl, piCID)
{
 if (! PlpDetectCookie())
    return false;
 
 if (navigator.appName=="Microsoft Internet Explorer")
 {
    if( window.event != null)
    {
    	window.event.returnValue = false;
    }
 }
 
 var sInv_sessionID;
 var sTmp;
 var nPos;
 sInv_sessionID = "";
 sTmp = "";
 nPos=0;
 
 if(piCID !="" )
 {
     sInv_sessionID = ReadCookie(piCID + "_plp_inventory_session");
     
     if (sInv_sessionID != "" && sInv_sessionID != null )
     {
        nPos = piUrl.indexOf('&inv_sid=');
	    if (nPos > 0)
	    {
	     sTmp = piUrl.substring (nPos);
	    }
    	
	    if (sTmp == "&inv_sid=")
	    {
	       piUrl = piUrl + sInv_sessionID;
	       //alert(piUrl);
	    }
     }
 }
 	
 window.location.href = piUrl + "&plpurl=" + escape(piPlpUrl);
 
 return true;
}

function GotoReuiredCookieUrlForAS(piUrl)
{
 if (! window.navigator.cookieEnabled)
 {
   var sMsg="Please Note: Your internet settings currently block cookies.\nYou must Allow Cookies before executing Advanced Search in order for Advanced Search to function without problems.";
   alert(sMsg);
 }
     
 window.location.href = piUrl;
 
 return true;
}

function OnRequiredCookieClick(oForm)
{
 return PlpDetectCookie();
}

function OnRequiredCookieClickForItemdetail(oForm)
{
 return PlpDetectCookieForItemDetail();
}

function GotoRequiredCookieWarning(piUrl)
{
	if (! window.navigator.cookieEnabled)
	{
//        var sMsg="Your internet settings currently block cookies.\nYou will not be able to do this."
        alert(window.message255);
		//return false;
	}
	else
	{   
		window.location.href = piUrl;
	 
		return true;
	}
}

