// JavaScript Document


//==============FOR COMMENT SYSTEM===========
function processForm(sid)
{
var TestForm = checkForm('CommentsForm');

if(TestForm)
{
$('contact').disabled = true;	
get(sid);
}

}


function $(id) {
  return document.getElementById(id);
}

function createXMLHttpRequest() {
      try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
      try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
      try { return new XMLHttpRequest(); } catch(e) {}
      alert("XMLHttpRequest not supported");
      return null;
}


 function makePOSTRequest(url, parameters) {
      http_request = false;
	
	http_request = createXMLHttpRequest();
      
	  if (http_request.overrideMimeType)
            http_request.overrideMimeType('text/html');
	  
	  //build body for Form Post
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
          //  alert(http_request.responseText);
            result = http_request.responseText;
				if(result == "success")
				{
					$('commentForm').style.display = 'none';
					$('commentMsg').innerHTML = "Your comment has been received and is pending approval, thank you!<br/><br/>";
				//	$('submitCommentLink').innerHTML ="Submit a Comment";
					$('contact').disabled = false;	
					$('Name').value = '';
					$('Comment').value = '';
					$('rating').value = '5';
					$('review_rate_btn').src ="images/review_rate.png";	
					
				}
				else
				{
					$('commentForm').style.display = 'none';
					$('submitCommentLink').innerHTML ="Submit a Comment";
					$('commentMsg').innerHTML = "There was an error sending your request, please try again later.";	
					$('contact').disabled = false;	

				}

         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   

   //this get function encodes the form values into URIs which can be sent as Post Vars to the CFM page
   function get(sid) 
   {

	var poststr = "reviewer_name=" + encodeURI( $('Name').value ) + "&comment=" + encodeURI( $('Comment').value ) 
	+ "&rating=" + encodeURI( $('rating').value ) + "&key=" + encodeURI( $('key').value ) + "&sid=" + encodeURI( sid);
	
  	//alert(poststr);

   makePOSTRequest('comment_submit.php', poststr);
   }
