
var ajax = new sack();

function getCityList(sel)
{

 	var countryCode = sel.options[sel.selectedIndex].value;
	document.getElementById('secondlevel').options.length = 0;	// Empty city select box
	//document.getElementById('loadingCity').innerHTML = "<img src='images/loading.gif' border=0/> <span style='color:#089CDF;'>City loading...</span>";
	if(countryCode.length>0){
		ajax.requestFile = 'getFiles.php?getDetail=state&countryCode='+countryCode;	// Specifying which file to get
		ajax.onCompletion = createCities;		// Specify function that will be executed after file has been found
		ajax.runAJAX();		// Execute AJAX function
		//document.getElementById('loadingCity').innerHTML = "";
	}
}

function createCities()
{
	var obj = document.getElementById('secondlevel');
	// Executing the response from Ajax as Javascript code
	eval(ajax.response);	
}

function getList(sel)
{

	var countryCode1 = sel.options[sel.selectedIndex].value;
	document.getElementById('thirdlevel').options.length = 0;	// Empty city select box
	//document.getElementById('loadingCity').innerHTML = "<img src='images/loading.gif' border=0/> <span style='color:#089CDF;'>Locality loading...</span>";
	if(countryCode1.length>0){
		ajax.requestFile = 'getFiles.php?getDetail=location&countryCode1='+countryCode1;	// Specifying which file to get
		ajax.onCompletion = createlocal;	// Specify function that will be executed after file has been found
		ajax.runAJAX();		// Execute AJAX function
		//document.getElementById('loadingCity').innerHTML = "";
	}
}
function createlocal()
{
	var obj = document.getElementById('thirdlevel');	
	eval(ajax.response);	// Executing the response from Ajax as Javascript code
}
function others_insert()
{
  var frm = document.property;
  if(frm.thirdlevel.value=='others')
	{
	 
		document.getElementById('other_div').style.visibility = 'visible';
	}
	else
	{
		document.getElementById('other_div').style.visibility = 'hidden';
	}

}

function enableLimit()
{
  var frm = document.quicksearch;
  var selObj_min = document.getElementById('from_min');
  selObj_min.options[0] = new Option('--Budget Min--',0);
  var selObj_max = document.getElementById('to_max');
  selObj_max.options[0] = new Option('--Budget Max--',0);
	
  // Following array used to give min and max amount for rent and sale
  // This is seperated by option name and value

  var min_amount_rent_array = "1,000:1000|5,000:5000|10,000:10000|15,000:15000|20,000:20000|25,000:25000|40,000:40000|75,000:75000|1 Lac:100000";

  var min_amount_sale_array = "< 1 Lac:99999|1 Lac:100000|5 Lacs:500000|10 Lacs:1000000|20 Lacs:2000000|30 Lacs:3000000|40 Lacs:4000000|50 Lacs:5000000|75 Lacs:7500000|1 Crore:10000000";

  var max_amount_rent_array = "5,000:5000|10,000:10000|20,000:20000|30,000:30000|40,000:40000|50,000:50000|75,000:75000|1 Lac:100000|2 Lac:200000|3 Lac:300000|> 5 Lac:500001";

  var max_amount_sale_array = "3 Lacs:300000|5 Lacs:500000|25 Lacs:2500000|50 Lacs:5000000|75 Lacs:7500000|1 Crore:10000000|2 Crore:20000000|3 Crore:30000000|4 Crore:40000000|5 Crore:50000000|> 5 Crores:50000001";

	
	myOption = 2;

	var typeSelValue = frm.propertyCategory.value;
	if(typeSelValue=='R')
		myOption =1;

	if(myOption==2){
		var min_amount_array = min_amount_sale_array.split('|');
		var max_amount_array = max_amount_sale_array.split('|');
		frm.rent.value = 2;
	}else{
		var min_amount_array = min_amount_rent_array.split('|');
		var max_amount_array = max_amount_rent_array.split('|');
		frm.rent.value = 1;
	}

	for(var loop=0;loop<min_amount_array.length;loop++){
		var min_amount_value = min_amount_array[loop].split(':');
		var newOption = new Option(min_amount_value[0],min_amount_value[1]);
		selObj_min.options[loop+1] = newOption;
	}

	for(var loop=0;loop<max_amount_array.length;loop++){
		var max_amount_value = max_amount_array[loop].split(':');
		var newOption = new Option(max_amount_value[0],max_amount_value[1]);
		selObj_max.options[loop+1] = newOption;
	}  
}
function disableMaxBudget(){
	var frm = document.quicksearch;
	if((frm.from_min.value!="") && (frm.from_min.value=="99999")){
		document.getElementById('to_max').disabled=true;
	}
	else{
		//document.getElementById('to_max').enabled=true;
		document.getElementById('to_max').disabled=false;
		
	}
}

function frmQuickSearch()
{
var frm = document.quicksearch;
var cfirstlevel = frm.firstlevel.value;
var csecondlevel = frm.secondlevel.value;
var ctype = frm.propertyCategory.value;
var type_val = frm.property_type.value;
var from_min_value = frm.from_min.value;
if(frm.to_max.disabled==true){
	var to_max_value = "100000";
}
else{
	var to_max_value = frm.to_max.value;
}

 if(ctype <= 0)
    {
        alert('Please Select Category');
        frm.propertyCategory.focus();
        return false;
    }
	if(type_val =='-1')
    {
        alert('Please Select Property Type');
        frm.property_type.focus();
        return false;
    }
	
	if (((to_max_value!= 0) && (from_min_value!= 0))|| ((to_max_value!= '') && (from_min_value!= '')) )
	{
	if(parseInt(to_max_value)<parseInt(from_min_value))
		{
			alert("Maximum budget should be greater than Minimum budget");
			frm.to_max.focus();
			return false;

		}
	}
	
	if(trim(cfirstlevel) == '')
    {
        alert('Please select State');
        frm.firstlevel.focus();
        return false;
    }
	if(trim(csecondlevel) == '')
    {
        alert('Please Select City');
        frm.secondlevel.focus();
        return false;
    }
 frm.submit();
}

