function trim() {
	for (j=0; j<document.forms.length; j++) {
		for (i=0; i<document.forms[j].elements.length; i++) {
			if (((document.forms[j].elements[i].type == "text") || (document.forms[j].elements.type == "password")) && (document.forms[j].elements[i].value != "")) {
				var tmp = document.forms[j].elements[i].value;
				while (tmp.indexOf(" ") == 0) {
					tmp = tmp.substring(1, tmp.length);
					if (tmp.length == 0) {
						break;
					}
				}
				while (tmp.lastIndexOf(" ") == tmp.length-1) {
					tmp = tmp.substring(0, tmp.length-1);
					if (tmp.length == 0) {
						break;
					}
				}
				document.forms[j].elements[i].value = tmp;
			}
		}
	}
}
function changeImg(name,file) {
	if (document.images) {
		eval("document.images['"+name+"'].src='"+file+"'");
	}
}
/*
function popWindow(url,popname,popwidth,popheight,scrolling) {
	window.name = "daddy";
	var scrollBoolean = "yes";
	if (scrolling) {
		scrollBoolean = scrolling;
	}
	var popupWin = window.open(url,popname,"width="+popwidth+",height="+popheight+",menubar=no,toolbar=no,location=no,status=no,resizable=yes,scrollbars="+scrollBoolean)
	if (!document.all && window.focus) popupWin.focus();
}
*/
function popWindow(url,popname,popwidth,popheight,scrolling,status) {
	// this function pops a new window and centers it over the active browser window
	// rather than displaying it in the top left corner of the entire desktop space
	window.name = "daddy";
	var scrollBoolean = "yes";
	if (scrolling) {
		scrollBoolean = scrolling;
	}
	var statusBoolean = "yes";
	if (status) {
		statusBoolean = status;
	}
	var newWidth = popwidth;
	var newHeight = popheight;
	var newTop = 0, newLeft = 0;
	if (window.outerHeight) {
		newTop = window.screenY + ((window.outerHeight - newHeight) / 2);
	} 
	else {
		newTop = window.screenTop + ((document.body.offsetHeight - newHeight) / 2);
	}
	if (window.outerWidth) {
		newLeft = window.screenX + ((window.outerWidth - newWidth) / 2);
	} 
	else {
		newLeft = window.screenLeft + ((document.body.offsetWidth - newWidth) /	2);
	}
	var popupWin = window.open(url, popname, 
		'screenX=' + newLeft +
		',screenY=' + newTop +
		',left=' + newLeft +
		',top=' + newTop +
		',width=' + newWidth +
		',height=' + newHeight +
		',menubar=no' +
		',toolbar=no' +
		',location=no' +
		',status=' + statusBoolean +
		',resizable=yes' +
		',scrollbars=' + scrollBoolean);

	if (!document.all && window.focus) popupWin.focus();
}
function validateEmail(email) {
	invalidChars = " /:,;"
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) != -1) {
			return false;
		}
	}
	atPos = email.indexOf("@",1);
	if (atPos == -1) {
		return false;
	}
	if (email.indexOf("@",atPos+1) != -1) {
		return false;
	}
	periodPos = email.indexOf(".",atPos);
	if (periodPos == -1) {
		return false;
	}
	if (periodPos+3 > email.length) {
		return false;
	}
	return true;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
MM_preloadImages("images/arrowbullet.gif");

function validateQuickSearchForm() {
	trim();
	if ((document.quickSearchForm.mls.value == "") && (document.quickSearchForm.keyword.value == "")) {
		alert("Please enter an MLS number or a keyword");
		return false;
	}
	else {
		return true;
	}
}
function validateQuickSearchFormV4(isCommercial) {
	trim();
	if (isCommercial) {
		if ((document.quickSearchForm.keyword.value == "")
			|| 
			(document.quickSearchForm.keyword.value == "Keyword/Address")) {
				alert("Please enter an address or keyword");
				return false;
			}
		else {
			document.quickSearchForm.elements["action"].value = "search";
			if (document.quickSearchForm.keyword.value == "") {
				document.quickSearchForm.keyword.value = "";
			}
			return true;
		}
	}
	else {
		if ((document.quickSearchForm.mls.value == "" && document.quickSearchForm.keyword.value == "")
			|| 
			(document.quickSearchForm.mls.value == "MLS #" && document.quickSearchForm.keyword.value == "Address/Keyword")) {
				alert("Please enter an MLS number or a keyword");
				return false;
			}
		else {
			document.quickSearchForm.elements["action"].value = "search";
			if (document.quickSearchForm.mls.value == "MLS #") {
				document.quickSearchForm.mls.value = "";
			}
			if (document.quickSearchForm.keyword.value == "") {
				document.quickSearchForm.keyword.value = "";
			}
			return true;
		}
	}
}
function validateQuickLoginFormV4() {
	if (document.quickLoginForm.email.value == "" || document.quickLoginForm.email.value == "Email") {
		alert("Please enter your email address");
		return false;
	}
	else if (document.quickLoginForm.password.value == "" || document.quickLoginForm.password.value == "Password") {
		alert("Please enter your password");
		return false;
	}
	else {
		return true;
	}
}
function setFieldVal(theField, theVal) {
	//alert(theField.type);
	if (theField.value == theVal) {
		if (theField.name == "password") {
			//theField.type = "password";
		}
		theField.value = "";
		theField.style.color="black";			
	}
	else if (theField.value == "") {
		if (theField.name == "password") {
			//theField.type = "text";
		}
		theField.value = theVal;
		theField.style.color="7F7F7F";			
	}
}
function clearBG(theForm) {
	for (i=0; i<theForm.elements.length; i++) {
		if ((theForm.elements[i].type != "submit") && 
			(theForm.elements[i].type != "button") &&
			(theForm.elements[i].type != "checkbox") &&
			(theForm.elements[i].type != "select-one")) {
			theForm.elements[i].style.background = 'ffffff';
		}
	}
}
function setRedBG(formElement,theColor) {
	//var toEvaluate=formElement+".style.background = '"+theColor+"'";
	var toEvaluate=formElement+".style.background = '"+theColor+"'";
	//EAD7DC
	eval(toEvaluate);
}
function checkdate(object_value) { 
	//Returns true if value is a date format or is NULL
	//otherwise returns false	
	if (object_value.length == 0)  return true; 

	//Returns true if value is a date in the mm/dd/yyyy format
	isplit = object_value.indexOf('/');

	if (isplit == -1 || isplit == object_value.length)	
		return false; 

	sMonth = object_value.substring(0, isplit);
	isplit = object_value.indexOf('/', isplit + 1);

	if (isplit == -1 || (isplit + 1 ) == object_value.length)
		return false;
		
	sDay = object_value.substring((sMonth.length + 1), isplit);
	sYear = object_value.substring(isplit + 1);

	var chkint = checkinteger(sMonth);
	if (chkint == false) //check month
		return false;

	var chkrng = checkrange(sMonth, 1, 12);
	if (chkrng == false) //check month
		return false;
	else if (! checkinteger(sYear)) //check year
		return false;
	else if (! checkrange(sYear, 0, 9999)) //check year
		return false;
	else if (! checkyearspecial(sYear)) // more year checks
		return false;
	else if (! checkinteger(sDay)) //check day
		return false;
	else if (! checkday(sYear, sMonth, sDay)) // check day
		return false;
	else
		return true;
}


function checkrange(object_value, min_value, max_value) { 
	//if value is in range then return true else return false
	if (object_value.length == 0)
		return true;

	var chknum = checknumber(object_value);
	if (chknum == false)
		return false;
	else {
		var rng = numberrange(eval(object_value), min_value, max_value);
		return (numberrange((eval(object_value)), min_value, max_value));
	}

	//All tests passed, so...
	return true;
}

function numberrange(object_value, min_value, max_value) {
	// check minimum
	if (min_value != null) {
		if (object_value < min_value)
			return false;
	}

	// check maximum
	if (max_value != null) {
		if (object_value > max_value)
			return false;
	}

	//All tests passed, so...
	return true;
}

function checkday(checkYear, checkMonth, checkDay) {
	maxDay = 31;

	if (checkMonth == 4 || checkMonth == 6 ||
		checkMonth == 9 || checkMonth == 11)
		maxDay = 30;
	else if (checkMonth == 2) {
		if (checkYear % 4 > 0)
			maxDay =28;
		else if (checkYear % 100 == 0 && checkYear % 400 > 0)
			maxDay = 28;
		else
			maxDay = 29;
	}
	return checkrange(checkDay, 1, maxDay); //check day
}

function checkinteger(object_value) {
	//Returns true if value is a number or is NULL
	//otherwise returns false	

	if (object_value.length == 0)
		return true;

	//Returns true if value is an integer defined as
	//   having an optional leading + or -.
	//   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;

	//The first character can be + -  blank or a digit.
	check_char = object_value.indexOf(decimal_format)
	//Was it a decimal?
	if (check_char < 1)
		return checknumber(object_value);
	else
		return false;
}


function checknumber(object_value) {
	//Returns true if value is a number or is NULL
	//otherwise returns false	

	if (object_value.length == 0)
		return true;
		
	//Returns true if value is a number defined as
	//   having an optional leading + or -.
	//   having at most 1 decimal point.
	//   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

	//The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
	//Was it a decimal?
	if (check_char == 1)
		decimal = true;
	else if (check_char < 1)
		return false;
	
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++) {
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1) {
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0) {
			if (decimal || digits)	
				trailing_blank = true;
				// ignore leading blanks
		}
		else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
	
	//All tests passed, so...
	return true
}
function checkyearspecial(syear) {
	// The year must be either 2 digits or 4 digits
	if (syear.length != 2 && syear.length != 4) {
		return false;
	}

	// For the database the year must be >= 1753 and <= 9999
	if (syear.length == 4) {
		if (syear < 1753 || syear > 9999) 
		return false;
	}
	//All tests passed, so...
	return true;
}

// Some generic functions for checking fields

function checkRequired(thisField) {
	// This function will check to see if a field is empty.  If it
	// is false will be returned.  Otherwise true will be returned.
	
	// thisField = removeSpaces(thisField);
	if (thisField == "") { 
		return false; 
	}
	return true;
}

function checkLength(thisField, maxl) {
	// This function will check the length of the field passed in.
	// If it exceeds the max length passed, the false will be returned.
	ll = thisField.length;
	if (ll > maxl) { 
		return false; 
	}
	return true;
}
	
function removeSpaces(somestr) {
	// remove all the spaces in case the value is just spaces
	do  { 
		i = somestr.search(" ");
		if (i > -1) { 
			somestr = somestr.replace(" ", ""); 
		}
	} 
	while (i > -1);
		return somestr;
}
//utility function that returns true if a string contains only whitespace characters
function isblank(s){
	for(var i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}	
	return true;
}
//function to check for phone format
function checkphone(theFormField,object_value){
	if (object_value.length == 0) {
		return true;
	}
	newPhone=removeCharacters(object_value);
			
	if ((newPhone.length != 10) || isNaN(newPhone)) {
		return false;
	}
	else {
		theFormField.value=newPhone;
		return true;
	}
}
//function to check for zip format
function checkpostalcode(object_value){
	if (object_value.length == 0) {
		return true;
	}
	else if (isUSA) {
		if (object_value.length != 5 && object_value.length != 10) {
			return false;
		}
	
		// make sure first 5 digits are a valid integer
		if (object_value.charAt(0) == "-" || object_value.charAt(0) == "+") {
			return false;
		}
	
		if (!checkinteger(object_value.substring(0,5))) {
			return false;
		}
	
		if (object_value.length == 5) {
			return true;
		}
			
		// check if separator is either a'-' or ' '
		if (object_value.charAt(5) != "-" && object_value.charAt(5) != " ") {
			return false;
		}
	
		// check if last 4 digits are a valid integer
		if (object_value.charAt(6) == "-" || object_value.charAt(6) == "+") {
			return false;
		}
	
		return (checkinteger(object_value.substring(6,10)));
	}
	else {
		return true;
	}
}
//function to check for ssn format
function checkssn(theObject,object_value){
	if (object_value.length == 0) {
		return true;
	}
	else {		
		newSSN = removeCharacters(object_value);
		
		if (newSSN.length != 9) {
			return false;
		}

		// make sure all 9 digits are a valid integer
		/*
		if (newSSN.charAt(0) == "-" || newSSN.charAt(0) == "+")
			return false;
		*/

		if (isNaN(newSSN)) {
			return false;
		}

		else {
			theObject.value=newSSN;
			return true;
		}
	}
}
function removeCharacters(theString) {
	newString=theString.replace(/[^0-9]/g, '');
	return newString;
}
function addFormField(form, fieldName, fieldValue) {
    var inputField = document.createElement("input");
    inputField.setAttribute("name", fieldName);
    inputField.setAttribute("id", fieldName);
    inputField.setAttribute("type", "hidden");
    inputField.setAttribute("value", fieldValue);
    form.appendChild(inputField);
}
var addthis_config = {
	data_track_clickback: true
}