﻿// JScript File




function clearvalues()
    {
    document.getElementById('txtname').value='';
    document.getElementById('txtEmail').value='';
    document.getElementById('txtPhone').value='';
     document.getElementById('txtage').value='';
     document.getElementById('txtcity').value='';
     document.getElementById('txtCountry').value='';
     document.getElementById('txtComments').value='';
  
    return false;
    }
    function IsOK(str,validchars)
    {
    var blnresult=true;
    for(var i=0;i<str.length;i++)
    {
    var st=str.charAt(i);
    if(validchars.indexOf(st)==-1)
    {
    blnresult=false;
    }
    }
    return blnresult;
    }
    
function IsValidEmail(stremail)
{
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
return filter.test(stremail);
}
function Validate()
{
    //-------------------------
    
   if(document.getElementById('txtname').value=='')
    {
    alert('Please Enter Name.');
    document.getElementById('txtname').focus();
    return false;
    }
    if(!IsOK(document.getElementById('txtname').value,".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz "))
    {
    alert('Please Enter Valid Name.');
    document.getElementById('txtname').focus();
    return false; 
    }    
    if(document.getElementById('txtname').value.charAt(0)==' ')
    {
    alert('Please Enter Name.');
    document.getElementById('txtname').focus();
    return false; 
    }  
   if(document.getElementById('txtEmail').value=='')
    {
    alert('Please Enter Email ID');
    document.getElementById('txtEmail').focus();
    return false;
    } 
    if(!IsValidEmail(document.getElementById('txtEmail').value))
    {
    alert('Please Enter Valid Email ID');
    document.getElementById('txtEmail').focus();
    return false;
    }
     
     if(document.getElementById('txtPhone').value!='')
    {
             if(!IsOK(document.getElementById('txtPhone').value,"+-0123456789 "))
            {
                alert('Please Enter Valid Mobile Number.');
                document.getElementById('txtPhone').focus();
                return false;
            }
            if (document.getElementById('txtPhone').value.length < 10 ||document.getElementById('txtPhone').value.length > 15)
            {		
                alert("Mobile Number should be minimum 10 digits and maximum 15 digits");
                document.getElementById('txtPhone').focus();
                return false;
            }	
    }
    
   if(document.getElementById('txtage').value!='')
    {
        if(document.getElementById('txtage').value>100)
        {
            alert('Please Enter valid Age.');
            document.getElementById('txtage').focus();
            return false;
        }
    }
    //-----------------------
    
      if(document.getElementById('txtcity').value!='')
    {
            if(!IsOK(document.getElementById('txtcity').value,".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz "))
            {
            alert('Please Enter valid City');
            document.getElementById('txtcity').focus();
            return false; 
            }    
            if(document.getElementById('txtcity').value.charAt(0)==' ')
            {
            alert('Please Enter valid City');
            document.getElementById('txtcity').focus();
            return false; 
            } 
    }
      if(document.getElementById('txtCountry').value!='')
    {
         if(!IsOK(document.getElementById('txtCountry').value,".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz "))
            {
            alert('Please Enter valid Country');
            document.getElementById('txtCountry').focus();
            return false; 
            }    
            if(document.getElementById('txtCountry').value.charAt(0)==' ')
            {
            alert('Please Enter valid Country');
            document.getElementById('txtCountry').focus();
            return false; 
            } 
    }
    
    if(document.getElementById('txtComments').value=='')
    {
    alert('Please Enter Comments');
    document.getElementById('txtComments').focus();
    return false;
    }
   
    if(document.getElementById('txtComments').value.charAt(0)==' ')
    {
    alert('Please Enter Comments');
    document.getElementById('txtComments').focus();
    return false; 
    }
 
} 
function textCounter(maxlimit) 
   {
    
   var field=document.getElementById("txtComments");
   //var cntfield=document.getElementById("txtcnt");
  
    if (field.value.length >= maxlimit) {
    field.value = field.value.substring(0, maxlimit);
   alert('Max 500 characters allowed');
    }

}


