﻿/**
 * HEADER FUNCTIONS.
 */

/**
 * Causes the page to redirect to the contact us page.
 */
function callus() {
	window.location = "contactus.php";
}

/**
 * Start live chat.
 */
function chat() {
	alert("However it is that live chat does when it starts will be performed when this button is pressed.");
}

/**
 * Closes the contact us form.
 */
function closeemail() {
	document.getElementById("emailus").setAttribute("class", "invisible");
	document.getElementById("emailus").className = "invisible";
}

/**
 * Causes the email form to pop up.
 */
function emailus() {
	document.getElementById("emailus").setAttribute("class", "emailussurround");
	document.getElementById("emailus").className = "emailussurround";
}

/**
 * Sends an email.
 */
function sendemail() {
	//1.  get the from address, subject, and body.
	var fromAddr = document.getElementById("from").value;
	var subject = document.getElementById("subject").value;
	var body = document.getElementById("body").value;
	//2.  post it to the form.
	var paramarray = new Array();
	paramarray["from"] = fromAddr;
	paramarray["subject"] = subject;
	paramarray["body"] = body;
	var response = cajax.GetText("php/contactmailercb.php", paramarray);
	switch (response) {
		case "nosubject":
			alert("You must provide a subject.");
			break;
		case "nobody":
			alert("You must provide a nessage to send.");
			break;
		case "nofromaddr":
			alert("You must provide your email address so we can get back to you.  Don't worry; it isn't recorded by this contact form.");
			break;
		case "invalidemail":
			alert("The email address you provided is not valid.  Please fill in the value correctly.");
			break;
		case "fishysubject":
			alert("The subject you provided contains a url.  That is not allowed because it's almost always spam.");
			break;
		case "fishybody":
			alert("The message you provided contains a url.  That is not allowed because it's almost always spam.");
			break;
		case "fishybodygt":
			alert("The message you provided contains '>'.  That is not allowed because it's almost always spam.");
			break;
		case "fishybodylt":
			alert("The message you provided contains '<'.  That is not allowed because it's almost always spam.");
			break;
		case "no":
			alert("Sorry for the inconvenience, but your message was not sent successfully.  If this happens repeatedly, please call us and let us know so that we can serve you better.");
			break;
		case "yes":
			alert("Thank you for contacting us!  We will get back to you as soon as possible.");
			closeemail();
			break;
		default:
			alert("There was an unknown error.  Sorry for the inconvenience.");
			break;
	}
}


