var selectorForm = "#popDivForm";
var selectorAlert = "#popDivAlert";

function shwContFrm() {
	// code for popping jquery popup
	$(selectorForm).bPopup({scrollBar:false});
}

function hidContFrm() {
	$(selectorForm).bPopup().close();
}

function shwTempMsg() {
	$(selectorAlert).bPopup({scrollBar:false});
}

function hidTempMsg() {
	$(selectorAlert).bPopup().close();
}

function validateFrm() {
	var errorStr = "";
	if (document.getElementById("nameTb").value == "") {
		//missing name
		errorStr += "\n Name"
	}
	if (document.getElementById("emailTb").value == "") {
		//missing email
		errorStr += "\n Email"
	}
	if (document.getElementById("msgTa").value == "") {
		//missing message
		errorStr += "\n Message"
	}
	if (errorStr != "") {
		alert("Please fill out the following fields:\n" + errorStr);
		return false;
	}
	else {
		return true;
	}
}

submitFrm = function () {
	if (validateFrm() == true) {
		//submit form and swap out thanks message
		var name = document.getElementById("nameTb").value;
		var email = document.getElementById("emailTb").value;
		var message = document.getElementById("msgTa").value;
		var qstring = "name=" + escape(name) + "&" + "email=" + escape(email) + "&" + "message=" + escape(message);
		callPage("sendForm.php",qstring);
		document.getElementById("formThanksContainer").style.display = "block";
		document.getElementById("formTblContainer").style.display = "none";
		return false;
	}
}

function callPage(url,qstring) {
	if (window.XMLHttpRequest) {
		xmlHttp=new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	var openpage = url + "?" + qstring;
	xmlHttp.open('GET',openpage);
	xmlHttp.send(null);
}
