<!--//

/* ####################### start set cookie  ####################### */

function setNoEscapeCookie(name, value, expires, path, domain, secure) {

  var thisCookie = name + "=" + value +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "; path=/") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = thisCookie;
}


function setCookie(name, value, expires, path, domain, secure) {


  var thisCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = thisCookie;
}
/* ####################### start show cookie ####################### */

function showCookie(){

alert(unescape(document.cookie));
}
/* ####################### start get cookie value ####################### */

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
/* ####################### end get cookie value ####################### */

}
/* ####################### start get cookie (name) ####################### */

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
/* ####################### end get cookie (name) ####################### */

/* ####################### start delete cookie ####################### */
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
/* ####################### end of delete cookie ####################### */


/* ####################### start setSubCookieAndCookie ####################### */
function setSubCookieAndCookie(cookieName, subCookieName, subCookieValue)
{
	var cookieValue = GetCookie(cookieName);
	if (cookieValue == null) {
		cookieValue = "";
	}
	if(cookieValue.length ==0) {
		cookieValue = subCookieName + '=' + subCookieValue;
	}
	else {
		var posStart = cookieValue.indexOf(subCookieName + '=');
		var posEnd = cookieValue.indexOf('&', posStart+1);
		if (posEnd == -1) {
			posEnd = cookieValue.length;
		}
		if (posStart >= 0 && posEnd > 0) {
			cookieValue = cookieValue.substring(0, posStart) +
			subCookieName + '=' + subCookieValue +
			cookieValue.substring(posEnd, cookieValue.length);
			}
		else {
			if (cookieValue.length > 0){
				cookieValue = cookieValue + '&' + subCookieName + '=' + subCookieValue;
				}
			}
		
	}
	setNoEscapeCookie(cookieName, cookieValue);
}

function myCustomAlert()
{
	alert("myCustomAlert");
}
/* ####################### end setSubCookieAndCookie ####################### */

/* ####################### start GetSubCookie ####################### */
function GetSubCookieValue(cookieName, subCookieName)
{
	var cookieValue = GetCookie(cookieName);
	if (cookieValue != null)
	{
		if (cookieValue.length > 0)
		{
			var arrSubCookies = cookieValue.split('&');
			for(var i = 0; i < arrSubCookies.length; i++)
			{
				if (arrSubCookies[i].indexOf(subCookieName) == 0)
				{
					return arrSubCookies[i].substring(subCookieName.length+1,arrSubCookies[i].length);
				}
			}
		}
	}
	return null;	
}
/* ####################### end GetSubCookie ####################### */
//-->

/* ####################### cookie functions for microsite integration ####################### */


function SetVendorCookie(vendorName)
{
    var cookieValue = GetSubCookieValue('Basket', 'Indy.Basket.BasketCount');
    
    if (cookieValue != null && cookieValue != "")
    {
	   Set_CookieForVendor(vendorName + ".Basket.BasketCount",cookieValue,30);
	}
    else
    {
	    DeleteCookie_Vendor(vendorName + '.Basket.BasketCount');
	}
	
    cookieValue = Get_CookieForVendor('LastViewedProducts');
    if (cookieValue != null && cookieValue != "")
    {
	   Set_CookieForVendor(vendorName + ".LastViewedProducts",cookieValue,30);
	}
    else
    {
	    DeleteCookie_Vendor(vendorName + '.LastViewedProducts');
	}
	
	cookieValue = GetSubCookieValue('User','Indy.FirstName');
    if (cookieValue != null)
    {
       setSubCookieAndCookieForVendor(vendorName + '.User', vendorName + '.FirstName', GetSubCookieValue('User','Indy.FirstName'));
       setSubCookieAndCookieForVendor(vendorName + '.User',vendorName + '.HasAdsCard',GetSubCookieValue('User','Indy.HasAdsCard'));
       setSubCookieAndCookieForVendor(vendorName + '.User',vendorName + '.HasPreApprovedOffer',GetSubCookieValue('User','Indy.HasPreApprovedOffer'));
       setSubCookieAndCookieForVendor(vendorName + '.User',vendorName + '.CreditInfoString',GetSubCookieValue('User','Indy.CreditInfoString'));
       setSubCookieAndCookieForVendor(vendorName + '.User',vendorName + '.PreApprovedCardType',GetSubCookieValue('User','Indy.PreApprovedCardType'));
       setSubCookieAndCookieForVendor(vendorName + '.User',vendorName + '.PreApprovedOfferDeclined',GetSubCookieValue('User','Indy.PreApprovedOfferDeclined'));        
       setSubCookieAndCookieForVendor(vendorName + '.User',vendorName + '.MasterId',GetSubCookieValue('User','Indy.MasterId'));        
	}
    else
    {
         DeleteCookie_Vendor(vendorName + '.PreApprovedCardType');
         DeleteCookie_Vendor(vendorName + '.FirstName');
         DeleteCookie_Vendor(vendorName + '.HasAdsCard');
         DeleteCookie_Vendor(vendorName + '.HasPreApprovedOffer');
         DeleteCookie_Vendor(vendorName + '.CreditInfoString');
         DeleteCookie_Vendor(vendorName + '.PreApprovedOfferDeclined');
         DeleteCookie_Vendor(vendorName + '.User');     
	}
}
function Get_CookieForVendor(cookiename) 
	{
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return ""; 
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
	}

function Set_CookieForVendor(name,value,durataion){
var domainName = getDomain();
if(domainName)
    cookiestring=name+"="+value+";EXPIRES="+getexpirydate(durataion)+";DOMAIN="+ domainName + ";path=/";
else
    cookiestring=name+"="+value+";EXPIRES="+getexpirydate(durataion)+";path=/";
    
//cookiestring=name+"="+value+";EXPIRES="+getexpirydate(durataion)+ ";path=/";
document.cookie=cookiestring;
}
function DeleteCookie_Vendor( name )
{
    var domainName = getDomain();
    if(domainName)
        document.cookie = name + "=;path=/;DOMAIN=" + domainName + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    else
        document.cookie = name + "=;path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function getexpirydate( nodays){
var UTCstring;
if (nodays == 0)
	return 0;
Today = new Date();
nomilli=Date.parse(Today);
Today.setTime(nomilli+nodays*24*60*60*1000);
UTCstring = Today.toUTCString();
return UTCstring;
}

function getDomain()
{
    var domainname = document.location.hostname;
    if(domainname == "localhost")
        return null;
    var dotIndex = domainname.indexOf(".");
    return domainname.substring(dotIndex, domainname.length);
}
        
function setSubCookieAndCookieForVendor(cookieName, subCookieName, subCookieValue)
{
	var cookieValue = GetCookie(cookieName);
	if (cookieValue == null) {
		cookieValue = "";
	}
	if(cookieValue.length ==0) {
		cookieValue = subCookieName + '=' + subCookieValue;
	}
	else {
		var posStart = cookieValue.indexOf(subCookieName + '=');
		var posEnd = cookieValue.indexOf('&', posStart+1);
		if (posEnd == -1) {
			posEnd = cookieValue.length;
		}
		if (posStart >= 0 && posEnd > 0) {
			cookieValue = cookieValue.substring(0, posStart) +
			subCookieName + '=' + subCookieValue +
			cookieValue.substring(posEnd, cookieValue.length);
			}
		else {
			if (cookieValue.length > 0){
				cookieValue = cookieValue + '&' + subCookieName + '=' + subCookieValue;
				}
			}
		
	}
	Set_CookieForVendor(cookieName, cookieValue,30);
	
}
/* ####################### cookie functions for Art Select ####################### */

/*Required to clean 1.1 version cookie for basket count*/
DeleteCookie ('Indy.Basket.BasketCount','/');

/*************************Get Decode Values from Cookie **************************/
function GetDecodedCookieValue(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return decode(getCookieVal (j));
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

/* ####################### start GetSubCookie ####################### */
function GetDecodedSubCookieValue(cookieName, subCookieName)
{
	var cookieValue = GetCookie(cookieName);
	if (cookieValue != null)
	{
		if (cookieValue.length > 0)
		{
			var arrSubCookies = cookieValue.split('&');
			for(var i = 0; i < arrSubCookies.length; i++)
			{
				if (arrSubCookies[i].indexOf(subCookieName) == 0)
				{
					return decode(arrSubCookies[i].substring(subCookieName.length+1,arrSubCookies[i].length));
				}
			}
		}
	}
	return null;	
}

function CopyOmnitureVisitorIdCookie(sendVisitorIdUrl, cookieName)
{
    // do nothing if on https page
    var protocol = parent.location.protocol;
    if(typeof(protocol) == "undefined" || protocol == null || protocol.indexOf("https") != -1)
    {
        return;
    }
    
    // prepare pixel only if visitor cookie is not present
    var visitorCookie = GetCookie(cookieName);
    if(typeof(visitorCookie) == "undefined" || visitorCookie == null)
    {
        document.write("<img src='" + sendVisitorIdUrl + "' style='display:none' />");
    }
}
