// stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject(); 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{  
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)


    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

// make asynchronous HTTP request using the XMLHttpRequest object 
function login()
{
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
		var u_name = encodeURIComponent(document.getElementById("username").value);
		var pwd = encodeURIComponent(document.getElementById("password").value);
	   // execute the quickstart.php page from the server
		 xmlHttp.open("GET", "../audience/login.php?u="+u_name+"&p="+pwd , true);
		// define the method to handle server responses
		xmlHttp.onreadystatechange = Loadmsg;
		// make the server request
		xmlHttp.send(null);
  }
}

// executed automatically when a message is received from the server
function Loadmsg()
{
  // move forward only if the transaction has completed
   if (xmlHttp.readyState == 4) 
  {
	//alert( xmlHttp.responseText);
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
		  // update the client display using the data received from the server
			//alert( xmlHttp.responseText);
		 if(xmlHttp.responseText=="<font color='#932923'><b>Logging Successfully</b></font>")
		 {
			window.location.href="index.php?m=login";	
		 }
		  document.getElementById("message").innerHTML = xmlHttp.responseText ;
		  // restart sequence
		 // setTimeout('process()', 1000);
		 
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("here was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
  else 
    {
      //alert("here was a problem accessing the server: " );
    }
}

function signup()
{
  // proceed only if the xmlHttp object isn't busy
	if(xmlHttp.readyState == 1)
	{
	//document.getElementById('loadingmessage').innerHTML='';
	//	alert("in");
	document.getElementById('loadingmessage').innerHTML = 'Loading...';
	}
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
	
		var u_name = encodeURIComponent(document.getElementById("username").value);
		var pwd = encodeURIComponent(document.getElementById("password").value);
		var re_pwd = encodeURIComponent(document.getElementById("re_pwd").value);
		//var symbol = encodeURIComponent(document.getElementById("symbol").value);
		var movie_c = encodeURIComponent(document.getElementById("movie_c").value);
		var email = encodeURIComponent(document.getElementById("email").value);
	   // execute the quickstart.php page from the server
		 xmlHttp.open("GET", "../audience/signup.php?u="+u_name+"&p="+pwd+"&m="+movie_c+"&email="+email+"&re_pwd="+re_pwd , true);
		// define the method to handle server responses
		xmlHttp.onreadystatechange = Loadsignup;
		// make the server request
		xmlHttp.send(null);
  }
}

// executed automatically when a message is received from the server
function Loadsignup()
{
  // move forward only if the transaction has completed
   if (xmlHttp.readyState == 4) 
  {
	
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
		  // update the client display using the data received from the server
			var msg = xmlHttp.responseText;
			//alert( xmlHttp.responseText);
			//alert(msg.indexOf("Thanks"));
		if(msg.indexOf("Thanks")>0)
		 {
			window.location.href="index.php?m=login";	
		 }
		 document.getElementById("message").innerHTML = xmlHttp.responseText ;
		  // restart sequence
		 // setTimeout('process()', 1000);
		 
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("here was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
  else 
    {
      	///alert("loading");
		//document.getElementById("loadingmessage").innerHTML="<font color='#000000'><b>Loading....</b></font>";
    }
}
/***************addtional info ***********************/
function addinfo(uid)
{
  // proceed only if the xmlHttp object isn't busy
	if(xmlHttp.readyState == 1)
	{
	//document.getElementById('loadingmessage').innerHTML='';
	//	alert("in");
	document.getElementById('loadingmessage').innerHTML = 'Loading...';
	}
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
	
		var realname = encodeURIComponent(document.getElementById("realname").value);
		var urllink = encodeURIComponent(document.getElementById("link").value);
		var reason = encodeURIComponent(document.getElementById("reason").value);
	   // execute the quickstart.php page from the server
		 xmlHttp.open("GET", "../audience/add_more_detail.php?uid="+uid+"&name="+realname+"&link="+urllink+"&reason="+reason , true);
		// define the method to handle server responses
		xmlHttp.onreadystatechange = Loadinfo;
		// make the server request
		xmlHttp.send(null);
  }
}

// executed automatically when a message is received from the server
function Loadinfo()
{
  // move forward only if the transaction has completed
   if (xmlHttp.readyState == 4) 
  {
	
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
		  // update the client display using the data received from the server
			var msg = xmlHttp.responseText;
			//alert( xmlHttp.responseText);
			//alert(msg.indexOf("Thanks"));
		//if(msg.indexOf("Thanks")>0)
//		 {
//			//window.location.href="index.php?m=suc";	
//		 }
		 document.getElementById("message").innerHTML = xmlHttp.responseText ;
		  // restart sequence
		 // setTimeout('process()', 1000);
		 
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("here was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
  else 
    {
      	///alert("loading");
		//document.getElementById("loadingmessage").innerHTML="<font color='#000000'><b>Loading....</b></font>";
    }
}
/****************login to post comment**********************/
function login_for_comment()
{
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
		var u_name = encodeURIComponent(document.getElementById("username").value);
		var pwd = encodeURIComponent(document.getElementById("password").value);
	   // execute the quickstart.php page from the server
		 xmlHttp.open("GET", "../audience/login.php?u="+u_name+"&p="+pwd , true);
		// define the method to handle server responses
		xmlHttp.onreadystatechange = Loadpage;
		// make the server request
		xmlHttp.send(null);
  }
}

// executed automatically when a message is received from the server
function Loadpage()
{
  // move forward only if the transaction has completed
   if (xmlHttp.readyState == 4) 
  {
	//alert( xmlHttp.responseText);
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
		  // update the client display using the data received from the server
			//alert( xmlHttp.responseText);
		 if(xmlHttp.responseText=="<font color='#932923'><b>Logging Successfully</b></font>")
		 {
			window.location.href="comment.php";	
		 }
		  document.getElementById("message").innerHTML = xmlHttp.responseText ;
		  // restart sequence
		 // setTimeout('process()', 1000);
		 
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("here was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
  else 
    {
      //alert("here was a problem accessing the server: " );
    }
}
