

var xmlhttp=false;



/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/


if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
       try {
              xmlhttp = new XMLHttpRequest();
       } catch (e) {
              xmlhttp=false;
       }
}
if (!xmlhttp && window.createRequest) {
       try {
              xmlhttp = window.createRequest();
       } catch (e) {
              xmlhttp=false;
       }
}

var img_added = new Image();
img_added.src = '_Images/propertynav/btn_propnav_added.gif';

var img_add = new Image();
img_add.src = '_Images/propertynav/btn_propnav_add.gif';

var img_wait = new Image();
img_wait.src = '_Images/propertynav/btn_propnav_wait.gif';


var nav_count=0;

function set_addedOLD(iimg) {
	if (nav_count<10) {
	document.images[iimg].src = img_added.src;
	}
}

function set_added(iimg,propno) {
	document.images[iimg].src = img_wait.src;
	var img_added2 = new Image();
	img_added2.src = 'http://www.toop.com.au/propnav_addbtn.asp?propno=' + propno;
	document.images[iimg].src = img_added2.src;

}

function set_wait(iimg) {
	if (nav_count<10) {
	document.images[iimg].src = img_wait.src;
	}
}

function set_add(iimg) {
	if(document.images[iimg]){
		document.images[iimg].src = img_add.src;
	}
}


function addnav(address,coordinates,geo_address,visittype,propno,visittime,tripdate) {
	if (!visittime) {visittime=''}
	if (tripdate+''!='') {
			//document.getElementById('tripdate_display').value = tripdate;
			document.getElementById('tripdate').value = tripdate;
			xmlhttp.open("GET", "http://www.toop.com.au/propnav_set_navdate.asp?sDate="+document.getElementById('tripdate').value+"&r="+Math.random(),false);
 			xmlhttp.send(null);
		}
	if (nav_count<10) {
	xmlhttp.open("GET", "http://www.toop.com.au/propnav_add.asp?address="+escape(address)+'&coordinates='+escape(coordinates)+'&geo_address='+escape(geo_address)+'&visittype='+escape(visittype)+'&propno='+escape(propno)+'&timevalue='+escape(visittime)+'&r='+Math.random(),false);
 	xmlhttp.send(null);
		
	nav_count++;}
}

function addnavdebug(address,coordinates,geo_address,visittype,propno,visittime,tripdate) {
	if (!visittime) {visittime=''}
	if (tripdate+''!='') {
			//document.getElementById('tripdate_display').value = tripdate;
			alert(1);
			document.getElementById('tripdate').value = tripdate;
			xmlhttp.open("GET", "http://www.toop.com.au/propnav_set_navdate.asp?sDate="+document.getElementById('tripdate').value+"&r="+Math.random(),false);
 			xmlhttp.send(null);
		}
	alert(2);
	if (nav_count<10) {
	xmlhttp.open("GET", "http://www.toop.com.au/propnav_add.asp?address="+escape(address)+'&coordinates='+escape(coordinates)+'&geo_address='+escape(geo_address)+'&visittype='+escape(visittype)+'&propno='+escape(propno)+'&timevalue='+escape(visittime)+'&r='+Math.random(),false);
 	xmlhttp.send(null);
		
	nav_count++;}
}



function clearnav() {
	xmlhttp.open("GET", "http://www.toop.com.au/propnav_clear.asp?r="+Math.random(),false);
 	xmlhttp.send(null);
	nav_count = 0;
	newLoc = window.location.href;
	newLoc = newLoc.replace("#googlemap","");
	//window.location.reload( false ); //  so that all [Added] imgs change back to [+Propertynav]
	window.location=newLoc;
}

function undonav() {
	xmlhttp.open("GET", "http://www.toop.com.au/propnav_undo.asp?r="+Math.random(),false);
 	xmlhttp.send(null);
}

function bestpath_nav() {
	xmlhttp.open("GET", "http://www.toop.com.au/propnav_bestpath.asp?r="+Math.random(),false);
 	xmlhttp.send(null);
	window.location.reload( false );
}

function shownav() {
	var myDays= ["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun"];
	if (document.getElementById('tripdate')){
		curdt=document.getElementById('tripdate').value;
		curdtarr=curdt.split('/');
		isdt=true;
		for(var k=0;k<curdtarr.length;k++) {
			if (isNaN(curdtarr[k]))
				isdt=false;
		}
		if (isdt&(curdtarr.length==3)) {
			ccm=curdtarr[1]-1;
			ccy=curdtarr[2];
			var d = new Date(curdtarr[2],curdtarr[1]-1,curdtarr[0])
		}
	}
	xmlhttp.open("GET", "http://www.toop.com.au/propnav_update_inspectiontimes.asp?r="+Math.random(),false);
 	xmlhttp.send(null);
	xmlhttp.open("GET", "http://www.toop.com.au/propnav_show.asp?r="+Math.random(),false);
 	xmlhttp.send(null);
	document.getElementById('propnavlist').innerHTML = xmlhttp.responseText;
	
	if (document.getElementById('tripdate')){
		var disp = new String(d);
		rExp=/00:.+/gi;
		rExp2=/\d{4}/gi;
		disp=disp.replace(rExp,'');
		disp=disp.replace(rExp2,'');
		document.getElementById('tripdate_display').value=disp;
	}
	
}

function sethomestart() {
	alert(escape(document.getElementById('prop_nav_start').value));
}

function swapnav(first,second){
	xmlhttp.open("GET", "http://www.toop.com.au/propnav_swap.asp?first="+first+"&second="+second+"&r="+Math.random(),false);
 	xmlhttp.send(null);
}

function inserthomestop(afterpos){
	xmlhttp.open("GET", "http://www.toop.com.au/propnav_inserthomestop.asp?afterpos=" + afterpos + "&r="+Math.random(),false);
 	xmlhttp.send(null);
}

function insertotheraddr(afterpos){
	xmlhttp.open("GET", "http://www.toop.com.au/propnav_insertcompstop.asp?afterpos=" + afterpos + "&r="+Math.random(),false);
 	xmlhttp.send(null);
}

function removenav(pos){
	xmlhttp.open("GET", "http://www.toop.com.au/propnav_remove.asp?pos="+pos+"&r="+Math.random(),false);
 	xmlhttp.send(null);
	nav_count--;
	
}

function setvisittime(spos,svisittime) {
	xmlhttp.open("GET", "http://www.toop.com.au/propnav_setvisittime.asp?pos="+spos+"&visittime="+svisittime+"&r="+Math.random(),false);
 	xmlhttp.send(null);
	
}

function displaytrip(isrent) {

	window.open("http://www.toop.com.au/propnav_displaytrip.asp"+isrent,"_blank",'scrollbars=yes,menubar=yes,toolbar=yes, resizable=yes, top=0, left=0, width=980, height=690');
}

function input_edit(input_b) {
	input_b.style.backgroundImage='none';
	if (input_b.value == '> Enter START address here') {
		input_b.value = '';
	} 
}

function input_edit_competitor(input_b) {
	input_b.style.backgroundImage='none';
	if (input_b.value == '> Enter an address here') {
		input_b.value = '';
	} 
}

function setNavDate() {
	//only called imediately after tripdate_display has been changed by the Cal. JS
	document.getElementById('tripdate').value = document.getElementById('tripdate_display').value;
	xmlhttp.open("GET", "http://www.toop.com.au/propnav_set_navdate.asp?sDate="+document.getElementById('tripdate').value+"&r="+Math.random(),false);
 	xmlhttp.send(null);
	shownav();
}

function sethomestart2(current) {
	//if (current.value==''){
	//current.style.backgroundImage='url(../_Images/propertynav/home_sign.jpg)';
		//return;}
	var sadr = String(current.value);
	sadr = sadr.replace(/\s+/g,' ');
	sadr = sadr.replace(/^\s+(.*?)/g,'$1');
	//sadr = escape(sadr);
	
	var geocoder = new GClientGeocoder();
	
		geocoder.getLatLng(
						   sadr,
						   function(point) {
							   if (!point) {
								   alert(sadr + " could not be found.");
									shownav();
								} else {
									sadr = escape(sadr);
									sadr = sadr.replace('\%0D\%0A','');
									xmlhttp.open("GET", "http://www.toop.com.au/propnav_set_home.asp?coords="+point.lat()+", "+point.lng()+"&address="+sadr+"&r="+Math.random(),false);
 									xmlhttp.send(null);
									shownav();
								}
							}
						);
		
	
}

function setCompetitorStop(current,iindex) {
	//if (current.value==''){
	//current.style.backgroundImage='url(../_Images/propertynav/home_sign.jpg)';
		//return;}
	var sadr = String(current.value);
	sadr = sadr.replace(/\s+/g,' ');
	sadr = sadr.replace(/^\s+(.*?)/g,'$1');

	var geocoder = new GClientGeocoder();
	
	geocoder.getLatLng(
						   sadr,
						   function(point) {
							   if (!point) {
								   alert(sadr + " not found");
								} else {
									sadr = escape(sadr);
									sadr = sadr.replace('\%0D\%0A','');
									xmlhttp.open("GET", "http://www.toop.com.au/propnav_update_competitor_stop.asp?coords="+point.lat()+", "+point.lng()+"&iindex="+iindex+"&address="+sadr+"&r="+Math.random(),false);
 									xmlhttp.send(null);
									
									shownav();
								}
							}
						);
	
}

function sethomestart3() {
	//if (current.value==''){
		//current.style.backgroundImage='url(../_Images/propertynav/bg_input_start.gif)';
		//return;}
	var sadr = String(document.getElementById('prop_nav_start').value);
	sadr = sadr.replace(/\s+/g,' ');
	sadr = sadr.replace(/^\s+(.*?)/g,'$1');
	sadr = escape(sadr);
	sadr = sadr.replace('\%0D\%0A','');
	alert(sadr);
	xmlhttp.open("GET", "http://www.toop.com.au/propnav_set_home.asp?address="+sadr+"&r="+Math.random(),false);
 	xmlhttp.send(null);
	shownav();
}