﻿var isdstatus=new Boolean(false);
function cleartext(id)
                    {
                        if (id=="passwd" || id=="userid")
                        {
                          document.getElementById("mailid").className="normal";
                          document.getElementById("PhoneNo").className="normal";  
                          document.getElementById("name").className="normal"; 
                          document.getElementById("isd").className="normalisd"; 
                        }
                        else
                        {
                          document.getElementById("passwd").className="normal";
                          document.getElementById("userid").className="normal";  
                        }
                          if (id=="PhoneNo" && document.getElementById(id).value=="0000000")
                          {document.getElementById(id).value="";
                          }
                           
                          if(id=="isd")
                          {
                                 document.getElementById(id).className="activeisd";
                                if(document.getElementById(id).value=="+")
                               { 
                                   
                                    document.getElementById("PhoneNo").className="activetext";
                                    document.getElementById(id).className="activeisd";
                                    return false;
                               }
                                 if(document.getElementById(id).value=="")
                               { 
                                     document.getElementById("PhoneNo").className="activetext";
                                     document.getElementById(id).className="activeisd";
                                     return false;
                                }
                               
                               if(document.getElementById(id).value=="+000")
                               { 
                                    document.getElementById("PhoneNo").className="activetext";
                                    
                                    document.getElementById(id).className="activeisd";
                                    document.getElementById(id).value="+";
                                    return false;
                                }
                          }
                         if(id!="isd")
                            document.getElementById(id).className="activetext"; 
                      
                    }
              
function isdcheck()
                    {
                      var isd=document.getElementById("isd").value; 
                      var reg=/[^0-9+]/;
                      if( isd=="" || isd==null || reg.test(isd)==true || isd.length<2 || isd=="+" || isd=="+000")
                      {
                        document.getElementById("isd").className="redisd";
                        document.getElementById("PhoneNo").className="red";
                        isdstatus=false;
                        return false;                     
                      }
                      else
                      xmlHttp = GetXmlHtpObject();
                         if(xmlHttp == null)
                        {
                            alert('Browser does not support HTTP Request');
                            return;
                        }
                         
			            sendData("http://www.leathericon.com/purchase/isdcheck.aspx");
                     
                    }   
function namecheck()
                    {
                      var name=document.getElementById("name").value; 
                      var reg=/[^a-zA-Z\s]/;
                      if( name=="" || name==null || reg.test(name)==true)
                      {
                        document.getElementById("name").className="red";
                        return false;
                       }
                      else
                      document.getElementById("name").className="activetext";
                      return true;
                    }                                            
                    
function callwindow()
                    {
                        //$('#simplemodal-overlay').hide();
						//$('#simplemodal-container').hide();
						//$('#login_form').hide();
                        window.open('http://www.leathericon.com/forgotpassword.aspx','forgotpassword','scrollbars=0,status=no,toolbar=no,menubar=no,left=250,top=150,width=640,height=350');
                    }                    
function validuser()
            {
               var address = document.getElementById("userid").value;

				if (address=='' || address==null)
             {
             	document.getElementById("userid").className="red";
	            document.getElementById("userid").focus=true;
             	return false;
			 }
			 document.getElementById("userid").className="activetext";
			 return true;
            }
function validmail()
            {
             
               var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
               var address = document.getElementById("mailid").value;
               if(reg.test(address) == false) 
                   {
                    document.getElementById("mailid").className="red";
                    //document.getElementById("mailerror").innerHTML="<img src='http://localweb/static1.onlygowns/small_cross.gif' width='12px' height='12px' />";
                    return false;
                    }
               else
                  {  
                   document.getElementById("mailid").className="activetext";
                   //document.getElementById("mailerror").innerHTML="";
                   return true;
                  }
            }
 function validpass()
            {
             if ( document.getElementById("passwd").value=='' || document.getElementById("passwd").value==null)
             {
                 //document.getElementById("passcheck").innerHTML="Enter Password";
                 document.getElementById("passwd").focus=true;
                 document.getElementById("passwd").className="red";
                 return false;
             }
			 
             else
              { //document.getElementById("passcheck").innerHTML="";
                document.getElementById("passwd").className="activetext";
                }
              return true;
             
          } 
       
       
function validphone()
		  {
		  //(eg. 02 1234 5678 or 123 123 4567) or international format (eg. +61 (0) 2 1234 5678 or +1 123 123 4567). It also accepts an optional extention of up to five digits prefixed by x or ext (eg. 123 123 4567 x89). 
		  
		  	phoneRe1 = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;
		  	phoneRe2 = /^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( |-|\.)?\d{4,4}(( |-|\.)?[ext\.]+ ?\d+)?$/;
		      if(document.getElementById("PhoneNo").value=="0000000")
		         {	
		            document.getElementById("PhoneNo").className="red";
		  	        return false;
		  	     }
		  	
            if(document.getElementById("PhoneNo").value=="" || document.getElementById("PhoneNo").value==null)
		     {			        
		        document.getElementById("PhoneNo").value="0000000";
		        document.getElementById("PhoneNo").className="red";		      
		  	    return false;
		  	 }		  	 
		  	if(phoneRe1.test(document.getElementById("PhoneNo").value)==false && phoneRe2.test(document.getElementById("PhoneNo").value)==false  )
		  	{
		  	   document.getElementById("PhoneNo").className="red";
		  	   return false;
		  	}
		  	else
		  	{    
		  	     document.getElementById("PhoneNo").className="activetext";
		  	     return true;
		  	}
		  	
		  }
		  
 function userlogin()
       {
             if (validuser()==false)
            {document.gĂtElementById("userid").focus=true;return false;}
            
            if ( validpass()==false)
            {document.getElementById("passwd").focus=true;return false;}
              document.getElementById("Error").innerHTML="" ;
             document.getElementById("blanck").className="ajaxlogin";
             xmlHttp = GetXmlHtpObject();
             if(xmlHttp == null)
            {
                alert('Browser does not support HTTP Request');
                return;
            }
			sendData("http://www.leathericon.com/purchase/userlogin.aspx");
        }


function guestsignup()
       {             
              if (namecheck()==false)
            {document.getElementById("name").focus=true;return false;}
             
             if (validmail()==false)
            {document.getElementById("mailid").focus=true;return false;}
             if (isdstatus==false)
            {document.getElementById("isd").focus=true;return false;}
             
            if ( validphone()==false)
            {document.getElementById("PhoneNo").focus=true;return false;}
            document.getElementById("Error").innerHTML="" ;
            document.getElementById("blanck").className="ajaxsignup";
             xmlHttp = GetXmlHtpObject();
             if(xmlHttp == null)
            {
                alert('Browser does not support HTTP Request');
                return;
            }           
			sendData("http://www.leathericon.com/purchase/guestsignup.aspx");
        }
		
function RecoverPassword()
{
 if (validuser()==false)
            {document.getElementById("userid").focus=true;return false;}
			
			xmlHttp = GetXmlHtpObject();
             if(xmlHttp == null)
            {
                alert('Browser does not support HTTP Request');
                return;
            }
			sendData("http://www.leathericon.com/purchase/RecoverPassword.aspx");
}		
		
function sendData(sendingPath)
{
	    	var url = sendingPath;
	    	var name = document.getElementById("name").value;
            var userid = document.getElementById("userid").value;
            var mailid = document.getElementById("mailid").value;
            var passwd = document.getElementById("passwd").value;
            var PhoneNo = document.getElementById("isd").value + document.getElementById("PhoneNo").value;
            var isd = document.getElementById("isd").value;
             
               url= url + "?CusID=" +userid+ "&ISD=" +isd+ "&cusName=" +name+"&cusEmail=" +mailid+ "&Password=" +passwd+"&phoneNo="+ PhoneNo +"&popupLogin=YES";
			   xmlHttp.open("Get",url,false);
               xmlHttp.send(null);
               xmlHttp.onreadystatechange = stateChanged();			
}         
function stateChanged()
            { 
                if(xmlHttp.readyState==4)
                {
					// For ISD Check 
                     if(xmlHttp.responseText=='ISD')
                     { 
	                         document.getElementById("isd").className="activeisd";
	                         isdstatus=true;	                       
	                  }
	                  else
                      if(xmlHttp.responseText=='NOTISD')
                     { 
	                         document.getElementById("PhoneNo").className="red";
	                         document.getElementById("isd").className="redisd";
	                         isdstatus=false;	                        
                     }				
					else
				    // For Login 
                     if(xmlHttp.responseText=='YES')
                     { 
							 document.getElementById("simplemodal-overlay").style.visibility="hidden";
 							 document.getElementById("simplemodal-container").style.display="none";							 
                             window.location.reload(true);
                     }
				   // New Guest Created
				    else if(xmlHttp.responseText=='RECORD_INSERTED')
					 {
						$('#simplemodal-overlay').hide();
						$('#simplemodal-container').hide();
						$('#login_form').hide();						
					 }
					  // New Password request failed
			         else if(xmlHttp.responseText=='IDNOTFOUND')
					 {
						document.getElementById("mailcheck").innerHTML="Your EMailID doesn't Exist!";
					 }	 // New Password recovery mail sent
				        else if(xmlHttp.responseText=='RECOVER-MAIL-SENT')
					 {
						IWantToSignIn();
					 }	// Login Failed
                else if(xmlHttp.responseText=='NO')
					 {
                       document.getElementById("Error").innerHTML="<span style='font-size:10px; color:#3892de; font-weight:bold'>( Wrong Id/Password )</span>" ;
					 }	
					document.getElementById("blanck").className="";   
				} 				
            }
function GetXmlHtpObject()
            {
                var objXmlHttp = null;
                if(window.XMLHttpRequest)
                {
                objXmlHttp = new XMLHttpRequest();
                }
                else if(window.ActiveXObject)
                {
                objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                return objXmlHttp;                 
            }   
   
    
