
function isEmpty(s)
    {  return ((s == null) || (s.length == 0))
    }

function keyPressDateNew(mfield)
{
   keyvalue=event.keyCode; 
   var txtLength =eval(mfield+".value.length");
   var txtValue =eval(mfield+".value");
   if(keyvalue <48  || keyvalue >58 || txtLength >= 10)   
   {      event.returnValue = false;   }   if((txtLength==2)||(txtLength==5))  {
   eval(mfield+".value +='/'");   }
   return true
 }



function dateFormatC(FieldName)
{

	 dateVal = FieldName+".value"
     l_focus	= FieldName+".focus()"
     l_select= FieldName+".select()"
     mdateVal = ""
	 str = ""
		 
	 if(eval(dateVal) != "")
     {
		l_yy=eval(dateVal).substr(6,4)
		l_mm=eval(dateVal).substr(3,2)
		l_dd=eval(dateVal).substr(0,2)
		str =l_mm+"/"+l_dd+"/"+l_yy   ;
		eval(FieldName).value = str
	 }
}



function chk_Emptystr(mfield,namevar)
  {
					l_value=eval(mfield+".value")
					l_value=trim(l_value,"both") 
					l_focus=eval(mfield+".focus()")
					
					newstr = new String(l_value)
					  if(newstr=="")
						{
							alert("Enter value for "+namevar);
							eval(l_focus);
							return false;
						}
					
					
					return true;

  }	


function isValidDateNew(FieldName) 
{
     dateVal = FieldName+".value"
     l_focus	= FieldName+".focus()"
     l_select= FieldName+".select()"
     mdateVal = ""
     if(eval(dateVal) != "")
     {
	     if((eval(dateVal+".length")<10)||(eval(dateVal+".length")>10))
	     {
		  alert("Date is not in the valid format, Please enter the date in DD/MM/YYYY format");
		  eval(l_focus);
		  eval(l_select);
		  return false;
	     }
	     str = eval(dateVal)
	     l_yy=str.substr(6,4)
		 l_mm=str.substr(3,2)
		 l_dd=str.substr(0,2)
		 str=l_mm+"/"+l_dd+"/"+l_yy        
	     dateVal = str
	     mdateVal = dateVal
     }
     
     if(mdateVal!="")
     {
        var datePattern = /^(\d{1,2})(\d{1,2})\2(\d{4})$/;
        var matches = mdateVal.match(datePattern);
        if (matches == null)
        {
           // for 2 digit years
           datePattern = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
           matches = mdateVal.match(datePattern);
         
           if (matches == null)
		   {
			alert("Date is not in the valid format, Please enter the date in DD/MM/YYYY format");
				eval(l_focus)  
				eval(l_select)
                return false
		   }
        }
        month = matches[1];
        day = matches[3];
        year = matches[4];
        if (month < 1 || month > 12)
        {
                alert("Month must be between 1 and 12.");
            	eval(l_focus)  
				eval(l_select)
                return false;
        }
		if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
        {
               if (( day > 31)||(day < 1))
               {
                  alert("Day must be between 1 and 31");
		   		  eval(l_focus)  
				  eval(l_select)
                  return false;
               }  
        }
        if ( month == 4 || month == 6 || month == 9 || month == 11)
        {
               if (( day > 30)||(day < 1))
               {
                  alert("Day must be between 1 and 30");
				  eval(l_focus)  
				  eval(l_select)
				  return false;
               }  
        }
        if (month==2)
        {
          if (((year%400)==0)||(((year%4)==0)&&((year%100)!=0)))
          {
            if((day > 29) ||(day < 1))
            {
                alert("Day must be between 1 and 29");
				eval(l_focus)  
				eval(l_select)
                return false;
             
            }
          }
          else
          {
            if(day > 28)
            {
                  alert("Day must be between 1 and 28");
				  eval(l_focus)  
				  eval(l_select)
				  return false;
            }
          
          }
        } 
        return true;
     } 
  }

function checkDate(dd,mm,yy,val,field)
{

	var sysDate = new Date() ;
	var sYear=sysDate.getFullYear();
	var sDate=sysDate.getDate();
	var sMonth=sysDate.getMonth();
	if(mm.length == 1)
		var passDate = '0'+mm+'/'+dd+'/'+yy;
	else
		var passDate = mm+'/'+dd+'/'+yy;
	
	var theDate = new Date(sYear,sMonth+1,sDate) ;  // current date
	var todate=new Date(yy,mm,dd);  // passed date

	todate = Date.parse(todate);  
	theDate = Date.parse(theDate);

	 l_focusD = field+".focus()"
    

	if(isValidDate(field,passDate) == false)
	{
		return false;
	}
	else if(theDate > todate)
	{
		alert("" + val + "Date should be more than or equal to Current Date..");
		eval(l_focusD)
		return false;
	}
	else
	{
		return true;
	}
}


function MaxLimitTextArea(field, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
  field.value = field.value.substring(0, maxlimit);
}

function checkSelect(lfield,namevar)
	{
		
	l_index = eval(lfield+".options["+lfield+".selectedIndex].value");
	l_focus= eval(lfield+".focus()");
	if(l_index=="")
	{
		alert("Select Value for "+namevar  );
		eval(l_focus);
		return false;
	}			
	return true;
	}
		
	
function keyCheck(mfield)
		{
			
		   keyvalue=event.keyCode;

			var txtLength =eval(mfield+".value.length");
			var txtValue =eval(mfield+".value");
		   
		  	    
		   if (keyvalue <48  || keyvalue >58)
		   {
		      event.returnValue = false;
		   }
}	



function onlyNumbers()
{

   if (keyvalue <48  || keyvalue >58)
      event.returnValue = false;
		   
}

function NoRightClick(b) 
{
	var message = "You cannot use right-click.";
   if(((navigator.appName=="Microsoft Internet Explorer")&&(event.button > 1)) ||((navigator.appName=="Netscape")&&(b.which > 1)))
   {
   alert(message);
   return false;
   }
document.onmousedown = NoRightClick;   
}


function popupmenu(choice,wt,ht)
{
ltt= (700-wt)/2;
var winOpts="toolbars=no,scrollbars=yes,maximize=no,resize=no,width="+500+",height="+300+",location=no,directories=no,left="+0+",top=5";
confirmWin=window.open(choice,'theconfirmWin',winOpts);
}


function fnLogout(fname)
{
	if (confirm('Are you sure You want to Logout from the System ?')==true)
		{
		location.href=fname;
		return false;
		}
}


function fnCheckDigits(arg)
{
		arglen = arg.length;
		i = 0;
		digits= 0;
		while (i < arglen)
			{
			if (!isNaN(arg.charAt(i)))
				digits=digits+1;	 
			i++;
			}
		if (digits<2)
			return false;
		else
			return true;
}

	
// function for the validation of Phone ,Fax & Mobile.	
function checkPhoMobFax(mfield,namevar)
  {
  	keyvalue=event.keyCode;
    l_value=eval(mfield+".value")
    l_focus=eval(mfield+".focus()")

	if (keyvalue <45  || keyvalue >58  || keyvalue==46 || keyvalue==47 ||  keyvalue==58)
		{
			event.returnValue = false;
		}
				
	if (keyvalue == 188 ||keyvalue == 187 || keyvalue == 189 || keyvalue == 8 || keyvalue==43 || keyvalue==44)
		{
			event.returnValue = true;
		}
  }
function isValid(pattern, str) {
	return pattern.test(str)
}

function setSelected(mfield)
  {
  	    l_value=eval(mfield+".value")
        newstr= new String(l_value)
        l_focus=eval(mfield+".focus()")
        l_focus;
  }	

function CheckEmail(f_Field) {
        emailStr= eval(f_Field+".value")
	l_select=f_Field+".select()"
	l_focus=f_Field+".focus()"
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Please enter the correct email")
		eval(l_select)
		eval(l_focus)
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
		alert("Please enter the correct email")
		eval(l_select)
		eval(l_focus)
		return false

	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
		alert("Please enter the correct email")
		eval(l_select)
		eval(l_focus)
		return false

			}
		}
		return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("Please enter the correct email")
		eval(l_select)
		eval(l_focus)
		return false

	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
		alert("Please enter the correct email")
		eval(l_select)
		eval(l_focus)
		return false

	}

	if (len<2) {
		alert("Please enter the correct email")
		eval(l_select)
		eval(l_focus)
		return false
	
	}

	return true;
}

 function chk_list_selected(lfield,namevar)
	{
	
		l_index = eval(lfield+".selectedIndex")
		l_value = eval(lfield+".value")
		l_focus= eval(lfield+".focus()")

		if(l_index == 0 && l_value == "" || l_index < 0  && l_value == "" )
		{
			alert("Select value for "+namevar  );
			eval(l_focus);
			return false;
		}			
		return true;
	} 

/*To check empty field as no trim function available*/
function trim(arg,func) 
{

	var trimvalue = "";
	arglen = arg.length;
	if (arglen < 1) return trimvalue;

	if (func == "left" || func== "both")
	 {
			i = 0;
			pos = -1;
			while (i < arglen) {
			if (arg.charCodeAt(i) != 32 && !isNaN(arg.charCodeAt(i))) {
			pos = i;
			break;
			}
			i++;
			}
	 }

	if (func == "right" || func== "both")
	 {
		var lastpos = -1;
		i = arglen;
		while (i >= 0) {
		if (arg.charCodeAt(i) != 32 && !isNaN(arg.charCodeAt(i))) {
		lastpos = i;
		break;
		}
		i--;
		}
	}

	if (func == "left") 
	{
		trimvalue = arg.substring(pos,arglen-1);
	}

	if (func == "right") 
	{
	trimvalue = arg.substring(0,lastpos+1);
	}

	if (func == "both")
	{
	trimvalue = arg.substring(pos,lastpos + 1);
	}
return trimvalue;
}


function checkSelected(lfield,namevar)
	{
		
		l_disabled= eval(lfield+".disabled")
		

		if(l_disabled==false)
		{
			l_index = eval(lfield+".options["+lfield+".selectedIndex].value")
			l_focus= eval(lfield+".focus()")
		
			if(l_index=="")
			{
				alert("Select Value for "+namevar  );
				eval(l_focus);
				return false;
			}			
				return true;
		}
		
	} 
	



function fnOnlyNumbers(mfield,mxLength,dot)
		{
			
			keyvalue=event.keyCode;
			//alert(keyvalue);
			
			var txtLength =eval(mfield+".value.length");
			var txtValue =eval(mfield+".value");
			
			if (dot=='Y')
				{
					if (keyvalue <45  || keyvalue >58 ||  keyvalue ==58)
						{
							event.returnValue = false;
						}
					
					if (keyvalue == 45  || keyvalue == 47)
						{
							event.returnValue = false;
						}
					
				    
					
					if (txtLength == mxLength && keyvalue!=46 && txtValue.indexOf(".") == -1)
						{
							event.returnValue = false;
						}
							
					if (keyvalue==46)  
						{
							if (txtValue.indexOf(".") != -1)
								{
									event.returnValue = false;
								}
						}
					
					if (txtValue.indexOf(".") != -1)
						{
							var nextlength=txtValue.substr(txtValue.indexOf(".")+1,4).length;
						}
      
					if (nextlength==2)
						{
							event.returnValue = false;
						}
					
				}
				
			if (dot=='N')
				{
					if (keyvalue <45  || keyvalue >58)
						{
							event.returnValue = false;
						}
					
					if (keyvalue == 45  || keyvalue == 47 || keyvalue == 46)
						{
							event.returnValue = false;
						}
						
					if (mxLength!='')
						{
							if (txtLength == mxLength)
								{
									event.returnValue = false;
								}
						}	
					
				}	
		}
	
function keyPressDate(mfield)
		{
			
		   keyvalue=event.keyCode;

			var txtLength =eval(mfield+".value.length");
			var txtValue =eval(mfield+".value");
		   
		  	    
		   if (keyvalue <48  || keyvalue >58)
		   {
		      event.returnValue = false;
		    
		   }
		   if (txtLength==2)
		   {
		     eval(mfield+".value +='/'");
		       
		   }
		   //if (txtLength==5)
		   //{
		   //  eval(mfield+".value +='/';")
		       
		   //}
		}
		
		
		


		

function isValidDate(FieldName,value) 
{
     dateVal = value


     l_focusD = FieldName+".focus()"
    

     mdateVal = dateVal
     
     if(mdateVal!="")
     {
        var datePattern = /^(\d{1,2})(\d{1,2})\2(\d{4})$/;
        var matches = mdateVal.match(datePattern);
        if (matches == null)
        {
           // for 2 digit years
           datePattern = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
           matches = mdateVal.match(datePattern);
         
           if (matches == null)
		   {
			alert("Date is not in the valid format, Please enter the date in DD/MM/YYYY format");
				eval(l_focusD)  
				//eval(l_select)
                return false
		   }
        }
        month = matches[1];
        day = matches[3];
        year = matches[4];

	
	if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
        {
               if (( day > 31)||(day < 1))
               {
                  alert("Day must be between 1 and 31");
		   		  eval(l_focusD)  
				  //eval(l_select)
                  return false;
               }  
        }
        if ( month == 4 || month == 6 || month == 9 || month == 11)
        {
               if (( day > 30)||(day < 1))
               {
                  alert("Day must be between 1 and 30");
				  eval(l_focusD)  
				  //eval(l_select)
				  return false;
               }  
        }
        if (month==2)
        {
	
          if (((year%400)==0)||(((year%4)==0)&&((year%100)!=0)))
          {
            if((day > 29) ||(day < 1))
            {
                alert("Day must be between 1 and 29");
				eval(l_focusD)  
				//eval(l_select)
                return false;
             
            }
          }
          else
          {
            if(day > 28)
            {
                  alert("Day must be between 1 and 28");
				  eval(l_focusD)  
				  //eval(l_select)
				  return false;
            }
          
          }
        } 
        return true;
     } 
  }
