function formControls() {
	if (document.getElementById("QuickSearchForm")) {
		countryBox = document.getElementById("QuickSearchForm").countryID;
		regionBox = document.getElementById("QuickSearchForm").regionID;
		stateBox = document.getElementById("QuickSearchForm").stateID;
		locationBox = document.getElementById("QuickSearchForm").locationID;
		countryBox.onchange = new Function("populateSelect('userSearch')");
		regionBox.onchange = new Function("populateSelect('userSearch')");
		stateBox.onchange = new Function("populateSelect('userSearch')");
		locationBox.onchange = new Function("populateSelect('userSearch')");
		document.getElementById("QuickSearchSubmit").onclick = new Function("generateSearchURL()");
	}
	if (document.getElementById("ContactForm")) {
		name = document.getElementById("ContactForm").Name;
		email = document.getElementById("ContactForm").Email;
		phoneNumber = document.getElementById("ContactForm").PhoneNumber;
		mobileNumber = document.getElementById("ContactForm").MobileNumber;
		address = document.getElementById("ContactForm").Address;
		name.onfocus = new Function("focusValues(name, 'Name')");
		name.onblur = new Function("blurValues(name, 'Name')");
		email.onfocus = new Function("focusValues(email, 'E-Mail')");
		email.onblur = new Function("blurValues(email, 'E-Mail')");
		phoneNumber.onfocus = new Function("focusValues(phoneNumber, 'Phone Number')");
		phoneNumber.onblur = new Function("blurValues(phoneNumber, 'Phone Number')");
		mobileNumber.onfocus = new Function("focusValues(mobileNumber, 'MobileNumber')");
		mobileNumber.onblur = new Function("blurValues(mobileNumber, 'Mobile Number')");
		address.onfocus = new Function("focusValues(address, 'Address')");
		address.onblur = new Function("blurValues(address, 'Address')")
	}
}

function generateSearchURL() {
	countryValue = document.getElementById("QuickSearchForm").countryID.value;
	regionValue = document.getElementById("QuickSearchForm").regionID.value;
	stateValue = document.getElementById("QuickSearchForm").stateID.value;
	locationValue = document.getElementById("QuickSearchForm").locationID.value;
	hotelValue = document.getElementById("QuickSearchForm").hotelID.value;
	requestURL = "/ajax/searchURL.php";
	requestVar = "countryID=" + countryValue;
	requestVar += "&regionID=" + regionValue;
	requestVar += "&stateID=" + stateValue;
	requestVar += "&locationID=" + locationValue;
	requestVar += "&hotelID=" + hotelValue;
	myRequest = new ajaxObject(requestURL);
	myRequest.callback = function(responseText,responseStatus) { processResult(responseText,responseStatus);}
	myRequest.update(requestVar,"POST");
}

function scrollDownForm() {
	$("#ScrollDownForm").append("<span id=\"loading\">Processing</span>");
	var fem = $("#ScrollDownForm").serialize(),
	note = $(".note");
	$.ajax({
		type: "POST",
		url: "/ajax/checkTrip.php?Submit=1",
		data: fem,
		success: function(msg) {
			if ( note.height() ) {			
				note.slideUp(1000, function() { $(this).hide(); });
			} else {
				note.hide();
			}

			$("#loading").fadeOut(300, function() {
				$(this).remove();
				// Address Sent? Show the "Thank You" message and hide the form
				if (msg >= 0) {
					result = "Your message has been sent. Thank you!";
					updateTripPlanner(msg);
					//$('#PopInfo').trigger('reveal:close');
					//window.location.href = "/trip_planner/";
				} else {
					result =msg;
				}
				var i = setInterval(function() {
					if ( !note.is(":visible") ) {
						note.html(result).slideDown(1000);
						clearInterval(i);
					}
				}, 40);	
			});
		}
	});
	//return false;
}

function popoverForm() {
	$("#PopUpForm").append("<span id=\"loading\">Processing</span>");
	var fem = $("#PopUpForm").serialize(),
	note = $(".note");
	$.ajax({
		type: "POST",
		url: "/ajax/addTrip.php?Submit=1",
		data: fem,
		success: function(msg) {
			if ( note.height() ) {			
				note.slideUp(1000, function() { $(this).hide(); });
			} else {
				note.hide();
			}

			$("#loading").fadeOut(300, function() {
				$(this).remove();
				// Address Sent? Show the "Thank You" message and hide the form
				if (msg >= 0) {
					result = "Your message has been sent. Thank you!";
					updateTripPlanner(msg);
					$('#PopInfo').trigger('reveal:close');
				} else {
					result =msg;
				}
				var i = setInterval(function() {
					if ( !note.is(":visible") ) {
						note.html(result).slideDown(1000);
						clearInterval(i);
					}
				}, 40);	
			});
		}
	});
	//return false;
}

function focusValues(formElement, val) {
	if (formElement.value == val) {
		formElement.value = "";
	}
}

function blurValues(formElement, val) {
	if (formElement.value == "") {
		formElement.value = val;
	}
}

function trimString(str) {
	str = this != window? this : str;
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function isEmpty(TmpString) {
	if (!TmpString) {
		return true;
	}
	TmpString = trimString(TmpString);
	if (TmpString.length <= 0) {
		return true;
	}
	return false;
}

function clearOptions(obj) {
	objGroups = obj.getElementsByTagName("optgroup");
	if (objGroups.length >= 1) {
		for (var i=objGroups.length-1;i>=0;i--) {
			obj.removeChild(objGroups[i]);
		}
	}
	if ((obj) && (obj.length)) {
		obj.length = 0;
	}
}
