﻿<!--//

/* ####################### start set cookie  ####################### */

function setNoEscapeCookie(name, value, expires, path, domain, secure) {
  var thisCookie = name + "=" + value +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "; path=/") +
      //((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = thisCookie;
}

/* ################### start Is Customer New ############################*/

function IsCustomerNew()
{
    if(GetSubCookieValue('CustomerSegment', 'CustomerType') == "New")
    {
        return true;
    }
    else
    {
        return false;
    }
}

/* ################### end Is Customer New ##############################*/


function setCookie(name, value, expires, path, domain, secure) {
  var thisCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "; path=/") +
      //((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 : "; path=/") +
      //((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)
{
	setSubCookieAndCookie(cookieName, subCookieName, subCookieValue, null)
}
function setSubCookieAndCookie(cookieName, subCookieName, subCookieValue, expires)
{
	var cookieValue = GetCookie(cookieName);
	if (cookieValue == null || 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, expires);
}
/* ####################### end setSubCookieAndCookie ####################### */

/*##### Create GUID */
function CreateGUID()
{
    var result, i, j;
    result = '';
    for(j=0; j<32; j++) 
    {
        if( j == 8 || j == 12|| j == 16|| j == 20)
        {
            result = result + '-';
            }
        i = Math.floor(Math.random()*16).toString(16).toUpperCase();
        result = result + i;
  }
  return result;
}
/*##### Create GUID */
/* ####################### 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;	
}

/*######  Setting Market Place Cookie */
function SetMarketPlaceCookie(customerSegment, customerType, cutomerTypeValue, customerId, customerIdValue, uniqueWebUserId)
{
    if (null == GetCookie(customerSegment))
    {
        var d = new Date();
        d.setTime(d.getTime()+(3650*24*60*60*1000));
        setSubCookieAndCookie(customerSegment, customerType, cutomerTypeValue, d);
        setSubCookieAndCookie(customerSegment, customerId, customerIdValue, d);
        var x = CreateGUID();
        setSubCookieAndCookie(customerSegment, uniqueWebUserId, x, d);
    }
}
/*######  End Market Place Cookie */
/* ####################### end GetSubCookie ####################### */

function setRefreshCookie(val)
	{
		//alert("test");
		document.cookie= "refreshCookie=" + val;		
		
	}
	
function GetSubCookieValueFor(CookieNameString)
	{
		var cookieContents = this.document.cookie; 		
		var startIndex = cookieContents.indexOf(CookieNameString + '=');
		var cookieValue = "";
		
		if (startIndex != -1)
		{
			startIndex += CookieNameString.length + 1;			
			var endIndex = cookieContents.indexOf('&', startIndex);
			
			if (endIndex == -1)
				endIndex = cookieContents.length;		    
			cookieValue = cookieContents.substring(startIndex, endIndex);		   
		}
		
		return cookieValue;
	}
/* ##############################Start -- Get Query String value from the URL ##################### */

function PageQuery(q) 
{
    if(q.length > 1) this.q = q.substring(1, q.length);
    else this.q = null;
    this.keyValuePairs = new Array();
    if(q) 
    {
        for(var i=0; i < this.q.split("&").length; i++) 
        {
            this.keyValuePairs[i] = this.q.split("&")[i];
        }
    }
    this.getKeyValuePairs = function() { return this.keyValuePairs; }
    this.getValue = function(s) 
    {
        for(var j=0; j < this.keyValuePairs.length; j++) 
        {
            if(this.keyValuePairs[j].split("=")[0] == s)
            return this.keyValuePairs[j].split("=")[1];
        }
        return false;
    }
    this.getParameters = function() 
    {
        var a = new Array(this.getLength());
        for(var j=0; j < this.keyValuePairs.length; j++) 
        {
            a[j] = this.keyValuePairs[j].split("=")[0];
        }
        return a;
    }
    this.getLength = function() { return this.keyValuePairs.length; } 
}

function GetQueryStringValueFromURL(key)
{
    var page = new PageQuery(window.location.search); 
    return unescape(page.getValue(key)); 
}
function displayItem(key)
{
    if(queryString(key)=='false') 
    {
        document.write("you didn't enter a ?name=value querystring item.");
    }
    else
    {
        document.write(queryString(key));
    }
}
function GetDecodedCookieValueFor(CookieNameString)
	{
		var cookieContents = this.document.cookie; 		
		var startIndex = cookieContents.indexOf(CookieNameString + '=');
		var cookieValue = "";
		
		if (startIndex != -1)
		{
			startIndex += CookieNameString.length + 1;			
			var endIndex = cookieContents.indexOf(';', startIndex);
			
			if (endIndex == -1)
				endIndex = cookieContents.length;		    
			cookieValue = decode(cookieContents.substring(startIndex, endIndex)).replace(/%0/g, '');
		    
			if (cookieValue.substring(0,3) == '%$&')
				cookieValue = unicodelessDecode(cookieContents.substring(startIndex, endIndex)).replace(/%0/g, '');
		}
		
		return cookieValue;
	}
//Decoder
function decode(mystring) 
{
	b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
	pad="000000";
	pads = mystring.match(/=+/) ? mystring.match(/=+/)[0].length : 0;
	mystring=mystring.replace(/=/g,"A");
	out="";
	for (var i = 0; i<mystring.length; i+=4) 
	{
		temp=((b64.indexOf(mystring.charAt(i))<<18) + (b64.indexOf(mystring.charAt(i+1))<<12) + (b64.indexOf(mystring.charAt(i+2))<<6) + (b64.indexOf(mystring.charAt(i+3)))).toString(16);
		out+=(pad.substring(0,6-temp.length)+temp).replace(/../g,"%$&");
	}
	out=unescape(out.substring(0,out.length-pads*3).replace(/%00/g,""));
	return out
}
/* ##############################End -- Get Query String value from the URL ##################### */

//-->
