// JavaScript Document
var url = "validate.php?action="; // The server-side script 
var pid;
function valid_email(project_id) 
{  
	var password = document.login_form.password.value;
	var email_id = document.login_form.username.value;
	//alert(password);
	//alert(project_id);
	pid = project_id;
	http.open("GET", url + escape('') +'&password='+ escape(password)+'&email_id='+escape(email_id)+'&project_id='+escape(project_id), true); 
	http.onreadystatechange = handleHttpResponse; 
	http.send(null);
} 
function handleHttpResponse() 
{    
	if (http.readyState == 4) 
	{ 
		if(http.status==200) 
		{ 
			var results=http.responseText; 
			//alert(results);
			if(results == 'invalid')
			{
				alert('Login Unsuccessful, invalid Email ID or Password');
				document.login_form.password.value="";
				document.login_form.username.value="";
				document.login_form.username.focus();
			}
			else if(results == 'details')
			{
				document.location = "project.php?action=view_details&project_id="+pid;
			}
			else if(results == 'pledges')
			{
				document.location = "members.php?action=view_pledges";
			}
			/*else
			{
				document.location = "members.php?action=view_pledges";
			}*/
		} 
	} 
}

var url = "validate.php?action="; // The server-side script 
function pr_email(member_id) 
{  
	//alert(member_id);
	var email = document.form3.email.value;
	http.open("GET", url + escape('pr_email')+'&email='+escape(email)+'&member_id='+escape(member_id), true); 
	http.onreadystatechange = handleHttpResponse2; 
	http.send(null);
} 
function handleHttpResponse2() 
{    
	if (http.readyState == 4) 
	{ 
		if(http.status==200) 
		{ 
			var results=http.responseText; 
			if(results == 'existing')
			{
				alert('Email Id already existing. Please enter a different Email Id');
				//document.form3.email.value="";
				document.form3.email.focus();
			}
			if(results == 'invalid')
			{
				alert('Invalid Email Id. Please enter your full Email Id');
				//document.form3.email.value="";
				document.form3.email.focus();
			}
		} 
	} 
} 


// This function is required to run the AJAX Function.
function getHTTPObject() 
{ 
  var xmlhttp; 
  if(window.XMLHttpRequest)
  { 
    xmlhttp = new XMLHttpRequest(); 
  } 
  else if (window.ActiveXObject)
  { 
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    if (!xmlhttp)
	{ 
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
    } 
    
  } 
  return xmlhttp; 
} 
var http = getHTTPObject();
