function onload_select() {
	var prop_type = document.getElementById('user_search_prop_type');
	var county = document.getElementById('user_search_area');
	if (prop_type != null && prop_type.options[0].selected == true) {
		prop_type.options[0].selected = false;
		prop_type.options[1].selected = true;
	}
	if (county != null && county.options[0].selected == true) {
		county.options[0].selected = false;
		//county.options[2].selected = true;
	}
	
	var prop_type1 = document.getElementById('advanced_user_search_a_prop_type');
	var county1 = document.getElementById('advanced_user_search_a_area');
	if (prop_type1 != null && prop_type1.options[0].selected == true) {
		prop_type1.options[0].selected = false;
		prop_type1.options[1].selected = true;
	}
	if (county1 != null && county1.options[0].selected == true) {
		county1.options[0].selected = false;
		//county1.options[2].selected = true;
	}		
}

function select_city(type) {
	
	//get area
	var ctr = type.toString();

	var area = document.getElementById(ctr).value;
	//get city object
	var city_select = document.getElementById(ctr+'name');
	
	//populate area data
    var arr = [1,2,3,5,7,9,10,11,12,13,14,15,16,18,19,20,21,25,35,48,52,99];
    arr[1] = ['Belington', 'Junior', 'Philippi'];
    arr[2] = [''];
    arr[3] = ['Hedgesville','Inwood','Martinsburg'];
    arr[5] = ['Beech Bottom', 'Bethany', 'Follansbee', 'Hooverson Heights', 'Weirton', 'Wellsburg'];
	arr[7] = ['Grantsville'];
	arr[9] = ['West Union'];
	arr[10] = ['Ansted', 'Fayetteville', 'Gauley Bridge', 'Meadow Bridge', 'Montgomery', 'Mount Hope', 'Oak Hill', 'Pax', 'Powellton', 'Smithers', 'Thurmond'];
	arr[11] = ['Glenville', 'Sand Fork'];
	arr[12] = ['Bayard', 'Petersburg'];
	arr[13] = ['Alderson','Fairlea','Falling Spring', 'Lewisburg', 'Quinwood', 'Rainelle', 'Ronceverte', 'Rupert', 'White Sulphur Springs'];
	arr[14] = ['Capon Bridge','Romney'];
	arr[15] = ['Chester','New Cumberland','Newell', 'Weirton'];
	arr[16] = ['Moorefield','Wardensville'];
	arr[18] = ['Ravenswood','Ripley'];
	arr[19] = ['Bolivar','Charles Town','Corporation of Ranson','Harpers Ferry','Shepherdstown'];
	arr[20] = ['Cedar Grove','Charleston','Chesapeake','Clendenin','Coal Fork','Cross Lanes','Dunbar','East Bank','Elkview','Glasgow','Handley','Marmet','Montgomery','Nitro','Pinch','Pratt','Sissonville','Smithers','South Charleston','St. Albans','Tornado'];
	arr[21] = ['Jane Lew','Weston'];
	arr[25] = ['Benwood','Cameron','Glen Dale','McMechen', 'Moundsville', 'Wheeling'];
	arr[35] = ['Bethlehem', 'Clearview', 'Triadelphia','Valley Grove','West Liberty','Wheeling'];
	arr[48] = ['Friendly','Middlebourne', 'Paden City', 'Sistersville'];
	arr[52] = ['Hundred','Littleton', 'New Martinsville', 'Paden City', 'Pine Grove', 'Smithfield'];
	arr[99] = ['OTHER AREAS'];
    //delete all cities
    var j;
    for (j = city_select.options.length-1; j>0; j--) {
    	city_select.remove(j);
    }
    
    //add first select option default text
    //city_select.add(new Option('ALL', 0), city_select.options[0]); //add new option to end of "sample"
    city_select.options[0].selected = true;
    
    //add all cities
    /*
    var i;
    for (i in arr[area]) {
	    try{
			city_select.add(new Option(arr[area][i], arr[area][i]), null); //add new option to the end
		}
		catch(e){ //try this in IE
			city_select.add(new Option(arr[area][i], arr[area][i])); //add new option to the end
		}
    
		//alert(arr[1][i]);
	}*/
	var i;
	if (arr[area] != undefined) {
		for (i =0; i < arr[area].length; i++) {
			try{
				city_select.add(new Option(arr[area][i], arr[area][i]), null); //add new option to the end
			}
			catch(e){ //try this in IE
				city_select.add(new Option(arr[area][i], arr[area][i])); //add new option to the end
			}
		}
	} else {
		for (var j=0; j < 100; j++) {
			if (arr[j] != undefined) {
				for (i =0; i < arr[j].length; i++) {
					try{
						city_select.add(new Option(arr[j][i], arr[j][i]), null); //add new option to the end
					}
					catch(e){ //try this in IE
						city_select.add(new Option(arr[j][i], arr[j][i])); //add new option to the end
					}
				}
			}
	    }
	}
}

function clear_quick_search(param) {
	var elem = document.getElementById("search_form").elements;
	for(var i = 0; i < elem.length; i++)
	{
		if (elem[i].type != "submit" && elem[i].id != "user_search_mls_number" && elem[i].id != "user_search_zip") elem[i].value = "";
		if (elem[i].type != "submit" && elem[i].id == "user_search_mls_number" && (param == "all" || param == "zip")) elem[i].value = "";
		if (elem[i].type != "submit" && elem[i].id == "user_search_zip" && (param == "all" || param == "mls")) elem[i].value = "";
	}
}

function clear_advanced_search(param) {
	var elem = document.getElementById('advanced_search_form').elements;
	for(var i = 0; i < elem.length; i++)
	{
		if (elem[i].type != 'submit' && elem[i].id != "advanced_user_search_a_mls_number" && elem[i].id != "advanced_user_search_a_zip") elem[i].value = '';
		if (elem[i].type != 'submit' && elem[i].id == "advanced_user_search_a_mls_number" && (param == "all" || param == "zip")) elem[i].value = '';
		if (elem[i].type != 'submit' && elem[i].id == "advanced_user_search_a_zip" && (param == "all" || param == "mls")) elem[i].value = '';
		if (elem[i].type == 'select-one') {
			if (elem[i].id == 'advanced_user_search_a_bedrooms') elem[i].value = 0;
			if (elem[i].id == 'advanced_user_search_a_full_baths') elem[i].value = 0;
			if (elem[i].id == 'advanced_user_search_a_half_baths') elem[i].value = 0;
			if (elem[i].id == 'advanced_user_search_a_listings_per_page') elem[i].value = 5;
			if (elem[i].id == 'advanced_user_search_a_order_by') elem[i].value = 'price';
			if (elem[i].id == 'advanced_user_search_a_order_type') elem[i].value = 'asc';
		}
	} 
}

function Morgcal()
{
	form = document.myform
	LoanAmount= form.LoanAmount.value
		
	DownPayment= "0"
	AnnualInterestRate = form.InterestRate.value/100
	Years= form.NumberOfYears.value
		MonthRate=AnnualInterestRate/12
	NumPayments=Years*12
	Prin=LoanAmount-DownPayment
	
	MonthPayment=Math.floor((Prin*MonthRate)/(1-Math.pow((1+MonthRate),(-1*NumPayments)))*100)/100
		form.NumberOfPayments.value=NumPayments
	form.MonthlyPayment.value=MonthPayment
}