/* 
##########################################################################
############# 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;

// 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
		   if (vars["_vsrefdom"]=="paidsearch")
			  {
				 ////////////////////////////////////////////////////////////////////////////////////////////////
				 // 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=yes; expires=" + expires_date.toGMTString() + "; path=/";
				 cookie_exists = 1;
				 // prepare for setting a cookie & set cookie /\
				 ////////////////////////////////////////////////////////////////////////////////////////////////
			  }
   }
else // if there is a cookie
   {
	   cookie_exists = 1;
   }

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



function getPhoneNumber(location)
   {
      if (location == 'national')
	     {
			  // if cookie exists display the voice star phone number, otherwise display the regular:
			  phonenumber = (cookie_exists) ? '1-866-907-3174' : '1-866-534-4696';
		 }
      else if (location == 'local')
	     {
			  // if cookie exists display the voice star phone number, otherwise display the regular:
			  phonenumber = (cookie_exists) ? '1-778-785-1310' : '1-604-534-4696';
		 }
      else if (location == 'national_landing')
	     {
			  // if cookie exists display the voice star phone number, otherwise display the regular:
			  phonenumber = (cookie_exists) ? '1-866-907-3174' : '1-866-534-4696';
		 }
      else if (location == 'local_landing')
	     {
			  // if cookie exists display the voice star phone number, otherwise display the regular:
			  phonenumber = (cookie_exists) ? '1-778-785-1310' : '1-604-534-4696';
		 }
	  document.write (phonenumber);
   }

function supportemail(actname)
   {
	   if(!cookie_exists)
	      {
			   var emailaddress;
			   emailaddress = actname+"@directdryers.com";
			   document.write('E-mail: <a href="mailto:' + emailaddress + '">' + emailaddress + '</a>')
		  }
   }

function emailadrs(position)
   {
	   var emailcode;
	   switch (position)
	      {
			case "default_td":
			   emailcode = (cookie_exists) ? '<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>' : '<td align="right"><strong>E-mail: </strong></td><td>&nbsp;</td><td> direct@directdryers.com </td>';
			   break;
			case "default_email":
			   emailcode = (cookie_exists) ? '' : '<strong>Email:</strong> <a href="mailto:direct@directdryers.com">direct@directdryers.com</a>';
			   break;
			case "footer_email":
			   emailcode = (cookie_exists) ? '' : '<strong>Email:</strong> <a href="mailto:direct@directdryers.com">direct@directdryers.com</a>';
			   break;
			case "header_td":
			   emailcode = (cookie_exists) ? '<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>' : '<td align="right"><strong>E-mail: </strong></td><td>&nbsp;</td><td> direct@directdryers.com </td>';
			   break;
			case "or_email_direct":
			    emailcode = (cookie_exists) ? '' : 'or email <a href="mailto:direct@directdryers.com">direct@directdryers.com</a></center>';
			   break;
			case "template_email":
			   emailcode = (cookie_exists) ? '' : 'Email: <a href="mailto:direct@directdryers.com">direct@directdryers.com</a>';
			   break;
		  }
	   document.write (emailcode);
   }
   
function bodyclass(option) // for the image
   {
	  if (option == 'reg')
	     {
	        thetag = (cookie_exists) ? '<body class=\"bodycpc\">' : '<body>';
		 }
	  else if (option == 'onld')
	     {
	        thetag = (cookie_exists) ? '<body class=\"bodycpc\" onload=\"showHideContent(\'residential\', false, \'res\'); showHideContent(\'commercial\', false, \'com\'); showHideContent(\'locker\', false, \'loc\'); showHideContent(\'duty\', false, \'dut\');\">' : '<body onload=\"showHideContent(\'residential\', false, \'res\'); showHideContent(\'commercial\', false, \'com\'); showHideContent(\'locker\', false, \'loc\'); showHideContent(\'duty\', false, \'dut\');\">';
		 }
	  document.write (thetag);
   } 
   
function ppedryers_com_sendCookie(option)
   {
	  if (option=="lightwindow_page_options")
	     {
			 linkCode = (cookie_exists) ? '<a href="\http:\/\/www.ppedryers.com?adw=y\" class=\"lightwindow page-options\" title=\"PPE Dryers\" \/>' : '<a href="\http:\/\/www.ppedryers.com\" class=\"lightwindow page-options\" title=\"PPE Dryers\" \/>';
		 }
	  else if (option=="button")
	     {
			 linkCode = (cookie_exists) ? '<input type=\"button\" onclick=\"javascript: myLightWindow.activateWindow({href: \'http:\/\/www.ppedryers.com?adw=y\', title: \'PPEDryers.com\', width: 985});\" value=\"Launch Sister Company PPE Dryers!\" \/>' : '<input type=\"button\" onclick=\"javascript: myLightWindow.activateWindow({href: \'http:\/\/www.ppedryers.com\', title: \'PPEDryers.com\', width: 985});\" value=\"Launch Sister Company PPE Dryers!\" \/>';
		 }
	  document.write (linkCode);	      
   }  
