﻿


var whitespace = " \t\n\r";



 function TextChk(val,txt)
  {
         var Target=trimAll(document.getElementById(val).value);   
        if(Target=='')
        {
             alert('Enter '+txt);
             document.getElementById(val).focus();             
             return false;
        }
        
        return true;
  }
  
  
  function CheckBoxChk(val,txt)
  {
        if(document.getElementById(val).checked == false)  
        {
             alert(txt);
             return false;
        }
        return true;
  }
  
  
  function IsEmpty(val,txt)
  {
        var Target=trimAll(document.getElementById(val).value);   
        if(Target=='')
        {
             alert(txt);
             document.getElementById(val).focus();
             return false;
        }
        
        return true;
  }
  
  
   function TextChk1(val,txt)
  {
         var Target=trimAll(document.getElementById(val).value);   
        if(Target=='')
        {
             document.getElementById(val).focus();
             alert(txt);
             return false;
        }
        
        return true;
  }
  
   function TextChk2(val,txt,val2)
  {
         var Target=trimAll(document.getElementById(val).value);   
        if(Target=='')
        {
             document.getElementById(val2).focus();
             alert(txt);
             return false;
        }
        
        return true;
  }   
        
function trimAll(str) 
{
    return str.replace(/^\s*|\s*$/g,'');
}        

function checkEmail (val,txt)
{   
    if(document.getElementById(val).value=='')
    {
     return true;
    }
   
    var s = document.getElementById(val);
   
    if(isEmail(s,s.value)==false)
    {
        alert(txt);
     
     return false;
    }
    return true;
}


function checkValidEmail(val)
{
    inputvalue = document.getElementById(val).value
    //var pattern=/^[a-z|0-9][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z][a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$/;
    var pattern = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (trimAll(inputvalue) != '') 
    {
        if (pattern.test(inputvalue))
         {
            return true
        }
        else 
        {

            alert('Enter a Valid Email Address')
            document.getElementById(val).focus();
            return false
        }
    }
    else     
    {
        return true;
    }
}


function isEmail(t,s)
{
 
    var i = 1;
    var sLength = s.length;
    

// is s whitespace?
    if (isWhitespace(s))
    {
      t.focus();  
      return false;
     }
     
     
     
     //look for whitespace
    while ((i < sLength))
    { 
      if(isWhitespace(s.charAt(i)))
      {
          t.focus();  
          return false;
      }
      i++      
    }
    i = 1;
    
        //look for whitespace
    while ((i < sLength))
    { 
      if(isSplChar(s.charAt(i)))
      {
          t.focus();  
          return false;
      }
      i++      
    }
    
    
     i = 1;
    
     
    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { 
      i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) 
    {
      t.focus();  
      return false;
     }
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != "."))
    {
      t.focus();  
      return false;
     }
    else return true;
}


function CheckDot(id,msg)
{
    val=document.getElementById(id).value;
    if (val.indexOf('.') > -1)
    {
        alert('Enter Numbers only in '+msg)
        document.getElementById(id).focus()
        return false;
    }
    else
    {
        return true;
    }
}


function onlyNumbers(event,val)
{
    var e = event || evt; // for trans-browser compatibility
	var charCode = e.which || e.keyCode;
	if (charCode == 37 || charCode == 39 || charCode == 46)
	{
	    return true
	}
	if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode!=37 || charCode!=39))
	{
	    alert('Enter Numbers')
		return false
	}
    else
    {
        return true;
     }
}

function isNumeric(x) {
// I use this function like this: if (isNumeric(myVar)) { }
// regular expression that validates a value is numeric
var RegExp = /^(-)?(\d*)(\.?)(\d*)$/; // Note: this WILL allow a number that ends in a decimal: -452.
// compare the argument to the RegEx
// the 'match' function returns 0 if the value didn't match
var result = x.match(RegExp);
return result;
}

function onlyDecimals(event,txt)
{
    var e = event || evt; // for trans-browser compatibility
	var charCode = e.which || e.keyCode;	
	var Dot=document.getElementById(txt.id).value.indexOf('.');
	if(Dot>-1 && charCode == 46)
	{
	    return false
	}
	if (charCode == 37 || charCode == 39)
	{
	    return true
	}
	//alert(dot)
if (charCode != 46)
{
	if (charCode > 31 && (charCode < 48 || charCode > 57))
	{
	    alert('Enter Numbers');
		return false;
	}
    else
    {
        return true;
     }
}
}


function isWhitespace (s)

{  

 
 var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);       
        if (whitespace.indexOf(c) == -1)        
        return false;
    }

    // All characters are whitespace.
    return true;
}


function isSplChar(str)
{		
    var spchar;		
    spchar="`()(\\~!^&*+\"|%:=,<>";	
    for(var j=0; j<	spchar.length-1;j++)	
    {						
        if(str== spchar.charAt(j))			
        {							
            return true;		
        }	     		
    }	
    
    if(str=="'")
    {
       return true;	
    }
   
   return false;        
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}


 function DropDownChk(val,txt)
    {      
        if(document.getElementById(val).value=='0')
        {
            alert("Select " + txt);
            document.getElementById(val).focus()
            return false;
        }
        else
        {  
          return true;        
        }
    }
    
 
 function IsDropDownEmpty(val,txt)
    {
   
        if(document.getElementById(val).value==0)
        {
            alert(txt);
            document.getElementById(val).focus()
            return false;
        }
        
        return true;
    }
    
    
    
  function IsDateCheck(val)
{
    var ctlValue=document.getElementById(val).value;
    if (ctlValue !='')
    {   
      
        if (isDate(ctlValue)== false)
        {
            
            document.getElementById(val).focus()
            return false;   
                   
        }
       return true;
   }
   else
   {
    return true;
   }
   
 }
 
 
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
function isDate(dtStr)
{
        if(dtStr == '')
          return true
        var daysInMonth = DaysArray(12)
        var pos1=dtStr.indexOf(dtCh)
        var pos2=dtStr.indexOf(dtCh,pos1+1)
        var strMonth=dtStr.substring(0,pos1)
        var strDay=dtStr.substring(pos1+1,pos2)
        var strYear=dtStr.substring(pos2+1)
        strYr=strYear
        if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
        if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
        for (var i = 1; i <= 3; i++) {
            if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
        }
        month=parseInt(strMonth)
        day=parseInt(strDay)
        year=parseInt(strYr)
        if (pos1==-1 || pos2==-1){
            alert("Date of Birth Must Be In MM/DD/YYYY Format")
            return false
        }
        if (strMonth.length<1 || month<1 || month>12){
            alert("Please enter a valid month")
            return false
        }
        if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
            alert("Please enter a valid day")
            return false
        }
        if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
            alert("Please enter a valid 4 digit year")
            return false
        }
        if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
            alert("Please enter a valid date")
            return false
        }
    return true
}


  
  function IsDateCheck1(val,txt)
{
    var ctlValue=document.getElementById(val).value;
    if (ctlValue !='')
    {   
      
        if (isDate1(ctlValue,txt)== false)
        {
            
            document.getElementById(val).focus()
            return false;   
                   
        }
       return true;
   }
   else
   {
    return true;
   }
   
 }
 
 
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
function isDate1(dtStr,txt)
{
        if(dtStr == '')
          return true
        var daysInMonth = DaysArray(12)
        var pos1=dtStr.indexOf(dtCh)
        var pos2=dtStr.indexOf(dtCh,pos1+1)
        var strMonth=dtStr.substring(0,pos1)
        var strDay=dtStr.substring(pos1+1,pos2)
        var strYear=dtStr.substring(pos2+1)
        strYr=strYear
        if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
        if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
        for (var i = 1; i <= 3; i++) {
            if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
        }
        month=parseInt(strMonth)
        day=parseInt(strDay)
        year=parseInt(strYr)
        if (pos1==-1 || pos2==-1){
            alert(txt + " Must Be In MM/DD/YYYY Format")
            return false
        }
        if (strMonth.length<1 || month<1 || month>12){
            alert(txt + " Must Be In MM/DD/YYYY Format")
            return false
        }
        if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
            alert(txt + " Must Be In MM/DD/YYYY Format")
            return false
        }
        if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
            alert(txt + " Must Be In MM/DD/YYYY Format")
            return false
        }
        if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
            alert(txt + " Must Be In MM/DD/YYYY Format")
            return false
        }
    return true
}


 function stripCharsInBag(s, bag){
	            var i;
                var returnString = "";
                // Search through string's characters one by one.
                // If character is not in bag, append to returnString.
                for (i = 0; i < s.length; i++){   
                    var c = s.charAt(i);
                    if (bag.indexOf(c) == -1) returnString += c;
                }
                return returnString;
            }
  function isInteger(s){
	            var i;
                for (i = 0; i < s.length; i++){   
                    // Check that current character is number.
                    var c = s.charAt(i);
                    if (((c < "0") || (c > "9"))) return false;
                }
                // All characters are numbers.
                return true;
            }
            
 function daysInFebruary (year)
 {
        // February has 29 days in any year evenly divisible by four,
        // EXCEPT for centurial years which are not also divisible by 400.
        return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
    }
    function DaysArray(n) {
        for (var i = 1; i <= n; i++) {
            this[i] = 31
            if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
            if (i==2) {this[i] = 29}
       } 
       return this
    }


function onlyNumbersyear(event,val)
{
	var e = event || evt; // for trans-browser compatibility
	var charCode = e.which || e.keyCode;
	if (charCode == 37 || charCode == 39 || charCode == 46)
	{
	    return true
	}
	if (charCode > 31 && (charCode < 48 || charCode > 57))
	{
	    alert('Years Divorced Must Be a Number');
	    document.getElementById(val).focus()
		return false;
	}
    else
    {
        return true;
     }
}


function echeck(str,txt,h,m) 
{     
     if(emailchecking(str,txt)==false)
     {
            if(document.getElementById(h).value=='')
            {
                document.getElementById(h).value=str;
                document.getElementById(m).innerHTML  ="Invalid " + txt 
            }                
      } 
      
    var s = document.getElementById(str);
    if(isEmail(s,s.value)==false)
    {
     //alert("Please enter valid " + txt)
     //document.getElementById(val).focus();  
         if(document.getElementById(h).value=='')
            {
                document.getElementById(h).value=str;
                document.getElementById(m).innerHTML  ="Invalid " + txt 
            }    
     
     return false;
    }
    
    
    return true;
}



function checkpassword(val,txt)
{
var ctlValue=document.getElementById(val).value;
var sLength = ctlValue.length;
var lower   = "abcdefghijklmnopqrstuvwxyz";
var upper   = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var numbers = "0123456789";

var i;
var fchar=0,fnum=0;
if(sLength >= 7)
{

    for (i = 0; i < ctlValue.length; i++)
    {        
        var c = ctlValue.charAt(i);       
        
        if(lower.indexOf( c)   > -1 || upper.indexOf(c)   > -1)
        {
            fchar =1
        }
       
        if(numbers.indexOf( c)   > -1)
        {
            fnum =1
        }
        
    }
}

if (fchar ==0 || fnum ==0)           
{     
    alert('Password Must Be At Least 7 Characters and Have At Least 1 Number and 1 Letter');
    document.getElementById(val).focus();
    return false;
}
else 
{
    return true;
}

}
//Added By Suresh.G//

 function CheckLength(val,Msg,Length)
  {
     var digits=document.getElementById(val).value.length;
    if (digits!=Length)
      {
         alert(Msg);
         document.getElementById(val).focus();
         return false;
      }
     return true;
  }
  

//Added by Suresh.G//
function OpenPopUp(url,header,width,height,Scroll)
    {
        sBrowser=navigator.userAgent;
        if (window.showModalDialog)
        {
            if (sBrowser.toLowerCase().indexOf('msie') > 0)
            {
                window.showModalDialog(url,header,'Width='+width+';Height='+height+';scroll='+Scroll+';status=no;resizable=1;maximize=yes;minimize=yes;');return false;
            }
            else if (sBrowser.toLowerCase().indexOf('firefox') > 0)
            {
                window.showModalDialog(url,header,'dialogWidth='+width+';dialogHeight='+height+';scrollbars=no;status=no;');return false;
            }
            else if (sBrowser.toLowerCase().indexOf('safari') > 0)
            {
                window.open(url,header,'dialogWidth='+width+';dialogHeight='+height+';scroll=no;status=no;');return false;
            }
        }
        else
        {
            window.open(url,header,'dialogWidth='+width+';dialogHeight='+height+';scrollbars=yes;status=yes;');return false;
        }
    }

function onlyNumeric(event,txt)
{
    var e = event || evt; // for trans-browser compatibility
	var charCode = e.which || e.keyCode;
	if (charCode == 37 || charCode == 39 || charCode == 46)
	{
	    return true
	}
	if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode!=37 || charCode!=39))
	{
	    alert(txt)
		return false
	}
    else
    {
        return true;
     }
}
    
function ValidateDate(CtrlSDate,CtrlEDate)
    {
    var SDate = document.getElementById(CtrlSDate).value;    	
    var EDate =  document.getElementById(CtrlEDate).value;
       
          
    var alertReason1 =  'From Date can not be after To Date.' 
    var alertReason2 =  'End Date can not be less than Current Date.';
	
    var endDate = new Date(EDate);    	
    var startDate= new Date(SDate);
     
    if(SDate != '' && EDate != '' && startDate > endDate)
    {
	    alert(alertReason1);
	    document.getElementById(CtrlEDate).value = "";
        document.getElementById(CtrlEDate).focus();	    
	    return false;
    }
    else if(SDate == '')	
    {
        alert("Please enter Start Date");
        document.getElementById(CtrlSDate).focus();	
        return false;
    }
    else if(EDate == '')	
    {
        alert("Please enter End Date");
        document.getElementById(CtrlEDate).focus();	
        return false;
    }	    
    else
        return true;
}

//Make radio button list readonly
function MakeRadioButtonListReadOnly(RB,Index) 
{
  var list = document.getElementById(RB);
  var options = list.getElementsByTagName('input');
  options[Index].checked=true;
  return false;
}
//Compare Password
function ComparePassword(val1, val2, txt) {

    var Pass = document.getElementById(val1);
    var VerifyPass = document.getElementById(val2);
    if (Pass.value == VerifyPass.value) 
    {

        return true;
    }
    else
    {
        alert(txt);
        return false;
    }
}