﻿// JScript File

var xmlHttp;

    //-----------------------------------------------------------------
    // function:checkEmailId
    // 
    // Synopsis:
    //      This Function is used to check whether 
    //      EmailId entered by User is already exist
    
function checkEmailId()
{ 
    
    var _userName = trim(document.getElementById("txtPrimaryEmail").value);
    if(_userName!="")
    {
        xmlHttp= null;
        xmlHttp=GetXmlHttpObject();
       
        if (xmlHttp==null)
        {
            alert("Browser does not support HTTP Request.");
            return;
        } 
        var url="../checkEmail.aspx";
        url=url+"?varUserName="+_userName; 
        
        xmlHttp.onreadystatechange=stateChangedCheckEmail;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    }
    
}
    // end of function checkEmailId
    //---------------------------------------------------------------------


    //---------------------------------------------------------------------
    // function:stateChanged
    // 
    // Synopsis:
    //      This Function is used to display  message depending 
    //      upon result of checkUserId function 


function stateChangedCheckEmail() 
{ 
    //var loadstatustext="<img src='../../Images/warning.gif' /> This email address already exists.";
    var loadstatustext=" This email address already exists.";
   
    if (xmlHttp.readyState==4 )
    { 
       
       if((xmlHttp.responseText).search(/exists/i) > 0)
       {
          var emailDiv = document.getElementById("WarningMsgs_RegistrationErrors");
          emailDiv.style.display = "block";
          document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
	  
          emailDiv.innerHTML = loadstatustext;
//          var EmailAvailabilityObj = document.getElementById("hidEmailNotAvailable");
//          if(EmailAvailabilityObj != null && EmailAvailabilityObj != "")
//          {
//            EmailAvailabilityObj.value = "1";
//          }
         var emailIdObj = document.getElementById("txtPrimaryEmail");
         if(emailIdObj != null && emailIdObj != "")
         {
            emailIdObj.value = "";
            emailIdObj.focus();
         }
         return false;   
       }
       else
       {
            var emailDiv = document.getElementById("WarningMsgs_RegistrationErrors");
            if((emailDiv.innerHTML).search(/already/i) > 0)
            {
                    emailDiv.style.display = "none";
                    document.getElementById("WarningMsgs_divWarningInfo").style.display = "none";
                    emailDiv.innerHTML="";
            }
//            var EmailAvailabilityObj = document.getElementById("hidEmailNotAvailable");
//            if(EmailAvailabilityObj != null && EmailAvailabilityObj != "")
//            {
//                EmailAvailabilityObj.value = "";
//            }
            
            return true;
        }
     } 
} 
    // end of function checkEmailId
    //---------------------------------------------------------------------

     //-----------------------------------------------------------------
    // function:checkDisplayName
    // 
    // Synopsis:
    //      This Function is used to check whether 
    //      Display Name is already exist
    
function checkDisplayName()
{   
    var _DisplayName = trim(document.getElementById("txtDisplayName").value);
    if(_DisplayName!="")
    {
        xmlHttp= null;
        xmlHttp=GetXmlHttpObject();
       
        if (xmlHttp==null)
        {
            alert("Browser does not support HTTP Request.");
            return;
        } 
        var url="../checkDisplayName.aspx";
        url=url+"?varDisplayName="+_DisplayName; 
        
        xmlHttp.onreadystatechange=stateChangedCheckDisplayName;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    }
    
}
    // end of function checkDisplayName
    //---------------------------------------------------------------------

 
 
 
 //---------------------------------------------------------------------
    // function:stateChangedCheckDisplayName
    // 
    // Synopsis:
    //      This Function is used to display  message depending 
    //      upon result of checkDisplayName function 


function stateChangedCheckDisplayName() 
{ 
    //var loadstatustext="<img src='../../Images/warning.gif' /> This display name already exists.";
    var loadstatustext=" This display name already exists.";
   
    if (xmlHttp.readyState==4 )
    {        
       if((xmlHttp.responseText).search(/exists/i) > 0)
       {
          var displaynameDiv = document.getElementById("WarningMsgs_RegistrationErrors");
          displaynameDiv.style.display = "block";
           document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
	  
          displaynameDiv.innerHTML = loadstatustext;
         
//          var EmailAvailabilityObj = document.getElementById("hidEmailNotAvailable");
//          if(EmailAvailabilityObj != null && EmailAvailabilityObj != "")
//          {
//            EmailAvailabilityObj.value = "1";
//          }
         var emailIdObj = document.getElementById("txtDisplayName");
         if(emailIdObj != null && emailIdObj != "")
         {
            emailIdObj.value = "";
            emailIdObj.focus();
         }
         return false;   
       }
       else
       {
            var displaynameDiv = document.getElementById("WarningMsgs_RegistrationErrors");  
            if((displaynameDiv.innerHTML).search(/already/i) > 0)
            {                     
                        displaynameDiv.style.display = "none";
                         document.getElementById("WarningMsgs_divWarningInfo").style.display = "none";
                        displaynameDiv.innerHTML = "";

            }
            
           // displaynameDiv.innerHTML="";
//            var EmailAvailabilityObj = document.getElementById("hidEmailNotAvailable");
//            if(EmailAvailabilityObj != null && EmailAvailabilityObj != "")
//            {
//                EmailAvailabilityObj.value = "";
//            }
            
            return true;
        }
     } 
}      
     
    //-----------------------------------------------------------------
    // function:recoverPassword
    // 
    // Synopsis:
    //      This Function is used to recover Password 
    //      and mail will be send on users EmailId entered by User 
     
     
function recoverPassword()
{ 
    
    var _userName = document.getElementById("txtEmailId").value;
   
    xmlHttp= null;
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert("Browser does not support HTTP Request.");
        return false;
    } 
    var url="../recoverPasswordTemp.aspx";
    
    url=url+"?varUserName="+_userName; 
    xmlHttp.onreadystatechange=stateChangedRecoverPassword
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    
    return false;
}     
     
     
     
    //---------------------------------------------------------------------
    // function:stateChangedRecoverPassword
    // 
    // Synopsis:
    //      This Function is used to display  message depending 
    //      upon result of recoverPassword function 


function stateChangedRecoverPassword() 
{ 
   
    
    if (xmlHttp.readyState==4 )
    { 
      
       if((xmlHttp.responseText).search(/Invalid/i) > 0)
       {
       //   var divFailure = document.getElementById("divPasswordRecoveryFailed");
          var divStatus = document.getElementById("divStatus");
          var divOriginal = document.getElementById("divPasswordRecovery");
        //  divOriginal.style.display = 'block';
        //  divFailure.style.display = 'block';
          divStatus.style.display = 'block';
          alert(xmlHttp.responseText);
          divStatus.innerHTML = xmlHttp.responseText;
    
       }
       else
       {
       //   var divFailure = document.getElementById("divPasswordRecoveryFailed");
          var divStatus = document.getElementById("divStatus");
          var divOriginal = document.getElementById("divPasswordRecovery");
        //  divOriginal.style.display = 'block';
        //  divFailure.style.display = 'block';
          divStatus.style.display = 'block';
          
          divStatus.innerHTML = xmlHttp.responseText;
            
        }
    } 
} 
    // end of function checkEmailId
    //---------------------------------------------------------------------
     
     

    //---------------------------------------------------------------------
    // function:GetXmlHttpObject
    // 
    // Synopsis:
    //      This Function is used to get object of xmlHttpRequest
    //      depending upon browser 

function GetXmlHttpObject()
{ 
    var objXMLHttp=null;
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp;
}
    // end of function checkEmailId
    //---------------------------------------------------------------------
