﻿// JScript File
var xmlHttp
///server email check
function sort(str)
{

emailcheck(str);
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  //alert(str);
var url="emailcheck.aspx";
url=url+"?q="+str;
//alert(url);

xmlHttp.onreadystatechange=stateChanged;
//alert("aa");
//alert(xmlHttp.onreadystatechange)
xmlHttp.open("GET",url,true);

xmlHttp.send(null);
xmlHttp.clear();

}

function stateChanged() 
{ 

if (xmlHttp.readyState==4)
{ 
//alert(xmlHttp.status);


var str1=xmlHttp.responseText;
if (str1 != "")
{
    alert(str1);
//    document.getElementById("ctl00_mainContent_ErrorMessage").innerHTML=str1;
    document.getElementById("ctl00_mainContent_ContactEmail").focus();
    document.getElementById("ctl00_mainContent_ContactEmail").select();
//    setTimeout("window.scrollTo(0,290)",0);
}
else
{
    document.getElementById("ctl00_mainContent_ErrorMessage").innerHTML="";
}

}
}

/// server email check
/// window scroll on error
function ajaxscroll()
{
var str="0,290";
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="ajaxscroll.aspx";
url=url+"?q="+str;

xmlHttp.onreadystatechange=stateChangedscroll;
////alert("aa");
////alert(xmlHttp.onreadystatechange)
xmlHttp.open("GET",url,true);

xmlHttp.send(null);
xmlHttp.clear();

}

function stateChangedscroll() 
{ 

if (xmlHttp.readyState==4)
{ 
var str1=xmlHttp.responseText;
if (str1 != "")
{
    setTimeout("window.scrollTo(" + str1 + ")",0);
}
else
{
    document.getElementById("ctl00_mainContent_ErrorMessage").innerHTML="";
}

}
}

//window scroll on error

function LostFocusFromText()
{
if (event.keyCode == 13)
{
return false;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


function emailcheck(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: " + str)
             document.getElementById("ctl00_mainContent_ContactEmail").focus();
             document.getElementById("ctl00_mainContent_ContactEmail").select();
             return false 
          }

          if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
          {
             alert("Invalid E-mail ID: " + str)
             document.getElementById("ctl00_mainContent_ContactEmail").focus();
             document.getElementById("ctl00_mainContent_ContactEmail").select();
             return false
          }

          if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
          {
              alert("Invalid E-mail ID: " + str)
              document.getElementById("ctl00_mainContent_ContactEmail").focus();
              document.getElementById("ctl00_mainContent_ContactEmail").select();
              return false
          }

           if (str.indexOf(at,(lat+1))!=-1)
           {
              alert("Invalid E-mail ID: " + str)
              document.getElementById("ctl00_mainContent_ContactEmail").focus();
             document.getElementById("ctl00_mainContent_ContactEmail").select();
             return false
           }

           if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
           {
              alert("Invalid E-mail ID: " + str)
              document.getElementById("ctl00_mainContent_ContactEmail").focus();
             document.getElementById("ctl00_mainContent_ContactEmail").select();
             return false
           }

           if (str.indexOf(dot,(lat+2))==-1)
           {
              alert("Invalid E-mail ID: " + str)
              document.getElementById("ctl00_mainContent_ContactEmail").focus();
             document.getElementById("ctl00_mainContent_ContactEmail").select();
             return false
           }
          
           if (str.indexOf(" ")!=-1)
           {
              alert("Invalid E-mail ID: " + str)
              document.getElementById("ctl00_mainContent_ContactEmail").focus();
             document.getElementById("ctl00_mainContent_ContactEmail").select();
             return false 
           }

            return true     
         }
         
 //server phone check
function checkPhone(str)
{

if(str.length > 0)
{

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  //alert(str);
var url="emailcheck.aspx";
url=url+"?p="+str;
//alert(url);

xmlHttp.onreadystatechange=phonestateChanged;
//alert("aa");
//alert(xmlHttp.onreadystatechange)
xmlHttp.open("GET",url,true);

xmlHttp.send(null);
xmlHttp.clear();

}

}
function phonestateChanged() 
{ 

if (xmlHttp.readyState==4)
{ 
//alert(xmlHttp.status);


var str1=xmlHttp.responseText;
if (str1 != "")
{
    document.getElementById("ctl00_mainContent_AddBusinessInfoButton").disabled=true;
    alert(str1);
//    document.getElementById("ctl00_mainContent_ErrorMessage").innerHTML=str1;
    document.getElementById("ctl00_mainContent_Phone").focus();
    document.getElementById("ctl00_mainContent_Phone").select();
    
//    setTimeout("window.scrollTo(0,290)",0);
}
else
{
    document.getElementById("ctl00_mainContent_AddBusinessInfoButton").disabled=false;
    document.getElementById("ctl00_mainContent_ErrorMessage").innerHTML="";
    
}

}
}

//server phone check

//server fax check
function checkFax(str)
{
if(str.length > 0)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  //alert(str);
var url="emailcheck.aspx";
url=url+"?f="+str;
//alert(url);

xmlHttp.onreadystatechange=faxstateChanged;
//alert("aa");
//alert(xmlHttp.onreadystatechange)
xmlHttp.open("GET",url,true);

xmlHttp.send(null);
xmlHttp.clear();
}
}

function faxstateChanged() 
{ 

if (xmlHttp.readyState==4)
{ 
//alert(xmlHttp.status);


var str1=xmlHttp.responseText;
if (str1 != "")
{
    document.getElementById("ctl00_mainContent_AddBusinessInfoButton").disabled=true;
    alert(str1);
//    document.getElementById("ctl00_mainContent_ErrorMessage").innerHTML=str1;
    document.getElementById("ctl00_mainContent_Fax").focus();
    document.getElementById("ctl00_mainContent_Fax").select();
//    setTimeout("window.scrollTo(0,290)",0);
}
else
{
    document.getElementById("ctl00_mainContent_AddBusinessInfoButton").disabled=false;
    document.getElementById("ctl00_mainContent_ErrorMessage").innerHTML="";
}

}
}
//server fax check

//popup error message
function popuperror(str)
{
    alert(str);

}
//popup error message
