var ratingFocus = 0;

/*---------------------------------------------AJAX FUNCTIONS----------------------------------------------*/
function getHTTPObject(){
	var xmlhttp;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
         xmlhttp = new XMLHttpRequest();
         if (xmlhttp.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            xmlhttp.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
	  return xmlhttp;
}

function handleAJAXRequest(url,method,params){
		var xmlhttp = getHTTPObject();
		xmlhttp.open(method, url, true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send(params);
		
}

/*---------------------------------------------AJAX SURVEY----------------------------------------------*/
function ajaxSubmit(page){
  if(rating == ""){
	  alert("Please Select a Rating");
  }
  else{
	  var url = "/tools/RatingSystem/submitRating.php";
	  var params = "page=" + page;
	  params += "&communicationType=" + document.getElementById('communicationType').value;
	  params += "&communicationId=" + document.getElementById('communicationId').value;
	  params += "&rating=" + rating;
	  params += "&why=" + document.getElementById('whyRating').value;
	  handleAJAXRequest(url,"POST",params);
	  document.getElementById("ratingwhyarea").innerHTML = "Thank You";
  }
}

var rating = "";

function setRating(number){
		rating = number;
		switch(number){
			case "1":
				document.getElementById('rater').className = "rating onestar"; 
				break;
			case "2":
				document.getElementById('rater').className = "rating twostar"; 
				break;
			case "3":
				document.getElementById('rater').className = "rating threestar"; 
				break;
			case "4":
				document.getElementById('rater').className = "rating fourstar"; 
				break;
			case "5":
				document.getElementById('rater').className = "rating fivestar"; 
				break;
		}
}


function showRating(){	
	document.getElementById('ratingwhyarea').style.display = "block";
}

function hideRating(){
	if(!ratingFocus)
		document.getElementById('ratingwhyarea').style.display = "none";
}

function ratingFocusing(){
	ratingFocus = 1;
}

function ratingBlur(){
	ratingFocus = 0;
}