function checkemail(theform){
	if ((theform.email.value == "") || (theform.email.value.indexOf('@') == -1) || (theform.email.value.indexOf('.') == -1)){ 
		alert("_____________________________\n\nPlease enter a valid e-mail address\n_____________________________");
		return false;
	}else return true;
}

function openalertpopup(temail){
	if ((temail == "") || (temail.indexOf('@') == -1) || (temail.indexOf('.') == -1)) 
		alert("Please enter a valid email address and click go again");
	else
		loadtipopup('/my-account/register-alerts.php?email=' + temail); 
	return false;
}

function openshortlistpopup(temail){
	if ((temail == "") || (temail.indexOf('@') == -1) || (temail.indexOf('.') == -1)) 
		alert("Please enter a valid email address and click go again");
	else
		loadtipopup('/my-account/register-shortlist.php?email=' + temail); 
	return false;
}

function set_searchtype(st){
	window.href.location=st + '&t=' + document.getElementById('t').value;
}

function checkminiregform(theform) {
	missinginfo = "";
	if ((theform.email.value == "") || (theform.email.value.indexOf('@') == -1) || (theform.email.value.indexOf('.') == -1)) 
		missinginfo += "\n     :  E-mail address";

	if(theform.password.value == '') 
		missinginfo += "\n     :  Password";

	if(theform.password.value != theform.password2.value) 
		missinginfo += "\n     :  Passwords must match";


	if (missinginfo != "") {
		missinginfo ="_____________________________\n" + "The following fields have not been entered correctly:\n" + missinginfo  + "\n_____________________________" + "\nPlease click the OK button and re-enter details";

		alert(missinginfo);
		return false;
	}else
		return true;
}
function setsessionvar(redirect, new_window){
	var xmlHttp;
	try{  // Firefox, Opera 8.0+, Safari  
		xmlHttp=new XMLHttpRequest();  
	}
	catch (e){  // Internet Explorer  
		try	{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
		}
		catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!"); 
				document.location.href='?noreglay=1';     
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
//			alert(xmlHttp.responseText + '\nRedirecting to ' + redirect);
			if(redirect!=''){
				if(new_window==1){
					window.open(redirect, '', '');
					document.location.reload();
				}else{
					document.location.href=redirect;
				}
			}				
		}
	}
	
//	alert("Making a request");
	xmlHttp.open("GET", "/supress_popup.php",true);
	xmlHttp.send(null);	
}

function get_div_content(qs, divid){	// qs is full page to submit to e.g. /map/text_list.php?text_output=shotrlist
	var xmlHttp;
		
	try{  // Firefox, Opera 8.0+, Safari  
		xmlHttp=new XMLHttpRequest();  
	}
	catch (e){  // Internet Explorer  
		try	{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
		}
		catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");      
				return false;      
			}
		}
	}
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
//			alert("content updated");
			document.getElementById(divid).innerHTML=xmlHttp.responseText;
		}
	}
//	alert("Making a request");
	xmlHttp.open("GET",qs,true);
	xmlHttp.send(null);		
}

function check_gmap_compatible(){
	if (GBrowserIsCompatible()) {
		return true;
	}else{
		alert("Sorry, your browser is not compatible with the google map features used in this site.\nIt might be possible to upgrade your browser via the website appropriate to your operating system.\n(e.g. apple.com or microsoft.com)");
	}
}

function moveup (map) { 
	map.panBy(new Point (0,-100)); // (x,y) 
} 
function movedown (map) { 
	map.panBy(new Point (0,100)); // (x,y) 
} 
function moveleft (map) { 
	map.panBy(new Point (-100,0)); // (x,y) 
} 
function moveright (map) { 
	map.panBy(new Point (100,0)); // (x,y) 
} 
function zoomin (map) { 
	map.setZoom(map.getZoom()+1); // (level:Number) 
} 
function zoomout (map) { 
	map.setZoom(map.getZoom()-1); // (level:Number) 
}

function addBookmark(title, url) {
	if (window.sidebar) { // firefox
		window.sidebar.addPanel(title, url, "");
	} else if( document.all ) { //MSIE
		window.external.AddFavorite(url,title);
	} else {
		alert("Sorry, your browser doesn't support this - please add the bookmark manually");
	}
}

function sl(dev){
	get_div_content('/search_results.php?add='+dev, 'aj_area');
	alert("This development has been added to your shortlist");
}

function change_devdiv(devdiv, bcol){
	if (document.all){
		var thestyle=eval('document.all.' + devdiv +'.style');
		thestyle.backgroundColor=bcol;
 	}
}

var isvis=0;

function makemultienqvis(){
	document.getElementById('slenquiryform').className='vis';
	
	document.getElementById('multienquirylink').innerHTML='';
//	isvis=1;

	$(function() {
		
		$('#visiting_date').datepicker({
            skin : "dmxCalendar",
            dateFormat : "D, d M yy",
            showStatus : false,
            numberOfMonths : [1,1],
            showAnim : "slide",
            showOptions : 
            {
              easing : "linear",
              direction : "up",
              mode : "show"
            },
            duration : "fast",
            showOn : "both",
            buttonImage : "/Styles/dmxCalendar/calendar_icon.gif",
            buttonImageOnly : true,
            prompt : "",
            highlightWeek : true,
            showOtherMonths : true,
            maxDate : "+2m",
            minDate : "+1",
            defaultDate : '',
            closeAtTop : false
        });
	})
}
/* new Date('<?=$_POST[visiting_date]?>') */
function checkmultienquiryform(theform) {

//alert("temporary overide");
//return true;

	missinginfo = "";
	if (theform.cust_name.value == "")
		missinginfo += "\n     :  Name";

	if(theform.cust_address.value == "") 
		missinginfo += "\n     :  Address";


	if ((theform.cust_email.value == "") || (theform.cust_email.value.indexOf('@') == -1) || (theform.cust_email.value.indexOf('.') == -1)) 
		missinginfo += "\n     :  E-mail address";

	// go through form elements if class="checkbox" / name=enq[] / id starts "enquirytype_" then one should be ticked.
	var enqtypechecked=false;
	for(i=0; i<theform.elements.length; i++){
		if(theform.elements[i].type == "checkbox"){
			if(theform.elements[i].name=='enquirytype[]' && theform.elements[i].checked){
				enqtypechecked=true;
//				alert(theform.elements[i].name + " | " + theform.elements[i].id + " | " + theform.elements[i].value);
			}
		}
	}	
	// if none ticked and no viewing request date
	if(!enqtypechecked && theform.visiting_date.value == "") 
		missinginfo += "\n     :  Please select an enquiry type or enter a viewing date";


	if (missinginfo != ""){
		missinginfo ="_____________________________\n" + "The following fields have not been entered correctly:\n" + missinginfo  + "\n_____________________________" + "\nPlease click the OK button and re-enter details";

		alert(missinginfo);
		return false;
	}else{
		return true;
	}
}