function cii_UtpBeacon(){
     var utpCodes = cii_UtpGetCookieCodes();
     var sCode = utpCodes.srccode;
     var cCode = utpCodes.cpncode;

     if(cii_UtpVerifyData() == 0){
            return;
     }

     if(cCode && sCode){
	     var imgURL = "https://secure.channelintelligence.com/links/pages/clkcmp.asp";

	     imgURL = imgURL + "?v=" + escape(cii_vendorID) + "&t=" + escape(sCode) + "&f=" + escape(cCode);
	     imgURL = imgURL + "&o=" + escape(cii_orderID);
                 
             for (var i = 0; i < cii_totalNumOfSku; i++) {
	           imgURL = imgURL + "&s=" + escape(cii_itemSku[i]);
	           imgURL = imgURL + "|"   + escape(cii_itemQtys[i]);
	           imgURL = imgURL + "|"   + escape(cii_itemPrice[i]);
	           imgURL = imgURL + "|"   + escape(cii_itemMfrNum[i]);
                 }


	     var pixelnode = document.createElement("IMG");
	     pixelnode.setAttribute("height", "1");
	     pixelnode.setAttribute("width", "1");
	     pixelnode.setAttribute("alt", "");
	     pixelnode.setAttribute("src", imgURL);

	     document.body.appendChild(pixelnode);

	     cii_Alert("imgURL = " + imgURL);
     } else {
	     cii_Alert("Tracking Codes not Set in Cookie");
     }
}

function cii_UtpVerifyData(){
     if(typeof cii_vendorID == 'undefined'){
         cii_Alert("Not defined: cii_vendorID. Please define CI Vendor ID");
             return(0);
     }
     if(typeof cii_totalNumOfSku == 'undefined'){
         cii_Alert("Not defined: cii_totalNumOfSku  Please define the total number of SKUs");
             return(0);
     }
     if(typeof cii_orderID == 'undefined'){
         cii_Alert("Not defined: cii_orderID  Please define the Order ID");
             return(0);
     }
     if(typeof cii_itemSku == 'undefined'){
         cii_Alert("Not defined: cii_itemSku  Please define the array of SKUs");
             return(0);
     }
     if(typeof cii_itemQtys == 'undefined'){
         cii_Alert("Not defined: cii_itemQtys  Please define the array of Qtys");
             return(0);
     }
     if(typeof cii_itemMfrNum == 'undefined'){
         cii_Alert("Not defined: cii_itemMfrNum  Please define the array of Manufacturer Model Numbers");
             return(0);
     }
     if(typeof cii_itemPrice == 'undefined'){
         cii_Alert("Not defined: cii_itemPrice  Please define the array of Prices");
             return(0);
     }

     if((cii_itemSku.length-1) != cii_totalNumOfSku ){
           cii_Alert("Bad Array Size: cii_itemSku "+cii_itemSku.length-1+ "  is not the same length as cii_totalNumOfSku "+cii_totalNumOfSku );
               return(0);
     }
     if((cii_itemQtys.length-1) != cii_totalNumOfSku ){
           cii_Alert("Bad Array Size: cii_itemQtys  is not the same length as cii_totalNumOfSku");
               return(0);
     }
     if((cii_itemMfrNum.length-1) != cii_totalNumOfSku){
           cii_Alert("Bad Array Size: cii_itemMfrNum  is not the same length as cii_totalNumOfSku");
               return(0);
     }
     if((cii_itemPrice.length-1) != cii_totalNumOfSku ){
           cii_Alert("Bad Array Size: cii_itemPrice  is not the same length as cii_totalNumOfSku");
               return(0);
     }
}

function cii_UtpGetCookieCodes(){
	var rawData = document.cookie.split(";");
    var cpnCode, srcCode;

	for (var i = 0; i < rawData.length; i++) {
		var workingData = rawData[i];
		workingData = workingData.replace(/^\s+|\s+$/, '');
		workingData = workingData.split("=");
		if (workingData[0] == "cii_rpt" && workingData.length > 1) {
			var rptCodes = workingData[1];
            rptCodes =  rptCodes.split(":");
            srcCode = rptCodes[0];
            cpnCode = rptCodes[1];
		}
	}
        
    if(!srcCode){
        cii_Alert("Found no SRCCODE and/or CPNCODE in the Cookie. Please verify the code on your landing page.");
        return {srccode : "", cpncode : ""};
    } else {
        return {srccode : srcCode, cpncode : cpnCode}
    }
}
function cii_UtpSetCookieCodes()
{
	var laCI = cii_UtpGetUrlCodes(location.search.substring(1))
	if (laCI.srccode && laCI.cpncode)
	{
		var FutDate = new Date();
		FutDate.setTime(FutDate.getTime()+2592000000);						

		document.cookie = "cii_rpt=" + laCI.srccode + ":" +  laCI.cpncode + "; path=/;expires=" + FutDate.toGMTString();
	} else {
        cii_Alert("CPNCODE and/or SRCCODE are not set in URL");
    }
	return {srccode : laCI.srccode, cpncode : laCI.cpncode};
}
function cii_Alert(s){
    if(cii_debug){
       alert("cii_rpt: " +s);
    }
}

function cii_UtpGetUrlCodes(rsURL)
{
	var sSrc = "";
	var sCPN = "";
	var aArgs = rsURL.split("&");
	for (var i = 0; i < aArgs.length; i++) {
		var aValue = aArgs[i].split("=");
		if (aValue[0].toLowerCase() == "srccode") { sSrc = escape(aValue[1]); }
		if (aValue[0].toLowerCase() == "cpncode") { sCPN = escape(aValue[1]); }
	}

	return {srccode : sSrc, cpncode : sCPN};
}

