﻿var requestS;
var responseS;
function IsEmailExists(eid)
	{	
		
	         if(eid != "")
	         {      
                    return SendRequestIsEmailExists(eid);
	         }
	         else
	         {
	              alert("Please must fill email-ID.");
	         }

	
	
	}

	function SendRequestIsEmailExists(ID)
		{	
			InitializeRequest();//Call InitializeRequest to set request object
			var dt=new Date();
			var url =sPath+"/IsExistsEmail.aspx?eid="+ ID + "&dt="+dt.toString();//Create the url to send the request to
			request.onreadystatechange = ProcessRequestIsEmailExists;//Delegate ProcessRequestCampus to onreadystatechange property so it gets called for every change in readyState value
			request.open("GET", url, true);//Open a GET request to the URL
			request.send(null);//Send the request with a null body.
		}


	function InitializeRequest()
	{
		try
		{
			request = new ActiveXObject("Microsoft.XMLHTTP");//Try creating an XMLHTTP Object
		}
		catch(Ex)
		{
			try
			{
				request = new ActiveXObject("Microsoft.XMLHTTP");//First failure, try again creating an XMLHTTP Object
			}
			catch(Ex)
			{
				request = null;//Else assign null to request
			}
		}

		if(!request&&typeof XMLHttpRequest != 'undefined')
		{
			request = new XMLHttpRequest();
		}
	}

function ProcessRequestIsEmailExists()
		{  
			if(request.readyState == 4)//If the readyState is in the "Ready" State
			{
				if(request.status == 200)//If the returned status code was 200. Everything was OK.
				{
					if(request.responseText != "")//If responseText is not blank
					{	
                        var returnval = request.responseText;
                        var arrval = returnval.split("~");
                        if(arrval.length > 0)
                        {
                            var isExists = arrval[0];
                            if(isExists == "1")
                            {
                               if(window.confirm("The Email-id you have entered is already exists. Do you want to continue?") == true)
                               {
                                    document.getElementById(preid+"tbxClientName").value = arrval[1];
                                     document.getElementById(preid+"tbxAgencyAddress").value = arrval[2];
                                      document.getElementById(preid+"tbxCLIA_IATA").value = arrval[3];
                                       document.getElementById(preid+"tbxManagerName").value = arrval[4];
                               }
                               else
                               {
                                    alert("You have to enter another Email-id");
                                    document.getElementById(preid+"tbxEmail").value = ""
                                    document.getElementById(preid+"tbxEmail").focus();
                               }
                            }
                            else if(isExists == "0")
                            {
                                //alert("Email-id does not exists.");
                            }
                            else if(isExists == "2")
                            {
                                alert("Email-id required.");
                            }
                            else
                            {
                                alert("Sorry. There is an error. Please try again.");
                            }
                        }
                        else
                        {
                            alert("Sorry. Please try again.");
                        }
						//status.innerText = "Cities Loaded";//Set the status to "Territories Loaded"
					}
					else
					{
						alert("Sorry. Please try again.");
						//status.innerText = "None Found";//Set the status to "None Found"
						//clearSelect(pModel);	
					}
				}
			}
			return true;//return
		}