function showContactTimer () {
	var loader = document.getElementById('loadBar');
	loader.style.display = 'block';
      var commentform = document.getElementById('commentform');
	commentform.style.display = 'none';
	sentTimer = setTimeout("hideContactTimer()",1800);
}

function hideContactTimer () {

	var loader = document.getElementById('loadBar');
	loader.style.display = "none";

      var mainsection = document.getElementById('mainsection');
	mainsection.style.display = 'block';

      var commentsection = document.getElementById('commentsection');
	commentsection.style.display = 'none';
}



function talktoServer(){

	var req = newXMLHttpRequest();

	//register the callback handler function

  	var callbackHandler = getReadyStateHandler(req, updateMsgOnBrowser);
  	req.onreadystatechange = callbackHandler;
  	req.open("POST", "processComment.php", true);
  	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

  	//get the value from the text input element and send it to server

  	var comment = document.getElementById("comment");
  	var msg_value = comment.value;

  	var author = document.getElementById("author");
  	var author_value = author.value;

	var entry = document.getElementById("entry");
  	var entry_value = entry.value;

	var success = document.getElementById('emailSuccess');

	showContactTimer();

	success.style.display = 'none';
  	req.send("msg="+msg_value+"&author="+author_value+"&entry="+entry_value);
}

// This is the callback functions that gets called
// for the response from the server with the XML data

function updateMsgOnBrowser(testXML) {

	var confirmation = testXML.getElementsByTagName("confirmation")[0];
	var thedate = testXML.getElementsByTagName("thedate")[0];
	var comment = testXML.getElementsByTagName("comment")[0];
	var author = testXML.getElementsByTagName("author")[0];
	var entry = testXML.getElementsByTagName("entry")[0];

	var confirmation_value = confirmation.firstChild.nodeValue;
	var thedate_value = thedate.firstChild.nodeValue;
	var comment_value = comment.firstChild.nodeValue;
	var author_value = author.firstChild.nodeValue;
	var entry_value = entry.firstChild.nodeValue;

	entry_value = "newcomment" + entry_value;
	var newc = document.getElementById(entry_value);
	newc.style.display = "block";
	var newcomment = comment_value+"<br/><small>Posted by <strong>"+author_value+"</strong> on <strong>"+thedate_value+"</strong></small>&nbsp;&nbsp;&nbsp;&nbsp;<strong style=\"color:green;\">"+confirmation_value+"</strong><br/><br/>";
      newc.innerHTML = newcomment;
	
}


//the following two functions are helper infrastructure to 
//craete a XMLHTTPRequest and register a listner callback function

function newXMLHttpRequest() {
	var xmlreq = false;
	if (window.XMLHttpRequest) {
		xmlreq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
    		// Try ActiveX
		try { 
			xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) { 
			// first method failed 
			try {
				xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				 // both methods failed 
			} 
		}
 	}
   	return xmlreq;
} 

function getReadyStateHandler(req, responseXmlHandler) {
	return function () {
	if (req.readyState == 4) {
		if (req.status == 200) {
        		responseXmlHandler(req.responseXML);
		} else {
			var hellomsg = document.getElementById("hellomsg");
			hellomsg.innerHTML = "ERROR: "+ req.status;
      		}
    	}
 	}
}

