﻿// JScript File       
 var checkValidate;
 var PassValue; 
 function AddNewUserAccount(strSitePath)
 {  
    var sEmailAddress=document.getElementById('txtEmailAddress');
    var sFirstName=document.getElementById('txtFirstName');
    var sLastName=document.getElementById('txtLastName');
    var sPassword=document.getElementById('txtPassword');   
    var sPasswordAgain=document.getElementById('txtPasswordAgain');
    var sCompanyName=document.getElementById('txtCompany');
    var sTitle=document.getElementById('txtTitle');
    var sCountryCode=document.getElementById('cboCountry1');
    var sIPAddress=document.getElementById('txtIPAddress');   
    var Charset = document.getElementById('txtCharacterset');
    var ImageCharset = document.getElementById('txtImageCharacter');
    var sSiteType = document.getElementById('SiteType');    
    //var divCodex=document.getElementById('Codex');        
    if (sCountryCode.value.length<3) sCountry.value='UUU';
         
     sPassword.style.backgroundColor='white';
     Charset.style.backgroundColor='white';
     sEmailAddress.style.backgroundColor='white';      
     checkValidate=1;     
     document.getElementById('Errormessage').innerHTML='';       
    var  sSubject='Confirmed Registration  ';    
    //var  sBody='please click on this link to confirm your registration http://jdbinternetdev/jdbinternet/frmRegConfirm.aspx?ID='+sEmailAddress.value;    
    var  sBody='please click on this link to confirm your registration ' + strSitePath + 'frmRegConfirm.aspx?ID='+sEmailAddress.value;    
    
     
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
      
      /// validateEmail Address Syntax
      
      if(sEmailAddress.value.indexOf('@')==-1)        
         {
            sEmailAddress.style.backgroundColor='red';            
            checkValidate=0;               
        } 

       if (!filter.test(sEmailAddress.value)) 
       {
	    sEmailAddress.style.backgroundColor='red';            
            checkValidate=0;               
       } 
                
        // validPassword
        
        if (sPassword.value != sPasswordAgain.value || sPassword.value.length <6)
        {                  
            sPassword.style.backgroundColor='red';
            checkValidate=0;                  
        }  
         
        //ValidcharacterSetWord(); 
            if (Charset.value!=ImageCharset.value)    
            {   Charset.style.backgroundColor='red';            
                checkValidate=0;                  
            }  
            
        //Valdate if Existing Email   
           var EmailConfirm=document.getElementById('EmailConfirm');
          if(EmailConfirm.value!=3)
          {  sEmailAddress.style.backgroundColor='red';            
             checkValidate=0;  
          }
                  
       if   (checkValidate == 0)
        {
            document.getElementById('Errormessage').style.color='red';
            document.getElementById('Errormessage').innerHTML='Please correct the highlighted field(s)'; 
            //alert('Can not create account' );            
            
        } 
        else
        {   
           //alert(sPassword.value);
          // ICTYJDB.Services.UserAccountServices.GetEncription(document.getElementById('txtPassword').value,onEncript,onEncriptError);
            //alert(PassValue);            
           
           //ICTYJDB.Services.UserAccountServices.AddNewUserAccount
            //(sEmailAddress.value,sFirstName.value,sCountryCode.value,sLastName.value,divCodex.value,
             //   sCompanyName.value, sTitle.value,sIPAddress.value,sSubject,sBody,sSiteType.value,onAddNewAccount,OnAddNewAccountError);
             
             ICTYJDB.Services.UserAccountServices.AddNewUserAccount
            (sEmailAddress.value,sFirstName.value,sCountryCode.value,sLastName.value,sPassword.value,
                sCompanyName.value, sTitle.value,sIPAddress.value,sSubject,sBody,sSiteType.value,onAddNewAccount,OnAddNewAccountError);
           
               
               if ( checkValidate==1)
               {        
                   window.location='frmPostReg.aspx?Emailaddress='+sEmailAddress.value;
               }
        }
    }    
    
  function  onAddNewAccount(returnValue) 
  {         
       if (returnValue =='0')  checkValidate=0;  
  }
    
  function OnAddNewAccountError(error)
  {
        checkValidate=0;                    
      
        //alert('Server process failed:'+error.get_message());
  }
  
  function  onEncript(returnValue) 
  {         
       PassValue=returnValue;       
  }
    
  function onEncriptError(error)
  {       
        alert('Password Server process failed:'+error.get_message());
  }
 
 
  
 function ValidPassowrd()
 {
   var sPassword=document.getElementById('txtPassword');
   
   var sPasswordAgain=document.getElementById('txtPasswordAgain');    
   
   if (sPassword.value != sPasswordAgain.value || sPassword.value.length <6)
     {                  
        sPassword.style.backgroundColor='red';
        checkValidate=0;                  
     }    
 }
 
 
 function ValidWord()
 {
    var Charset = document.getElementById('txtCharacterset');
    
    if (Charset.value!=ImageCharset.value)    
     { 
     
          Charset.style.backgroundColor='red';            
          
        checkValidate=0;                  
    }    
 }
 
  
function ValidateEmailAddress()
{
     var sEmailAddress=document.getElementById('txtEmailAddress');            
     
     if (sEmailAddress.value.indexOf('@')==-1)  checkValidate=0;               
     
      if (checkValidate==0)  
         {
            sEmailAddress.style.backgroundColor='red';            
         }             
}   
   
 function CheckEmailAddress()    
 { 
      var EmailConfirm=document.getElementById('EmailConfirm');
      
          if(EmailConfirm.value!=3) checkValidate=0;                         
 }

