//::Navigation-Only Pop-Up Window
var win = null;
function NavWin(mypage,myname,w,h){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
settings =
'height='+h+',width='+w+',left='+LeftPosition+',top=0,toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0';
window.onerror=ignore
function ignore(){return true}
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}

//::Print Pop-Up Window
var win = null;
function PrintWin(mypage,myname,w,h){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
settings =
'height='+h+',width='+w+',left='+LeftPosition+',top=0,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=0';
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}

//::Sub-Menu Hide
function SubMenuHide(submenu,hideshow){
	if (hideshow==1){
	submenu.style.display='';
	}
	else{
	submenu.style.display='none'
	}
}

//::Trim String Function
function Trim(str){
	str = str.replace(/\s+/,'');
	str = str.replace(/\s+$/,'');
	return str;
}

//::IsNumeric Function
function IsNumeric(val){
	for (i=0; i<val.length; i++){
		if (isNaN(val.charAt(i))){
			return false;
		}
	}
	return true;
}

//::Valid E-Mail
function ValidEmail(str){
	AccPos = str.indexOf('@');
	AccStr = str.substr(0,AccPos);
	AccLen = AccStr.length;
	DomPos = str.lastIndexOf('.');
	DomStr = str.substr(AccPos+1,(DomPos-AccPos)-1);
	DomLen = DomStr.length;
	ExtPos = DomPos + 1;
	ExtLen = str.length - ExtPos;
	ExtStr = str.substr(ExtPos,ExtLen);
	if(	   (AccPos != -1)
		&& (DomPos != -1)
		&& (AccLen >= 2)
		&& (DomLen >= 2)
		&& (ExtLen >= 2)
		&& (ExtLen <= 3)){
		return true;
	}
	else{return false}
}

//::Valid Phone
function ValidPhone(PhoneArea,PhonePre,PhoneSuf){
	if ((Trim(PhoneArea) == "") || 
		(Trim(PhonePre) == "") ||
		(Trim(PhoneSuf) == "") ||
		(PhoneArea.length != 3) || 
		(PhonePre.length != 3) ||
		(PhoneSuf.length != 4)){
		return false;
	}else{
		if (IsNumeric(PhoneArea) &&
			IsNumeric(PhonePre) &&
			IsNumeric(PhoneSuf) &&
			(PhoneArea.length == 3) && 
			(PhonePre.length == 3) &&
			(PhoneSuf.length == 4)){
			return true;
		}
	}
}

//::Validate Service Request
function ValidateServiceRequest(admin) {
	missinginfo = "";
	missingadmin = "";
	var objForm = document.forms[0];

	if (objForm.community.value == 0) {
	missinginfo += "\n     »  Community";
	}
	if (objForm.lotnumber.value == "") {
	missinginfo += "\n     »  Lot Number";
	}
	if (missinginfo != ""){
	missinginfo += "\n--------------------------";
	}
	if (admin == 1){
		if (objForm.method.value == 0) {
		missingadmin += "\n     »  Method";
		}
		if (missingadmin != ""){
		missingadmin += "\n--------------------------";
		}
		missinginfo += missingadmin;
	}
	if (objForm.firstname.value == "") {
	missinginfo += "\n     »  First Name";
	}
	if (objForm.lastname.value == "") {
	missinginfo += "\n     »  Last Name";
	}
	if (objForm.address.value == "") {
	missinginfo += "\n     »  Address";
	}
	if (objForm.city.value == "") {
	missinginfo += "\n     »  City";
	}
	if (objForm.state.value == 0) {
	missinginfo += "\n     »  State";
	}
	if (!IsNumeric(objForm.zip.value) || objForm.zip.value == "") {
	missinginfo += "\n     »  Zip";
	}
	if (!ValidPhone(objForm.phonearea.value,objForm.phonepre.value,objForm.phonesuf.value)) {
	missinginfo += "\n     »  Phone";
	}
	if (!ValidEmail(objForm.emailaddress.value)) {
	missinginfo += "\n     »  E-Mail";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Service Request Details Form
function ValidateServiceRequestDetails(cnt) {
	missinginfo = "";
	var objForm = document.forms[0];
	if (cnt == 0) {
		if (objForm.category.value == "") {
		missinginfo += "\n     »  Category";
		}
		if (Trim(objForm.description.value) == "") {
		missinginfo += "\n     »  Description";
		}

		if (missinginfo != "") {
		missinginfo = "The following information was entered incorrectly:\n" +
		missinginfo + "\n\nPlease re-enter the information and try again...";
		alert(missinginfo);
		return false;
		}
		else return true;
	}
	else {
		return true;
	}
}

//::Validate Service Request Finish Button
function ValidateServiceRequestFinish(details){
	if(details > 0){
		return true;
	}else{
		missinginfo = "\n» You must enter details in the form before finishing your service request.";
		missinginfo = "The following information was entered incorrectly:\n" +
		missinginfo + "\n\nPlease re-enter the information and try again...";
		alert(missinginfo);
		return false;
	}
}

//::Validate Contact Form
function ValidateContact() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.firstname.value == "") {
	missinginfo += "\n     »  First Name";
	}
	if (objForm.lastname.value == "") {
	missinginfo += "\n     »  Last Name";
	}
	if (!ValidPhone(objForm.phonearea.value,objForm.phonepre.value,objForm.phonesuf.value)) {
	missinginfo += "\n     »  Phone";
	}
	if (!ValidEmail(objForm.emailaddress.value)) {
	missinginfo += "\n     »  E-Mail";
	}
//	if (objForm.comments.value == "") {
//	missinginfo += "\n     »  Questions / Comments";
//	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Advanced Search Form
function ValidateSearch(){
	frm = document.forms[0];
	if((parseFloat(frm.sqft1.value) >= parseFloat(frm.sqft2.value)) && (frm.sqft2.value != "")){
		alert('Warning:\nThe starting Sq. Ft. value must be LESS than the ending value.')
		return false;
	}
	if((parseFloat(frm.price1.value) >= parseFloat(frm.price2.value)) && (frm.price2.value != "")){
		alert('Warning:\nThe starting Price must be LESS than the ending Price.')
		return false;
	}
}

//::Auto-Load Customer Information for Service Request
function AutoLoadCustomer(url){	
	var com = document.forms[0].community.value;
	var lot = document.forms[0].lotnumber.value;
	if (com != "" && lot != ""){
		document.location.href = url;
	}
}

//::Flash Plugin and Version Detection
var checkversion = 5;
var flashinstalled = 0;
var flashversion = 0;
MSDetect = "false";
if (navigator.plugins && navigator.plugins.length) {
	x = navigator.plugins["Shockwave Flash"];
	if (x) {
		flashinstalled = 2;
		if (x.description) {
			y = x.description;
			flashversion = y.charAt(y.indexOf('.')-1);
		}
	}
	else
		flashinstalled = 1;
	if (navigator.plugins["Shockwave Flash 2.0"]) {
		flashinstalled = 2;
		flashversion = 2;
	}
}
else if (navigator.mimeTypes && navigator.mimeTypes.length) {
	x = navigator.mimeTypes['application/x-shockwave-flash'];
	if (x && x.enabledPlugin)
		flashinstalled = 2;
	else
		flashinstalled = 1;
}
else {
	MSDetect = "true";
}

//::Block Characters
//ex.	onKeypress="BlockChar();"
function BlockChar(){
	if (event.keyCode==45) {
		event.returnValue = false;
	}
}

//::Limit TextArea Length
//ex.	onKeyDown="LimitTextarea(this,255);" onKeyUp="LimitTextarea(this,255);"
function LimitTextarea(fld,lmt) {
	if (fld.value.length > lmt) {
		fld.value = fld.value.substring(0, lmt);
	}
}