// cities for realestate
var Cities = new Array("0$Select City",
						"4$Ahmedabad",
						"2$Bangalore",
						"10$Chandigarh",
						"1$Chennai",
						"9$Cochin",
						"6$Delhi",
						"5$Hyderabad",
						"7$Kolkata","13$Kottayam",
						"3$Mumbai",
						"8$Pune","12$Trivandrum");	
						
// cites for property rates
var newCities = new Array("0$Select City",
						//"4$Ahmedabad",
						"2$Bangalore",
						//"10$Chandigarh",
						"1$Chennai",
						//"9$Cochin",
						"6$Delhi",
						"5$Hyderabad",
						"7$Kolkata",
						"3$Mumbai");
						//"8$Pune");	

// property types
var Properties = new Array("0$Select Property","d$Residential",
							//"2$Any",
							"3$Apartments",
							"4$Individual House",
							"5$Bungalow",
							"6$Villa",
							"7$Hostel",
							"8$Guest House",
							"9$Rowhouse",
							"10$Land",
							"11$Roommates/PG",
							"12$Holiday Home",
							"d$Commercial",
							//"14$Any",
							"15$Retail Space",
							"16$Office Space",
							"17$Warehouse/Godown",
							"18$Marriage/Exhibition Halls",
							"d$Others",
							//"20$Any",
							"21$Industrial Property",
							"22$Farm",
							"23$Agricultural Land");

// area
var Area = new Array("0$Select",
						"1$Acres",
						"2$Grounds",
						"3$Hectares",
						"4$Sq Feet",
						"5$Sq Yards",
						"6$Sq Meters",
						"7$Cents");
// bedroom types
var Bedrooms = new Array("0$Select",
						"1$1",
						"2$2",
						"3$3",
						"4$4",
						"5$more"
						);	
// bathroom types
var Bathrooms = new Array("0$Select",
						"1$1",
						"2$2",
						"3$3",
						"4$4",
						"5$more"
						);	
var Parking = new Array("0$Select",
				"1$Doesn't Matter",
				"2$Space for 1 car",
				"3$Space for 2 cars",
				"4$Space for 2 or more cars",
				"5$Parking for 2-wheeler",
				"6$Garage space for 1 car", 
				"7$Garage space for 2 cars",
				"8$Garage space for 2+ cars",
				"9$Unlimited parking space")
				
function trim(s)
{
	s =  s.replace( /^\s*/, "" );
	s =  s.replace( /\s*$/, "" );
	return s;
}


function validateEmail(src)
{
	if(src.indexOf(',') != -1 || src.indexOf(';')  != -1 || src.indexOf(' ')  != -1 || src.indexOf(':')  != -1)
	{
		return false;
	}
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp(emailReg);
	return regex.test(src);
}

//function to check for blank values, display alert /set the focus/remove the invalid data  - if required, 
function CheckForEmpty(objItem,strAlertText,blnClear,blnFocus)
{
	if(trim(objItem.value)=="")
	{
		ShowAlert(objItem,strAlertText,blnClear,blnFocus)
		return false;
	}
	return true;
}

function ShowAlert(objItem,strAlertText,blnClear,blnFocus)
{
	if(trim(strAlertText)!="")
	{	
		alert(strAlertText);
	}
	if(blnClear)
	{
		objItem.value="";
	}
	if(blnFocus)
	{
		objItem.focus();
	}
}

//function to check for max len, spl chars 
function CheckForSplCharAndMaxLength(objItem,intMinLength,intMaxLength,strMaxText,blnClear,blnFocus,strInvalidSplChar,strInvalidText)
{
	var strValue=objItem.value;
	
	if(trim(strValue)!="")
	{
		if(strValue.length>intMaxLength || strValue.length<intMinLength)
		{
			ShowAlert(objItem,strMaxText,blnClear,blnFocus);
			return false;
		}
	}
	if(trim(strValue)!="" && strInvalidSplChar != "")
	{
		for(var intSplChar=0; intSplChar<strInvalidSplChar.length; intSplChar++)
		{
			if(strValue.indexOf(strInvalidSplChar.charAt(intSplChar))!=-1)
			{
				ShowAlert(objItem,strInvalidText,blnClear,blnFocus);
				return false;
			}
		}
		
	}
	return true;
}

//function to check for numeric values, display alert /set the focus/remove the invalid data  - if required, 
//also checks for min & max value
function CheckForNumber(objItem,strAlertText,blnClear,blnFocus,dblMinValue,dblMaxValue,strMinText,strMaxText)
{
	if(CheckForEmpty(objItem,strAlertText,blnClear,blnFocus)==false)
	{
		return false;
	}
	var dblValue=objItem.value;
	if(isNaN(dblValue))
	{
		ShowAlert(objItem,strAlertText,blnClear,blnFocus);
		return false;
	}
	if (dblValue<dblMinValue)
	{
		alert(strMinText);
		objItem.focus();
		return false;
	}
	if (dblValue>dblMaxValue)
	{
		alert(strMaxText);
		objItem.focus();
		return false;
	}
	return true;
}

// cities -  city drop down name
function populatecities(cities)
{
	for(i=0;i<Cities.length;i++)
	{
		document.getElementById(cities).options[i] = new Option(Cities[i].split("$")[1], Cities[i].split("$")[0]);
	}
}


// properties -  property drop down name
function populatepropertype(properties)
{
	for(i=0;i<Properties.length;i++)
	{	
		document.getElementById(properties).options[i] = new Option(Properties[i].split("$")[1], Properties[i].split("$")[0]);
		if (Properties[i].split("$")[0] == 'd')
		{
			document.getElementById(properties).options[i].disabled=true;
		}
	}
}

// properties -  property drop down name
function GroupPropertiesInSelect(objTD,objSelectAttribs)
{
var sOpts="";
for(i=0;i<Properties.length;i++)
{	
if(Properties[i].split("$")[0]!='d'){sOpts+="<option value="+Properties[i].split("$")[0]+">"+Properties[i].split("$")[1]+"</option>";}
else{if(i==1){sOpts+="<optgroup label="+Properties[i].split("$")[1]+">";}
else{sOpts+="</optgroup><optgroup label="+Properties[i].split("$")[1]+">";}}}
document.getElementById(objTD).innerHTML="<select "+objSelectAttribs+">"+sOpts+"</optgroup></select>";
}

// bedrooms - bedroom drop down name
function populatebedrooms(bedrooms)
{
	for(i=0;i<Bedrooms.length;i++)
	{	
		document.getElementById(bedrooms).options[i] = new Option(Bedrooms[i].split("$")[1], Bedrooms[i].split("$")[0]);
		}
}

// bathrooms - bathroom drop down name
function populatebathrooms(bathrooms)
{
	for(i=0;i<Bathrooms.length;i++)
	{	
		document.getElementById(bathrooms).options[i] = new Option(Bathrooms[i].split("$")[1], Bathrooms[i].split("$")[0]);
		}
}

// parking - parking drop down name
function populateparking(parking)
{
	for(i=0;i<Parking.length;i++)
	{	
		document.getElementById(parking).options[i] = new Option(Parking[i].split("$")[1], Parking[i].split("$")[0]);
		}
}

// price - min/max drop down name
function populateprice(price)
{
	document.getElementById(price).options[0] = new Option("Select",0);
	document.getElementById(price).options[1] = new Option("5 Thousand",1);
	document.getElementById(price).options[2] = new Option("10 Thousand",2);
	var index=3;
	var i = 200000;
	var j= 10;
	var str="";
	do
	{
		if (j<100)
		{
			j = j + 10;
			if (j<100)
				str = j + " Thousand";
			else
			{
				str = "1 Lakh";
				t=1;
			}
		}
		else if ((j>=100)&&(j<10000))
		{
			j=j+50;
			if (j<10000)
				str = j / 100 +  " Lakhs";
			else
				str = j / 10000 +  " Crore";
		}
		else if (j>=10000)
		{
			j=j+10000;
			str = j / 10000 + " Crores";
		}
			document.getElementById(price).options[index] = new Option(str,j);
			index++;
	}while(j<i)
	
	
}

// Area drop down name
function populatearea(objLB)
{
	for(i=0;i<Area.length;i++)
	{	
		document.getElementById(objLB).options[i] = new Option(Area[i].split("$")[1], Area[i].split("$")[0]);
	}
	document.getElementById(objLB).selectedIndex=4;
}

// price - to populate property price based on selected category  - buy, sell...
function populatepropertyprice(objLB,intType)
{
	document.getElementById(objLB).options.length=0;
	document.getElementById(objLB).options[0] = new Option("Select",0);
	var index=1, i = 0;
	switch(intType)
	{
		case 1:
			document.getElementById(objLB).options[1] = new Option("1 Crore",10000000);
			index++;
			for(i=2; i<=20; i++)
			{
				document.getElementById(objLB).options[index] = new Option(i + " Crores",i*10000000);
				index++;
			}
			document.getElementById(objLB).options[index] = new Option("20+ Crores",210000000);
			break;
		case 2:
			document.getElementById(objLB).options[1] = new Option("1 Lakh",100000);
			document.getElementById(objLB).options[2] = new Option("1.5 Lakhs",150000);
			index=3;
			for(i=2; i<100; i++)
			{
				document.getElementById(objLB).options[index] = new Option(i + " Lakhs",i*100000);
				index++;
				document.getElementById(objLB).options[index] = new Option(i + ".5 Lakhs",(i*100000)+50000);
				index++;
			}
			break;
		case 3:
			document.getElementById(objLB).options[1] = new Option("5 Thousand",5000);
			index++;
			for(i=10; i<=90; i+=10)
			{
				document.getElementById(objLB).options[index] = new Option(i + " Thousand",i*1000);
				index++;
			}
			break;
	}
}

//convert a metric value to sq feet
function ConvertToSqFeet(intFromMetic,dblMetricValue)
{	dblMetricValue=parseFloat(dblMetricValue)
	switch(parseInt(intFromMetic))
	{
		case 1: // From Acres to Sq Feet
			return dblMetricValue * 43560
			break;
		case 2: // From Grounds to Sq Feet
			return dblMetricValue * 2400
			break;
		case 3: // From Hectares to Sq Feet
			return dblMetricValue * 107639.104
			break;
		case 5: // From Sq Yards to Sq Feet
			return dblMetricValue * 9
			break;
		case 6: // From Sq Meters to Sq Feet
			return dblMetricValue * 10.7639104
			break;	
		case 7: // From Cents to Sq Feet
			return dblMetricValue * 435.540069
			break;				
	}
}

//function to round a decimal number to given decimal places
function RoundDecimals(dblValue,intDecimals)
{
	return Math.round(dblValue*Math.pow(10,intDecimals))/Math.pow(10,intDecimals);
}
// query() and valbutton() is for search module
var flSearch=0;

function query()
{

	

flSearch=0;
document.getElementById("txtSearch").value = "";

var ds = document.getElementById("hdnsubmit");

var dsv,drc,drt,chk_loc,chk_loc_val,areac,area,flag=0,chk_amenities;
var bedc,bathc,parkc,bed,bath,park,amenities,SrchLocation,pricec,price;


var Srchlocation_ctrl = document.getElementById("txtSearchLocation");

if (ds!=null)
	dsv = ds.value;

	drc = document.getElementById("dr_cities");
	drt = document.getElementById("dr_property_type");

if ((dsv!="")&&(dsv=="2"))
{
	drc = document.getElementById("dr_cities1");
	drt = document.getElementById("dr_property_type1");
}
	
 
var dr_rdcat = document.frm.rd_cat;
var l1= document.getElementById("locality1")
//var l2 = document.getElementById("locality2") 
var drttype,drcity,drcategory,locality1,locality2,adid,txtadid;
drcity=''
drtype=''
adid = document.getElementById("txt_adid") 
chk_loc=document.frm.chk_locality;
chk_amenities=document.frm.chk_amenities;
areac=document.getElementById("txtArea") 
bedc=document.getElementById("dr_bedrooms") 
bathc=document.getElementById("dr_bathrooms") 
parkc=document.getElementById("dr_parking") 
pricec=document.getElementById("price")

// checking controls

if (dr_rdcat!=null)
{
	drcategory = '/' + valButton(dr_rdcat);
	if (drcategory=="share1")
		drcategory="Share";
}
	
if (drc!=null)
{
	if(drc.value != 0)
		drcity= '/' + drc.options[drc.selectedIndex].text.toLowerCase();
	else
		drcity= '/allcities';
}



if (drt!=null)
{
	if(drt.value != 0)
		drtype= '/' + replaceAll(replaceAll(drt.options[drt.selectedIndex].text,' ','-'),'/','-').toLowerCase();
	else
		drtype= '/allproperties';
}

if (l1!=null)
{
	if(l1.value != 0)
	{
		locstr = '';
		localities = 0;
		for(k = 0; k < l1.options.length; k++)
		{
			if(l1.options[k].selected && localities < 5)
			{
				//if(locstr == '')
				//	locstr = '(';
				//if(locstr != '(')
				//	locstr += ' OR ';
				//if(locstr != '')
				//	locstr += ' OR ';
				if(locstr != '')
					locstr += ',';

				locstr += replaceAll(replaceAll(l1.options[k].text,' ','-'),'/','-').replace('(','').replace(')','').toLowerCase();
				localities++;
			}
		}

		//if(locstr != '')
		//	locstr += ')';
		//if(locstr.indexOf(',') > -1)
		//	locstr = '(' + locstr + ')';
		locality1 = '/' + locstr;
	}
	else
	{
		locality1='/alllocalities';
	}
	//return false;
	//locality1= 'locality:"'+l1.options[l1.selectedIndex].text +'" ';
}
	
//if ((l2!=null) && (l2.value != 0))
//	locality2= 'locality:"'+l2.options[l2.selectedIndex].text +'" ';

if (pricec!=null) 
{
	price = '/price-';
	if(pricec.value != 0)
	{
		var fl_cat=0;

		if ((drcategory=="/Rent-in") || (drcategory=="/Rent-out")||(drcategory=="/Share"))
		{
			fl_cat=1;
		}
		if ((drcategory=="/Buy" || drcategory=="/Sell"))
		{
		
			fl_cat=2;
		}
		if ((drcategory==null) || (drcategory==''))
		{
			fl_cat=1;
		}

		if (fl_cat==1)
		{
			switch(pricec.value)
			{
				case '1000':
						price=price + pad('1000')+'-'+pad('5000');
						break;
				case '5000':
						price=price + pad('5000')+'-'+pad('10000');
						break;
				case '10000':
						price=price + pad('10000')+'-'+pad('20000');
						break;
				case '20000':
						price=price + pad('20000')+'-'+pad('30000');
						break;
				case '30000':
						price=price + pad('30000')+'-'+pad('40000');
						break;
				case '40000':
						price=price + pad('40000')+'-'+pad('50000');
						break;
				case '50000':
						price=price + pad('50000')+'-'+pad('75000');
						break;
				case '75000':
						price=price + pad('75000')+'-'+pad('100000');
						break;
				case '100000':
						price=price + pad('100000')+'-'+pad('200000');
						break;
				case '200000':
						price=price + pad('200000')+'-'+pad('400000');
						break;
				case '400000':
						price=price + pad('400000')+'-'+pad('600000');
						break;
				case '600000':
						price=price + pad('600000')+'-'+pad('1000000');
						break;
				case '1000000':
						price=price + pad('1000000')+'-'+pad('1000000000');
						break;
			}
		}	
		else
		{
		
			switch(pricec.value)
			{
				case '100000':
						price=price + pad('100000')+'-'+pad('700000');
						break;
				case '700000':
						price=price + pad('700000')+'-'+pad('1500000');
						break;
				case '1500000':
						price=price + pad('1500000')+'-'+pad('3000000');
						break;
				case '3000000':
						price=price + pad('3000000')+'-'+pad('4500000');
						break;
				case '4500000':
						price=price + pad('4500000')+'-'+pad('6000000');
						break;
				case '6000000':
						price=price + pad('6000000')+'-'+pad('7500000');
						break;
				case '7500000':
						price=price + pad('7500000')+'-'+pad('10000000');
						break;
				case '10000000':
						price=price + pad('10000000')+'-'+pad('20000000');
						break;
				case '20000000':
						price=price + pad('20000000')+'-'+pad('40000000');
						break;
				case '40000000':
						price=price + pad('40000000')+'-'+pad('60000000');
						break;
				case '60000000':
						price=price + pad('60000000')+'-'+pad('100000000');
						break;
				case '100000000':
						price=price + pad('100000000')+'-'+pad('100000000');
						break;
						
			}
		}
	}	
	else
	{
		price = '/price-any';
	}
}


if ((Srchlocation_ctrl != null)&&(Srchlocation_ctrl.value!="" ))
	SrchLocation= 'locality:"'+Srchlocation_ctrl.value+'" ';


if (adid!=null)
	txtadid=adid.value;
	
if (areac != null)
{
	area = '/area-' + areac.value;
	if(area == '/area-')
		area='/area-any';
}

if (bedc!=null)
{
	if(bedc.value != 0)
		bed = '/bed-'+bedc.options[bedc.selectedIndex].text;
	else
		bed = '/bed-any';
}

if (bathc!=null)
{
	if(bathc.value != 0)
		bath= '/bath-'+bathc.options[bathc.selectedIndex].text;
	else
		bath= '/bath-any';
}

if (parkc!=null)
{
	if(parkc.value != 0)
		park= '/parking-'+parkc.options[parkc.selectedIndex].value;
	else
		park = '/parking-any';
}
	
//forming query

if (drcity != '')
{
		Check_Search();
		document.getElementById("txtSearch").value = drcity;
}

if ((locality1!=null) && (locality1 != ""))
{
	Check_Search();
	document.getElementById("txtSearch").value += locality1;
}

if (drtype != '')
{
	Check_Search();
	document.getElementById("txtSearch").value +=  drtype.toLowerCase();
}


if (drcategory != null)
{
	document.getElementById("txtSearch").value += drcategory.toLowerCase();
	flSearch=1;
}


	




/*
if ((locality2!=null) && (locality2 != ""))
{
	Check_Search();
	document.getElementById("txtSearch").value = document.getElementById("txtSearch").value+ locality2+ ' ';
}
*/

if ((price!=null) && (price!=''))
{
	Check_Search();
	document.getElementById("txtSearch").value += price;
}

if ((area!=null) && (area!=""))
{
	Check_Search();	
	document.getElementById("txtSearch").value += area;
}


if((SrchLocation!=null)&&(SrchLocation!=""))
{
Check_Search();
document.getElementById("txtSearch").value += document.getElementById("txtSearch").value+ SrchLocation+ ' ';
}

if ((adid!=null) && (adid!=""))
{
	Check_Search();
	document.getElementById("txtSearch").value = document.getElementById("txtSearch").value+ 'adid:"'+txtadid+ '" '
}


if(chk_loc!=null)
{
	
	chk_loc_val="locality:(";
	flag=0;
	for (var i=0;i<chk_loc.length;i++)
	{
		if(chk_loc[i].checked)
		{
			flag=1;
			if(chk_loc_val != '/(')
				chk_loc_val += ' OR ';
			chk_loc_val=chk_loc_val+chk_loc[i].value;
		}
	}
	chk_loc_val += ')';
	if (flag == 1)
	{
		Check_Search();	
		document.getElementById("txtSearch").value=document.getElementById("txtSearch").value+chk_loc_val+' ';
	}
}



if ((bed!=null) && (bed!=""))
{
	Check_Search();	
	document.getElementById("txtSearch").value += bed;
}

if ((bath!=null) && (bath!=""))
{
	Check_Search();	
	document.getElementById("txtSearch").value += bath;
}

if ((park!=null) && (park!=""))
{
	Check_Search();	
	document.getElementById("txtSearch").value += park;
}


if(chk_amenities!=null)
{
	amenities='/';
	flag=0;
	for (var i=0;i<chk_amenities.length;i++)
	{
		if(chk_amenities[i].checked)
		{
			if(flag == 1)
				amenities += ' ';
			flag=1;
			amenities=amenities+chk_amenities[i].value;
		}
	}
	if (flag == 1)
	{
		Check_Search();	
		document.getElementById("txtSearch").value += amenities;
	}
	else
	{
		amenities='/any';
		document.getElementById("txtSearch").value += amenities;
	}
}
try
{
	if(document.getElementById("loccitytd") != undefined && document.getElementById("loccitytd") != null)
	{
		document.getElementById("txtSearch").value += ' AND city:' + document.getElementById("loccitytd").innerHTML + ' ';
	}
}
catch(err){}
}

function Check_Search()
{/*
	if (flSearch == 1)
		{
			document.getElementById("txtSearch").value = document.getElementById("txtSearch").value + " AND "
		}
	else
		{
			flSearch = 1;
		}
 */
}

function valButton(btn) {
var cnt = -1;
for (var i=btn.length-1; i > -1; i--) {
   if (btn[i].checked) {cnt = i; i = -1;}
   }
if (cnt > -1) 
{
return btn[cnt].value;
}
else return null;
}

function ShowChangePasswordScreen()
{
	window.open("/changepassword.aspx","chpassword","height=300,width=520,left=250,top=260,scrollbars=no");
}

function showAccountDetailsEditScreen()
{
	location.href='/editaccountDetails.aspx';
}
/*
function populatepropertypricefornewalert(objLB,intType)
{

document.getElementById(objLB).options.length=0;

//document.getElementById(objLB).options[0] = new Option("Select",0);

var index=1, i = 0;

switch(intType)

{

case 1:

document.getElementById(objLB).options[0] = new Option("Select Price",0);

document.getElementById(objLB).options[1] = new Option("1 - 5000",1001);

document.getElementById(objLB).options[2] = new Option("5000 - 10000",5001);

document.getElementById(objLB).options[3] = new Option("10000 - 20000",10001);

document.getElementById(objLB).options[4] = new Option("20000 - 30000",20001);

document.getElementById(objLB).options[5] = new Option("30000 - 40000",30001);

document.getElementById(objLB).options[6] = new Option("40000 - 50000",40001);

document.getElementById(objLB).options[7] = new Option("50000 - 75000",50001);

document.getElementById(objLB).options[8] = new Option("75000 - 1 Lakh",75001);

document.getElementById(objLB).options[9] = new Option("1 - 2 Lakhs",100001);

document.getElementById(objLB).options[10] = new Option("2- 4 Lakhs",200001);

document.getElementById(objLB).options[11] = new Option("4 - 6 Lakhs",400001);

document.getElementById(objLB).options[12] = new Option("6 - 10 Lakhs",600001);

document.getElementById(objLB).options[13] = new Option("10 Lakhs & Above",1000001);

break;

case 2:

document.getElementById(objLB).options[0] = new Option("Select Price",0);

document.getElementById(objLB).options[1] = new Option("1 - 7 Lakhs",100001);

document.getElementById(objLB).options[2] = new Option("7 - 15 Lakhs",700001);

document.getElementById(objLB).options[3] = new Option("15 -30 Lakhs",1500001);

document.getElementById(objLB).options[4] = new Option("30 -45 Lakhs",1500001);

document.getElementById(objLB).options[5] = new Option("45 - 60 Lakhs",4500001);

document.getElementById(objLB).options[6] = new Option("60 - 75 Lakhs",6000001);

document.getElementById(objLB).options[7] = new Option("75 - 100 Lakhs",7500001);

document.getElementById(objLB).options[8] = new Option("1 - 2 Crores",10000001);

document.getElementById(objLB).options[9] = new Option("2 - 4 Crores",20000001);

document.getElementById(objLB).options[10] = new Option("4 - 6 Crores",40000001);

document.getElementById(objLB).options[11] = new Option("6 - 10 Crores",60000001);

document.getElementById(objLB).options[12] = new Option("10 Crores & above",100000001);

break;

}

}
*/
function removeElements(objLB)
{
	try
	{
		var obj = document.getElementById(objLB);
		for(i = 0; i < obj.options.length; i++)
		{
			obj.remove(0);
		}
	}
	catch(err){}
}
function populatepropertypricefornewalert(objLB,intType)
{
	//document.getElementById(objLB).options.length=0;
	removeElements(objLB);
	document.getElementById(objLB).options[0] = new Option("Select",0);
	var index=1, i = 0;
	switch(intType)
	{
		case 1:
			document.getElementById(objLB).options[1] = new Option("1000 - 5000",1000);
			document.getElementById(objLB).options[2] = new Option("5000 - 10000",5000);
			document.getElementById(objLB).options[3] = new Option("10000 - 20000",10000);
			document.getElementById(objLB).options[4] = new Option("20000 - 30000",20000);
			document.getElementById(objLB).options[5] = new Option("30000 - 40000",30000);
			document.getElementById(objLB).options[6] = new Option("40000 - 50000",40000);
			document.getElementById(objLB).options[7] = new Option("50000 - 75000",50000);
			document.getElementById(objLB).options[8] = new Option("75000 - 1 Lakh",75000);
			document.getElementById(objLB).options[9] = new Option("1 - 2 Lakhs",100000);
			document.getElementById(objLB).options[10] = new Option("2 - 4 Lakhs",200000);
			document.getElementById(objLB).options[11] = new Option("4 - 6 Lakhs",400000);
			document.getElementById(objLB).options[12] = new Option("6 - 10 Lakhs",600000);
			document.getElementById(objLB).options[13] = new Option("10 Lakhs & Above",1000000);
			break;
		case 2:
			document.getElementById(objLB).options[1] = new Option("1 - 7 Lakhs",100000);
			document.getElementById(objLB).options[2] = new Option("7 - 15 Lakhs",700000);
			document.getElementById(objLB).options[3] = new Option("15 -30 Lakhs",1500000);
			document.getElementById(objLB).options[4] = new Option("30 - 45 Lakhs",3000000);
			document.getElementById(objLB).options[5] = new Option("45 - 60 Lakhs",4500000);
			document.getElementById(objLB).options[6] = new Option("60 - 75 Lakhs",6000000);
			document.getElementById(objLB).options[7] = new Option("75 - 100 Lakhs",7500000);
			document.getElementById(objLB).options[8] = new Option("1 - 2 Crores",10000000);
			document.getElementById(objLB).options[9] = new Option("2 - 4 Crores",20000000);
			document.getElementById(objLB).options[10] = new Option("4 - 6 Crores",40000000);
			document.getElementById(objLB).options[11] = new Option("6 - 10 Crores",60000000);
			document.getElementById(objLB).options[12] = new Option("10 Crores & above",100000000);
			break;
	}
}
/*function onSubmitDir()
{
var company =document.getElementById("txtCompany").value;
var category =document.getElementById("drCat").value;

var cities =document.getElementById("dr_cities").value;
var desc =document.getElementById("txtDesc").value;
var address =document.getElementById("txtAddress").value;
var contact=document.getElementById("txtContact").value;
var EmailId=document.getElementById("txtEmailId").value;
var ConEmailId=document.getElementById("txtConEmailId").value;
var Phone=document.getElementById("txtPhone").value;
var Mobile=document.getElementById("txtMobile").value;

if (company=='' || category=='0' || cities =='0' || desc=='' || address=='' || contact=='' || EmailId=='' || ConEmailId == '' || Phone == '' || Mobile ==''  )
{
alert("Please enter all the values");
return false;
}

if (EmailId != ConEmailId)
{
alert("ConEmailId is not matching EmailId");
return false;
}
return true;
}
*/



function pad(n)
{
	var strPad='';
	if (n.length != 10)
	{
		for (var i=0;i<10-n.length;i++)
		{
			strPad=strPad+'0';
		}
	}

	strPad=strPad+n+'.00';
	return strPad;
}

function DeleteAlertConf(alertid)
{
	var agree=confirm("Are you sure you wish to delete this ad?");
	if (agree)
	{
		location.href='/managealert.aspx?deletealertid='+alertid;
	}
}

function SetCount(obj,n)
{
var intLen = obj.value.length
var strLen=''

if ((n == null)||(n==''))
	n=500
if (intLen>n)
{
	window.event.keyCode=0;
	document.getElementById("spnMinCnt").innerHTML=500;
	obj.value=obj.value.substr(0,500)
	return;
}
if (intLen == 0)
	strLen='000'
else if (intLen <= 9)
	strLen='00'+(intLen)
else if (intLen <= 99) 	
	strLen='0'+(intLen)
else
	strLen=intLen
	document.getElementById("spnMinCnt").innerHTML=strLen;
}

function SetCountAddress(obj)
{
var intLen = obj.value.length;
if (intLen>150)
{
	window.event.keyCode=0;
	obj.value=obj.value.substr(0,150);
	alert('Address cannot exceed 150 characters');
	document.getElementById("spnMinCntAddress").innerHTML='150';
	return;
}
	if (intLen == 0)
		strLen='000';
	else if (intLen <= 9)
		strLen='00'+(intLen);
	else if (intLen <= 99) 	
		strLen='0'+(intLen);
	else
		strLen=intLen;
	document.getElementById("spnMinCntAddress").innerHTML=strLen;
}


function ChangeLink(val,obj)
{
	try
	{
		if(val == 0)
		{
			obj.style['text-decoration']='underline';
			obj.style['color']='#C30';
		}
		else if(val == 1)
		{
			obj.style['text-decoration']='none';
			obj.style['color']='#039';
		}	
	}
	catch(err){}
}

function ChangeLinkSummary(val,obj,clr)
{
	try
	{
		if(val == 0)
		{
			obj.style['text-decoration']='underline';
			obj.style['color']='#C30';
		}
		else if(val == 1)
		{
			obj.style['text-decoration']='none';
			obj.style['color']=clr;
		}	
	}
	catch(err){}
}

function ChangeLinkSitemap(val,obj,clr)
{
	try
	{
		if(val == 0)
		{
			obj.style['text-decoration']='underline';
			obj.style['color']='#C30';
		}
		else if(val == 1)
		{
			obj.style['text-decoration']='none';
			obj.style['color']=clr;
		}	
	}
	catch(err){}
}


function ParkingDesc(ParkingId,Control)
{
try{

		if(ParkingId==0)
	    {
			if ((document.getElementById("hidtype").value==2) || (document.getElementById("hidtype").value==4))
			{
				document.getElementById(Control).innerHTML= "None";
			}
			else 
			{
				document.getElementById(Control).innerHTML= "Doesn't Matter";
			}
		}
		else
		{	for(i=0;i<Parking.length;i++)
			{	
				if (Parking[i].split("$")[0] == ParkingId)
					document.getElementById(Control).innerHTML= Parking[i].split("$")[1];
			}
		}
	}
catch(err) {}
}


function  returnCityId(city)
{
for(i=0;i<Cities.length;i++)
	{
		if (Cities[i].toLowerCase().split("$")[1] == city.toLowerCase())
		{
			return Cities[i].split("$")[0];		
		}
	}
}

function  returnPropertyId(propertytype)
{
for(i=0;i<Properties.length;i++)
	{
		if (Properties[i].toLowerCase().split("$")[1] == propertytype.toLowerCase())
			return Properties[i].split("$")[0];		
	}
}
function submitlogin(){
	var objForm=document.loginform;
	if(objForm.logonname.value=="Username")
	{	alert("A valid email address is required.")	
		objForm.logonname.value="";
		objForm.logonname.focus();
		return false;
	}
	else if(CheckForEmpty(objForm.logonname,"A valid email address is required.",true,true)==false)
	{
		return false;
	}
	if(validateEmail(objForm.logonname.value)=="")
	{
		alert("The email address entered appears to be invalid.");
		objForm.logonname.focus();
		return false;
	}
	if(CheckForEmpty(objForm.password,"Please enter a Password.",true,true)==false)
	{
		return false;
	}
	objForm.submit.value="Submit";}
	
function doNothing(){history.back();}	

function replaceAll(text, strA, strB)
{
    return text.replace( new RegExp(strA,"g"), strB );    
}

function queryold()
{

flSearch=0;
document.getElementById("txtSearch").value = "";

var ds = document.getElementById("hdnsubmit");

var dsv,drc,drt,chk_loc,chk_loc_val,areac,area,flag=0,chk_amenities;
var bedc,bathc,parkc,bed,bath,park,amenities,SrchLocation,pricec,price;


var Srchlocation_ctrl = document.getElementById("txtSearchLocation");

if (ds!=null)
	dsv = ds.value;

	drc = document.getElementById("dr_cities");
	drt = document.getElementById("dr_property_type");

if ((dsv!="")&&(dsv=="2"))
{
	drc = document.getElementById("dr_cities1");
	drt = document.getElementById("dr_property_type1");
}
	
 
var dr_rdcat = document.frm.rd_cat;
var l1= document.getElementById("locality1")
//var l2 = document.getElementById("locality2") 
var drttype,drcity,drcategory,locality1,locality2,adid,txtadid;
drcity=''
drtype=''
adid = document.getElementById("txt_adid") 
chk_loc=document.frm.chk_locality;
chk_amenities=document.frm.chk_amenities;
areac=document.getElementById("txtArea") 
bedc=document.getElementById("dr_bedrooms") 
bathc=document.getElementById("dr_bathrooms") 
parkc=document.getElementById("dr_parking") 
pricec=document.getElementById("price")

// checking controls

if (dr_rdcat!=null)
{
	drcategory = valButton(dr_rdcat);
	if (drcategory=="share1")
		drcategory="Share";
}
	


if ((drc!=null) && (drc.value != 0))
{
	drcity= 'city:"'+drc.options[drc.selectedIndex].text+'" ';
}

if ((drt!=null) && (drt.value != 0))
	drtype= 'propertytype:"'+drt.options[drt.selectedIndex].text +'" ';

if ((l1!=null) && (l1.value != 0))
{
	locstr = '';
	localities = 0;
	for(k = 0; k < l1.options.length; k++)
	{
		if(l1.options[k].selected && localities < 5)
		{
			if(locstr == '')
				locstr = '(';
			if(locstr != '(')
				locstr += ' OR ';
			locstr +=l1.options[k].text;
			localities++;
		}
	}
	if(locstr != '')
		locstr += ')';
	locality1 = 'locality:' + locstr;
	//return false;
	//locality1= 'locality:"'+l1.options[l1.selectedIndex].text +'" ';
}
	
//if ((l2!=null) && (l2.value != 0))
//	locality2= 'locality:"'+l2.options[l2.selectedIndex].text +'" ';

if ((pricec!=null) && (pricec.value != 0))
{
	price = 'price:';
	var fl_cat=0;
	if ((drcategory=="Rent-in") || (drcategory=="Rent-out")||(drcategory=="Share"))
	{
		fl_cat=1;
	}
	if ((drcategory=="Buy" || drcategory=="Sell"))
	{
	
		fl_cat=2;
	}
	if ((drcategory==null) || (drcategory==''))
	{
		fl_cat=1;
	}
	if (fl_cat==1)
	{
	switch(pricec.value)
	{
		case '1000':
				price=price+'['+pad('1000')+' TO '+pad('5000')+']';
				break;
		case '5000':
				price=price+'['+pad('5000')+' TO '+pad('10000')+']';
				break;
		case '10000':
				price=price+'['+pad('10000')+' TO '+pad('20000')+']';
				break;
		case '20000':
				price=price+'['+pad('20000')+' TO '+pad('30000')+']';
				break;
		case '30000':
				price=price+'['+pad('30000')+' TO '+pad('40000')+']';
				break;
		case '40000':
				price=price+'['+pad('40000')+' TO '+pad('50000')+']';
				break;
		case '50000':
				price=price+'['+pad('50000')+' TO '+pad('75000')+']';
				break;
		case '75000':
				price=price+'['+pad('75000')+' TO '+pad('100000')+']';
				break;
		case '100000':
				price=price+'['+pad('100000')+' TO '+pad('200000')+']';
				break;
		case '200000':
				price=price+'['+pad('200000')+' TO '+pad('400000')+']';
				break;
		case '400000':
				price=price+'['+pad('400000')+' TO '+pad('600000')+']';
				break;
		case '600000':
				price=price+'['+pad('600000')+' TO '+pad('1000000')+']';
				break;
		case '1000000':
				price=price+'['+pad('1000000')+' TO '+pad('1000000000')+']';
				break;
	}
	}	
	else
	{
	
	switch(pricec.value)
	{
		case '100000':
				price=price+'['+pad('100000')+' TO '+pad('700000')+']';
				break;
		case '700000':
				price=price+'['+pad('700000')+' TO '+pad('1500000')+']';
				break;
		case '1500000':
				price=price+'['+pad('1500000')+' TO '+pad('3000000')+']';
				break;
		case '3000000':
				price=price+'['+pad('3000000')+' TO '+pad('4500000')+']';
				break;
		case '4500000':
				price=price+'['+pad('4500000')+' TO '+pad('6000000')+']';
				break;
		case '6000000':
				price=price+'['+pad('6000000')+' TO '+pad('7500000')+']';
				break;
		case '7500000':
				price=price+'['+pad('7500000')+' TO '+pad('10000000')+']';
				break;
		case '10000000':
				price=price+'['+pad('10000000')+' TO '+pad('20000000')+']';
				break;
		case '20000000':
				price=price+'['+pad('20000000')+' TO '+pad('40000000')+']';
				break;
		case '40000000':
				price=price+'['+pad('40000000')+' TO '+pad('60000000')+']';
				break;
		case '60000000':
				price=price+'['+pad('60000000')+' TO '+pad('100000000')+']';
				break;
		case '100000000':
				price=price+'['+pad('100000000')+' TO '+pad('100000000')+']';
				break;
				
	}
	}	
	
}


if ((Srchlocation_ctrl != null)&&(Srchlocation_ctrl.value!="" ))
	SrchLocation= 'locality:"'+Srchlocation_ctrl.value+'" ';


if (adid!=null)
	txtadid=adid.value;
	
if (areac!=null)
	area = areac.value;

if ((bedc!=null) && (bedc.value != 0))
{
	bed= 'bedrooms:"'+bedc.options[bedc.selectedIndex].text+'" ';
}

if ((bathc!=null) && (bathc.value != 0))
{
	bath= 'bathrooms:"'+bathc.options[bathc.selectedIndex].text+'" ';
}

if ((parkc!=null) && (parkc.value != 0))
{
	park= 'parking:"'+parkc.options[parkc.selectedIndex].text+'" ';
}
	
//forming query

if (drcategory!=null)
{
	document.getElementById("txtSearch").value = 'category:"'+drcategory+'" ' ;
	flSearch=1;
}

if (drtype != '')
{
	Check_Search();
	document.getElementById("txtSearch").value = document.getElementById("txtSearch").value+drtype +' ';
}
	

if (drcity != '')
{
		Check_Search();
		document.getElementById("txtSearch").value = document.getElementById("txtSearch").value + drcity+' ';
}


if ((locality1!=null) && (locality1 != ""))
{
	Check_Search();
	document.getElementById("txtSearch").value = document.getElementById("txtSearch").value+ locality1+' ';
}

/*
if ((locality2!=null) && (locality2 != ""))
{
	Check_Search();
	document.getElementById("txtSearch").value = document.getElementById("txtSearch").value+ locality2+ ' ';
}
*/

if ((price!=null) && (price!=''))
{
	Check_Search();
	document.getElementById("txtSearch").value = document.getElementById("txtSearch").value+ price;
}

if((SrchLocation!=null)&&(SrchLocation!=""))
{
Check_Search();
document.getElementById("txtSearch").value = document.getElementById("txtSearch").value+ SrchLocation+ ' ';
}

if ((adid!=null) && (adid!=""))
{
	Check_Search();
	document.getElementById("txtSearch").value = document.getElementById("txtSearch").value+ 'adid:"'+txtadid+ '" '
}


if(chk_loc!=null)
{
	
	chk_loc_val="locality:(";
	flag=0;
	for (var i=0;i<chk_loc.length;i++)
	{
		if(chk_loc[i].checked)
		{
			flag=1;
			if(chk_loc_val != 'locality:(')
				chk_loc_val += ' OR ';
			chk_loc_val=chk_loc_val+chk_loc[i].value;
		}
	}
	chk_loc_val += ')';
	if (flag == 1)
	{
		Check_Search();	
		document.getElementById("txtSearch").value=document.getElementById("txtSearch").value+chk_loc_val+' ';
	}
}

if ((area!=null) && (area!=""))
{
	Check_Search();	
	document.getElementById("txtSearch").value = document.getElementById("txtSearch").value+ 'areainsqfeet:"'+area+ '" '
}

if ((bed!=null) && (bed!=""))
{
	Check_Search();	
	document.getElementById("txtSearch").value = document.getElementById("txtSearch").value+ bed
}

if ((bath!=null) && (bath!=""))
{
	Check_Search();	
	document.getElementById("txtSearch").value = document.getElementById("txtSearch").value+ bath
}

if ((park!=null) && (park!=""))
{
	Check_Search();	
	document.getElementById("txtSearch").value = document.getElementById("txtSearch").value+ park
}


if(chk_amenities!=null)
{
	amenities='amenities:';
	flag=0;
	for (var i=0;i<chk_amenities.length;i++)
	{
		if(chk_amenities[i].checked)
		{
			flag=1;
			amenities=amenities+chk_amenities[i].value+" ";
		}
	}
	if (flag == 1)
	{
		Check_Search();	
		document.getElementById("txtSearch").value=document.getElementById("txtSearch").value+amenities+' ';
	}
}
try
{
	if(document.getElementById("loccitytd") != undefined && document.getElementById("loccitytd") != null)
	{
		document.getElementById("txtSearch").value += ' AND city:' + document.getElementById("loccitytd").innerHTML + ' ';
	}
}
catch(err){}
}


function CheckH1Border()
{
	try
	{
		obj = document.getElementById('citytext');
		if(obj != undefined && obj != null)
		{
			if(obj.innerHTML.toLowerCase() != "<h5></h5>")
			{
				document.getElementById('h1textdiv').className = "hdr_clasi";
			}
		}
	}
	catch(err) {}
}


function initCap(str) 
{

		if(str == '') return '';
		str = trim(str);
        var str = str.substring(0,1).toUpperCase() + str.substring(1,str.length).toLowerCase();
		return str;
} 


function NewsLetterReg()
{
	var newsname = document.getElementById('newsname');
	var newsemailid = document.getElementById('newsemailid');
	if(newsname.value == '')
	{
		alert('Please provide your name');
		newsname.focus();
		return false;
	}
	if(newsemailid.value == '')
	{
		alert('Please provide your emailid for subscription');
		newsemailid.focus();
		return false;
	}	
	
	if(validateEmail(newsemailid.value)=="")
	{
		alert("The email address entered appears to be invalid.");
		newsemailid.focus();
		return false;
	}	
	return (Default.NewsLetterReg(newsname.value,newsemailid.value, UpdateNewsReg)); 
}

function UpdateNewsReg(response)
{

	var newsemailid = document.getElementById('newsemailid');

	alert(response.value.replace("*","'"));
	
	if(response.value.indexOf('already') == -1)
	{
		newsname.value = '';
		newsemailid.value = '';
	}
	else
	{
		newsemailid.select();		
	}
}

