/* common.js */
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 validateForm(theForm){
	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;

	return true;
}

/**************************
Property Tax Map
***************************/

function CalculateTax(defval){
	var FinalValue = 0;
	var PropValue = document.getElementById('propertyvalue').value;
	if(PropValue == "" || PropValue == defval){
		alert("Please enter a property value");
		return;
	}
	
	//Remove special character
	re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|/g;
        FinalValue = PropValue.replace(re, "");

	//Check if value is numerical
	if(!IsNumeric(FinalValue)){
		alert("Please enter a numerical value");
		return;
	}
	
	//Spit out Values
	// OutputTax(Property Value, HTML Element ID, Millrate, Assessment Ratio)
	
	//Town of Hudson
	OutputTax(FinalValue,'town01',0.011532642,0.9286);
	//Town of Hammond
	OutputTax(FinalValue,'town02',0.014209644,0.9502);
	//Town of Warren
	OutputTax(FinalValue,'town03',0.019690979,0.7392);
	//Town of Troy
	OutputTax(FinalValue,'town04',0.012486066,0.8977);
	//Town of St.Joseph
	OutputTax(FinalValue,'town05',0.013283677,0.8597);
	//Town of Somerset
	OutputTax(FinalValue,'town06',0.019063750,0.7221);
	//Town of Richmond
	OutputTax(FinalValue,'town07',0.013974323,0.9708);
	//Village of North Hudson
	OutputTax(FinalValue,'town08',0.014027640,0.9484);
	//Village of Hammond
	OutputTax(FinalValue,'town09',0.020464476,0.9707);
	//Village of Roberts
	OutputTax(FinalValue,'town10',0.018730226,1.0123);
	//Village of Somerset
	OutputTax(FinalValue,'town11',0.019343196,0.9810);
	//Village of Star Prairie
	OutputTax(FinalValue,'town12',0.020117540,0.8186);
	//Village of Woodville
	OutputTax(FinalValue,'town13',0.018383433,0.9766);
	//City of Hudson
	OutputTax(FinalValue,'town14',0.013872927,1.0135);
	//City of New Richmond
	OutputTax(FinalValue,'town15',0.021850792,0.8633);
	//Town of Hudson
	//OutputTax(FinalValue,'town16',0,0);
	//City of River Falls
	OutputTax(FinalValue,'town17',0.017866818,1.0159);
	//Town of River Falls
	OutputTax(FinalValue,'town18',0.014882659,0.9738);
	//Town of Clifton
	OutputTax(FinalValue,'town19',0.017079959,0.8465);
	//City of Prescott
	OutputTax(FinalValue,'town20',0.024900752,0.7863);
	//Town of Oak Grove
	OutputTax(FinalValue,'town21',0.017730056,0.8566);

	return;
}

function OutputTax(FinalValue,ElementID,Millrate,AssessmentRatio){
	// Output value
	FinalValue = FinalValue*Millrate*AssessmentRatio;
	document.getElementById(ElementID).childNodes.item(0).data = '$' + FinalValue.toFixed(2);
	return;
}

function IsNumeric(sText){
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
 
	for (i = 0; i < sText.length && IsNumber == true; i++){ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
   }
   
/**************************
New Window Functions (EdinaRealty.com)
***************************/
var EdinaHome = "http://kernonbast.edinarealty.com/";
//function popup(D,A,B){var C=window.open(D,A,B); if(C){C.focus();}else{if(confirm("Your web browser appears to be configured to block popup windows.\nFor more information, please click OK.")){location.href=EdinaHome+"/Public/Popup_Info.aspx";}}}
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 booty(Z){return "bling";}
function getWindowHeight(A){var B=90;if(screen.height>=(A+B)){return A;}else{return(screen.height-B);}}
function open_tour(A){popup(A,"VirtualTour","height=360,width=512,scrollbars=yes,menubar=no,toolbar=no,resizable=yes");}
function open_showingtime(A){popup(A,"ShowingTime","height="+getWindowHeight(730)+",width=620,scrollbars=yes,menubar=no,toolbar=no,status=yes,resizable=yes");}
function openContactMe(A){popup(A,"ContactMe","height="+getWindowHeight(730)+",width=600,scrollbars=yes,menubar=no,toolbar=no,status=yes,resizable=yes");}
function open_map(A){popup(A,"ListingMap","height=600,width=800,scrollbars=yes,menubar=no,toolbar=no,resizable=yes");}
function open_printableBrochure(A){popup(A,"PrintableBrochure","height=600,width=735,scrollbars=yes,menubar=no,toolbar=no,status=yes,resizable=yes");}
function email_property(A){popup(A,"EmailProperty","height=600,width=475,scrollbars=yes,menubar=no,toolbar=no,resizable=yes");}
function open_TextProperty(A){popup(A,"TextProperty","height=220,width=460,scrollbars=no,menubar=no,toolbar=no,status=yes,resizable=yes");}
function open_mortgageApp(A){popup(A,"MortgageApplication","height=450,width=650,scrollbars=yes,menubar=yes,toolbar=yes,status=yes,resizable=yes");}






   
