﻿var isMap=0;
 var address,lat,longi,error,div,map_canvas;
function LoadMap(){

   
   // if(document.getElementById('div')) div=document.getElementById('div');  else  div=document.getElementById('ctl00_ContentPlaceHolder1_div'); 
    //if(document.getElementById('map_canvas'))   else  map_canvas=document.getElementById('ctl00_ContentPlaceHolder1_map_canvas');  
    //map_canvas=document.getElementById('map_canvas');

if(document.getElementById('lat')) lat=document.getElementById('lat');  else  lat=document.getElementById('ctl00_ContentPlaceHolder1_lat');
if(document.getElementById('long')) longi=document.getElementById('long');  else  longi=document.getElementById('ctl00_ContentPlaceHolder1_long');



    if(isMap==0){
        var geocoder;if(geocoder===undefined){geocoder=new google.maps.Geocoder()}
        var D=parseFloat(lat.innerHTML);
        var C=parseFloat(longi.innerHTML);	
        if(!isNaN(D)&&!isNaN(C)&&D>-90&&D<90&&C>-180&&C<180)
        {		
            var A=new google.maps.LatLng(D,C);
            isMap=1;
            createMap(A,true)		
        }
        else
        {
            var B=address.innerHTML;
            isMap=1;            
            geocoder.geocode({address:B},function(F,E){ if(E==google.maps.GeocoderStatus.OK){createMap(F[0].geometry.location,false)}else{showMapError();}})
        }        
    }
}		

function showMapError(){
if(document.getElementById('error')) error=document.getElementById('error');  else  error=document.getElementById('ctl00_ContentPlaceHolder1_error'); 

error.innerHTML="Sorry, we were unable to create a map for this property.";}

function AddPushPin(B,A, map){
if(document.getElementById('address')) address=document.getElementById('address');  else  address=document.getElementById('ctl00_ContentPlaceHolder1_address'); 
if(A){var F=document.createElement("div");F.innerHTML=address.innerHTML;var C=new google.maps.Marker({map:map,position:B,visible:true,clickable:true});var E=new google.maps.InfoWindow({content:F.innerHTML});E.open(map,C);}}
						
function createMap(B,A){var mapContainer=document.getElementById('map_canvas');var map=new google.maps.Map(mapContainer,{center:B,zoom:13,mapTypeId:google.maps.MapTypeId.ROADMAP,mapTypeControl:true,navigationControl:true,draggableCursor:"move",draggingCursor:"crosshair"});AddPushPin(B,A,map);}

// check date JavaScript function
// if date is valid then function returns true, otherwise returns false
function isDate(txtDate){
  var objDate;  // date object initialized from the txtDate string
  var mSeconds; // milliseconds from txtDate

	// date length should be 10 characters - no more, no less
  if (txtDate.length != 10) return false;

	// extract day, month and year from the txtDate string
	// expected format is mm/dd/yyyy
	// subtraction will cast variables to integer implicitly
  var day   = txtDate.substring(3,5)  - 0;
  var month = txtDate.substring(0,2)  - 1; // because months in JS start with 0
  var year  = txtDate.substring(6,10) - 0;

	// third and sixth character should be /
	if (txtDate.substring(2,3) != '/') return false;
	if (txtDate.substring(5,6) != '/') return false;

  // test year range
  if (year < 999 || year > 3000) return false;

  // convert txtDate to the milliseconds
  mSeconds = (new Date(year, month, day)).getTime();

  // initialize Date() object from calculated milliseconds
  objDate = new Date();
  objDate.setTime(mSeconds);

  // compare input parameter date and created Date() object
  // if difference exists then date isn't valid
  if (objDate.getFullYear() != year)  return false;
  if (objDate.getMonth()    != month) return false;
  if (objDate.getDate()     != day)   return false;

	// otherwise return true
  return true;
}

// how to use isDate() JavaScript function
// this function is called on button click event
function checkDate(txtDate, message){
	// define date string to test
	var txtDate1 = txtDate.value;
	if(txtDate1=="")
	{
	     return false;
    }
    else
    {
	    // check date and print message	
	    if (isDate(txtDate1))
	    {
	        __doPostBack(txtDate.name,'');
	        return true;
	    }
	    else {alert(message); false;}
    }
}

// how to use isDate() JavaScript function
// this function is called on button click event
function checkDate1(txtDate, message){
	// define date string to test
	var txtDate1 = txtDate.value;
	if(txtDate1=="")
	{
	     return false;
    }
    else
    {
	    // check date and print message	
	    if (isDate(txtDate1))
	    {	     
	        return true;
	    }
	    else {alert(message); false;}
    }
}



