﻿var arrayOfRolloverClasses = new Array();
	var arrayOfClickClasses = new Array();
	var activeRow = false;
	var activeRowClickArray = new Array();
	
	function highlightTableRow()
	{
		var tableObj = this.parentNode;
		if(tableObj.tagName!='TABLE')tableObj = tableObj.parentNode;

		if(this!=activeRow){
			this.setAttribute('origCl',this.className);
			this.origCl = this.className;
		}
		this.className = arrayOfRolloverClasses[tableObj.id];
		
		activeRow = this;
		
	}
	
	function clickOnTableRow()
	{
		var tableObj = this.parentNode;
		if(tableObj.tagName!='TABLE')tableObj = tableObj.parentNode;		
		
		if(activeRowClickArray[tableObj.id] && this!=activeRowClickArray[tableObj.id]){
			activeRowClickArray[tableObj.id].className='';
		}
		this.className = arrayOfClickClasses[tableObj.id];
		
		activeRowClickArray[tableObj.id] = this;
				
	}
	
	function resetRowStyle()
	{
		var tableObj = this.parentNode;
		if(tableObj.tagName!='TABLE')tableObj = tableObj.parentNode;

		if(activeRowClickArray[tableObj.id] && this==activeRowClickArray[tableObj.id]){
			this.className = arrayOfClickClasses[tableObj.id];
			return;	
		}
		
		var origCl = this.getAttribute('origCl');
		if(!origCl)origCl = this.origCl;
		this.className=origCl;
		
	}
		
	function addTableRolloverEffect(tableId,whichClass,whichClassOnClick)
	{
		arrayOfRolloverClasses[tableId] = whichClass;
		arrayOfClickClasses[tableId] = whichClassOnClick;
		
		var tableObj = document.getElementById(tableId);
		var tBody = tableObj.getElementsByTagName('TBODY');
		if(tBody){
			var rows = tBody[0].getElementsByTagName('TR');
		}else{
			var rows = tableObj.getElementsByTagName('TR');
		}
		for(var no=0;no<rows.length;no++){
			rows[no].onmouseover = highlightTableRow;
			rows[no].onmouseout = resetRowStyle;
			
			if(whichClassOnClick){
				rows[no].onclick = clickOnTableRow;	
			}
		}
		
	}
	
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function popup(URL, name, properties) {
	var myWindow = window.open(URL, name, properties);
	if (myWindow) {
		myWindow.focus();
	} else {
		if (confirm('Your web browser appears to be configured to block popup windows.\nFor more information, please click OK.')) {
			location.href='/Public/Popup_Info.aspx';
		}
	}
}

function open_showingtime(URL) {
	popup(URL, "ShowingTime", "height=" + getWindowHeight(730) + ",width=620,scrollbars=yes,menubar=no,toolbar=no,status=yes,resizable=yes");
}

function email_property(URL) {
	popup(URL, "EmailProperty", "height=600,width=475,scrollbars=yes,menubar=no,toolbar=no,resizable=yes");
}

function open_tour(URL) {
	popup(URL, "VirtualTour", "height=360,width=512,scrollbars=yes,menubar=no,toolbar=no,resizable=yes");
}

function openContactMe(URL) {
	popup(URL, "ContactMe", "height=" + getWindowHeight(730) + ",width=600,scrollbars=yes,menubar=no,toolbar=no,status=yes,resizable=yes");
}

function open_ScheduleViewing(URL) {
	popup(URL, "ScheduleViewing", "height=" + getWindowHeight(730) + ",width=600,scrollbars=yes,menubar=no,toolbar=no,status=yes,resizable=yes");
}

function open_map(URL) {
	popup(URL, "ListingMap", "height=600,width=730,scrollbars=yes,menubar=no,toolbar=no,resizable=yes");
}

function open_printableBrochure(URL) {
	popup(URL, "PrintableBrochure", "height=600,width=630,scrollbars=yes,menubar=no,toolbar=no,status=yes,resizable=yes");
}

function getWindowHeight(maxHeight) {
	var bufferHeight = 90;
	if (screen.height >= (maxHeight + bufferHeight)) {
		return maxHeight;
	} else {
		return (screen.height - bufferHeight);
	}
}

function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "")
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
	
	return result;
}

function validEmail(formField,fieldLabel,required)
{
	var result = true;
	
	if (required && !validRequired(formField,fieldLabel))
		result = false;

	if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
	{
		alert("Please enter a complete email address in the form: yourname@yourdomain.com");
		formField.focus();
		result = false;
	}
   
  return result;

}

function passwordcheck(formField,fieldLabel) 
{
	if (formField.value != fieldLabel.value) 
	{
		alert('The two emails entered do not match.');
		formField.focus();
		return false;
	}
	return true;
}

function validateForm(theForm)
{
	// Customize these calls for your form

	// Start ------->	
	
	
	if (!validRequired(theForm.firstName,"First Name"))
		return false;
	
	if (!validRequired(theForm.lastName,"Last Name"))
		return false;
		
	if (!validEmail(theForm.email,"Email Address",true))
		return false;
		
	if (!passwordcheck(theForm.email,theForm.confirmemail))
		return false;

	// <--------- End
	
	return true;
}