//onSubmit we need to check if we have selected a region/community.
//If so, then city/state is disregarded and this is a community search
//If not, then this is a text search, and we need to combine city + state into one "location" and send that
//Also, since the search types offered by the radio buttons are not actual search types
//we need to emulate that functionality.

function QSformSubmit(thisform){
	var postType = function(form){
	for (i=0; i<form.typeSearch.length; i++){
		var type = form.typeSearch[i];
		if(type.checked == true) {
			switch(type.value) {
				case "MLS":
					form.terms.value = "mlsonly";
					form.postType.value = "MLS";
					break;
				case "New Development":
					form.terms.value = "mlsonly";
					form.postType.value = "MLS";
					form.propertyType.value = "New Development";
					break;
				case "Classifieds":
					form.terms.value = "sell";
					break;
				case "Rent":
				form.terms.value = "rent";
				break;
				}
			} else {
			continue;
			}
		}
		for (i=0; i<form.typeSearch.length; i++){
			form.typeSearch[i].checked = false;
		}
		return true;
	}

	var isRegion = function(form){
		if(form.region.value == "All" || form.region.value == ""){
			return false;
		} else {
		return true;
		}
	}

	var makeLoc = function makeLoc(state, zip){
		if(state != "" && state != null){
			if(zip != "" && zip != null){
				return state + ", " + zip;
			} else {
				return state;
			}
		} else {
			return zip;
		}
		state = "";
		zip = "";
	}

	postType(thisform);
	if(!isRegion(thisform)){
	thisform.type.value = "text";
	thisform.location.value = makeLoc(thisform.state.value,thisform.zip.value);
	thisform.state.value = thisform.zip.value = "";

	} else {
		thisform.type.value = "region";
	}
	return true;
}


//When user uses form then hits back-button, reset the form to enable all fields again
var resetEmpty = function(form) {
	for (i=0; i<form.elements.length; i++) {
		form.elements[i].disabled = false;
	}
	form.postType.value = "";	
}


//Callback for onload to handle multiple onload events
function addLoadEvent(func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') { 
		window.onload = func; 
	} else { 
		window.onload = function() { 
			if (oldonload) { 
				oldonload(); 
			} 
			func(); 
		}
	}
}

