/* ===================================================== */
/* ======        JNID Contact Scripts            ======= */
/* ======          Version A09.07.11             ======= */
/* ===================================================== */
function ajax_insert_contact_box(contact){
	
	var xmlhttp = GetXmlHttpObject();
	if (xmlhttp == null) {
		alert ("You're browser does not support XML-HTTP, which is necessary to perform an action you requested.  We recommend that you use Internet Explorer 8, Mozilla Firefox 3, or Chrome 2.");
		}
			
	xmlhttp.open("GET",Cpath_toJnidComponents+"contact-box.php", true);
	xmlhttp.send(null);	
		
	xmlhttp.onreadystatechange = function () {
		
		// Check if the XML-HTTP connection is established
		if (xmlhttp.readyState == 4) {
			document.getElementById("contact_box").innerHTML = xmlhttp.responseText;
			ajax_load_contact(contact);
			return;
		    }
		}
}
function ajax_load_contact(contact) {
	
	var xmlhttp = GetXmlHttpObject();
	if (xmlhttp == null) {
		alert ("You're browser does not support XML-HTTP, which is necessary to perform an action you requested.  We recommend that you use Internet Explorer 8, Mozilla Firefox 3, or Chrome 2.");
		}
			
	xmlhttp.open("GET",Cpath_toXml+"contact/"+contact+".xml", true);
	xmlhttp.send(null);
		
	xmlhttp.onreadystatechange = function () {
		
		// Check if the XML-HTTP connection is established
		if (xmlhttp.readyState == 4) {
			var xml = xmlhttp.responseXML;
			document.getElementById("cb_who1").innerHTML = 
			document.getElementById("cb_who2").innerHTML = 
			document.getElementById("cb_who3").innerHTML = xml.getElementsByTagName("name")[0].childNodes[0].nodeValue;
			
			document.getElementById("cb1_head").innerHTML = xml.getElementsByTagName("category")[0].childNodes[0].nodeValue;
			document.getElementById("cb1_info").innerHTML = xml.getElementsByTagName("info")[0].childNodes[0].nodeValue;
			
			document.getElementById("cb2_head").innerHTML = xml.getElementsByTagName("category")[1].childNodes[0].nodeValue;
			document.getElementById("cb2_info").innerHTML = xml.getElementsByTagName("info")[1].childNodes[0].nodeValue;
			
			document.getElementById("cb3_head").innerHTML = xml.getElementsByTagName("category")[2].childNodes[0].nodeValue;
			document.getElementById("cb3_info").innerHTML = xml.getElementsByTagName("info")[2].childNodes[0].nodeValue;
			
			var emailRecipient = xml.getElementsByTagName("email")[0].childNodes[0].nodeValue;
			
			var parent = document.forms['contact_form'];
			var child = document.createElement("input");
			child.setAttribute("type", "hidden");
			child.setAttribute("name", "emailRecipient");
			child.setAttribute("value", emailRecipient);
			parent.appendChild(child);
				
			showFooterBox('contact_box',2);
			return;
			}
		}
}
function ajax_send_email() {
	
	// load email parameters from the form
	var encodedRecipient = encodeURIComponent(document.forms['contact_form'].emailRecipient.value)
	var encodedSender = encodeURIComponent(document.forms['contact_form'].emailSender.value)
	var encodedSubject = encodeURIComponent(document.forms['contact_form'].emailSubject.value)
	var encodedBody = encodeURIComponent(document.forms['contact_form'].emailBody.value)
	var encodedCopy = encodeURIComponent(document.forms['contact_form'].emailCopy.value)
	var emailParams =	'emailRecipient=' + encodedRecipient + '&emailSender=' + encodedSender + '&emailSubject=' + encodedSubject +
						'&emailBody=' + encodedBody + '&emailCopy=' + encodedCopy;
	
	var xmlhttp = GetXmlHttpObject();
	if (xmlhttp == null) {
		alert ("You're browser does not support XML-HTTP, which is necessary to perform an action you requested.  We recommend that you use Internet Explorer 8, Mozilla Firefox 3, or Chrome 2.");
		}
			
	xmlhttp.open("POST",Cpath_toScripts+"send-email.php", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send(emailParams);
		
	xmlhttp.onreadystatechange = function () {
		if(xmlhttp.readyState == 4) {
			var parentDIV = document.getElementById("contact_box");
			var childDIV = document.getElementById("contact_form_container");
			parentDIV.removeChild(childDIV);
			var newDIV = document.createElement("div"); // create newDiv

			newDIV.setAttribute("id", "contact_box_confirmation"); // set ID for newDiv
			if (encodedCopy == "yes") { var newHTML = '<h3>The following message was successfully sent to the server and a copy has been sent to "' + decodeURIComponent(encodedSender) + '".</h3>';
			} else { var newHTML = "<h3>The following message was successfully sent to the server.</h3>"; }
			newHTML += '<p id="contact_confirmation_subject"><b>Subject:</b> ' + decodeURIComponent(encodedSubject) + "</p>";
			newHTML += '<p id="contact_confirmation_body">' + decodeURIComponent(encodedBody) + "</p>";
			newDIV.innerHTML = newHTML;
			parentDIV.appendChild(newDIV);
			return;
			}
		}
}