﻿
var string = "";
var keywords="";
var docref="";
var thisdomainvalue=String(window.location);

//test if same domain or no referrer
docref=document.referrer; //get referrer


domain=docref;
domain = domain.replace(new RegExp(/^http:\/\//i),"");
domainname = domain.replace(new RegExp(/\/(.*)/),"");

if(domainname=="debtconsolidationconnection.com" || domainname=="www.debtconsolidationconnection.com") {  //don't do anything same domain

 //do nothing	
 
} else {

	myString = new String(docref); 

	if(!document.referrer) {  //no referrer

		keywords="None";
		docref="None";

	} else if(docref.search(/google/) != -1) {  //if google finding keyword parameter and stripping it out of url

		splitString = myString.split("q=");
		splitString = splitString[1].split("&");
		keywords=splitString[0].replace(new RegExp(/\+/g)," ");

	} else if(docref.search(/yahoo/) != -1) {   //if yahoo finding keyword parameter and stripping it out of url

		splitString = myString.split("p=");
		splitString = splitString[1].split("&");
		keywords=splitString[0].replace(new RegExp(/\+/g)," ");

	} else if (docref.search(/bing/) != -1) {     //if bing finding keyword parameter and stripping it out of url

		splitString = myString.split("q=");
		splitString = splitString[1].split("&");
		keywords=splitString[0].replace(new RegExp(/\+/g)," ");

	} else {   //if unknown referrer finding if parameters and stripping it out of url

		if (myString.indexOf("?")==-1 ){
			keywords="None";
		} else {
			splitString = myString.split("=");
			keywords=splitString[1].replace(new RegExp(/\+/g)," ");
		}
	}


//setting cookies

var timeToKeep = 60000; // one minute
var expires = new Date();
expires.setTime(expires.getTime() + timeToKeep); 

set_cookie('docref', docref, expires); 

var cookieName = 'keywords'; // give the cookie a name
field_1=keywords;
set_cookie(cookieName, field_1, expires); 

} //end function
