	var currentphoto=0;
	var map;
 
	function searchagain()
	{
		var url;
	 
		url="results.php?proptype="+$("proptype").value+"&locale="+$("locale").value+"&";
		url=url+"minprice="+$("minprice").value+"&maxprice="+$("maxprice").value;
		url=url+"&minbeds="+$("minbeds").value+"&limit="+$("limit").value+"&page=1";
		url=url+"&order="+$("order").value;
	 
		if($("includesa").checked==true)
		   url=url+"&includesa=on";
	 
		window.location=url;
	}
   
	function areapop()
	{
		pop=window.open("areas.php","","width=550,height=320,scrollbars=yes");
	}
 
	function current(img)
	{
		currentphoto=img;
	}
	
	function changephoto(dir)
	{     
		var url="prt.nextphoto.php?dir="+dir+"&pid="+currentphoto;
		new Ajax.Request(url,{onSuccess: 
		function(transport) 
		{  
			//reset to defaults
			$('thephoto').style.display="none";
			$('propphoto').style.display="none";
			$('thephoto').style.paddingTop="0px";
			$('thephoto').style.paddingBottom="0px";
			$('thephoto').style.height="200px";
		  
			// response will come in photoid;url;caption;height form 
			var fieldarray=transport.responseText.split(";");
			currentphoto=fieldarray[0];
			 
			// calculate the necessary top padding to maintain aspect ratio/correct letterboxing
			if(fieldarray[3]<200)
			{
				$('thephoto').style.paddingTop=Math.ceil((200-fieldarray[3])/2)+"px";
				$('thephoto').style.paddingBottom=Math.ceil((200-fieldarray[3])/2)+"px";
				$('thephoto').style.height=(200-Math.ceil((200-fieldarray[3])))+"px";
			}       
				
			$('propphoto').src=fieldarray[1];
			$('propphoto').alt=fieldarray[2];
			$('propphoto').title=fieldarray[2];
			$('thephoto').style.display="block";
			Effect.Appear("propphoto",{duration: 0.3});
		}});  
	}
   
	function success(t)
	{
		alert(t.responseText);
	}
	
	function enlargephoto()
	{      
		Effect.Fade("propinfo",{from:1, to:0.3, duration: 0.5, afterFinish: 
		function()
		{
			$('largephoto').style.display="block";
			$('propinfo_overlay').style.display="block";
			$('overlayheadingtext').innerHTML="Loading...";
			
			
			var photos=document.getElementsByClassName("photonav");
			for(i=0;i<photos.length;i++) 
			{
				photos[i].style.fontWeight="normal";
				photos[i].style.backgroundImage="url(img/blank.png)"; 
			}
			
			new Ajax.Request("prt.largephoto.php?phid="+currentphoto,{evalJSON: 'true', onSuccess:
			function(transport)
			{
				var data=transport.responseJSON;				
				var height=parseInt(data.height);
				var width=parseInt(data.width);

				if(height>width)
				{
					$('photoholder').style.paddingTop=Math.ceil((400-height)/2)+"px";
					$('photoholder').style.paddingBottom=Math.ceil((400-height)/2)+"px";
				}
				else
				{
					$('photoholder').style.paddingTop="0px";
					$('photoholder').style.paddingBottom="0px";        
				}
		   
			   $('photoholder').innerHTML="<img src='"+data.path+"' title='"+data.caption+"' alt='"+data.caption+"' />";
			   $('overlayheadingtext').innerHTML=data.caption;
			   $('photo'+data.id).style.fontWeight="bold";  
			   $('photo'+data.id).style.backgroundImage="url(img/picnavbg.png)";     
			}});
		}});
	}
	
	function validatemailing()
	{
		var fields="sn,a1,twn,c,pc,cno,em";
		var fieldlist=fields.split(",");
		var errors=0;
		
		//check for empty fields
		for(var i=0; i<fieldlist.length; i++)
		{  
			$('b'+fieldlist[i]).style.color="black";
			if($(fieldlist[i]).value=="" || $(fieldlist[i]).value==null)
			{
				$('b'+fieldlist[i]).style.color="red";
				errors++;
			}
		}
	   
		//check email address is ok
		if(!$('em').value.match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"))
		{
			$('bem').style.color="red";
			errors++;
		} 
	   
		if($('em').value!=$('em2').value)
		{
			$('bem').style.color="red";
			$('bem2').style.color="red";
			errors++;      
		}
	   
		//check at least one checkbox is checked for area
		var checkboxes=document.getElementsByClassName('check_box1');
		var count=0;
		for(i=0; i<checkboxes.length; i++)
		{
			if($(checkboxes[i]).checked==true)
				count++;
		}
	   
		if(!count)
		{
			$('barea').style.color="red";
			errors++;
		}
		else
			$('barea').style.color="black";
	   
		// same again for proptypes
		checkboxes=document.getElementsByClassName('check_box2');
		count=0;
		for(i=0; i<checkboxes.length; i++)
		{
			if($(checkboxes[i]).checked==true)
				count++;
		}
	   
		if(!count)
		{
			$('btypes').style.color="red";
			errors++;
		} 
		else
			$('btypes').style.color="black";    
		
		if(!errors)
		{
			$('frm').action="do.addapplicant.php";
			$('frm').submit();
		}
	}
	
	function mailingprices()
	{
		if($('rob').value=='1')
		   new Ajax.Updater('pricediv','prt.pricediv.php'); 
		else
		   new Ajax.Updater('pricediv','prt.pricediv.php?t=1');
	}
	
	// mapping functions
	function clearmap()
	{
		map.DeleteRoute();
		map.DeleteAllPushpins();
		map.DeleteAllPolylines();
		map.DeleteAllPolygons();
		map.Clear();
	}
	  
	function openmap(pc,ptitle,pdetails,pimg,olat,olong,oname,odesc,oimg)
	{
		Effect.Fade("propinfo",{from:1, to:0.3, duration: 0.5, afterFinish: 
		function()
		{
			$('overlayheadingtext').innerHTML="Map to "+ptitle+" relative to "+oname;
			$('propinfo_overlay').style.display="block";
			$('map').style.display="block";
			map = new VEMap('map');
			map.SetDashboardSize(VEDashboardSize.Small);
			map.LoadMap(null, 18,'r',false);
			map.Find(null,pc+" (postcode), United Kingdom",null,null,null,null,null,null,null,null,function(a,b,result,d,e)
			{
				var proplatlong=result[0].LatLong;
				var olatlong=new VELatLong(olat,olong);
	
				var proppin=map.AddPushpin(proplatlong);
				proppin.SetTitle(ptitle);
				proppin.SetDescription(pdetails);
				proppin.SetPhotoURL(pimg);	
	
				
				var opin=map.AddPushpin(olatlong);
				opin.SetTitle(oname);
				opin.SetDescription(odesc); 
				opin.SetPhotoURL(oimg);
				opin.SetCustomIcon("<span><img src='img/officepin.png' /></span>"); 
				
				map.SetMapView([olatlong,proplatlong]);  
			});
		}});    
	}
	
	function changelargephoto(phid)
	{
		var photos=document.getElementsByClassName("photonav");
		for(i=0;i<photos.length;i++) 
		{
			photos[i].style.fontWeight="normal";
			photos[i].style.backgroundImage="url(img/blank.png)"; 
		}
		  
		$('overlayheadingtext').innerHTML="Loading...";
		
		new Ajax.Request("prt.largephoto.php?phid="+phid,{evalJSON: 'true', onSuccess:
		function(transport)
		{
			var data=transport.responseJSON;				
			var height=parseInt(data.height);
			var width=parseInt(data.width);

			if(height>width)
			{
				$('photoholder').style.paddingTop=Math.ceil((400-height)/2)+"px";
				$('photoholder').style.paddingBottom=Math.ceil((400-height)/2)+"px";
			}
			else
			{
				$('photoholder').style.paddingTop="0px";
				$('photoholder').style.paddingBottom="0px";        
			}
	   
		   $('photoholder').innerHTML="<img src='"+data.path+"' title='"+data.caption+"' alt='"+data.caption+"' />";
		   $('overlayheadingtext').innerHTML=data.caption;
		   $('photo'+data.id).style.fontWeight="bold";  
		   $('photo'+data.id).style.backgroundImage="url(img/picnavbg.png)";     
		}});    
	}
	
	function closemap()
	{
		map=null;
		$('map').style.display="none";
		$('largephoto').style.display="none";
		$('propinfo_overlay').style.display="none";
		Effect.Appear("propinfo",{from:0.3, to:1, duration: 0.5, afterFinish: 
		function()
		{
		   $('propinfo').style.opacity=1;
		}}); 
	}
 
 
