// JavaScript Document

function feedbackUsProcess()
{
	var fullname = document.getElementById("feedbackName");
	//var email = document.getElementById("feedbackEmail");
	var comment = document.getElementById("feedbackComment");
	var isThisPage = document.getElementById("isThisPageQ");
	var feedbackType = document.getElementById("feedbackType");
	

  if (comment.value != "")
  {	  
  		var whichPage = "";
		
			var sPath = window.location.pathname;
			//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
			//var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
			
			whichPage = sPath;

	  var url = "feedback/processFeedback.php?fullname=" + fullname.value + "&email=none" + "&comment=" + comment.value + "&isThisPage=" + isThisPage.value + "&feedbackType=" + feedbackType.value + "&whichPage=" + whichPage;
	  
	  try
	{
		document.getElementById("feedbackInstruction").innerHTML = "Sending..";
		//disable the input forms so that the user wont interfere with the request
		fullname.disabled = true;
		//email.disabled = true;
		comment.disabled = true;
		
		
		asyncRequest = new XMLHttpRequest();		
		asyncRequest.open("GET", url, true);//prepare the request
		asyncRequest.onreadystatechange = handleRequest;
		asyncRequest.send(null); //send the request
				
	}
	catch (exception)
	{
		document.getElementById("feedbackInstruction").innerHTML = "Request Failed!: Please check your internet connection";
	}
  }
  
  else
  {
	  document.getElementById("feedbackInstruction").innerHTML = "Please fill in all the details.";
  }

}

//handles the function above
function handleRequest ()
{
	if (asyncRequest.readyState == 4 && asyncRequest.status == 200)
	{
		document.getElementById("feedbackInstruction").innerHTML = asyncRequest.responseText;
		//document.getElementById("feedBackFormElements").innerHTML = "";
		var fullname = document.getElementById("feedbackName");
		//var email = document.getElementById("feedbackEmail");
		var comment = document.getElementById("feedbackComment");
		
		
		fullname.disabled = false;
		//email.disabled = false;
		comment.disabled = false;
		clearElement(fullname);
		clearElement(comment);
		
	}
}


function hideElement(elename)
{
document.getElementById(elename).style.display = "none";
}
function clearElement(elename)
{
document.getElementById(elename).innerHTML = "";
}
function showElement(elename)
{
document.getElementById(elename).style.display = "inline";
}
