/* 
______________________________________________________ ! Please Note ! _________________________________________________________

      This file contains:
	  
	  1) code that contorl's the auto playing video on the right hand side of the template.
	  1) CPC phone tracking code.
________________________________________________________________________________________________________________________________

##########################################################################
#######################     Auto Play Video     ##########################
##########################################################################
####################### EDIT: javascriptFlash variable in playVid function
##########################################################################
############# 1. Check if coockie exists
############# 2. If coockie does not exist create cookie
############# 3. function to display the image or video
##########################################################################
##########################################################################
*/

// 1. Check if cookie exists
function isAutoPlayVid()   
	{
		// Declare vars
		var getCookie;
		
		// Get Cookie If Exists
		getCookie = get_cookie("AutoPlayVid");
		
		// Check if cookie exists or not
		if(getCookie == "")// If Cookie Does not exist
			{
				playVid();
				document.cookie = "AutoPlayVid=no";
			}
		else // If Cookie exists
			{
				//document.getElementById("vid").innerHTML = "<a href=\"javascript:playVid()\"><img src=\"/img/electronic-cigarette-video.jpg\"></a>";
				document.getElementById("vid").innerHTML = "<img src=\"/img/electronic-cigarette-video.jpg\" onclick=\"playVid();\">";
			}	
	}

function playVid()
	{
			var javascriptFlash="";
			javascriptFlash += "<embed height=\"216\" width=\"258\" type=\"application\/x-shockwave-flash\" pluginspage=\"http:\/\/www.adobe.com\/shockwave\/download\/download.cgi?P1_Prod_Version=ShockwaveFlash\" quality=\"high\" src=\"smart-fixx-video.swf\" title=\"smartfixx video\"> <noscript>&lt;object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=9,0,28,0\" width=\"258\" height=\"216\" title=\"smartfixx video\"&gt;";
			javascriptFlash += "    &lt;param name=\"movie\" value=\"smart-fixx-video.swf\" \/&gt;";
			javascriptFlash += "    &lt;param name=\"quality\" value=\"high\" \/&gt;";
			javascriptFlash += "    &lt;embed src=\"smart-fixx-video.swf\" quality=\"high\" pluginspage=\"http:\/\/www.adobe.com\/shockwave\/download\/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application\/x-shockwave-flash\" width=\"258\" height=\"216\"&gt;&lt;\/embed&gt;";
			javascriptFlash += "  &lt;\/object&gt;";
			javascriptFlash += "  <\/noscript>";
			document.getElementById("vid").innerHTML = javascriptFlash;
	}

//Get cookie routine
function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.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))
      }
   }
  return returnvalue;
}	

/*   
##########################################################################
#######################     CPC Phone Tracking     #######################
##########################################################################
############# 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" || vars["adw"]=="y")
			  {
				 ////////////////////////////////////////////////////////////////////////////////////////////////
				 // 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=/; domain=smartfixx.com";
				 cookie_exists = 1;
				 // prepare for setting a cookie & set cookie /\
				 ////////////////////////////////////////////////////////////////////////////////////////////////
			  }
   }
else // if there is a cookie
   {
	   cookie_exists = 1;
   }

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

  
   
function getPhoneNumber()
   {
      defaultphone = "1-866-456-1522";
	  // if cookie exists display the voice star phone number, otherwise display the regular:
	  phonenumber = (cookie_exists) ? '1-866-456-1522' : defaultphone;
	  document.write (phonenumber);
   }
   
function getPhoneImg()
   {
	  phoneimg = (cookie_exists) ? '<img src=\"\/images\/number_image_cpc.jpg\" alt=\"\" \/>' : '<img src=\"\/images\/number_image_normal.jpg\" alt=\"\" \/>';
	  document.write (phoneimg);
   } 

