

    $(document).ready(function () {
        // put all your jQuery goodness in here.

        var subAff = $.url.param("a");

        if (window.location.search.substring(1).indexOf('a=') != -1)//if contains a
        {
            //search for cookie named netreferPID
            var cookieIndex = -1;
            var ck = document.cookie.split('; ');

            for (var i = 0; i < ck.length; i++) 
            {
                if (ck[i].indexOf('NetReferPID') != -1)//if contains netreferPID
                {
                    cookieIndex = i; //if cookie exist, cookieIndex will become greater than or equal to 0
                }
            }

            if (cookieIndex != -1) 
            {

                var sptCookie = ck[cookieIndex].split('=');

                if (sptCookie[1] == 'ParentAffiliateId' && sptCookie[2] == null) 
                {
                    createCookie('NetReferPID=ParentAffiliateId', subAff, 150);
                }
                else 
                {
                   
                    if(sptCookie[1] == 'ParentAffiliateId' && sptCookie[2] != subAff)
		    {
			  eraseCookie('NetReferPID=ParentAffiliateId');
			  createCookie('NetReferPID=ParentAffiliateId', subAff, 150);
				
                    }
		}
                
            }
            else 
            {

                createCookie('NetReferPID=ParentAffiliateId', subAff, 150);
            }
        }
    });




function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


function eraseCookie(name) {
	createCookie(name,"",-1);
}
