// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// fcnSubmitNote - submit the email note via the popup box.									 //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
function fcnSubmitNote() {
  var dtDate = new Date();
  dtDate.setTime(dtDate.getTime()+120000);	// Cookies expire in about 120 seconds...
  
  var ok = 1;
  var str = "height=300,innerHeight=300,width=450,innerWidth=450"
  	str += ",left=" + ((screen.availWidth - 10) / 3) + ",screenX=" + ((screen.availWidth - 10) / 3);
  	str += ",top=0,screenY=0,dependent,menubar=0,resizable=0,location=0,scrollbars=1";
  var strSendTo = document.getElementById("strSendTo");
  var strName = document.getElementById("strName");
  var strEmail = document.getElementById("strEmail");
  var strMessage = document.getElementById("strMessage");
  
  var strFields = "";
  
  if (strName.value == "") { strFields += "   Your Name\n"};
  if (strEmail.value == "") { strFields += "   Your Email\n"};
  if (strMessage.value == "") { strFields += "   Message\n"};

  if (strFields != "") {
	alert("The following items must be filled in:\n\n" + strFields + "\n");
	document.all.strName.focus();
	ok = 0;
  }
  else {
  	if (strEmail.value.indexOf("@") == -1) {
  		alert("'Your Email' does not appear to be a valid email address.\n\nPlease correct before submitting.");
		document.all.strEmail.focus();
	 	ok = 0;
  	}
  }
  
  if (ok == 1) {
	if (strSendTo!=null) {
		document.cookie = "sendnote_strSendTo=" + escape(strSendTo.value) + "; expires=" + dtDate.toGMTString() + "; path=/";
	};
	document.cookie = "sendnote_strName=" + escape(strName.value) + "; expires=" + dtDate.toGMTString() + "; path=/";
	document.cookie = "sendnote_strEmail=" + escape(strEmail.value) + "; expires=" + dtDate.toGMTString() + "; path=/";
	document.cookie = "sendnote_strMessage=" + escape(strMessage.value) + "; expires=" + dtDate.toGMTString() + "; path=/";
	document.cookie = "sendmail_action=sendnote.asp; expires=" + dtDate.toGMTString() + "; path=/";

	var windowRef = window.open("sendmail.asp", "SendNote", str);
  	try {
	  	windowRef.focus();
		strName.value = "";
		strEmail.value = "";
		strMessage.value = "";
		return true;
		}
	catch(e) {
		alert('It appears you may have a Popup Blocker active.\n\nPlease allow popups from this website before clicking the submit button.');
		return false;
		}
  	}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// fcnSubmitForm - submit the information request form via the popup box. 					 //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
function fcnSubmitForm() {
  var dtDate = new Date();
  dtDate.setTime(dtDate.getTime()+60000);	// Cookies expire in about 60 seconds...
  
  var ok = 1;
  var str = "height=400,innerHeight=400,width=450,innerWidth=450"
  	str += ",left=" + ((screen.availWidth - 10) / 3) + ",screenX=" + ((screen.availWidth - 10) / 3);
  	str += ",top=0,screenY=0,dependent,menubar=0,resizable=0,location=0,scrollbars=1";

  // Check for missing critical information...
  var strFromName = document.getElementById("strFromName");
  var strFromEmail = document.getElementById("strFromEmail");
  var strFromAddress = document.getElementById("strFromAddress");
  var strFromCity = document.getElementById("strFromCity");
  var strFromProvince = document.getElementById("strFromProvince");
  var strFromPostal = document.getElementById("strFromPostal-Code");
 
  var strFields = "";
  if (strFromName.value == "") { strFields += "   Your Name\n"};
  if (strFromEmail.value == "") { strFields += "   Your Email\n"};
  if (strFromAddress.value == "") { strFields += "   Your Address\n"};
  if (strFromCity.value == "") { strFields += "   Your City\n"};
  if (strFromProvince.value == "") { strFields += "   Your Province\n"};
  if (strFromPostal.value == "") { strFields += "   Your Postal Code\n"};
  
  // Check for some basic errors...
  if (strFields != "") {
	alert("The following items must be filled in:\n\n" + strFields + "\n");
	document.all.strFromName.focus();
	ok = 0;
  	}
 	else {
  	if (strFromEmail.value.indexOf("@") == -1) {
  		alert("The email address entered does not appear to be a valid email address.\n\nPlease correct before submitting.");
		document.all.strFromEmail.focus();
	 	ok = 0;
  	}
  }

  if (ok == 1) {  
	  // Check input fields for some sort of survey information entered somewhere!!
	  strFieldsWithInput = "";
	  var inputFields = document.getElementsByTagName("input");
	  for(var i=0; i < inputFields.length; i++){
	  	if (inputFields[i].name.indexOf("strSurvey") >= 0) {
			if (inputFields[i].value != "") strFieldsWithInput += inputFields[i].name;
		}  
	  }

	  // Check freeform fields for some sort of survey information entered somewhere!!
  	 inputFields = document.getElementsByTagName("textarea");
	  for(var i=0; i < inputFields.length; i++){
	  	if (inputFields[i].name.indexOf("strText") >= 0) {
			if (inputFields[i].value != "") strFieldsWithInput += inputFields[i].name;
		}  
	  }

	  if (strFieldsWithInput == "") {
		alert("Please enter some information about the property to be surveyed.");
		document.all.strSurveyAddress.focus();
		ok = 0;
	  }
  }
  
  // No errors in the form - send the data off to be emailed!
  if (ok == 1) {

	var inputFields = document.getElementsByTagName("input");
  	for(var i=0; i < inputFields.length; i++){
  		if (inputFields[i].name.indexOf("strFrom") >= 0) {
			document.cookie = "sendform_" + inputFields[i].name + "=" + escape(inputFields[i].value) + "; expires=" + dtDate.toGMTString() + "; path=/";
		}  
  	}
  	for(var i=0; i < inputFields.length; i++){
  		if (inputFields[i].name.indexOf("strSurvey") >= 0) {
			document.cookie = "sendform_" + inputFields[i].name + "=" + escape(inputFields[i].value) + "; expires=" + dtDate.toGMTString() + "; path=/";
		}  
	}

 	inputFields = document.getElementsByTagName("textarea");
  	for(var i=0; i < inputFields.length; i++){
  		if (inputFields[i].name.indexOf("strText") >= 0) {
			document.cookie = "sendform_" + inputFields[i].name + "=" + escape(inputFields[i].value) + "; expires=" + dtDate.toGMTString() + "; path=/";
		}  
  	}

	document.cookie = "sendmail_action=sendform.asp; expires=" + dtDate.toGMTString() + "; path=/";
	var windowRef = window.open("sendmail.asp", "SendForm", str);
	try {
		fcnClearForm();
  		windowRef.focus();
		return true;
	}
	catch(e) {
		alert('It appears you may have a Popup Blocker active.\n\nPlease allow popups from this website before clicking the submit button.');
		return false;
		}
	}
}

function fcnClearForm() {
	// wipe out the regular input fields
	var inputFields = document.getElementsByTagName("input");
	for(var i=0; i < inputFields.length; i++){
		if (inputFields[i].name.indexOf("strFrom") >= 0) {
			inputFields[i].value = "";
		}  
	}
	for(var i=0; i < inputFields.length; i++){
		if (inputFields[i].name.indexOf("strSurvey") >= 0) {
			inputFields[i].value = "";
		}  
	}
	// wipe out text fields
	inputFields = document.getElementsByTagName("textarea");
	for(var i=0; i < inputFields.length; i++){
	  	if (inputFields[i].name.indexOf("strText") >= 0) {
			inputFields[i].value = "";
		}  
	}
	// set the province to to the special value
	document.all.strFromProvince.value = "NULL";
	
	document.all.strFromName.focus();
}

