var positionval;
function doHttpRequest(posval,fname) {  // This function does the AJAX request
 positionval = posval;
 
  //  Set our destination PHP page "ajaxpost.php"…
  http.open("POST", fname, true);
  http.onreadystatechange = getHttpRes;
  // Make our POST parameters string…
  var params = "toaddress=" + encodeURI(document.getElementById("toaddress").value)+
	"&subject=" + encodeURI(document.getElementById("subject").value)+
	"&videoid=" + encodeURI(document.getElementById("videoid").value)+
	"&message=" + encodeURI(document.getElementById("message").value);

  // Set our POST header correctly…
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");

  // Send the parms data…
  http.send(params);
  alert('sended');
 
}

function getHttpRes( ) {
  if (http.readyState == 4 && http.status == 200) { 
    res = http.responseText;  // These following lines get the response and update the page
	positionval = positionval.toString();
	 
    document.getElementById(positionval).innerHTML = res;
  }
}

function getXHTTP( ) {
  var xhttp;
   try {   // The following "try" blocks get the XMLHTTP object for various browsers…
      xhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
 		 // This block handles Mozilla/Firefox browsers...
	    try {
	      xhttp = new XMLHttpRequest();
	    } catch (e3) {
	      xhttp = false;
	    }
      }
    }
  return xhttp; // Return the XMLHTTP object
}

var http = getXHTTP(); // This executes when the page first loads.
