  var directionsDisplay;
  var directionsService = new google.maps.DirectionsService();
  var map;
  var oldDirections = [];
  var currentDirections = null;
  var vPicker=new Array()
  var vN=0
  var n=0
 
  function initialize() {
  if (document.all.T1.value.length<6){
  	alert("Starting - does not have enough information!")
  	document.all.T1.focus()
  	return
  }
  if (document.all.T2.value.length<6){
  	alert("Destination - does not have enough information!")
  	document.all.T2.focus()
  	return
  }
  directions_panel.innerHTML=""  
    var myOptions = {
      zoom: 7,
      center: new google.maps.LatLng(42.689030,-82.822380),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
 
    directionsDisplay = new google.maps.DirectionsRenderer({
        'map': map,
        'preserveViewport': true,
        'draggable': true
    });
    directionsDisplay.setPanel(document.getElementById("directions_panel"));
 
    google.maps.event.addListener(directionsDisplay, 'directions_changed',
    
      function() {
        if (currentDirections) {
          oldDirections.push(currentDirections);
          setUndoDisabled(false);
        }
        currentDirections = directionsDisplay.getDirections();
      });
 
    setUndoDisabled(true);
 
    calcRoute();
   //var vTimer=setTimeout("fShow()",5000)    
    
  }
 
  function calcRoute() {
    var start = document.all.T1.value // '7380 n indian lake dr, scotts mi';
    var end = document.all.T2.value //'lansing mi';
    var request = {
        origin:start,
        destination:end,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
      }
    });
    vN=vN+1
    vPicker[vN]= document.all.T1.value + ' -> ' + document.all.T2.value
    dHistory.innerHTML=dHistory.innerHTML+'<p><font face="verdana" size="2" onmouseover=style.cursor="hand";style.color="red" onmouseout=style.color="blue" onclick=fPicker(' + vN + ')>' + document.all.T1.value + ' -> ' + document.all.T2.value + '</font><br>'
 
    var vTimer=setTimeout("fShow()",5000)
  }
 
  function undo() {
    currentDirections = null;
    directionsDisplay.setDirections(oldDirections.pop());
    if (!oldDirections.length) {
      setUndoDisabled(true);
    }
  }
 
  function setUndoDisabled(value) {
    document.getElementById("undo").disabled = value;
  }
  
  
  
  
function fShow(){
	  //var vIT=directions_panel.innerText
	  var vIH=directions_panel.innerHTML
	  document.all.S1.style.height=600
	  document.all.S1.value=vIH
	  var vMD=document.all.S1.value
     document.all.S1.value="Start: " + document.all.T1.value + "\n\n" + "Destination: " + document.all.T2.value + "\n"

		var vMM=vMD


if (vMM.toUpperCase().indexOf('JSINSTANCE="*0')>-1){
	vMM=vMM.slice(vMD.toUpperCase().indexOf('JSINSTANCE="*0"')+15)
	vMM=vMM.slice(vMM.indexOf(">")+1)
	vMM=vMM.slice(0,vMM.toUpperCase().indexOf("</DIV"))
	var vMM2=vMM.slice(vMM.indexOf(">")+1)
	vMM=vMM.slice(vMM.indexOf(">")+1)
			vMM2=vMM.slice(0,vMM.indexOf('<'))
			while(vMM.indexOf('>')>-1){

				vMM2=vMM2+vMM.slice(vMM.indexOf('>')+1)
				if (vMM2.indexOf('<')>-1){
					vMM2=vMM2.slice(0,vMM2.indexOf('<'))
				}

				vMM=vMM.slice(vMM.indexOf('>')+1)
				
			}	
}
	document.all.S1.value=document.all.S1.value+ "\n" + vMM2 + "\n\n"
     

while (vMD.toUpperCase().indexOf('JSINSTANCE=')>-1){
	vMD=vMD.slice(vMD.toUpperCase().indexOf('JSINSTANCE=')+11)
	
	if (vMD.toUpperCase().indexOf('<TD')>-1){		
		vMD=vMD.slice(vMD.toUpperCase().indexOf('<TD')+3)
		var vHD=vMD.slice(vMD.indexOf('>')+1,vMD.toUpperCase().indexOf('</TD'))
		vMD=vMD.slice(vMD.toUpperCase().indexOf('</TD'))
		if (vMD.toUpperCase().indexOf('<TD')>-1){
			vMD=vMD.slice(vMD.toUpperCase().indexOf('<TD')+3)
			var vHC=vMD.slice(vMD.indexOf('>')+1,vMD.toUpperCase().indexOf('</TD'))
			vMD=vMD.slice(vMD.toUpperCase().indexOf('</TD')+3)
			var vTmp=vHC
			vHC=vTmp.slice(0,vTmp.indexOf('<'))
			while(vTmp.indexOf('>')>-1){

				vHC=vHC+vTmp.slice(vTmp.indexOf('>')+1)
				if (vHC.indexOf('<')>-1){
					vHC=vHC.slice(0,vHC.indexOf('<'))
				}

				vTmp=vTmp.slice(vTmp.indexOf('>')+1)
				//vTmp=vTmp.slice(vTmp.indexOf('<')+1)				
				
			}
			var vHM=""
		if (vMD.toUpperCase().indexOf('<TD')>-1){
			vMD=vMD.slice(vMD.toUpperCase().indexOf('<TD')+3)
			vHM=vMD.slice(vMD.indexOf('>')+1,vMD.toUpperCase().indexOf('</TD'))
			if (vHM.indexOf('>')>-1){
				vHM=vHM.slice(vHM.indexOf('>')+1)
				if (vHM.indexOf('<')>-1){
					vHM=vHM.slice(0,vHM.indexOf('<'))
				}
			}

		}			
		while (vHC.indexOf('\n')>-1){
			vHC=vHC.replace('\n','-')
			//vHC=vHC.replace(/^\+s/g,'')
		}		
		 while(vHC.indexOf('\r')>-1){
			vHC=vHC.replace('\r','')
			//vHC=vHC.replace(/^\+s/g,'')
		}
		 while(vHC.indexOf('--')>-1){
			vHC=vHC.replace('--','\n    - ')
			//vHC=vHC.replace(/^\+s/g,'')
		}
		if (eval(vHD)<10){
				document.all.S1.value=document.all.S1.value+vHD+'  ' + vHC + '\t' + vHM + "\n\n\n"
		} else {
			document.all.S1.value=document.all.S1.value+vHD+' ' + vHC + '\t' + vHM + "\n\n\n"		
		}
		}
	}

}	  
	  alert("Editable mapping directions - located at the bottom of this page!")
  }
  
  
  function fPicker(n){
		document.all.T1.value=vPicker[n].slice(0,vPicker[n].indexOf('->'))
		document.all.T2.value=vPicker[n].slice(vPicker[n].indexOf("->")+3)  	
  }
  
	function fEmail() {
	
		//if (document.all.TSubject.value.length<2){
		//	document.all.TSubject.value="From " + document.all.T1.value + " to " + document.all.T2.value + " With 15551212.com Map it!"
		//}
		if(document.all.TFrom.value!=""){
			if (document.all.TFrom.value.indexOf("@")==-1 || document.all.TFrom.value.indexOf(".")==-1) {
				alert("Email address is not valid.")
				document.all.TFrom.focus
				return
			} else if (document.all.TFrom.value.toUpperCase()!=document.all.TFromConfirmation.value.toUpperCase()){
				alert("Email confirmation does not match email address.\n" + document.all.TFrom.value + "\n" + document.all.TFromConfirmation.value)
				document.all.TTo.focus
				return
			}
		}
 

if (document.all.TFrom.value.indexOf("@")==-1 || document.all.TFromConfirmation.value.indexOf("@")==-1){
	alert("Not a valid email address!\n\nPlease check your email address!")
	document.all.TFrom.focus()
	return
}
/*
document.all.cHold.style.height=500
document.all.cHold.value=	  "To:            " + document.all.TTo.value + "\n"
								+ "Subject: " + document.all.TSubject.value + "\n"
								+ "From:        " + document.all.TFrom.value + "\n"

	+ "Travel Directions:  " + document.all.S1.value + "\n\n"
	+ "World Networking Group / LCDSearch.com Division\n\n"
	+ "Scotts, MI 49088 - Warehouse Kalamazoo MI\n"
	+ "Phone (269) 649.4949 or (269) 345.6600\n\n"
	
	+ "For Engineering & sales inquiries: sales@LCDSearch.com\nOrder Entry Billing & Accounting: info@LCDSearch.com\nShipments: info@LCDSearch.com\n"
*/
	document.all.TSubject.value="From " + document.all.T1.value + " to " + document.all.T2.value + " With 15551212.com Map it!"

	var vMail="mailto:" + document.all.TTo.value
	+ "?cc=info@15551212.com" + "&subject=" 
	+ escape(document.all.TSubject.value) 
	+ "&body=" 
	+ escape(document.all.S1.value)
	+ escape("From : " + document.all.TFrom.value + "\n")	
	+ escape("From : 15551212.com - Free GPS tracking - Map it!\n")
	+ escape("Scotts, MI 49088 & Kalamazoo, MI 49088\n\n")	
 
	window.location.href=vMail
	
	//alert("If your email application did not open, please copy the information listed at the bottom of this page and email us!\n\nOtherwise, thank you from all of us at LCDSearch.com!")
	alert("Please proof read and send your travel details.")
		//if (document.all.TSubject.value==""){
		//	document.all.TSubject.value="From " + document.all.T1.value + " to " + document.all.T2.value + " With 15551212.com Map it!"
		//}	
	
	}
