﻿/* Email Validation */

function emailCheck(param) 
{
   var len=0;   
   len=param.length;   
   if (param.indexOf("@")<1 || param.indexOf(".")<1 || param.indexOf(".")==(len-1))
   {
	   //alert("Please Enter Valid Email-ID.");
       //return("Please Enter Valid Email-ID.");       
       return false;
   }   
 }

 /* This is a perfunctory test of Decimal Numbers entry validity. */
 
 function decCheck(param) {
  flg=0;
  str="";
  spc=""
  arw="";
  for (var i=0;i<param.length;i++){
   cmp="0123456789."
   tst=param.substring(i,i+1)
   if (cmp.indexOf(tst)<0){
    flg++;
    str+=" "+tst;
    spc+=tst;
    arw+="^";
   }
   else{arw+=" ";}
  }
  if (flg!=0){
   if (spc.indexOf(" ")>-1) {
    str+=" and a space";
    }
   //alert(param+"\r"+arw+"\rEntry must be a number. I found "+flg+" unacceptable: "+str+".");
  //return(param+"\r"+arw+"\rEntry must be a number. I found "+flg+" unacceptable: "+str+".");
  return false;
  }
  
 }
 
 /* This is For Numeric Check. If the entry is not Numeric ,
 it will give the corresponding invalid character position */
 
 var nr=0;
 function numericCheck(param){
  
  flg=0;
  str="";
  spc=""
  arw="";
  for (var i=0;i<param.length;i++){
   cmp="0123456789/  "
   tst=param.substring(i,i+1)
   if (cmp.indexOf(tst)<0){
    flg++;
    str+=" "+tst;
    spc+=tst;
    arw+="^";
   }
   else{arw+=" ";}
  }
  if (flg!=0){
   if (spc.indexOf(" ")>-1) {
    str+=" and a space";
	return true;
    }
	
  //alert(param+"\r"+arw+"\rEntry must be a number. I found "+flg+" unacceptable: "+str+".");
  //return(param+"\r"+arw+"\rEntry must be a number. I found "+flg+" unacceptable: "+str+".");
  else
  return false;
  }
 }
 
 
 
 /* If the entry is missed */

 function noEntry(param)
 {
  for(i=0;i<param.length;i++)
   {
	 if (param.substring(i,i+1) != " ")
	 {
		 break ;
	 }
   }
   if (i == param.length)
		return(true)   
   else
		return(InvalidText(param))
 }
 
 /*Entry should be Valid text(for login verification).Invalid Characters(< > ; ')won't be allowed.*/
 function InvalidLogin(param){
  flg=0;
  str="";
  spc=""
  arw="";
  for (var i=0;i<param.length;i++){
   cmp="<>?;'%$#&- "
   tst=param.substring(i,i+1)
   if (cmp.indexOf(tst)>-1){
    flg++;
    str+=" "+tst;
    spc+=tst;
    arw+="^";
   }
   else{arw+=" ";}
  }
  if (flg!=0){
   if (spc.indexOf(" ")>-1) {
    str+=" and a space";
    }
   //alert(param+"\r"+arw+"\rThis entry must be a Valid Login Text. I found "+flg+" unacceptable: "+str+".");
   //return (param+"\r"+arw+"\rThis entry must be a Valid Login Text. I found "+flg+" unacceptable: "+str+".");
   return false;
  }
 }
 /* No negative Numbers will be accepted.*/
 
 function negCheck(param) {
    
    if ( param<0 ){
       //alert("No negative Numbers.");
      // return ("No negative Numbers.");
      return false;
 }
}
 
 /* Entry should be Valid text(for Special Circumstances).Invalid Characters won't be allowed.*/
 function InvalidText(param)
 {
  flg=0;
  str="";
  spc=""
  arw="";
  for (var i=0;i< param.length;i++){
   cmp="<>?;'%$&"
   tst=param.substring(i,i+1)
   if (cmp.indexOf(tst)>-1){
    flg++;
    str+=" "+tst;
    spc+=tst;
    arw+="^";
   }
   else{arw+=" ";}
  }
  if (flg!=0){
   if (spc.indexOf(" ")>-1) {
    str+=" and a space";
    }
   //alert(param+"\r"+arw+"\rThis entry must be a Valid Text. I found "+flg+" unacceptable: "+str+".");
  //return(param+"\r"+arw+"\rThis entry must be a Valid Text. I found "+flg+" unacceptable: "+str+".");
  return false;
  }
 }
 

/* Test for Zero Value.Zero Entry will give the alert. */
 
 function ZeroCheck(param) {
   
    if (parseInt(param)==0) {
      //alert("Enter Non-Zero Value");
     //return ("Enter Non-Zero Value");
     return false;
     }   
 }
 
 /* Testing For No Spaces entered. If it is so, it will be indicated . */
 function noSpaces(param){
  flg=0;
  str="";
  spc=""
  arw="";
  for (var i=0;i<param.length;i++){
   cmp=" "
   tst=param.substring(i,i+1)
   if (cmp.indexOf(tst)>-1){
    flg++;
    str+=" "+tst;
    spc+=tst;
    arw+="^";
   }
   else{arw+=" ";}
  }
  if (flg!=0){
   if (spc.indexOf(" ")>-1) {
    str+=" and a space";
    }
  //alert(param+"\r"+arw+"\rThis entry must not have any spaces. I found "+flg+" space(s).: "+str+".");
  //return(param+"\r"+arw+"\rThis entry must not have any spaces. I found "+flg+" space(s).: "+str+".");
  return false;
  }
 }

/* Testing For Minimum characters Checking. */
 
function minCheck(param) {
   if (param.length<4) {
      //alert("Enter Minimum 4 Characters");
      //return("Enter Minimum 4 Characters");        
      return false;
    }
    
 }
 /* Testing For Minimum characters Checking for login page. */
 function mnCheck(param) {
   if (param.length<2) {
      //alert("Enter Minimum 4 Characters");
      //return("Enter Minimum 4 Characters");        
      return false;
    }
    
 }

/* For Giving alert thru the function. */

function alertmsg(msg) {
    alert(msg);
}

/* For checking Password and Confirm Password */

function passCheck(param1,param2) {
   if(param1!=param2) {
      return true; }
}

function trimJS(value) {
       var param=value;
       var len=0;
       len=param.length;
       for (var i=0;i<len;i++)
       {
       if (param.charAt(i)!=" ")
         {
           param=param.substring(i,len);
           break;
         }        
       }
       len=param.length;
       for (i=len-1;i>0;i--)
       {
       if (param.charAt(i)!=" ")
         {
           param=param.substring(0,i+1);
           break;
         }        
       }
       return param;
       }

//To Check valid DOB
function funValidDob(DOB)
{  
    if(DOB!='')
    {
        var getDt=DOB;
        getDt = getDt.split('/')
        if(getDt.length<3)
            return false;
        var GetDy=getDt[0];
        var GetMth=getDt[1];
        var GetYr = getDt[2];
        if(GetYr.length<4 || GetDy.length<1 || GetMth.length<1)
            return false;
        var dt= new Date();
        var CurrDy=dt.getDate();
        var CurrMth =dt.getMonth();
        CurrMth=CurrMth+1;
        var CurrYr = dt.getFullYear();
        if (GetMth > 12) return false;
        else if (GetDy > 31) return false;
        else if (CurrYr > GetYr) return true;
        else if (CurrYr < GetYr) return false;
        else if (CurrMth > GetMth) return true;
        else if (CurrMth < GetMth) return false;    
        else if (CurrDy > GetDy) return true;
        else if (CurrDy < GetDy) return false;
        else return true;
    }
    else if(DOB=='')
        return false;
}

function funValidCurrDate(DOB)
{  
    if(DOB!='')
    {
        var getDt=DOB;
        getDt = getDt.split('/')
        if(getDt.length<3)
            return false;
        var GetDy=getDt[0];
        var GetMth=getDt[1];
        var GetYr = getDt[2];        
        var dt= new Date();
        var CurrDy=dt.getDate();
        var CurrMth =dt.getMonth();
        CurrMth=CurrMth+1;
        var CurrYr = dt.getFullYear();
        if(GetYr.length<4 || GetDy.length<1 || GetMth.length<1 || GetYr < CurrYr)
            return false;
        if (GetMth > 12) return false;
        else if (GetDy > 31) return false;
        else if (CurrYr > GetYr) return true;
        else if (CurrYr < GetYr) return false;
        else if (CurrMth > GetMth) return true;
        else if (CurrMth < GetMth) return false;    
        else if (CurrDy > GetDy) return true;
        else if (CurrDy < GetDy) return false;
        else return true;
    }
    else if(DOB=='')
        return false;
}
