/* 
##########################################################################
############# 1. Check if coockie exists
############# 2. If coockie does not exist check if need to create one
############# 3. Create coockie if needed
########################################################################## 
*/
var vars = [], hash, phonenumber;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
var cookie_exists = 0;
var cookie_content = "";
var name;
name = "cpctrk=";
// 1. get all get variables from the url
		for(var i = 0; i < hashes.length; i++)
		   {
			  hash = hashes[i].split('=');
			  vars.push(hash[0]);
			  vars[hash[0]] = hash[1];
		   }

// 2. Create / overwrite cookie if vsrefdom is in the querystring
		var querystr = vars["_vsrefdom"]
		
		if (querystr=="paidsearch" || querystr=="atlanta" || querystr=="sanfrancisco" || querystr=="phoenix" || querystr=="sandiego" || querystr=="newyork" || querystr=="boston" || querystr=="baltimore" || querystr=="dallas" || querystr=="houston" || querystr=="tampa" || querystr=="miami" || querystr=="charlotte" || querystr=="raleigh" || querystr=="orlando" )
			  {
				 ////////////////////////////////////////////////////////////////////////////////////////////////
				 // prepare for setting a cookie \/
				 var expires,name,expires_date;
				 var today = new Date();
				 today.setTime( today.getTime() );
				 expires = 365 * 1000 * 60 * 60 * 24;
				 expires_date  = new Date( today.getTime() + (expires) );
					
				 // set cookie
				 document.cookie = "cpctrk="+querystr+"; expires=" + expires_date.toGMTString() + "; path=/";
				 cookie_exists = 1;
				 cookie_content = querystr;
				 // prepare for setting a cookie & set cookie /\
				 ////////////////////////////////////////////////////////////////////////////////////////////////
			  }
			  else // if not in URL, check if cookie exists
			  {
				  	var returnvalue = "";
					if (document.cookie.length > 0) 
					   {
						  offset = document.cookie.indexOf(name)
						  // if cookie exists
						  if (offset != -1) 
							 {
								offset += name.length
								// set index of beginning of value
								end = document.cookie.indexOf(";", offset);
								// set index of end of cookie value
								if (end == -1) end = document.cookie.length;
								returnvalue=unescape(document.cookie.substring(offset, end))
							 }
						  if(returnvalue != "")
						  	{
							 	cookie_exists = 1;
								cookie_content = Get_Cookie("cpctrk");
							}
					   }
					   
					   
			  }
/*  

var vars = [], hash, phonenumber;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
var cookie_exists = 0;
var cookie_content = "";

// 1. Check if coockie exists
var name;
name = "cpctrk=";
var returnvalue = "";
if (document.cookie.length > 0) 
   {
      offset = document.cookie.indexOf(name)
      // if cookie exists
      if (offset != -1) 
         {
            offset += name.length
            // set index of beginning of value
            end = document.cookie.indexOf(";", offset);
            // set index of end of cookie value
            if (end == -1) end = document.cookie.length;
            returnvalue=unescape(document.cookie.substring(offset, end))
			
         }
   }




   
// 2. If coockie does not exist check if need to create one
if(returnvalue == "")
   {
		// get all get variables from the url
		for(var i = 0; i < hashes.length; i++)
		   {
			  hash = hashes[i].split('=');
			  vars.push(hash[0]);
			  vars[hash[0]] = hash[1];
		   }

		// 3. Create coockie if needed
		var querystr = vars["_vsrefdom"]
		if (querystr=="paidsearch" || querystr=="atlanta" || querystr=="sanfrancisco" || querystr=="phoenix" || querystr=="sandiego" || querystr=="newyork" || querystr=="boston" || querystr=="baltimore" || querystr=="houston" || querystr=="tampa" || querystr=="miami" || querystr=="charlotte" || querystr=="raleigh" || querystr=="orlando" )
			  {
				 ////////////////////////////////////////////////////////////////////////////////////////////////
				 // prepare for setting a cookie \/
				 var expires,name,expires_date;
				 var today = new Date();
				 today.setTime( today.getTime() );
				 expires = 365 * 1000 * 60 * 60 * 24;
				 expires_date  = new Date( today.getTime() + (expires) );
					
				 // set cookie
				 document.cookie = "cpctrk="+querystr+"; expires=" + expires_date.toGMTString() + "; path=/";
				 cookie_exists = 1;
				 cookie_content = querystr;
				 // prepare for setting a cookie & set cookie /\
				 ////////////////////////////////////////////////////////////////////////////////////////////////
			  }
   }
else // if there is a cookie
   {
		cookie_exists = 1;
		cookie_content = Get_Cookie("cpctrk");
   }
*/


/* ################################################################################################################################################################## */
/* ###################################################################>>>>> Functions <<<<<########################################################################## */
/* ################################################################################################################################################################## */


function getLocalInfo()
{
	//define vars: 
	var location = "";
	var address = "";
	var localPhone = "";
	
	// If cookie exists: Display CPC phone numbers
	if (cookie_exists)
		{
			switch(cookie_content)
				{
				case "atlanta":
				  location = "Atlanta Metro Office";
				  address = "4480 N Elizabeth Ln<br>Atlanta, GA 30339";
				  phone = "404-721-0263";
				  break;
				case "sanfrancisco":
				  location = "San Francisco Metro Office";
				  address = "4324 Redwood Hwy Ste 200<br>San Rafael, CA 94903";
				  phone = "415-868-5921";
				  break;
				case "phoenix":
				  location = "Phoenix Metro Office";
				  address = "16017 N 102nd Place<br>Scottsdale, AZ 85255";
				  phone = "480-630-2527";
				  break;
				case "sandiego":
				  location = "San Diego Metro";
				  address = "";
				  phone = "619-956-9514";
				  break;
				case "newyork":
				  location = "New York/Northern NJ";
				  address = "";
				  phone = "845-738-4617";
				  break;
				case "boston":
				  location = "Boston Metro Office";
				  address = "113 Park River Drive<br>Westfield, MA 01085";
				  phone = "617-945-8195";
				  break;
				case "baltimore":
				  location = "Baltimore Office";
				  address = "";
				  phone = "410-449-4678";
				  break;
				case "dallas":
				  location = "Dallas Metro Office";
				  address = "10661 Shady Trail<br>Dallas, TX. 75220";
				  phone = "214-504-1340";
				  break;
				case "houston":
				  location = "Houston Metro Office";
				  address = "";
				  phone = "281-896-0912";
				  break;
				case "tampa":
				  location = "Tampa Metro Office";
				  address = "5846 100th Ave E<br>Parrish, FL 34219";
				  phone = "813-641-4983";
				  break;
				case "miami":
				  location = "Miami Metro Office";
				  address = "5846 100th Ave E<br>Parrish, FL 34219";
				  phone = "305-707-6308";
				  break;
				case "charlotte":
				  location = "Charlotte Metro Office";
				  address = "124 Redhill Rd<br>Holly Springs, NC 27540";
				  phone = "704-980-9905";
				  break;
				case "raleigh":
				  location = "Raleigh Office";
				  address = "124 Redhill Rd<br>Holly Springs, NC 27540";
				  phone = "919-585-1134";
				  break;
				case "orlando":
				  location = "Orlando Office";
				  address = "5846 100th Ave E<br>Parrish, FL 34219";
				  phone = "321-248-4285";
				  break;
				default:
				  location = "XGrass Worldwide Headquarters";
				  address = "210 Howell Drive<br />Dalton, GA 30721";
				  phone = "877-769-1915";
				}
		}
	else // Display organic info
		{
			switch(cookie_content)
				{
				case "atlanta":
				  location = "Atlanta Metro Office";
				  address = "4480 N Elizabeth Ln<br>Atlanta, GA 30339";
				  phone = "877-881-8477";
				  break;
				case "sanfrancisco":
				  location = "San Francisco Metro Office";
				  address = "4324 Redwood Hwy Ste 200<br>San Rafael, CA 94903";
				  phone = "415-479-1234";
				  break;
				case "phoenix":
				  location = "Phoenix Metro Office";
				  address = "16017 N 102nd Place<br>Scottsdale, AZ 85255";
				  phone = "602-639-0893";
				  break;
				case "sandiego":
				  location = "San Diego Metro";
				  address = "";
				  phone = "706-272-0140";
				  break;
				case "newyork":
				  location = "New York/Northern NJ";
				  address = "";
				  phone = "413-575-7993";
				  break;
				case "boston":
				  location = "Boston Metro Office";
				  address = "113 Park River Drive<br>Westfield, MA 01085";
				  phone = "413-575-7993";
				  break;
				case "baltimore":
				  location = "Baltimore Office";
				  address = "";
				  phone = "413-575-7993";
				  break;
				case "dallas":
				  location = "Dallas Metro Office";
				  address = "10661 Shady Trail<br>Dallas, TX. 75220";
				  phone = "972-484-0600";
				  break;
				case "houston":
				  location = "Houston Metro Office";
				  address = "";
				  phone = "573-760-2560";
				  break;
				case "tampa":
				  location = "Tampa Metro Office";
				  address = "5846 100th Ave E<br>Parrish, FL 34219";
				  phone = "863-781-0136";
				  break;
				case "miami":
				  location = "Miami Metro Office";
				  address = "5846 100th Ave E<br>Parrish, FL 34219";
				  phone = "863-781-0136";
				  break;
				case "charlotte":
				  location = "Charlotte Metro Office";
				  address = "124 Redhill Rd<br>Holly Springs, NC 27540";
				  phone = "919-795-6196";
				  break;
				case "raleigh":
				  location = "Raleigh Office";
				  address = "124 Redhill Rd<br>Holly Springs, NC 27540";
				  phone = "919-795-6196";
				  break;
				case "orlando":
				  location = "Orlando Office";
				  address = "5846 100th Ave E<br>Parrish, FL 34219";
				  phone = "863-781-0136";
				  break;
				default:
				  location = "XGrass Worldwide Headquarters";
				  address = "210 Howell Drive<br />Dalton, GA 30721";
				  phone = "706-272-0140";
				  break;
				}
		}
		
	if(address!=""){address="Address: "+address+"<br><br />"}
	document.write ("<strong>"+location+"</strong><br /><br>"+address+"Phone: "+phone);
}

function getLocalNumber()
{
	
	//define vars: 
	var localPhone = "";
	
	// If cookie exists: Display CPC phone numbers
	if (cookie_exists)
		{
			switch(cookie_content)
				{
				case "atlanta":
				  localPhone = "404-721-0263";
				  break;
				case "sanfrancisco":
				  localPhone = "415-868-5921";
				  break;
				case "phoenix":
				  localPhone = "480-630-2527";
				  break;
				case "sandiego":
				  localPhone = "619-956-9514";
				  break;
				case "newyork":
				  localPhone = "845-738-4617";
				  break;
				case "boston":
				  localPhone = "617-945-8195";
				  break;
				case "baltimore":
				  localPhone = "410-449-4678";
				  break;
				case "dallas":
				  localPhone = "214-504-1340";
				  break;
				case "houston":
				  localPhone = "281-896-0912";
				  break;
				case "tampa":
				  localPhone = "813-641-4983";
				  break;
				case "miami":
				  localPhone = "305-707-6308";
				  break;
				case "charlotte":
				  localPhone = "704-980-9905";
				  break;
				case "raleigh":
				  localPhone = "919-585-1134";
				  break;
				case "orlando":
				  localPhone = "321-248-4285";
				  break;
				default:
				  localPhone = "877-769-1915";
				}
		}
	else // Display organic info
		{
			localPhone = "706-272-0140";
		}
	document.write (localPhone);
}

function getContactFormNumber()
{
	//define vars: 
	var localPhone = "";
	
	// If cookie exists: Display CPC phone numbers
	if (cookie_exists)
		{
			switch(cookie_content)
				{
				case "atlanta":
				  localPhone = "404-721-0263";
				  break;
				case "sanfrancisco":
				  localPhone = "415-868-5921";
				  break;
				case "phoenix":
				  localPhone = "480-630-2527";
				  break;
				case "sandiego":
				  localPhone = "619-956-9514";
				  break;
				case "newyork":
				  localPhone = "845-738-4617";
				  break;
				case "boston":
				  localPhone = "617-945-8195";
				  break;
				case "baltimore":
				  localPhone = "410-449-4678";
				  break;
				case "dallas":
				  localPhone = "214-504-1340";
				  break;
				case "houston":
				  localPhone = "281-896-0912";
				  break;
				case "tampa":
				  localPhone = "813-641-4983";
				  break;
				case "miami":
				  localPhone = "305-707-6308";
				  break;
				case "charlotte":
				  localPhone = "704-980-9905";
				  break;
				case "raleigh":
				  localPhone = "919-585-1134";
				  break;
				case "orlando":
				  localPhone = "321-248-4285";
				  break;
				default:
				  localPhone = "877-769-1915";
				}
		}
	else // Display organic info
		{
			localPhone = "877-881-8477";
		}
	document.write (localPhone);
}

function getLocalImg()
{
	//define vars: 
	var phoneimg = "";
	
	// If cookie exists: Display CPC phone numbers
	if (cookie_exists)
		{
			switch(cookie_content)
				{
				case "atlanta":
				  phoneimg = "<img src=\"images\/xgrass_logo_atlanta-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "sanfrancisco":
				  phoneimg = "<img src=\"images\/xgrass_logo_sanfrancisco-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "phoenix":
				  phoneimg = "<img src=\"images\/xgrass_logo_phoenix-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "sandiego":
				  phoneimg = "<img src=\"images\/xgrass_logo_sandiego-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "newyork":
				  phoneimg = "<img src=\"images\/xgrass_logo_newyork-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "boston":
				  phoneimg = "<img src=\"images\/xgrass_logo_boston-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "baltimore":
				  phoneimg = "<img src=\"images\/xgrass_logo_baltimore-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "dallas":
				  phoneimg = "<img src=\"images\/xgrass_logo_dallas-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "houston":
				  phoneimg = "<img src=\"images\/xgrass_logo_houston-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "tampa":
				  phoneimg = "<img src=\"images\/xgrass_logo_tampa-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "miami":
				  phoneimg = "<img src=\"images\/xgrass_logo_miami-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "charlotte":
				  phoneimg = "<img src=\"images\/xgrass_logo_charlotte-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "raleigh":
				  phoneimg = "<img src=\"images\/xgrass_logo_raleigh-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "orlando":
				  phoneimg = "<img src=\"images\/xgrass_logo_orlando-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				default:
				  phoneimg = "<img src=\"images\/xgrass_logo-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				}
		}
	else // Display organic info
		{
			switch(cookie_content)// this will always default to the last case since there is no cookie...
				{
				case "atlanta":
				  phoneimg = "<img src=\"images\/xgrass_logo_atlanta.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "sanfrancisco":
				  phoneimg = "<img src=\"images\/xgrass_logo_sanfrancisco.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "phoenix":
				  phoneimg = "<img src=\"images\/xgrass_logo_phoenix.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "sandiego":
				  phoneimg = "<img src=\"images\/xgrass_logo_sandiego.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "newyork":
				  phoneimg = "<img src=\"images\/xgrass_logo_newyork.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "boston":
				  phoneimg = "<img src=\"images\/xgrass_logo_boston.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "baltimore":
				  phoneimg = "<img src=\"images\/xgrass_logo_baltimore.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "dallas":
				  phoneimg = "<img src=\"images\/xgrass_logo_dallas.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "houston":
				  phoneimg = "<img src=\"images\/xgrass_logo_houston.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "tampa":
				  phoneimg = "<img src=\"images\/xgrass_logo_tampa.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "miami":
				  phoneimg = "<img src=\"images\/xgrass_logo_miami.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "charlotte":
				  phoneimg = "<img src=\"images\/xgrass_logo_charlotte.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "raleigh":
				  phoneimg = "<img src=\"images\/xgrass_logo_raleigh.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				case "orlando":
				  phoneimg = "<img src=\"images\/xgrass_logo_orlando.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				default:
				  phoneimg = "<img src=\"images\/xgrass_logo.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
				  break;
				}
		}
	document.write (phoneimg);
}

function getIfCPC()
   {
	  phonenumber = (cookie_exists) ? '<input type="hidden" value="Yes" name="From_CPC">' : '';
	  document.write (phonenumber);
   }


function getPhoneNumber()
   {
      // if cookie exists display the voice star phone number, otherwise display the regular:
	  phonenumber = (cookie_exists) ? '877-769-1915' : '877-881-8477';
	  document.write (phonenumber);
   }
   
function getDaltonPhoneNumber()
   {
      // if cookie exists display the voice star phone number, otherwise display the regular:
	  phonenumber = (cookie_exists) ? '877-769-1915' : '706-272-0140';
	  document.write (phonenumber);
   }
   
function getPhoneImg()
   {
	  phoneimg = (cookie_exists) ? "<img src=\"images\/xgrass_logo-cpc.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">" : "<img src=\"images\/xgrass_logo.gif\" alt=\"Artificial Grass and Synthetic Turf by XGrass\" width=\"225\" height=\"85\" border=\"0\">";
	  document.write (phoneimg);
   }   
   
function softrakgreens_com_sendCookie(cls)
   {
	  if (cls!="")
	     {
			 linkCode = (cookie_exists) ? '<a href=\"http:\/\/www.softrakgreens.com\/?adw=y\" class=\"'+cls+'\" \/>' : '<a href=\"http:\/\/www.softrakgreens.com\" class=\"'+cls+'\" \/>';
		 }
	  else
	     {
			 linkCode = (cookie_exists) ? '<a href=\"http:\/\/www.softrakgreens.com\/?adw=y\" \/>' : '<a href=\"http:\/\/www.softrakgreens.com\" \/>';
		 }
	  document.write (linkCode);	      
   }

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}   
