/* 
##########################################################################
############# 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(defaultphone)
   {
      // if cookie exists display the voice star phone number, otherwise display the regular:
	  if(defaultphone=='(602) 234-6856')
	     {
			 phonenumber = (cookie_exists) ? '(623) 239-3592' : defaultphone;
		 }
	  else if(defaultphone=='(877) 492-7549')
	    {
			phonenumber = (cookie_exists) ? '(800) 836-4208' : defaultphone;
		}
	  
	  document.write (phonenumber);
   }
   
function getPhoneImgTag()
   {
	  phoneimg = (cookie_exists) ? '<img src=\"images/inner_logo3_cpc.jpg\" width=\"165\" height=\"139\" alt=\"\" />' : '<img src=\"images/inner_logo3.jpg\" width=\"165\" height=\"139\" alt=\"\" />';
	  document.write (phoneimg);
   } 
 function getPhoneImgDiv()
   {
	  phoneimg = (cookie_exists) ? '<div id="bioprohomepage-01-cpc">' : '<div id="bioprohomepage-01">';
	  document.write (phoneimg);
   }  

