 //Begin Cashback Tracking Cookie Code

//Create an array to capture URL parameters
var GETDATA = new Object(); //more properly an object, since its elements aren't numbered

//String trimming functions
//--------------------------------
function LTrim(str){if(str==null){return null;}for(var i=0;str.charAt(i)==" ";i++);return str.substring(i,str.length);}
function RTrim(str){if(str==null){return null;}for(var i=str.length-1;str.charAt(i)==" ";i--);return str.substring(0,i+1);}
function Trim(str){return LTrim(RTrim(str));}
 

//Cookie Saving Function
//--------------------------------

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());
}

function placeBCBCookie()
{
      //Get the URL and NVP parameters
      var sGet = window.location.search;
       
      //If the URL is captured
      if (sGet && sGet != "") // if has a value...
      {
          // Drop the leading "?"
          //Perform a length check prior to using "substr" to avoid errors on pages that have no query string.
          if(sGet.length && sGet.length > 0)
            {
                if (sGet.charAt(0) == '?') {sGet = sGet.substr(1);}
                //Generate a string array of the name value pairs. Each array element will (should) have the form "foo=bar"
                var sNVPairs = sGet.split("&");
                
                //Now, for each name-value pair, we need to extract the name and value.
                for (var i = 0; i < sNVPairs.length; i++)
                {
                    //sNVPairs[i] contains the current element... Split it on each equals sign.
                    var sNV = sNVPairs[i].split("=");
                    if(sNV.length && sNV.length == 2) //Test to see if there is indeed even an array length and, in fact an array length of 2. (also trim the results of blank spaces)
                      {                        
                        //Assign the pair to the GETDATA object.
                        var sName = Trim(sNV[0]);
                        var sValue = Trim(sNV[1]);
                        GETDATA[sName] = sValue;      
                      }                          
                }             
            }       
      }
      // End: Get the URL and NVP parameters
     
     
      //If the URL indicates that this is a CashBack transaction
      if (GETDATA["utm_source"] && GETDATA["utm_source"] == 'Bing_CB') //test that property exists before testing value
      {
        setCookie('is_BingCashback',true,1);
      }
}


 
//Call to Cookie Saving function
placeBCBCookie();