
function highlight(selobj, value) {
	for(var i=0; i<selobj.options.length; i++) {
		if (selobj.options[i].value == value)
		{
			selobj.options[i].selected = true;
			return;
		}
	}
}

function checkCityName() {
	if (document.frm.cityid.selectedIndex == 0)
	{
		return "select a region and city to continue";
	}
	if (document.frm.locationId.selectedIndex == 0)
	{
		return "select a city to continue";
	}
	return "";

}

function trim (txt) {
	return txt.replace(/^\s+|\s+$/g,"");
}

function populateLocations() {
	
	if (document.frm.cityid.selectedIndex >0)
	{			
		window.location.href='index.php?cityid=' + document.frm.cityid.options[document.frm.cityid.selectedIndex].value;
	}else{
		alert('select a region name from the list and click edit');
		document.frm.reset();
		document.frm['action'].value='add';		
	}
}

function resetForm() {
	document.frm.reset();
	document.frm['action'].value='add';		
}

function formValidate() { 
	var err = "";
	
	err += checkCityName();
	if (trim(err)!=""){
		err ="Please correct following."
		+"\n----------------------------------------------------------------------\n"
		+ err 
		+"\n----------------------------------------------------------------------\n"; 
		alert(err); 
	} else { 
		document.frm.submit();
	}
}
