// The following tag should be placed at the top of the page body:
//  <script src='travisredirect.js'></script>
//  This file should be in the same directory as the page


function nameDefined(ckie,nme)
{
   var splitValues
   var i
   for (i=0;i<ckie.length;++i)
   {
      splitValues=ckie[i].split("=")
      if (splitValues[0]==nme) return true
   }
   return false
}
function delBlanks(strng)
{
   var result=""
   var i
   var chrn
   for (i=0;i<strng.length;++i) {
      chrn=strng.charAt(i)
      if (chrn!=" ") result += chrn
   }
   return result
}
function getCookieValue(ckie,nme)
{
   var splitValues
   var i
   for(i=0;i<ckie.length;++i) {
      splitValues=ckie[i].split("=")
      if(splitValues[0]==nme) return splitValues[1]
   }
   return ""
}
function testCookie(cname, cvalue) {         //Tests to see if the cookie 
   var cookie=document.cookie                //with the name and value 
   var chkdCookie=delBlanks(cookie)         //are on the client computer
   var nvpair=chkdCookie.split(";")
   if(nameDefined(nvpair,cname))             //See if the name is in any pair
   {   
      tvalue=getCookieValue(nvpair,cname)  //Gets the value of the cookie
      if (tvalue == cvalue) return true
	   else return false
   }
   else return false
}
function redirectLink() {
   //document.writeln('Redirecting');
   var pattern=/^.*(google).*[?&]q=([^&]*)/;
   var result=pattern.exec(document.referrer);
   if (result) {
	   if (testCookie("travisredirect", "yes")) {
                    //document.writeln('Already redirected');
           }
	   else {
	      var cookieTest="cookietest=yes; path=/;";	 //Set the test cookie values up
	      window.document.cookie=cookieTest;           //Write the cookie
	      if (testCookie("cookietest", "yes")) {          // Cookies enabled. Write redirect cookie and redirect
		      var futdate = new Date();		 //Get the current time and date
		      var expdate = futdate.getTime();     //Get the milliseconds since Jan 1, 1970
		      expdate += 3600*1000*24*30;        //expires in 30 days(milliseconds)
		      futdate.setTime(expdate);
		      var newCookie="travisredirect=yes; path=/;";	//Set the new cookie values up
		      newCookie += " expires=" + futdate.toGMTString();
		      window.document.cookie=newCookie;//Write the cookie
		      window.location='http://gmstravis.bosscasinos.com/re.asp?name=1110&camp='+result[1]+'&asystem=SEO&acode='+result[1]+'_'+result[2]+'&go='+document.URL;	//Redirect back to this page through travis
	      }
	   }
   }
  else
  {
      //document.writeln('Not google organic');
  }
}
redirectLink();