/*************************************************************************
* Name: searchforclose_again
*************************************************************************/
function searchforclose_again(page, url) {
	document.cookie = "SEARCH_PAGE=" + page;
	window.location = url;
}

/*************************************************************************
* Name: search_again
*
* this functions works as if the user submitted the search form
*************************************************************************/
function search_again(page, url) {
	document.cookie = "SEARCH_PAGE=" + page;
	window.location = url;
}

/******************************************************************************
 * Name: enableDisableSearchLocations
******************************************************************************/
function enableDisableSearchLocations(search_type) {

	if(search_type == 'chicago_search') {
		/* deselect all cities that were selected */
		for(var i = 0; i < document.search_form['location2[]'].length; i++){
			document.search_form['location2[]'].options[i].selected = false;
		}

		/* disable the city-select-box */
		document.search_form['location2[]'].disabled = true;

		/* enable the zipcode-select-box */
		document.search_form['location1[]'].disabled = false;
	}
	else {
		/* deselect all zipcodes that were selected */
		for(var i = 0; i < document.search_form['location1[]'].length; i++){
			document.search_form['location1[]'].options[i].selected = false;
		}

		/* enable the city-select-box */
		document.search_form['location2[]'].disabled = false;

		/* disable the zipcode-select-box */
		document.search_form['location1[]'].disabled = true;
	}
}

/******************************************************************************
 * Name: ValidateRegistrationForm
******************************************************************************/
function ValidateRegistrationForm(the_form) {

	var office_agent_id   = the_form.office_agent.options[the_form.office_agent.selectedIndex].value;
	var office_agent_name = the_form.office_agent.options[the_form.office_agent.selectedIndex].text;

	if(isEmpty(the_form.email.value)) {
		alert("Please provide your email address");
		return false;
	}

	if(isEmpty(the_form.first_name.value)) {
		alert("Please provide your first name");
		return false;
	}

	if(isEmpty(the_form.last_name.value)) {
		alert("Please provide your last name");
		return false;
	}

	if(isEmpty(the_form.phone_number.value)) {
		alert("Please provide your home phone number");
		return false;
	}

	if(office_agent_id == '') {
		alert("Please answer the question, Are you currently working with a Mi Casa agent?");
		return false;
	}

	/* check to see where the user wants the password to be sent: 0 = email addrees, 1 = cell phone */
	if(the_form.send_to[0].checked) {
		if(isEmpty(the_form.email.value)) {
			alert("Please provide your email address");
			return false;
		}
	}
	else {
		if(isEmpty(the_form.phone1.value) || isEmpty(the_form.phone2.value) || isEmpty(the_form.phone3.value)) {
			alert("Please provide your correct cell phone number");
			return false;
		}

		var selected_cellphone_provider = the_form.cellphone_provider.options[the_form.cellphone_provider.selectedIndex].value;
		if(selected_cellphone_provider == '') {
			alert("Please provide your cell phone service provider");
			return false;
		}
	}

	return true;
}

/******************************************************************************
 * Name: isEmpty
******************************************************************************/
function isEmpty(my_string) {
	var clean_string = my_string.replace(/ +/g, "");

	if(clean_string.length == 0) { return true; }

	return false;
}

/******************************************************************************
 * Name: OpenNewPublicWindow
******************************************************************************/
function OpenNewPublicWindow(url, w, h) {
	/* grab the width and height of the window */
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;

	/* create the window */
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes,status=no'
	win      = window.open(url, 'PublicWindow', winprops);

	win.focus();
}

