function propSearchKeywordFocus(field) {
	if ( field.value == searchPropKeywordInfo) {
		field.value = "";
		document.getElementById('prop_search_keyword').className = "sp_form_textbox_kword_sel";	
	}
}
function propSearchKeywordBlur(field) {
	if( field.value == "" || field.value == " " || field.value == "   " ) {
		field.value = searchPropKeywordInfo;
		document.getElementById('prop_search_keyword').className = "sp_form_textbox_kword_def";	
	}
}
function validatePostedType(form, val, checked) {
	if ( checked == true ) {
		if ( val == 0 ) {
			form.postedType[1].checked = false; form.postedType[2].checked = false; form.postedType[3].checked = false;
		}
		else if ( val == 1 || val == 2 || val == 4 ) {
			if ( form.postedType[1].checked == true && form.postedType[2].checked == true && form.postedType[3].checked == true ) {
				form.postedType[0].checked = true; form.postedType[1].checked = false; form.postedType[2].checked = false; form.postedType[3].checked = false;
			} else {
				form.postedType[0].checked = false;
			}
		}
	}
	else if ( checked == false ) { }
}

var propBasicSearchLocationField = null;
var propBasicSearchForm = null;

function loadLocations(form, cityField, locationField) {
	var cityId = cityField.value;
	propBasicSearchLocationField = locationField;
	propBasicSearchForm = form;
	if ( cityId != "" && cityId != 0 && cityId != 1 ) {
		sendAjaxReq(showLocations, 'getSearchPropLocations', cityId, 'places.do');
		locationField.disabled = true;
		form.search.disabled = true;
	} else {
		setSearchLocationDefault();
	}
}
function showLocations(locationXML) {
	propBasicSearchLocationField.disabled = false;
	propBasicSearchForm.search.disabled = false;
	removeSearchPlacesOptionData(propBasicSearchLocationField);
	var locationIdField = propBasicSearchLocationField;
	var content = locationXML.getElementsByTagName("content")[0];
	var total = content.getAttribute("total");
	if ( total > 0 ) {
		if ( locationIdField )
			locationIdField.appendChild(createSearchPlaceOption("All",""));
		var location = content.getElementsByTagName("location");
		for (var i = 0 ; i < location.length ; i++) {
			var item = location[i];
			var id = item.getElementsByTagName("id")[0].firstChild.nodeValue;
		    var name = item.getElementsByTagName("name")[0].firstChild.nodeValue;
			if ( locationIdField )
				locationIdField.appendChild(createSearchPlaceOption(name,id));
		}
	} else {
		setSearchLocationDefault();
	}
	if ( locationIdField )
		locationIdField.appendChild(createSearchPlaceOption("Other","1"));
}
function setSearchLocationDefault() {
	removeSearchPlacesOptionData(propBasicSearchLocationField);
	if ( propBasicSearchLocationField )
		propBasicSearchLocationField.appendChild(createSearchPlaceOption("All",""));
}
function removeSearchPlacesOptionData(fieldName) {
	if ( fieldName) {
		if ( fieldName.options)
			if ( fieldName.options.length > 0 )
				fieldName.options.length = 0 ;
	}
}
function createSearchPlaceOption(optionText, optionValue) {
	var option = document.createElement("option");
	option.setAttribute("value",optionValue);
	var text=document.createTextNode(optionText);
	option.appendChild(text);
	return option;
}
function searchProp(form) {
	var status = true;
	var message = new Array();
	var messageCount = 0;
	var field = null;
	if ( form.transactionType.value == "" ) {
		message[messageCount++] = searchPropTransReq;
		if ( field == null ) field = form.transactionType;		
	}
	if ( form.propertyType.value == "" ) {
		message[messageCount++] = searchPropTypeReq;
		if ( field == null ) field = form.propertyType;		
	}
	if ( form.cityId.value == "" ) {	
		message[messageCount++] = searchPropCityReq;
		if ( field == null ) field = form.cityId;		
	}
	var postedTypeSelFlag = false;
	for (var i=0; i<form.postedType.length; i++ ) {
		if ( form.postedType[i].checked == true ) {
			postedTypeSelFlag = true;
			break;
		}
	}
	if ( postedTypeSelFlag == false ) {
		message[messageCount++] = searchPropPostReq;
		if ( field == null ) field = form.postedType[0];		
	}
	if ( messageCount > 0 ) {
		showAlert(message); 
		field.focus(); status = false; return false;
	}
	if ( status == true ) {
		form.propSearchListPage.value = "0";
		form.propSortId.value = "";
		form.propSortOrder.value = "";
		form.submit();
	}
	return false;
}

function searchProfes(form) {
	var status = true;
	var message = new Array();
	var messageCount = 0;
	var field = null;
	if ( form.cityId.value == "" ) {	
		message[messageCount++] = searchProfesCityReq;
		if ( field == null ) field = form.cityId;		
	}
	if ( form.profTypeId.value == "" ) {	
		message[messageCount++] = searchProfesTypeReq;
		if ( field == null ) field = form.cityId;		
	}
	if ( messageCount > 0 ) {
		showAlert(message); 
		field.focus(); status = false; return false;
	}
	if ( status == true ) {
		form.profSearchListPage.value = "1";
		form.submit();
	}
	return false;
}
function postDivOver(type) {
	if ( type == "prop" ) {
		document.getElementById('post_prop_div').className='sp_div_post_on'; 
		document.getElementById('post_prop_title').className='sp_link_post_title_on'; 
		document.getElementById('post_prop_text').className='sp_link_post_text_on'; 
	} else if ( type == "req" ) {
		document.getElementById('post_req_div').className='sp_div_post_on'; 
		document.getElementById('post_req_title').className='sp_link_post_title_on'; 
		document.getElementById('post_req_text').className='sp_link_post_text_on'; 
	}
}
function postDivOut(type) {
	if ( type == "prop" ) {
		document.getElementById('post_prop_div').className='sp_div_post_off'; 
		document.getElementById('post_prop_title').className='sp_link_post_title_off'; 
		document.getElementById('post_prop_text').className='sp_link_post_text_off'; 
	} else if ( type == "req" ) {
		document.getElementById('post_req_div').className='sp_div_post_off'; 
		document.getElementById('post_req_title').className='sp_link_post_title_off'; 
		document.getElementById('post_req_text').className='sp_link_post_text_off'; 
	}
}