mapIterator = 0;
display = 1;
function hideSelect(){
		if(display == 0){
		
			document.homeSearch.newReleases.style.position = 'absolute'; 
			document.homeSearch.newReleases.style.left = '-9000px';
			document.homeSearch.searchType.style.position = 'absolute'; 
			document.homeSearch.searchType.style.left = '-9000px';
		
			document.homeSearch.searchSuburb.style.position = 'absolute'; 
			document.homeSearch.searchSuburb.style.left = '-9000px';
			
			
		}
}

function showSelect(){
		if(display == 1){
			document.homeSearch.newReleases.style.position = 'relative';
			document.homeSearch.newReleases.style.left = '0px';
			document.homeSearch.searchType.style.position = 'relative'; 
			document.homeSearch.searchType.style.left = '0px';
			document.homeSearch.searchSuburb.style.position = 'relative'; 
			document.homeSearch.searchSuburb.style.left = '0px';
		
		}
}

function switchOff(){
	display = 1;
	hideshow();
}
function switchOn(){
	display = 0;	
	hideshow();
}

function hideshow(){
	hideSelect();
	showSelect();	
}


function setMainImage(image, id){
	bigImage = document.getElementById('mainPic').src;
	document.getElementById('mainPic').src = image;
	document.getElementById('subImage'+id).src = bigImage;
		
}

function emailSearchSimilar(searchType, suburb){
	// rentals or houses
	if(searchType == 1){
		document.location.href='page.php?page=114&section=4&houseid=search&type=quick&suburb='+suburb+'&surrounding=true';
	}else{
		document.location.href='page.php?page=139&section=19&houseid=search&type=quick&suburb='+suburb+'&surrounding=true';
	}		
}

function getSearchType()
{
	for (var i=0; i < document.homeSearch.searchType.length; i++) {
   		if (document.homeSearch.searchType[i].checked) {
      		var val = document.homeSearch.searchType[i].value;
			return val;
      	}
   	}	
}
function getNewReleases()
{
	for (var i=0; i < document.homeSearch.newReleases.length; i++) {
   		if (document.homeSearch.newReleases[i].checked) {
      		var val = document.homeSearch.newReleases[i].value;
			return val;
      	}
   	}	
}

function HomeSearch(type)
{
	
	
	switch(type){
		case 'newRelease':
			value = document.homeSearch.newReleases.options[document.homeSearch.newReleases.selectedIndex].value;
			//var value = getNewReleases();
			if(value == 1){
				document.location.href='page.php?page=114&section=4&houseid=search&type=newRelease&value=1';
			}else{
				document.location.href='page.php?page=139&section=19&houseid=search&type=newRelease&value=2';
			}
		break;
		case 'quick':
			
			 value = document.homeSearch.searchType.options[document.homeSearch.searchType.selectedIndex].value;
			if(document.homeSearch.surrounding.checked == 1){
				surrounding = 'true';	
			}else{
				surrounding = 'false';		
			}
			suburb = document.homeSearch.searchSuburb.options[document.homeSearch.searchSuburb.selectedIndex].value;
			//alert(suburb);return false;
			if(value == 1){
				document.location.href='page.php?page=114&section=4&houseid=search&type=quick&suburb='+suburb+'&surrounding='+surrounding;
			}else{
				document.location.href='page.php?page=139&section=19&houseid=search&type=quick&suburb='+suburb+'&surrounding='+surrounding;
			}
		break;
		case 'webid':
			webid = document.homeSearch.searchWebId.value;
			document.location.href='page.php?page=114&section=4&houseid=search&type=webid&webid='+webid;
		break;
		case 'map':
			document.location.href='page.php?page=114&section=4&map=all';
		break;
	}
	
}

function searcher(type, value)
{
	
	
	switch(type){
		case 'newRelease':
			//newSearchType = document.homeSearch.newReleases.options[document.homeSearch.newReleases.selectedIndex].value;
			var value = getNewReleases();
			if(value == 1){
				document.location.href='page.php?page=114&section=4&houseid=search&type=newRelease&value=1';
			}else{
				document.location.href='page.php?page=139&section=19&houseid=search&type=newRelease&value=2';
			}
		break;
		case 'quick':
			
			//searchType = document.homeSearch.searchType.options[document.homeSearch.searchType.selectedIndex].value;
			var value = getSearchType();
			if(document.homeSearch.surrounding.checked == 1){
				surrounding = 'true';	
			}else{
				surrounding = 'false';		
			}
			suburb = document.homeSearch.searchSuburb.options[document.homeSearch.searchSuburb.selectedIndex].value;
			//alert(suburb);return false;
			if(value == 1){
				document.location.href='page.php?page=114&section=4&houseid=search&type=quick&suburb='+suburb+'&surrounding='+surrounding;
			}else{
				document.location.href='page.php?page=139&section=19&houseid=search&type=quick&suburb='+suburb+'&surrounding='+surrounding;
			}
		break;
		case 'webid':
			webid = document.homeSearch.searchWebId.value;
			document.location.href='page.php?page=114&section=4&houseid=search&type=webid&webid='+webid;
		break;
		case 'map':
			document.location.href='page.php?page=114&section=4&map=all';
		break;
	}
	
}

function loadPropertyByWebId(id)
{
	// <![CDATA[
	var ajax;
	var d = new Date();
	var t = d.getTime(); 	
	$('houseContainer').style.display = 'block';
	ajax =  new Ajax.Updater(
		 'houseContainer',        		// DIV id must be declared before the method was called
		 'ajax/getHouseByWeb.php?id='+id+'&section=details&date='+t,{method:'get',asynchronous:true});
}


function loadRPropertyByWebId(id)
{
	// <![CDATA[
	var ajax;
	var d = new Date();
	var t = d.getTime(); 	
	$('houseContainer').style.display = 'block';
	ajax =  new Ajax.Updater(
		 'houseContainer',        		// DIV id must be declared before the method was called
		 'ajax/getRentalByWeb.php?id='+id+'&section=details&date='+t,{method:'get',asynchronous:true});
}

 function loadGFromList(id, long, lat, image, address, price, suburb, args) { 
 		// <![CDATA[
	
		var ajax;
		var d = new Date();
		var t = d.getTime(); 
		
		//amount = document.calculator.loanAmount.value;
		//rate = document.calculator.interestRate.value;
		//term = document.calculator.loanTerm.value;
		//frequency = document.calculator.repaymentFrequency.options[document.calculator.repaymentFrequency.selectedIndex].value;
		$('houseContainer').style.display = 'block';	
		//alert('amount = ' + amount +'\n' + 'rate = ' + rate +'\n' + 'frequency = ' + frequency); 
		
			
		ajax =  new Ajax.Updater(
			 'houseContainer',        		// DIV id must be declared before the method was called
			 'ajax/getHouse.php?id='+id+'&section=map&date='+t+'&'+args,{
				 method:'get',
				 asynchronous:true,
				 onComplete: function(transport) {
					 loadG(long, lat, image, address, price, suburb);
					 /*var h = $('highlight');
					 var d = $('deadLight');
					 
					 h.id = 'deadLight';
					 d.id = 'highlight';
					 d.className = 'on';
					 h.className = 'off';*/
					 
				 }
			});
		
		
		//$('map').style.display = 'block';
		// ]]>
		
 
 }

function showHouse2(id, section, galleryNum){
	var ajax;
	var d = new Date();
	var t = d.getTime(); 
	ajax = new Ajax.Updater(
		 'houseContainer',        		// DIV id must be declared before the method was called
		 'gallery.php?id='+id+'&section='+section+'&galleryNum='+galleryNum+'&date='+t,{method:'get',asynchronous:true});
}
function showHouseR2(id, section, galleryNum){
	var ajax;
	var d = new Date();
	var t = d.getTime(); 
	ajax = new Ajax.Updater(
		 'houseContainer',        		// DIV id must be declared before the method was called
		 'galleryR.php?id='+id+'&section='+section+'&galleryNum='+galleryNum+'&date='+t,{method:'get',asynchronous:true});
}

function showHouse(id, section, galleryNum, args)
	{
		// <![CDATA[
		var ajax;
		var d = new Date();
		var t = d.getTime(); 
		
		//amount = document.calculator.loanAmount.value;
		//rate = document.calculator.interestRate.value;
		//term = document.calculator.loanTerm.value;
		//frequency = document.calculator.repaymentFrequency.options[document.calculator.repaymentFrequency.selectedIndex].value;
		//$('houseContainer').style.display = 'block';	
		//alert('amount = ' + amount +'\n' + 'rate = ' + rate +'\n' + 'frequency = ' + frequency); 
		switch(section){
			case 'details':
				ajax =  new Ajax.Updater(
				 'houseContainer',        		// DIV id must be declared before the method was called
			 	 'ajax/getHouse.php?id='+id+'&section='+section+'&date='+t+'&'+args,{
					 method:'get',
					 asynchronous:true,
					 onComplete: function(s) {
						 $('houseContainer').show();
					 }
				});
			break;
			case 'gallery':
				myWin = window.open("gallery.php?id="+id+"&section="+section+"&galleryNum="+galleryNum+"&date="+t+'&'+args, 'Gallery', "height=600,width=800,status=yes,toolbar=no,menubar=no,location=no,scrollbars=1");
				try{
				//	myWin.moveTo(0,0);
				}catch(err){
				}
				/*ajax =  new Ajax.Updater(
				 'houseContainer',        		// DIV id must be declared before the method was called
			 	 'ajax/getHouseGallery.php?id='+id+'&section='+section+'&galleryNum='+galleryNum+'&date='+t,{method:'get',asynchronous:true});*/
			break;
			case 'floorplan':
				ajax =  new Ajax.Updater(
				 'houseContainer',        		// DIV id must be declared before the method was called
			 	 'ajax/getHouseFloorplan.php?id='+id+'&section='+section+'&fileNum='+galleryNum+'&date='+t+'&'+args,{
					 method:'get',
					 asynchronous:true,
					 onSuccess: function(s) {
						 $('houseContainer').show();
					 }
			});
			break;
			case 'map':
				ajax =  new Ajax.Updater(
				 'houseContainer',        		// DIV id must be declared before the method was called
			 	 'ajax/getMap.php?id='+id+'&section='+section+'&date='+t+'&'+args,{
					 method:'get',
					 asynchronous:true,
					 onSuccess: function(s) {
						 $('houseContainer').show();
					 }
				});
			break;
			
		}
		// ]]>
	}
	
	function showRental(id, section, galleryNum)
	{
		
		// <![CDATA[
		var ajax;
		var d = new Date();
		var t = d.getTime(); 
		//amount = document.calculator.loanAmount.value;
		//rate = document.calculator.interestRate.value;
		//term = document.calculator.loanTerm.value;
		//frequency = document.calculator.repaymentFrequency.options[document.calculator.repaymentFrequency.selectedIndex].value;
		$('houseContainer').style.display = 'block';	
		//alert('amount = ' + amount +'\n' + 'rate = ' + rate +'\n' + 'frequency = ' + frequency); 
		switch(section){
			case 'details':
				ajax =  new Ajax.Updater(
				 'houseContainer',        		// DIV id must be declared before the method was called
			 	 'ajax/getRental.php?id='+id+'&section='+section+'&date='+t,{method:'get',asynchronous:true});
			break;
			case 'gallery':
				myWin = window.open("galleryR.php?id="+id+"&section="+section+"&galleryNum="+galleryNum+"&date="+t, 'Gallery', "height=600,width=800,status=yes,toolbar=no,menubar=no,location=no,scrollbars=1");
				try{
					//myWin.moveTo(0,0);
				}catch(err){
				}
				/*ajax =  new Ajax.Updater(
				 'houseContainer',        		// DIV id must be declared before the method was called
			 	 'ajax/getRentalGallery.php?id='+id+'&section='+section+'&galleryNum='+galleryNum+'&date='+t,{method:'get',asynchronous:true});*/
			break;
			case 'floorplan':
				ajax =  new Ajax.Updater(
				 'houseContainer',        		// DIV id must be declared before the method was called
			 	 'ajax/getRentalFloorplan.php?id='+id+'&section='+section+'&date='+t,{method:'get',asynchronous:true});
			break;
			case 'map':
				
				ajax =  new Ajax.Updater(
				 'houseContainer',        		// DIV id must be declared before the method was called
			 	 'ajax/getMap.php?id='+id+'&section='+section+'&date='+t,{method:'get',asynchronous:true});
			break;
			
		}
	 	
		// ]]>
	
	}
	
	
	function getSuburb(id){
		var ajax;
		var d = new Date();
		var t = d.getTime(); 
		$('suburbResult').style.display = 'block';	
		//alert('amount = ' + amount +'\n' + 'rate = ' + rate +'\n' + 'frequency = ' + frequency); 
		
	 	ajax =  new Ajax.Updater(
			 'suburbResult',        		// DIV id must be declared before the method was called
			 'ajax/getSuburb.php?id='+id+'&date='+t,{method:'get',asynchronous:true});
		// ]]>	
	}
	
	function getSuburbByName(name){
		var ajax;
		var d = new Date();
		var t = d.getTime(); 
		$('suburbResult').style.display = 'block';	
		//alert('amount = ' + amount +'\n' + 'rate = ' + rate +'\n' + 'frequency = ' + frequency); 
		
	 	ajax =  new Ajax.Updater(
			 'suburbResult',        		// DIV id must be declared before the method was called
			 'ajax/getSuburbByName.php?suburbName='+name+'&date='+t,{method:'get',asynchronous:true});
		// ]]>	
	}
	
	function backToList(){
		s = new String(self.location);
		if(s.indexOf("&pageUp") > 0){
			s = s.substring(0, s.indexOf("&pageUp"));
			self.location = s.toString()+"&samePage=true";		
		}else{
			self.location = s = s.substring(0, s.indexOf("#"));
		}
	}
	

function emailIt(){
		document.getElementById("emailIt").style.display = "block";
	}	
	
	function closeEmailIt(){
		document.getElementById("emailIt").style.display = "none";
	}
	
	function closeEmailIt2(){
		document.getElementById("emailIt2").style.display = "none";
	}
	
	function checkEmailForm(theform){
		fields = "";
		valid = true;
		
		if(theform.recipientName.value == ""){
			fields += "Name\n";
			valid = false;
		}
		if(theform.recipientEmail.value == ""){
			fields += "Email\n";
			valid = false;
		}
		if(valid == false){
			message = "Please fill in the following fields\n";
			message += "--------------------------------------\n";
			message += fields;
			alert(message);
			return(false);
		}else{
			return(true);
		}	
	}
	
	
	function checkForm(theform){
		fields = "";
		valid = true;
		
		if(theform.name.value == ""){
			fields += "Name\n";
			valid = false;
		}
		if(theform.email.value == ""){
			fields += "Email\n";
			valid = false;
		}
		/*if(theform.phone.value == ""){
			fields += "Phone\n";
			valid = false;
		}*/
		if(theform.message.value == ""){
			fields += "Message\n";
			valid = false;
		}	
		
		if(valid == false){
			message = "Please fill in the following fields\n";
			message += "--------------------------------------\n";
			message += fields;
			alert(message);
			return(false);
		}else{
			return(true);
		}
		
	}
	
function ValidateForm(me) {
   myerr = 'Please Ensure the HIGHLIGHTED fields are filled in.'+ unescape('%0D%0A')+ unescape('%0D%0A')
   retval = true;
   
   if(me.name.value=='') {
	  me.name.style.backgroundColor='#ffae4e';
	  retval = false;
   }
   
   if(me.email.value=='') {
	  me.email.style.backgroundColor='#ffae4e';
	  retval = false;
   }
   
   if(me.message.value=='') {
	  me.message.style.backgroundColor='#ffae4e';
	  
	  retval = false;
   }
	 
   if(!retval){
	 //alert(myerr);
	 document.getElementById('importantmsg').style.display="block";	 
   }
   return retval;
}



    //<![CDATA[

    function loadG(long, lat, image, address, price, suburb) { 
		
	  // disabled for testing
	// return;
		if($('deadLight')){
		  $('deadLight').className = "on";
		  if($('highlight')) {
		  	$('highlight').className = "off";
		  }
		  if($('deadImage')){
		  	$('deadImage').style.display = "none";
		  }
		  if($('deadImage1')){
		  	$('deadImage1').style.display = "none";
		  }
		}
	  if($('deadImage2')){
	   	$('deadImage2').style.display = "inline";
	  }
	  if($('mapToggle')){
	 	 $('mapToggle').style.display = "block";
	  }
	  if($('mapToggle1')){
	 	 $('mapToggle1').style.display = "block";
	  }
	 if($('nonMap1')){
	 	 $('nonMap1').style.display = "none";
	  }
	  if($('nonMap2')){
	  	$('nonMap2').style.display = "none";
	  }
	  if($('nonMap3')){
	 	 $('nonMap3').style.display = "none";
	  }
	  if($('nonMap4')){
		$('nonMap4').style.display = "none";  
	  }
	  if($('nonMap5')){
		$('nonMap5').style.display = "none";  
	  }
	   if($('nonMapb1')){
	 	 $('nonMapb1').style.display = "block";
	  }
	  if($('nonMapb2')){
	  	$('nonMapb2').style.display = "none";
	  }
	  if($('nonMapb3')){
	 	 $('nonMapb3').style.display = "none";
	  }
	   if($('nonMapc1')){
	 	 $('nonMapb1').style.display = "block";
	  }
	  if($('nonMapc2')){
	  	$('nonMapc2').style.display = "none";
	  }
	  if($('nonMapc3')){
	 	 $('nonMapc3').style.display = "none";
	  }
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(long, lat), 13);
		var point = new GLatLng(long, lat);
		
		map.addOverlay(createMarker(point, 1, image, address, price, long, lat, suburb));
      }
    }
	
	
	 //<![CDATA[

    function loadGJock() { 
		
	 
	
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map2"));
		map.addControl(new GSmallMapControl());
		//map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(-34.927776798290914, 138.63010168075562), 16);
		var point = new GLatLng(-34.927776798290914, 138.63010168075562);
		var marker = new GMarker(point);
		map.addOverlay(marker);
		
		GEvent.addListener(map, 'click', function(overlay, point) {
			//document.write(point.y);
			//document.write('<>'+point.x);
		});	
      }
	  
    }
	
	
	
   


	function moveG(long, lat, zoom, image, address, price, suburb, webid){
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(long, lat), zoom);	
		//map.openInfoWindow(map.getCenter(),document.createTextNode("Hello, world"));
		mapIterator++;
		
		 var point = new GLatLng(long, lat);
		 if(mapIterator % 2 == 0){
			map.addOverlay(createMarker(point, 1, image, address, price, long, lat, suburb, webid));	 
		 }else{
			map.addOverlay(createMarker2(point, 1, image, address, price, long, lat, suburb, webid));	 	 
		 }
		 
		
	}
	
	function createMarker(point, number, image, address, price, longitude, latitude, suburb, webid) {
	  var marker = new GMarker(point);
	  GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml("<div style=\"color:#000000;\"><table><tr><td><img width=\"120px\" src=\""+image+"\" /></td><td><p style=\"padding-left:7px;\"><b>"+suburb+"</b><br /></p><p><a href=\"page.php?page=114&section=4&webid="+webid+"&houseid=search&type=webid\">Details</a><br /><a onclick=\"moveG("+longitude+", "+latitude+", 17, '"+image+"', '"+price+"', '"+suburb+"')\" href=\"#\">Zoom In</a></p></td></tr></table><br /></div>");
	  });
	  return marker;
	}
	
	function createMarker2(point, number, image, address, price, longitude, latitude, suburb, webid) {
	  var marker = new GMarker(point);
	  GEvent.addListener(marker, "click", function() {
	  marker.openInfoWindowHtml("<div style=\"color:#000000;\"><table><tr><td><img width=\"120px\" src=\""+image+"\" /></td><td><p style=\"padding-left:7px;\"><b>"+suburb+"</b><br /></p><p><a href=\"page.php?page=114&section=4&webid="+webid+"&houseid=search&type=webid\">Details</a><br /><a onclick=\"moveG("+longitude+", "+latitude+", 13, '"+image+"', '"+price+"', '"+suburb+"', '"+webid+"')\" href=\"page.php?page=157&section=28&map=all\">Zoom Out</a></p></td></tr></table><br /></div>");
	  });
	  return marker;
	}
	
	
