function allowJustDigits(evt){

var eve = evt ? evt : window.event;
var charCode = 0;

if(eve) charCode = eve.charCode ? eve.charCode : (eve.keyCode? eve.keyCode : (eve.which ? eve.which : 0)); 

if(charCode > 31 && (charCode < 48 || charCode>57)) return false;

else return true;

}

function calculate(){

var val = document.formaDis.startzip.value;
       if(val.length != 5) {document.getElementById("szipspan").style.color="red";document.getElementById("errorLabel").innerHTML="Type the start zip";return;}
	   else if(val.length == 5) {document.getElementById("szipspan").style.color="black";document.getElementById("errorLabel").innerHTML="";}
	   
	   val = document.formaDis.endzip.value;
	   if(val.length != 5) {document.getElementById("ezipspan").style.color="red";document.getElementById("errorLabel").innerHTML="Type the end zip";return;}
	   else if(val.length == 5) {document.getElementById("ezipspan").style.color="black";document.getElementById("errorLabel").innerHTML="";}
           
           document.getElementById("calButtonID").disabled="true"; 

           xmlHttp=getXMLHTTP();
	xmlHttp.onreadystatechange=display;
  try{
        xmlHttp.open("POST","http://www.matchmovers.com/mover/distanceCalculator",true);
     }catch(e){
               try{
                    xmlHttp.open("POST","http://matchmovers.com/mover/distanceCalculator",true);
                  }catch(ee){}
              }
        xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
        xmlHttp.send("startzip="+document.formaDis.startzip.value+"&endzip="+document.formaDis.endzip.value);          

}

var xmlHttp;
function getXMLHTTP(){
var barbosXmlHttp=false;
 


  try{
      barbosXmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
     }catch(e){
              try{
                  barbosXmlHttp=new ActivexObject("Miscrosoft.XMLHTTP");
                 }catch(ee){
                         barbosXmlHttp=false; 
                         }
              }



if(!barbosXmlHttp && typeof XMLHttpRequest != 'undefined'){
   try{
       barbosXmlHttp=new XMLHttpRequest();
      }catch(eee){
               barbosXmlHttp=false;
              }
}
return barbosXmlHttp;
}

function display(){//document.getElementById("distanceLabel").innerHTML="";
if(xmlHttp.readyState==4){
           if(xmlHttp.status==200) {
		      var doc = xmlHttp.responseXML;
                      var resCode = doc.getElementsByTagName("code")[0].firstChild.nodeValue;
			  if(resCode == "1") document.getElementById("errorLabel").innerHTML="Error. Page has same errors. Missing parameter"; 	
                          else if(resCode ==2) document.getElementById("errorLabel").innerHTML="The start zip does not exists."; 
                          else if(resCode ==3) document.getElementById("errorLabel").innerHTML="The end zip does not exists."; 
                          else if(resCode ==4) {
                                   document.getElementById("errorLabel").innerHTML="";
                                   document.getElementById("distanceLabel").innerHTML=""+doc.getElementsByTagName("distance")[0].firstChild.nodeValue+" miles";
                                   lat1= doc.getElementsByTagName("lat1")[0].firstChild.nodeValue;
                                   lon1=doc.getElementsByTagName("lon1")[0].firstChild.nodeValue;
                                   lat2=doc.getElementsByTagName("lat2")[0].firstChild.nodeValue;
                                   lon2=doc.getElementsByTagName("lon2")[0].firstChild.nodeValue;
                                   
                                        createDrivingMap(lat1,lon1,lat2,lon2,'drimap','drivepanel');
                                   }
                          else document.getElementById("errorLabel").innerHTML=""; 	
                        
                                   
		   }
		   }
document.getElementById("calButtonID").disabled=false;
}


var lat1="";
var lon1="";
var lat2="";
var lon2="";



function createDrivingMap(lat_start, lon_start, lat_end, lon_end, map_id, direction_id) {try{
		var map2 = new GMap2(document.getElementById(map_id));
		map2.addControl(new GLargeMapControl());
		map2.addControl(new GMenuMapTypeControl());
		map2.addControl(new GOverviewMapControl());
		//directionsPanel = document.getElementById(direction_id);
		directions = new GDirections(map2);// directionsPanel
		// var p1 = ax+","+ay;
		// gdir.loadFromWaypoints([p1,"cagliari","olbia"],... 
		directions.loadFromWaypoints([new GLatLng(lat_start, lon_start), new GLatLng(lat_end, lon_end)]); }catch(e){alert(e);}
	}


