function ProfesType (id, name ) {
	this.id	= id;
	this.name = name;
}
var	profTypes =	new	Array();
var	ptCount = 0;
function getProfTypeName(id) {
	for (var i=0; i<profTypes.length; i++ )
		if (profTypes[i].id == id )
			return profTypes[i].name;
}
function ProfesLocation(id, name) {
	this.id = id;
	this.name = name;
}
var profLocs = new Array();
function getProfLocName(id) {
	for (var i=0; i<profLocs.length; i++ )
		if (profLocs[i].id == id )
			return profLocs[i].name;
}
function setContent(form) {
	if (form.cityId.value != "" )
		profSearchLoadLocations(form);
}
function profSearchCheckProfTypes(field) {
	var profTypeIds = document.profesAdvSearchForm.profTypeIds.value;
	var profTypeNames = document.profesAdvSearchForm.profTypeNames.value;
	if ( field.checked == true ) {
		if ( profTypeIds != "" ) {
			document.profesAdvSearchForm.profTypeIds.value = profTypeIds + "," + field.value;
			document.profesAdvSearchForm.profTypeNames.value = profTypeNames + "|" + getProfTypeName(field.value);
		} else {
			document.profesAdvSearchForm.profTypeIds.value = field.value;
			document.profesAdvSearchForm.profTypeNames.value = getProfTypeName(field.value);
		}
	} else if ( field.checked == false ) {
		if ( profTypeIds != "" ) {
			var ids = profTypeIds.split(",");
			var text = "";
			for ( i=0; i<ids.length; i++ ) {
				if ( ids[i] != field.value )
				text = text + ids[i] + ",";
			}
			if ( text.length>0 )
				text = text.substring(0, text.length-1);
			document.profesAdvSearchForm.profTypeIds.value = text;
		}
		if ( profTypeNames != "" ) {
			var ids = profTypeNames.split("|");
			var text = "";
			for ( i=0; i<ids.length; i++ ) {
				if ( ids[i] != getProfTypeName(field.value) )
				text = text + ids[i] + "|";
			}
			if ( text.length>0 )
				text = text.substring(0, text.length-1);
			document.profesAdvSearchForm.profTypeNames.value = text;
		}
	}
}
function profSearchLoadLocations(form) {
	document.getElementById('prof_loc_row').style.display = 'none';
	form.locationIds.value = "";
	form.locationNames.value = "";
	var cityId = form.cityId.value;
	if ( cityId != "" && cityId != 0 && cityId != 1 ) {
		sendAjaxReq(profSearchUpdateLocations, "getSearchProfLocations", cityId, "places.do")
		document.getElementById('prof_loc_row').style.display='';
		document.getElementById('prof_loc_div').innerHTML = '<font class="sf_form_label_text">&nbsp;&nbsp;Loading...</font>';
		form.search.disabled = true;
	} else {
		document.getElementById('prof_loc_div').innerHTML = "";
	}
}
function profSearchUpdateLocations(locationXML) {
	var content = locationXML.getElementsByTagName("content")[0];
	var total = content.getAttribute("total");
	if ( total > 0 ) {
		var locText = ""
		locText = locText + '<table border="0" cellpadding="0" cellspacing="0">' ;
		locText = locText + '<tr>';
		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;
		    profLocs[i] = new ProfesLocation(id, name);
			locText = locText + '<td><input type="checkbox" name="locationId" value="' + id + '" onclick="profSearchCheckLocations(this);">';
			locText = locText + '<font class="sf_form_label_text"> ' + name + '</font></td>';
			locText = locText + '<td width="5"></td>';
			if ( (i+1)%2 == 0 )
				locText = locText + '</tr><tr>';
		}
		locText = locText + '<td><input type="checkbox" name="locationId" value="1" onclick="profSearchCheckLocations(this);">';
		locText = locText + '<font class="sf_form_label_text"> Other</font></td>';
		document.getElementById('prof_loc_row').style.display='';
		document.getElementById('prof_loc_div').innerHTML = locText;
	} else {
		document.getElementById('prof_loc_row').style.display='';
		document.getElementById('prof_loc_div').innerHTML = '<font class="sf_form_label_text">&nbsp;&nbsp;None</font>';
	}
	document.profesAdvSearchForm.search.disabled = false;
}
function profSearchCheckLocations(field) {
	var locationIds = document.profesAdvSearchForm.locationIds.value;
	var locationNames = document.profesAdvSearchForm.locationNames.value;
	if ( field.checked == true ) {
		if ( locationIds != "" ) {
			document.profesAdvSearchForm.locationIds.value = locationIds + "," + field.value;
			if ( field.value == 1 )
				document.profesAdvSearchForm.locationNames.value = locationNames + "|Other";
			else
				document.profesAdvSearchForm.locationNames.value = locationNames + "|" + getProfLocName(field.value);
		} else {
			document.profesAdvSearchForm.locationIds.value = field.value;
			if ( field.value == 1 )
				document.profesAdvSearchForm.locationNames.value= "Other";
			else
				document.profesAdvSearchForm.locationNames.value = getProfLocName(field.value);
		}
	} else if ( field.checked == false ) {
		if ( locationIds != "" ) {
			var ids = locationIds.split(",");
			var idText = "";
			var nameText = "";
			for ( i=0; i<ids.length; i++ ) {
				if ( ids[i] != field.value ) {
					idText = idText + ids[i] + ",";
					if ( ids[i] == 1 )
						nameText = nameText + "Other" + "|";
					else
						nameText = nameText + getProfLocName(ids[i]) + "|";
				}
			}
			if ( idText.length>0 )
				idText = idText.substring(0, idText.length-1);
			document.profesAdvSearchForm.locationIds.value = idText;
			if ( nameText.length>0 )
				nameText = nameText.substring(0, nameText.length-1);
			document.profesAdvSearchForm.locationNames.value = nameText;
		}
	}
}
function searchProfessionals(form) {
	if ( validateProfesAdvSearchForm(form) ) {
		//disableAction(form);
		form.submit();
	}
	return false;
}



