function createRequestObject(){
var request_;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
 request_ = new ActiveXObject("Microsoft.XMLHTTP"); // If microsoft
}else{
 request_ = new XMLHttpRequest(); // if other
}
return request_;
}
var http_resigncheck = createRequestObject();
var http_mailcheck = createRequestObject();
var http_sentmail = createRequestObject();

function ajaxEmailExist(emailid,byear,bmonth,bday,zip) 
{	
	//window.open(siteurl+'/enlist/check-resign-exist.php?emailid='+emailid+'&byear='+byear+'&bmonth='+bmonth+'&bday='+bday+'&zip='+zip,'','')
	//alert(siteurl+'/enlist/check-resign-exist.php?emailid='+emailid+'&byear='+byear+'&bmonth='+bmonth+'&bday='+bday+'&zip='+zip);
	
	http_resigncheck.open('get',siteurl+'/enlist/check-resign-exist.php?emailid='+emailid+'&byear='+byear+'&bmonth='+bmonth+'&bday='+bday+'&zip='+zip);
	http_resigncheck.onreadystatechange = handleEmailExistInfo;	
	http_resigncheck.send(null);
}

function handleEmailExistInfo()
{
	// If you are using div for displaying that some process are being then write code in below condition....
	if(http_resigncheck.readyState == 1)
	{
	//	document.getElementById('content_div').innerHTML = '<table cellpadding="0" cellspacing="0" border="0" width="100%" height="300"><tr><td class="extlarge_text" align="center">Loading...</td></tr></table>';
	}
	// if object state is 4 then we can say, the file has been sucessfully executed.
	if(http_resigncheck.readyState == 4)
	{

		// method will return printed text
		var response_resigncheck = http_resigncheck.responseText; 	
		if(response_resigncheck == "no")
		{			
			alert(errmsg1);		
		}
		else if(response_resigncheck == "yes")
		{		
			alert(alertmsg);
			window.location = siteurl ;					  
		}
		
		
	}
}


function ajaxEmailSendCheck(emailid) 
{	
	if(document.frmunregister.email_confirm.value == "")
	{
		alert("Please enter Email-ID!");
	}
	else if(!echeck(document.frmunregister.email_confirm.value))
	{
		alert("Please enter valid Email-ID!");
	}
	else
	{

		//alert(siteurl+'/enlist/check-email-exist.php?emailid='+emailid);
		http_mailcheck.open('get',siteurl+'/enlist/check-email-exist.php?emailid='+emailid);
		http_mailcheck.onreadystatechange = handleEmailSendCheckInfo;	
		http_mailcheck.send(null);
	}
	//return false;
}
function handleEmailSendCheckInfo()
{
	// If you are using div for displaying that some process are being then write code in below condition....
	if(http_mailcheck.readyState == 1)
	{
	//	document.getElementById('content_div').innerHTML = '<table cellpadding="0" cellspacing="0" border="0" width="100%" height="300"><tr><td class="extlarge_text" align="center">Loading...</td></tr></table>';
	}
	// if object state is 4 then we can say, the file has been sucessfully executed.
	if(http_mailcheck.readyState == 4)
	{

		// method will return printed text
		var response_mailcheck = http_mailcheck.responseText; 
		
		if(response_mailcheck == "no")
		{
			alert(errmsg2);
		}
		else if(response_mailcheck == "yes")
		{			
			ajaxSendMail(document.frmunregister.email_confirm.value);
		}
		
	}
}


function ajaxSendMail(emailid) 
{	
	//alert(siteurl+'/enlist/check-email-exist.php?emailid='+emailid);
	http_sentmail.open('get',siteurl+'/enlist/sendinfomail.php?emailid='+emailid);
	http_sentmail.onreadystatechange = handleSendMailInfo;	
	http_sentmail.send(null);

}
function handleSendMailInfo()
{
	// If you are using div for displaying that some process are being then write code in below condition....
	if(http_sentmail.readyState == 1)
	{
	//	document.getElementById('content_div').innerHTML = '<table cellpadding="0" cellspacing="0" border="0" width="100%" height="300"><tr><td class="extlarge_text" align="center">Loading...</td></tr></table>';
	}
	// if object state is 4 then we can say, the file has been sucessfully executed.
	if(http_sentmail.readyState == 4)
	{

		// method will return printed text
		var response_sentmail = http_sentmail.responseText; 
		alert(response_sentmail);
	}
}


function check_unregister()
{
	var msg = "<-----------Please fill up following fields-------------> \n\n";
	var msg1 = "";

	if(document.frmunregister.email_confirm.value == "")
	{
		msg1 += "--> Email-ID\n";
	}
	else if(!echeck(document.frmunregister.email_confirm.value))
	{
		msg1 += "--> Valid Email-ID\n";
	}

	if(document.frmunregister.Year.value == "")
	{
		msg1 += "--> Birthday Year\n";
	}
	if(document.frmunregister.Day.value == "")
	{
		msg1 += "--> Birthday Day\n";
	}
	if(document.frmunregister.Month.value == "")
	{
		msg1 += "--> Birthday Month\n";
	}
	if(document.frmunregister.zip.value == "")
	{
		msg1 += "--> Postal/Zip code\n";
	}

	if(msg1 != "")
	{
		msg = msg + msg1;
		alert(msg);
		return false;
		
	}
	else
	{	
		ajaxEmailExist(document.frmunregister.email_confirm.value,document.frmunregister.Year.value,document.frmunregister.Month.value,document.frmunregister.Day.value,document.frmunregister.zip.value);		
		
	}
}

function send_mailinfo()
{
	return false;
}

