﻿// JScript File


      var avail='1';
      var validusr='';
      var availability='';
      var avail1='1';
      var validusr1='';
      var availability1='';
      
      function CallMe(src,dest) 
        { 
	
          var ctrl = document.getElementById(src);           
         if(fill_Shop(src)==true)
            {
                PageMethods.set_path("signup.aspx");
               PageMethods.GetUser(ctrl.value, CallSuccess, CallFailed, dest);             
             }
         }
    // set the destination textbox value with the ContactName
  function CallSuccess(res, destCtrl)
  { 
   var dest = document.getElementById(destCtrl);
   
   var dest_array=res.split(",");
   avail=dest_array[0];
   availability=dest_array[1];
   validusr=dest_array[2];
   dest.value=dest_array[1];
   
  //alert(avail);
    if(avail=='0')
       {
        document.getElementById('shop_correct').style.display='block'
        document.getElementById('shop_wrong').style.display='none'
       }
       else
       {
         document.getElementById('shop_correct').style.display='none'
         document.getElementById('shop_wrong').style.display='block'
       }
  
   }
  
   function CallFailed(res, destCtrl)
   {
   alert(res.get_message());
  
   }
   
   function validate()
   {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z0-9]{2,9})$/;
   var msg='';
   var fg='0';
   if(avail1=='1')//Check for Availability of user name
    {
    //alert('Check Username Availability');   
    //return false;
    msg=msg+'-Check Username Availability\n';
    fg='1';
    }
    if(avail=='1')//Check for Availability of user name
    {
    //alert('Check Shop Url Availability');   
    //return false;
    msg=msg+'-Check Shop Url Availability\n';
    fg='1';
    }
   // alert(chkSpecialChars(document.getElementById('texturl').value)
   
        
    if(document.getElementById('TShopname').value=='')
    {
    msg=msg+'-Enter Shop Name\n';
    fg='1';
    }
    if(document.getElementById('txtpwd').value=='')
    {
    msg=msg+'-Enter Password\n';
    fg='1';
    }
    
    if(chkSpecialChars(document.getElementById('txtpwd').value)==false)
        {
         msg=msg+'-Special Charectors Are Not Allowed  In Password\n';
            fg='1';
            
        }
    if(document.getElementById('txtcpwd').value=='')
    {
    msg=msg+'-Enter Confirm Password\n';
    fg='1';
    }
    
    if(document.getElementById('txtpwd').value!=document.getElementById('txtcpwd').value)
    {
    msg=msg+'-Password and Confirm Password Not Match\n';
    fg='1';
    }
    
   
    
     if(chkSpecialChars(document.getElementById('txtcpwd').value)==false)
        {
         msg=msg+'-Special Charectors Are Not Allowed  In Confirm Password\n';
            fg='1';
            
        }
     if(document.getElementById('texturl').value=='')
    {   
    msg=msg+'-Enter shop Url\n';
    fg='1';
    }
     if(document.getElementById('ddlnature').value=='Select')
    {   
    msg=msg+'-Select Nature Of Business\n';
    fg='1';
    }
   if(document.getElementById('txtfname').value=='')
    {   
    msg=msg+'-Enter First Name\n';
    fg='1';
    }
    
    if(document.getElementById('txtlname').value=='')
    {    
    msg=msg+'-Enter Last Name\n';
    fg='1';
    }
    if(document.getElementById('txtcompname').value=='')
    {
   
    msg=msg+'-Enter Business Name\n';
    fg='1';
    }   
    
     
    if(document.getElementById('txtmobile').value=='')
    {    
    msg=msg+'-Enter Mobile No\n';
    fg='1';
    }
    if(document.getElementById('ddlcurrency').value=='0')
    {    
    msg=msg+'-Select Shop Currency\n';
    fg='1';
    }
    
  if(isPositiveInteger1(document.getElementById('txtmobile').value,'Only Digit Allowed in Mobile No')==false && document.getElementById('txtmobile').value!='')
   {
    msg=msg+'-Only Digit Allowed in Mobile No\n';
    fg='1';
    }
    
    if (isMininumtenDigit_withoutmessage("txtmobile",10)==false&& document.getElementById('txtmobile').value!='')
    {
        msg=msg+'-Enter 10 Digit Mobile No\n';
        fg='1';
    }
    if(chkSpecialChars(document.getElementById('texturl').value)==false)
    { 
    
    msg=msg+'-Special Charectors Are Not Allowed  In Shop Url\n';            
    fg='1';
    }
    
    if(fg=='1')
    {
    alert(msg);
    return false;
    }
    else
    {
        showhidediv();
    }
 
   }




//Validation for only digit
function isPositiveInteger1(val,alertText){
//alert(id1);
//var val=document.getElementById(id1).value;
//alert(val);
      if(val==null||val==''){return false;}
      if (val.length==0){return false;}
      for (var i = 0; i < val.length; i++) {
            var ch = val.charAt(i)
            if (ch < "0" || ch > "9") {
            //alert(alertText);
            return false;
            }
      }
      return true;
}

function isMininumtenDigit_withoutmessage(txt,len)
{
val=document.getElementById(txt).value;
if(val.length<len)
{
return false;
}
return true;

}




        	
 
          
     
      
        function CallMeuser(src,dest) 
            { 
//	        alert(src);
//	        alert(dest);
	        //$('#usernameLoading').show();
            var ctrl = document.getElementById(src);
             if(fill_username(src)==true)
             {
                    // call server side method
		        //	alert("true");
                        PageMethods.set_path("signup.aspx");
                        PageMethods.GetUseremail(ctrl.value, CallSuccess1, CallFailed1, dest); 
             }
             else
             {
              //   $('#usernameLoading').hide();
             }
        }
         // set the destination textbox value with the ContactName
  function CallSuccess1(res, destCtrl)
  { 
       var dest = document.getElementById(destCtrl);
       //dest.value = res;
       var dest_array=res.split(",");
       avail1=dest_array[0];
       availability1=dest_array[1];
       validus1r=dest_array[2];
       dest.value=dest_array[1];
       if(avail1=='0')
       {
        document.getElementById('div_correct').style.display='block'
        document.getElementById('div_wrong').style.display='none'
       }
       else
       {
         document.getElementById('div_correct').style.display='none'
         document.getElementById('div_wrong').style.display='block'
       }
       //$('#usernameLoading').hide();
       //alert(dest_array[0]+' '+dest_array[1]+' '+ dest_array[2]);
   }
   // alert message on some failure
   function CallFailed1(res, destCtrl)
   {
       alert(res.get_message());
       //$('#usernameLoading').hide();
   }
   
function fill_username(id1)
{

    var user=document.getElementById(id1);
    if(user.value=='')
    {
    
        alert('Enter UserName First');
        //user.focus();
        return false;
    }
    //alert('Hello1');
    
    if (validate_email(user,"UserName should be a valid e-mail address!")==false)
    {
   
    //alert('Hello');
        return false;
    }
   else
    {
    
        return true;
    }
}

function fill_Shop(id1)
{
//alert(id1);

    var shop1=document.getElementById(id1);
    if(shop1.value=='')
    {
    
        alert('Enter Shop Url');
        //user.focus();
        return false;
    }
    else if(shop1.value.length<3)
    {
    
        alert('Please enter store name with atleast 3 char.');
        //shop1.focus();
        return false;
    }
    
      if(chkSpecialChars(shop1.value)==false)
        {
            alert('Special Charectors Are Not Allowed  In Shop Url');
            
            return false;
        }
        
    else
    {
    
        return true;
    }
}
   
   
function validate_email(field,alerttxt)
{
//alert('HEllo2');
with (field)
{
len=value.length;
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2||(len-1)==dotpos) 
  {
  alert(alerttxt);return false;}
else {return true;}
}
}

function chkSpecialChars(input)
{
var iChars = "_ !@#$%^&*()+=-[]\\\';,./{}|\":<>?";
 for (var i = 0; i < input.length; i++)
 {
 if (iChars.indexOf(input.charAt(i)) != -1)
 {
 return false;
 //alert ("You are using special characters. \nThese are not allowed.\n Please remove them and try again."); return false;
 }
 }
 return true;
 }
 

 
function showhidediv()
 {
//alert('HI');
 document.getElementById('createimage2').style.display='block';
 document.getElementById('createimage1').style.display='none';
 } 
