function checkformadvs(f){
	if(f.t_normal.checked==false && f.t_shared.checked==false && f.t_retirement.checked==false){
		alert("Please select either New homes, Shared ownership homes or Retirement homes to continue");
		return false;
	}
	return true;
}


function ajaxloader(cssselect, url){
	$.ajax({
	  url: url,
	  success: function(data) {
	    $(cssselect).html(data);
	  }
	});
}

function ajaxcheckemail(email){
	if(email=='') return false;
	var html = $.ajax({
	  url: "/includes/dev-view-ajax/checkemail.php?checkemail=" + email,
	  async: false
	});

	if(html.responseText=='OK') return true;
	else if(html.responseText=='FAILED') return false;
	else if(html.responseText=='NOSESSION') alert("Not authorised to use function - check session variables");	
	else if(html.responseText=='') alert("Error checking e-mail address ("+email+").\nPlease click submit again to re-try");
	else alert("Error checking e-mail address:" + html);
}
function checkdigits(strString){
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	var strReturn='';
	
	if (strString.length == 0) return '';
	for (i = 0; i < strString.length; i++){
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) != -1) strReturn+=strChar;
	}
	return strReturn;
}
function checkemail(theform){
	if (!ajaxcheckemail(theform.email.value)){ 
		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, postevent){	// qs is full page to submit to e.g. /map/text_list.php?text_output=shotrlist
	var xmlHttp;
	if(!postevent) postevent='none';
		
	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){
			document.getElementById(divid).innerHTML=xmlHttp.responseText;
			if(postevent=='loadmap') loadmainmap();
			if(postevent=='hidemap') hide_element(document.getElementById('searchfeatures'));
			
			if(qs.indexOf('/search_results.php')==0) postevent='reloadsearchbar';
			if(postevent=='reloadsearchbar') get_div_content('/includes/ajax/searchtabs.php', 'searchtabs');
		}
	}
//	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('/includes/ajax/shortlist.php?add='+dev, 'ajaxupdates');
	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;
	}
}

function checkPhone(strString){
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	var strReturn='';
	
	if (strString.length == 0) return '';
	for (i = 0; i < strString.length; i++){
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) != -1) strReturn+=strChar;
	}
	if(strReturn.length==11) return strReturn;
	else return '';
}

function hide_element(el){
	el.style.display='none';
	el.style.visibility='hidden';
}
function show_element(el){
	el.style.display='block';
	el.style.visibility='visible';
}
function toggle_element(el){
	if(el.style.display=='block') hide_element(el);
	else show_element(el);
}

