


// BEGIN AJAX/INNERHTML for SMS Form
		// Genric Request Function
		var st;
		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/gurneehyunai/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/gurneehyunai/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/gurneehyunai/images/pocket.gif' 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/gurneehyunai/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/gurneehyunai/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*/    
  
var metas = document.getElementsByTagName('meta');
  var i;
  for (i = 0; i < metas.length; i++){
    if (metas[i].getAttribute('NAME') == "description"){
     var TestVar = metas[i].getAttribute('CONTENT');
     }
  }	 	 
 split1=TestVar.split("The stock number is");
 st=split1[1].split(" ");
 st=st[1];
 



