//ENLARGE IMAGES
function enlargeImage(width, height, image) {
	var newWindow=window.open('includes/enlarge.inc.php?image='+image, 'image', 'width='+width+', height='+height+', scrollbars=no');
	//var newWindow=window.open('images/properties/enlargements/'+image+'.jpg', 'image', 'width='+width+', height='+height+', scrollbars=no');
	newWindow;
}

//VALIDATE SEARCH
function validateSearch() {
	var empty="";
	var sector=document.getElementById("sector");
	/*var type=document.getElementById("type");
	var area=document.getElementById("area");
	var size=document.getElementById("size");
	if((sector.value=="0")&&(type.value=="0")&&(size.value=="0")&&(area.value=="0")) {
		alert("Please select some search options\n");
		return false;
	}else{
		return true;
	}*/
	if(sector.value=="0") {
		alert("Please select a sector for you search\n");
		return false;
	}else{
		return true;
	}
	
}

//This is all the AJAX stuff

var req;
var url;
function Initialize()
	{
    try
    	{
        req=new ActiveXObject("Msxml2.XMLHTTP");
    	}
    catch(e)
    	{
        try
       	 {
            req=new ActiveXObject("Microsoft.XMLHTTP");
        	}
        catch(oc)
        	{
            req=null;
        	}
    	}

    if(!req&&typeof XMLHttpRequest!="undefined")
    	{
        req= new XMLHttpRequest();
		}	
	}

function Sector(div, include, key, type)
    {
    Initialize();
	var url="includes/"+include+".inc.php?sector="+key+"&div="+div+"&type="+type+"&include="+include;
    if(req!=null)
    	{
		/*window.alert("page doesn't exist!");*/
        req.onreadystatechange = function ()
			{
			if (req.readyState == 4) 
				{
				// only if "OK"
					if (req.status == 200) 
					{
						document.getElementById(div).innerHTML =req.responseText;
					}
					else 
						{
						document.getElementById(div).innerHTML=
							"There was a problem retrieving data:<br />"+req.statusText;
						}
				}
			}
        req.open("GET", url, true);
        req.send(null);
    	}
	}
	
function Refine(div, include, key, type)	{
		Initialize();
		var url="includes/"+include+".inc.php?sector="+key+"&div="+div+"&type="+type+"&include="+include;
		if(req!=null) {
			req.onreadystatechange = function () {
				if (req.readyState==4) {
					if(req.status==200) {
						document.getElementById(div).innerHTML=req.responseText;
					}else{
						document.getElementById(div).innerHTML="There was a problem retrieving data:<br />"+req.statusText;
					}
				}
			}
			req.open("GET", url, true);
			req.send(null);
		}
}
	
function validateForm(formName) {
	var emptyFields="";
	
	//CHECK FORM FOR REQUIRED INPUTS
	var inputs = document.forms[formName].getElementsByTagName("input");
	var textareas = document.forms[formName].getElementsByTagName("textarea");
	var selects = document.forms[formName].getElementsByTagName("select");
	
	//LOOP THROUGH INPUTS
	for(var i=0; i<inputs.length; i++) {
			//FIND THE CLASS NAME
			if(inputs[i].className=="mand") {
				//IS THE MANDATORY FIELD EMPTY
				if(inputs[i].value=="") {
					//HIGHLIGHT REQUIRED EMPTY FIELD
					inputs[i].style.border="1px solid #cf4c4c";
					inputs[i].style.background="#f2e8e6";
					emptyFields="Y";
				}else{
					inputs[i].style.border="1px solid #a5acb2";
					inputs[i].style.background="#fff";
				}
			}
	}
	
	//LOOP THROUGH TEXTAREAS
	for(var i=0; i<textareas.length; i++) {
			//FIND THE CLASS NAME
			if(textareas[i].className=="mand") {
				//IS THE MANDATORY FIELD EMPTY
				if(textareas[i].value=="") {
					//HIGHLIGHT REQUIRED EMPTY FIELD
					textareas[i].style.border="1px solid #cf4c4c";
					textareas[i].style.background="#f2e8e6";
					emptyFields="Y";
				}else{
					textareas[i].style.border="1px solid #a5acb2";
					textareas[i].style.background="#fff";
				}
			}
	}
	
	//LOOP THROUGH SELECTS
	for(var i=0; i<selects.length; i++) {
			//FIND THE CLASS NAME
			if(selects[i].className=="mand") {
				//IS THE MANDATORY FIELD EMPTY
				if(selects[i].value=="0") {
					//HIGHLIGHT REQUIRED EMPTY FIELD
					selects[i].style.border="1px solid #cf4c4c";
					selects[i].style.background="#f2e8e6";
					emptyFields="Y";
				}else{
					selects[i].style.border="1px solid #a5acb2";
					selects[i].style.background="#fff";
				}
			}
	}
	
	//ALERT EMPTY FIELDS
	if(emptyFields) {
		document.getElementById("error").style.display="block";
		return false;
	}else{
		return true;
	}
	
}