
/* Clicky code started */

var clicky={init:function(){if(document.location.protocol=="https:"){clicky.domain="https://static.getclicky.com";clicky.secure=1;}else{clicky.domain="http://static.getclicky.com";clicky.secure=0;}clicky.img=new Image();clicky.img_base=clicky.domain+"/in.php?site_id=119779&srv=db16"+"&res="+screen.width+"x"+screen.height+"&lang="+(navigator.language||navigator.browserLanguage).substr(0,2)+"&secure="+clicky.secure;if(clicky_custom.session){for(var i in clicky_custom.session){clicky.img_base+="&custom["+clicky.enc(i)+"]="+clicky.enc(clicky_custom.session[i]);}}if(clicky_custom.goal){for(var i in clicky_custom.goal){clicky.img_base+="&goal["+clicky.enc(i)+"]="+clicky.enc(clicky_custom.goal[i]);}}var r=RegExp("^https?://[^/]*"+location.host.replace(/^www\./i,"")+"/","i").test(document.referrer)?"":clicky.enc(document.referrer);if(clicky_custom.pageview_disable){clicky.img_base+="&ref="+r;}else{clicky.img.src=clicky.img_base+"&ref="+r+"&title="+clicky.enc(clicky_custom.title?clicky_custom.title:document.title)+"&href="+clicky.enc(clicky_custom.href?clicky_custom.href:location.pathname+location.search)+"&x="+Math.random();}clicky.add_event(window,'load',clicky.advanced);},isset:function(e){return(typeof(window[e])!="undefined");},enc:function(e){return window.encodeURIComponent?encodeURIComponent(e):escape(e);},log:function(href,title,type){type=type||"click";if(type=="pageview")href=href.replace(/^https?:\/\/([^\/]+)/i,"");clicky.img.src=clicky.img_base+"&type="+type+"&title="+clicky.enc(title)+"&href="+clicky.enc(href)+"&x="+Math.random();clicky.pause();},pause:function(x){var now=new Date();var stop=now.getTime()+(x||clicky_custom.timer||500);while(now.getTime()<stop)var now=new Date();},goal:function(id,revenue){clicky.img.src=clicky.img_base+"&type=goal&goal[id]="+id+"&goal[revenue]="+revenue+"&x="+Math.random();},add_event:function(e,type,func){if(e.addEventListener){e.addEventListener(type,func,false);}else if(e.attachEvent){e.attachEvent("on"+type,func);}},download:function(e){clicky.img_src(e,"download");},outbound:function(e){clicky.img_src(e,"outbound");},click:function(e){clicky.img_src(e,"click");},img_src:function(e,type){obj=clicky.get_target(e);clicky.log(clicky.get_href(obj),clicky.get_text(obj),type);},get_text:function(e){do{var txt=e.text?e.text:e.innerText;if(txt)return txt;if(e.alt)return e.alt;if(e.title)return e.title;if(e.src)return e.src;e=clicky.get_parent(e);}while(e);return"";},get_href:function(e){do{if(e.href&&!e.src)return e.href;e=clicky.get_parent(e);}while(e);return"";},get_parent:function(e){return e.parentElement||e.parentNode;},get_target:function(e){if(!e)var e=window.event;var t=e.target?e.target:e.srcElement;if(t.nodeType&&t.nodeType==3)t=t.parentNode;return t;},advanced:function(){if(clicky_custom.advanced_disable)return;var is_download=new RegExp("\\.(7z|aac|avi|cab|csv|doc(x|m)?|exe|flv|gif|gz|jpe?g|js|m4a|mp(3|4|e?g)|mov|msi|ods|pdf|phps|png|ppt(x|m)?|rar|rtf|sea|sit|tar|torrent|txt|wma|wmv|xls(x|m)?|xml|zip)$","i");var is_link=new RegExp("^(https?|ftp|telnet|mailto):","i");var is_link_internal=new RegExp("^https?:\/\/(.*)"+location.host.replace(/^www\./i,""),"i");var a=document.getElementsByTagName("a");for(var i=0;i<a.length;i++){if(a[i].className.match(/clicky_log/i)){if(a[i].className.match(/clicky_log_download/i)){clicky.add_event(a[i],"mousedown",clicky.download);}else if(a[i].className.match(/clicky_log_outbound/i)){clicky.add_event(a[i],"mousedown",clicky.outbound);}else{clicky.add_event(a[i],"mousedown",clicky.click);}}else{if(is_link.test(a[i].href)&&!a[i].className.match(/clicky_ignore/i)){if(is_download.test(a[i].href)){clicky.add_event(a[i],"mousedown",clicky.download);}else if(!is_link_internal.test(a[i].href)){clicky.add_event(a[i],"mousedown",clicky.outbound);}}}}}};if(!clicky.isset("clicky_custom"))clicky_custom={};if(clicky.isset("clicky_page_title"))clicky_custom.title=clicky_page_title;if(clicky.isset("clicky_advanced_disable"))clicky_custom.advanced_disable=1;if(clicky.isset("clicky_pause_timer"))clicky_custom.timer=clicky_pause_timer;if(clicky.isset("clicky_custom_session"))clicky_custom.session=clicky_custom_session;if(clicky.isset("clicky_goal"))clicky_custom.goal=clicky_goal;clicky.init();

/* Clicky Code Ended */





// BEGIN AJAX/INNERHTML for SMS Form
		// Genric Request Function
		function ajaxRequest(){
		 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
		 if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
		  for (var i=0; i<activexmodes.length; i++){
		   try{
		    return new ActiveXObject(activexmodes[i])
		   }
		   catch(e){
		    //suppress error
		   }
		  }
		 }else if (window.XMLHttpRequest){ // if Mozilla, Safari etc
		  return new XMLHttpRequest()
		  }else{
		  return false
		 }
		}
		// Submit SMS Function
		function sendSMS(whichForm){
			if(document.getElementById("sms_destination_number").value.length==10){
				var smsgetrequest=new ajaxRequest()
				smsgetrequest.onreadystatechange=function(){
					document.getElementById("sms_status").innerHTML="<img src='http://www.technomile.com/text2drive/widget/images/ajax-loader.gif'>"
					if (smsgetrequest.readyState==4){
						if (smsgetrequest.status==200 || window.location.href.indexOf("http")==-1){
							document.getElementById("smsForm"+whichForm).innerHTML=smsgetrequest.responseText
						}else{
							alert("An error has occured making the request (3:"+smsgetrequest.status+")")
							document.getElementById("sms_status").innerHTML=""
						}
					}
				}
				var sms_destination_number_value=encodeURIComponent(document.getElementById("sms_destination_number").value)
				var sms_stock_number_value=encodeURIComponent(document.getElementById("sms_stock_number").value)
				smsgetrequest.open("GET", "http://www.technomile.com/text2drive/widget/smsrequest.php?sms_destination_number="+sms_destination_number_value+"&sms_stock_number="+sms_stock_number_value+"&form_number="+whichForm, true)
				smsgetrequest.send(null)
			}else{
				alert("Your Phone Number Must Be 10 Digits Long")
			}
		}
		// Reset SMS Form Function
		function smsFormReset(stock1){
			try{
				document.getElementById("smsForm1").innerHTML="<img src='http://www.technomile.com/text2drive/widget/images/pocket.png' border='0' onclick=javascript:smsFormShow(1,'"+stock1+"'); id='link1' style='cursor:pointer'>"
			}catch(err){}
			return true;
		}

		// Clean up Phone Numbers
		function phoneClean(){
			var s = document.getElementById("sms_destination_number").value;
			var pattern=/[^0-9]/
			while (pattern.test(s)==true){
				var s = s.replace(/[^\d]/,'');
			}
			document.getElementById("sms_destination_number").value = s;
		}
		
		function smsFormShow(whichForm,stockNum){
		//alert(stockNum);
			var reset_form = smsFormReset();
			document.getElementById("smsForm"+whichForm).innerHTML="<div class='widgetform'><br><form action='' method='get'>Enter Your Mobile Phone Number:<br /><input name='sms_destination_number' id='sms_destination_number' type='text' size='30' onBlur='phoneClean();' class='txtField'  /><input name='sms_stock_number' id='sms_stock_number' type='hidden' value='"+stockNum+"' /><br /><input type='button' value='Submit' onClick='javascript:getAd("+whichForm+");' class='widgetbutton' /><span id='sms_status'></span></form></div>"
		}
		// Show SMS Form Function
		// END AJAX/INNERHTML for SMS Form
		

function getAd(whichForm) {
if(document.getElementById("sms_destination_number").value.length==10){
	formName=whichForm;
     var sms_destination_number_value=encodeURIComponent(document.getElementById("sms_destination_number").value)
				var sms_stock_number_value=encodeURIComponent(document.getElementById("sms_stock_number").value)
            //shamelessly hard code the url of the request
            //var request = "http://bestofatlanta.technomile.com/b.php?clientId=really_cool_cars&callback=showAd";
var request="http://www.technomile.com/text2drive/widget/smsrequest.php?sms_destination_number="+sms_destination_number_value+"&sms_stock_number="+sms_stock_number_value+"&form_number="+whichForm+"&callback=showAd"
            //Construct script node and add it to the document, causing the Get request
            //to the PHP script
             document.getElementById("sms_status").innerHTML="<img src='http://www.technomile.com/text2drive/widget/images/ajax-loader.gif'>"
            //Check for the existing script node
            var oScript = document.getElementById("dynamic_script_injection_node");

          // Get the script tag, if it exists
              var head = document.getElementsByTagName("head").item(0);
           // Remove the tag, if it exists to avoid the increase in size
          if (oScript) {
                
                head.removeChild(oScript);
          }

            script = document.createElement("script");
            script.setAttribute("id", "dynamic_script_injection_node");
            script.setAttribute("type", "text/javascript");
            script.setAttribute("src", request);
            // all set, add the script
            head.appendChild(script);
            }else{
				alert("Your Phone Number Must Be 10 Digits Long")
			}
      }
      /*
       * THis function is called when the JSON string is returned from GiveAd.php
       */
      function showAd(Ad) {
       
       // Find the div where the ad will be displayed
       var divElem = document.getElementById ("addDisplay");
       
       //Using dot notation collect the data from Ad object sent by GiveAd.php
	  document.getElementById("sms_status").innerHTML="";
       var title = Ad.Title;
	   var formdef= Ad.form;
	   document.getElementById("smsForm1").innerHTML="<div class='widgetform'>"+title+formdef+"</div>";
       //var punchLine = "<p align='center'>"+Ad.Ad_Body.Punch_line+"<br>";
      // var url = "<a href='http://"+Ad.Ad_Body.URL+"'>"+Ad.Ad_Body.URL+"</a></p>";

        //put the content of the ad into div
        //divElem.innerHTML = title+punchLine+url;       
       
       
      
      }

/*to get skunumber*/    
divs=document.getElementsByTagName("span");
for(i=0;i<divs.length;i++){

//alert(divs[i].innerHTML);
str=divs[i].innerHTML;
 if(str.indexOf("Stock Number:") != -1){
 
 var st=divs[i+1].innerHTML;
 }
}

