/* SEARCH FUNCTIONS */
var win = null;

function CheckSimpleSearch(theForm){

	if (theForm.minprice && theForm.maxprice){
		if (!isNaN(theForm.minprice.value) && !isNaN(theForm.maxprice.value)){
			if (parseInt(theForm.minprice.value) >= parseInt(theForm.maxprice.value)){
				alert('Please select a maximum price higher than the minimum price selected');
				return false;
			}
		}
	}
	
	return true;
}

function EstateWeb_Search_AllAreas(obj){
	if (obj){
		try{
				for(i=1;i<obj.length;i++){
					obj[i].checked = false;
				}
		}catch(e){
		
		}
	}
}

function EstateWeb_Search_Area(obj){
	try{
		obj.checked = false;
	}catch(e){
	
	}
}

function ChangeSimpleSearchOptions(Value, IndicatorField, theForm){

	//Depending on the listing type selected we display different price options
	var groups = 1;
	var group = new Array(groups);
	var group2 = new Array(groups);

	var temp = theForm.minprice;
	var temp2 = theForm.maxprice;

	for (i=0; i<groups+1; i++){
		group[i]=new Array();
		group2[i]=new Array();
	}
	group[0][0]=new Option("No min price","0");
	group[0][1]=new Option("\243100,000","100000");
	group[0][2]=new Option("\243200,000","200000"); 
	group[0][3]=new Option("\243300,000","300000"); 
	group[0][4]=new Option("\243400,000","400000"); 
	group[0][5]=new Option("\243500,000","500000");
	group[0][6]=new Option("\243750,000","750000");
	group[0][7]=new Option("\2431,000,000","1000000");
	group2[0][0]=new Option("No max price ","99999999");
	group2[0][1]=new Option("\243200,000","200000"); 
	group2[0][2]=new Option("\243300,000","300000"); 
	group2[0][3]=new Option("\243400,000","400000"); 
	group2[0][4]=new Option("\243500,000","500000");
	group2[0][5]=new Option("\243750,000","750000");
	group2[0][6]=new Option("\2431,000,000","1000000");
	group2[0][7]=new Option("\2432,000,000","2000000");
	group2[0][8]=new Option("\2435,000,000+","999999999");

	group[1][0]=new Option("No min price","0");
	group[1][1]=new Option("\243100.00","100");
	group[1][2]=new Option("\243200.00","200");
	group[1][3]=new Option("\243300.00","300"); 
	group[1][4]=new Option("\243400.00","400"); 
	group[1][5]=new Option("\243700.00","700");
	group[1][6]=new Option("\2431000.00","1000");
	group2[1][0]=new Option("No max price","99999999");
	group2[1][1]=new Option("\243200.00","200");
	group2[1][2]=new Option("\243300.00","300"); 
	group2[1][3]=new Option("\243400.00","400"); 
	group2[1][4]=new Option("\243700.00","700"); 
	group2[1][5]=new Option("\2431000.00+","999999999");
	

	switch (Value){
		case '6':
			RecalSimpleSearchPriceRanges(1, temp, temp2, group, group2);
			break;
		default:
			RecalSimpleSearchPriceRanges(0, temp, temp2, group, group2);
			break;
	}

}

function RecalSimpleSearchPriceRanges(x, temp, temp2, group, group2){

		for (m=temp.options.length-1;m>0;m--){
			temp.options[m]=null
		}
		for (i=0;i<group[x].length;i++){
			temp.options[i]=new Option(group[x][i].text,group[x][i].value)
		}
		for (m=temp2.options.length-1;m>0;m--){
			temp2.options[m]=null
		}
		for (i=0;i<group2[x].length;i++){
			temp2.options[i]=new Option(group2[x][i].text,group2[x][i].value)
		}
		temp.options[0].selected=true;
		temp2.options[0].selected=true;
	}
	
	
function OpenWindow(url,name,features){

	window.open(url,name,features);
}


function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
	if(win.window.focus){win.window.focus();}
}

function MM_openBrWindow(theURL,winName,features) { //v1.2
	window.open(theURL,winName,features);
}