 function refCookie()
 { 
    var refDate = new Date();
    var expiration = new Date();
    expiration.setTime(expiration.getTime() + (30*24*60*60*1000));
    
    //old checking style with referrer error check
    refName = document.referrer;
    refIndex = document.cookie.indexOf("refSite"); 
    thisPage = document.URL;
    if ( (refIndex == -1) && (refName.match("nationalpayday.com") == null) ) 
    { 
        if ( refName == null || refName == "" )
        {
            //document.cookie = "refSite= emptyref "+thisPage+" ;PATH=/nat/"; 
        }
        else
        {
            document.cookie = "refSite=" + refName +";PATH=/nat/ ;EXPIRES="+ expiration.toGMTString() ; 
        }
    }
    
    //chunk to look for any campaign flags.  
    var CampaignFlag
    var re = new RegExp("[campaign|flag]=([a-zA-Z0-9\_\-]+)");
    var s = "";
    var IncomingURL = document.URL;
    
    if (IncomingURL.match(re)) 
    {
        var m = re.exec(IncomingURL);
    	for (i = 0; i < m.length; i++) 
    	{
    	    s = s + m[i] + "\n";
    	}
        CampaignFlag = m[1];
        
        document.cookie = "campaignFlag=" + CampaignFlag +";PATH=/nat/ ;EXPIRES="+ expiration.toGMTString() ; 
    }
    //end campaign flag section
}

 function getCookie( cookieName )
 {
    //check to see if cookie is already set.
	if( document.cookie.indexOf( cookieName ) != -1 )
	{
	    cookieName += "=";
	    
        var c = "";
		var contentArray = document.cookie.split(';');
		
		if( contentArray.length > 1 )
		{
		    for(var i=0;i < contentArray.length;i++)
		    {    
		        if (contentArray[i].indexOf( cookieName ) == 1 )
		        {
		           return( contentArray[i].replace( cookieName, '' ) );
		        }
		    }
		}
		else
		{
		    return( contentArray[0].replace( cookieName, '' ) );
		}
	}
	
	return( "" );
 }
 
refCookie();