﻿// JScript File


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}



function DoesExistEMail(strValue,ClientName)
{

xmlHttpEmail=GetXmlHttpObjectEmail();
  if (xmlHttpEmail==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
   if(document.getElementById("ctl00_ContentPlaceHolder1_TxtClientMailID").value=="")
    {
        alert("Enter Email Id");
        document.getElementById("ctl00_ContentPlaceHolder1_TxtClientMailID").focus();
        return false;
    }
var url="../Email/AjaxCountEmail.aspx?Email="+strValue+"&ClientName="+ClientName;

xmlHttpEmail.onreadystatechange=EmailstateChanged;
xmlHttpEmail.open("GET",url,true);
xmlHttpEmail.send(null);
} 

var xmlHttp


function GetXmlHttpObjectEmail()
{
var xmlHttpEmail=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttpEmail=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttpEmail=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttpEmail=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttpEmail;
}

function EmailstateChanged() 
{ 
 
	// To make sure receiving response data from server is completed
	if(xmlHttpEmail.readyState == 4)
	{
	
		
		// To make sure valid response is received from the server, 200 means response received is OK
		if(xmlHttpEmail.status == 200)
		{	
            var strdata = xmlHttpEmail.responseText;
            var arrData = strdata.split("|");
            //alert(strdata)
          if(echeck(document.getElementById("ctl00_ContentPlaceHolder1_TxtClientMailID").value)==false)
          {
            document.getElementById("ctl00_ContentPlaceHolder1_TxtClientMailID").value="";
		    document.getElementById("ctl00_ContentPlaceHolder1_TxtClientMailID").focus();
		    return false
          }
          else
          { 
             if(eval(arrData[0]) > 0)
            {
               alert("EmailId Already Exists");
               document.getElementById("ctl00_ContentPlaceHolder1_TxtClientMailID").value="";
               document.getElementById("ctl00_ContentPlaceHolder1_TxtClientMailID").focus();
                return false;
            }
            else
            {
            
                alert("EmailId Available");
               
             }
            }
         }
    }
 
}

function ReplaceSingle(Ele)
{
    if(Ele.value.indexOf("'")!=-1)
    {
        alert("Please remove single quote");
        Ele.focus();
    }
}

