var submitcount=0;
   function checkSubmit() {

      if (submitcount == 0)
      {
      submitcount++;
      document.Surv.submit();
      }
   }


function wordCounter(field, countfield, maxlimit) {
wordcounter=0;
for (x=0;x<field.value.length;x++) {
      if (field.value.charAt(x) == " " && field.value.charAt(x-1) != " ")  {wordcounter++}  // Counts the spaces while ignoring double spaces, usually one in between each word.
      if (wordcounter > 250) {field.value = field.value.substring(0, x);}
      else {countfield.value = maxlimit - wordcounter;}
      }
   }

function textCounter(field, countfield, maxlimit) {
  if (field.value.length > maxlimit)
      {field.value = field.value.substring(0, maxlimit);}
      else
      {countfield.value = maxlimit - field.value.length;}
  }
//  End -->
// + ------------------------- +
// |        COMMENT POST       |
// + ------------------------- +
function comment_handleResponse() {
	try {
		if((http.readyState == 4)&&(http.status == 200)){
			var response = http.responseText;
			if (response == 'OK') {
				media_id = encodeURIComponent(document.getElementById("media_id").value);
				showComment(media_id);
			}
			else document.getElementById("comment_loading").innerHTML = response;

		}
  	}
	catch(e){}
	finally{}
}

function comment_check_values() {
	media_id = encodeURIComponent(document.getElementById("media_id").value);
	comment_content = encodeURIComponent(document.getElementById("comment_content").value);
	if(trim(comment_content) == "")
		alert("Bạn chưa nhập cảm nhận");
	else {
		try {
			document.getElementById("comment_loading").innerHTML = loadingText;
			document.getElementById("comment_loading").style.display = "block";
			http.open('POST',  'comment.php');
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
			http.onreadystatechange = comment_handleResponse;
			http.send('comment=1&media_id='+media_id+'&comment_content='+comment_content);
			document.getElementById("submit").disabled=true;document.getElementById("submit").value="Wait...";
		}
		catch(e){}
		finally{}
	}
	return false;
}

function comment_delete(media_id,comment_id) {
	if (confirm("Bạn có muốn xóa cảm nhận này không ?")) {
		document.getElementById("comment_loading").innerHTML = loadingText;
		document.getElementById("comment_loading").style.display = "block";
		http.open('POST',  'comment.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
		http.onreadystatechange = comment_handleResponse;
		http.send('delete=1&media_id='+media_id+'&comment_id='+comment_id);
	}
	return false;
}
