
<!-- hide javascript from old browsers

function lastPage() {
	history.go(-1);
	return true;
}

function checkInputSize(input,minsize) {
	msg = "Input field [" + input.name + "] must contain a value.";
	var sStr = input.value;
	if (sStr.length < minsize) {
		input.focus();
		alert(msg);
		return false;
	}
	return true;
}

function required(input, strMsg) {
	var msg = "The form is incomplete! Please complete the form and resubmit.";
	var bTest
	var form =  document.forms['guestbook']
	
	if (input.type=="text" || input.type=="hidden" || input.type=="password"){
		bTest=(input.value.length == 0);
	}else if (input.type=="radio"){
		var strRadioName=input.name
		var intRadioLength=eval("form.elements[\"" + strRadioName + "\"].length")
		bTest=true;
		for (var m=0;m<intRadioLength;m++){
			if (eval("form.elements[\"" + strRadioName + "\"][m].checked")){
				bTest=false;
				break;
			}
		}
	}
	if (bTest) {
		input.focus();
		if (strMsg.length > 0)
			alert(strMsg);
		else
			alert(msg);
		return false;
	}
	
	return true;
}

function verifyEmailAddress(input) {
	var msg = "Invalid e-mail address: '" + input.value + "'!  Please enter a valid e-mail address."
	sValue = input.value
	bValidAddress = false;
	nPeriodsFound = 0
	for ( var i = 0, x = 0 ; i < sValue.length ; i++ ) {
		var ch = sValue.substring( i, i + 1);
		var msg1 = "[" + ch + "]";
		if (ch == "@") {
			bValidAddress = true;
		}
		else
		if (ch == ".") {
			nPeriodsFound++;
		}
	}
	if (bValidAddress && nPeriodsFound > 0) {
		if (sValue.toLowerCase() == "username@worldnet.com") {
			msg = "Please specify your E-Mail Address!";
			input.focus();
			alert(msg);
			return false;
		}
		return true;
	}
	alert(msg);
	return false;
}

function checkAreaCode(input) {
	var sStr = input.value;
	var msg = sStr + " is not a valid telephone area code!  Please enter a valid area code."
	if (sStr.length != 3) {
			input.focus();
			alert(msg);
			return false;
	}
	for ( var i = 0 ; i < sStr.length ; i++ ) {
		var ch = sStr.substring( i, i + 1);
		if (ch == "-") {
			continue;
		}
		if (ch < "0" || ch > "9") {
			input.focus();
			alert(msg);
			return false;
		}
	}
	return true;
}

function checkPhoneNo(input) {
	var sStr = input.value;
	var msg = sStr + " is not a valid telephone number!  Please enter a valid telephone number."
	for ( var i = 0 ; i < sStr.length ; i++ ) {
		var ch = sStr.substring( i, i + 1);
		if (ch == "-") {
			continue;
		}
		if (ch < "0" || ch > "9") {
			input.focus();
			alert(msg);
			return false;
		}
	}
	return true;
}

function checkGuestBook() {
	if (!required(document.guestbook.first_name, "Please enter your first name."))
		return false;
	else
	if (!required(document.guestbook.last_name, "Please enter your last name."))
		return false;
	else
	if (!required(document.guestbook.cust_email, "Please enter your e-mail address."))
		return false;
	else
	if (!verifyEmailAddress(document.guestbook.cust_email))
		return false;
	else
	if (!required(document.guestbook.cust_area, "Please enter your area code."))
		return false;
	else 
	if (!checkAreaCode(document.guestbook.cust_area))
		return false;
	else
	if (!required(document.guestbook.cust_phone, "Please enter your telephone number."))
		return false;
	else
	if (!checkPhoneNo(document.guestbook.cust_phone))
		return false;
	else
	/*if (!required(document.guestbook.withBroker[0], "Please indicate whether you are currently working with an Agent/Broker."))
		return false;*/
	return true;
}

/* elements can be turned on and off on the registration form */
var g_arrUserConfigElements = new Array();
var g_arrRequiredElements = new Array();
function checkRegistrationForm(form)
{
	if (!required(form.first_name, "Please enter your first name."))
		return false;
	else if (!required(form.last_name, "Please enter your last name."))
		return false;
	else if (!required(form.cust_email, "Please enter your e-mail address."))
		return false;
	else if (!verifyEmailAddress(form.cust_email))
		return false;
	else if (!checkFormElement(form.cust_day_phone, "Please enter your telephone number."))
		return false;
		
	if (form.cust_street && form.cust_city && form.cust_state && form.cust_postal)
	{
		var strName = "address";
		var bRequired = false;
		if (!isUserConfigElement(strName))
		{
			// this is not a user config element -- default behavior is it's NOT required, (to be backwards compatible with old version)
			bRequired = false;
		}
		else if(isRequiredUserConfigElement(strName))
			bRequired = true;
			
		if (bRequired)
		{
			// Address is required
			if (!required(form.cust_street, "Please enter your street address."))
				return false;
			else if (!required(form.cust_city, "Please enter your city."))
				return false;
			else if (!required(form.cust_state, "Please enter your state."))
				return false;
			else if (!required(form.cust_postal, "Please enter your zip."))
				return false;
		}
	}
	
	if (!required(form.password, "Please enter your password."))
		return false;
	else if (form.password_confirm)
	{
		if (!required(form.password_confirm, "Please confirm your password."))
			return false;
		else if (form.password_confirm.value!=form.password.value)
		{
			alert("Your password and confirmation password do not match.")
			return false;
		}
	}

	if (form.password_question_code && form.password_question_code.type)
	{
		if (form.password_question_code.type != "hidden")
		{
			// check if password hint is a user config element
			var strName = "passwordhint";
			var bRequired = false;
			if (!isUserConfigElement(strName))
			{
				// this is not a user config element -- default behavior is it's required
				bRequired = true;
			}
			else if(isRequiredUserConfigElement(strName))
				bRequired = true;
				
			if (bRequired)
			{
				//Password Hint is required
				if (form.password_question_code.options[form.password_question_code.selectedIndex].value=='')
				{
					alert("Please select your password hint question.")
					return false;
				}
				else
				{
					if (!required(form.password_answer, "Please answer your password hint question."))
					{
						return false;
					}
				}
			}
		}
	}

	if (!checkFormElement(form.cust_q1, "Please select if you need to sell your current property before you can buy."))
		return false;
	else if (!checkFormElement(form.cust_q2, "Please select if you are working with any other real estate professionals."))
		return false;

	return true;
}

function isUserConfigElement(strName)
{
	if (!strName)
		strName = "";
		
	strName = strName.toLocaleLowerCase();
	// user configurable elements are added to g_arrUserConfigElements by calling script
	for (var i=0; i<g_arrUserConfigElements.length; i++)
	{
		if (strName == g_arrUserConfigElements[i])
			return true;
	}
	return false;
}

function isRequiredUserConfigElement(strName)
{
	// required user configurable elements are added to g_arrRequiredElements by calling script
	if (!strName)
		strName = "";
		
	strName = strName.toLocaleLowerCase();
	for (var i=0; i<g_arrRequiredElements.length; i++)
	{
		if (strName == g_arrRequiredElements[i])
			return true;
	}
	return false;
}

function checkFormElement(input, strMsg) 
{
	if (!input)
		return true;	// element was never added to form, so it's not required
	else if (input.type=="hidden")
		return true;	// element was added as hidden var, it's not editable by user

	var msg = "The form is incomplete! Please complete the form and resubmit.";
	var bTest, bRadioGroup, bRequired

	bRadioGroup = false;
	if (input.type=="text" || input.type=="hidden" || input.type=="password")
	{
		bTest=(input.value.length == 0);
	}
	else if (input.type=="radio")
	{
		var strRadioName=input.name
		var intRadioLength=eval("form.elements[\"" + strRadioName + "\"].length")
		bTest=true;
		for (var m=0;m<intRadioLength;m++)
		{
			if (eval("form.elements[\"" + strRadioName + "\"][m].checked"))
			{
				bTest=false;
				break;
			}
		}
	}
	else if (isRadioGroup(input))
	{
		bRadioGroup = true;
		bTest = true;
		for (var i=0; i<input.length; i++)
		{
			if (input[i].checked)
			{
				bTest = false;
				break;
			}
		}
	}

	if (bTest) 
	{
		// element has no value; check if it's a user config element
		var strName;
		if (bRadioGroup)
			strName = new String(input[0].id);
		else
			strName = new String(input.name);
		
		bRequired = false;	
		if (!isUserConfigElement(strName))
		{
			// this is not a user config element -- default behavior is it's required
			bRequired = true;
		}
		else if(isRequiredUserConfigElement(strName))
			bRequired = true;
		
		if (!bRequired)
		{
			// element is not required
			return true;
		}

		// element is required
		if (bRadioGroup)
			input[0].focus();
		else
			input.focus();
			
		if (strMsg.length > 0)
			alert(strMsg);
		else
			alert(msg);
		return false;
	}
	return true;
}

function isRadioGroup(r)
{
	if (!r.length)
		return false;
	if (r.length < 1)
		return false;
	for (var i=0; i<r.length; i++)
	{
		if (r[i].type != "radio")
			return false;
	}
	return true;		
}


function checkProfile(form,err_msg) {
	if (intSubmitClicks<1 || true){
	if (!required(form.first_name, "Please enter your first name."))
		return false;
	else
	if (!required(form.last_name, "Please enter your last name."))
		return false;
	else
	if (!required(form.cust_email, "Please enter your e-mail address."))
		return false;
	else
	if (!verifyEmailAddress(form.cust_email))
		return false;
	else
	if (!required(form.cust_day_phone, "Please enter your telephone number."))
		return false;
	else
	if (!required(form.password, "Please enter your password."))
		return false;
	else
	if (form.password_confirm){
		if (!required(form.password_confirm, "Please confirm your password."))
		return false;
		else
		if (form.password_confirm.value!=form.password.value){
			alert("Your password and confirmation password do not match.")
		return false;
	}
	}
	
		if (form.password_question_code && form.password_question_code.type){
			if (form.password_question_code.type != "hidden"){
	if (form.password_question_code.options[form.password_question_code.selectedIndex].value==''){
		alert("Please select your password hint question.")
		return false;
	}else{
		if (!required(form.password_answer, "Please answer your password hint question.")){
			return false;
		}
	}
		}
		}
	}else{
		intSubmitClicks++;
		return false;	
	}
	intSubmitClicks++;
	return true;
}

var intSubmitClicks=0
function disableSecondClick(form,strSubmitText){
	if (intSubmitClicks<1){
		if (document.all) {
			try{
				for (var i=0;i<document.all.length;i++){
					document.all("spanSubmit").style.cursor="wait"
					if (document.all.item(i).id=="spanSubmit"){
						spanSubmit.innerHTML="Searching..."
					}else{
						document.all.item(i).style.cursor="wait"
					}
				}
			}catch(e){
				form.submit();
				return;
			}
		}
		if (checkGuestBook()){
			intSubmitClicks++;
			form.submit();
		}else{
			if (document.all) {
				try{
					document.all("spanSubmit").style.cursor=""
					for (var i=0;i<document.all.length;i++){
						if (document.all.item(i).id=="spanSubmit"){
							spanSubmit.innerHTML="<INPUT TYPE=\"button\" onClick=\"disableSecondClick(this.form,'" + strSubmitText  +  "')\" NAME=\"action\" VALUE=\"" + strSubmitText + "\">"
						}else{
							document.all.item(i).style.cursor=""
						}
					}
				}catch(e){
					form.submit();
					return;
				}
			}
		} 
	}
}

// end of hiding -->


