//   function isPhone(s,message,n,f)               only digits commas forward and spaces are allowed. 
//   function isdigits(s,message,n,f)              only digits and spaces are allowed. 
//   function isName(s,message,n,f)                only character and spaces are allowed. 
//   function isAllSpaces(s,message)
//   function isAddress(s,message,f)               apostrophes (') and double quotes (\") are not allowed
//   function isCity(s,message,n,f)					atleast 3 characters + isName
//   function isLetters(s,message,n,f)              only accept the a-z and A-Z
//   function isZip(s,message,n,f)
//   function isNumericDigit(c)                     only accepts digits
//   function IsLettersNumber(c)                    this function only check character is number or letter
//   function isSpecialChar(s,message1)             to find the special characters including blank spaces
//   function isAllZeros(s,message)
//   function isLetterDigitSpace(s,message,n,f)		only characters , digits , braces ,dots and space are allowed.
//	 function trim(text)							trim leading and trailing spaces
//   function isEmail(s,message)	
//   function isNumberDecimal(s,message,n,f)	
//   function isDecimal(c)			   
//-----------------------------------------------------------------//

function isName(s,message,n,f)
{
 	s1=s.value
 	tt=s.value.length
	f=f*1
	if (f)
	{
		if (isBlank(s,message))
		{
			s.focus();
			s.select();
			return false;
		}
	}
	for (i = 0; i < tt; i++)
	{   
	    var c = s1.charAt(i);
	    if (!( (c == " ") || ((c >= "A") && (c <= "Z")) || ((c >= "a") && (c <= "z")) ))
		{
			alert("Invalid entry, only characters are allowed.\nPlease re-enter");
			s.focus();
   			s.select();
			return false;
		} 
	}
	return true;
}

function isAllSpaces(s,message)
{
	count=0
	slen=s.value.length
	for(i=0;i<=slen-1;i++)
	{
		if (s.value.charAt(i)==" ")
	    { 
			count=count+1
	    }
	}
	if (count!=slen)
	{
		return false
	}
	else 
	{
		alert(message);
		s.focus();
		s.select();
		return true;	    
    }
   return false;	    
}

//apostrophes (') and double quotes (\") are not allowed
function isAddress(s,message,f)
{
    s1=s.value
    tt=s.value.length
	f=f*1
   if (f)
    {
	  if (isBlank(s,message))
      {
		s.focus();
		s.select();
		return false;
	  }
    }
      for (i = 0; i < tt; i++)
	   {
	    var c = s1.charAt(i);
	    if ( (c == "'" || c == "\"" ) )
	     {
		  alert("Invalid entry,  apostrophes (') and double quotes (\") are not allowed.\nPlease re-enter");
          s.focus();
   		  s.select();
		  return false;
	     } 
  	   }
  
	return true;
}



function isCity(s,message,n,f)
{
	f=f*1
	if((f==1)&&(s.value.length < 3))
	{
		alert("Please enter the City name.")
		s.focus();
		s.select();
		return false;
	}
	return isName(s,message,n,f);
}


function isState(s,message,n,f)
{
	f=f*1
	if((f==1)&&(s.value.length < 3))
	{
		alert("Please enter the State name.")
		s.focus();
		s.select();
		return false;
	}
	return isName(s,message,n,f);
}

//only characters and spaces are allowed
function isLetters(s,message,n,f)
{ 
   f=f*1
	if (f)
	{
	  if (isBlank(s,message))
	  {
		s.focus();
		s.select();
		return false;
	  }
    }

	s1=s.value
    tt=s.value.length
    if (tt>0)
    {
	  for (i = 0; i < tt; i++)
	   {   
	    var c = s1.charAt(i);
	    if (!(  ((c >= "A") && (c <= "Z")) || ((c >= "a") && (c <= "z")) || (c == " ") ))
	     {
		  alert("Invalid entry, only alphabets are allowed.\nPlease re-enter");
          s.focus();
   		  s.select();
		  return false;
	     } 
  	  }
    }
    return true

}


function isZip(s,message,n,f)
{
	f=f*1
	if (f)
	{
		if (isBlank(s,message))
		{
			s.focus();
			return false;
		}
	}
	if(s.value!="")
   	{
		retVal=isAllZeros(s,"Zip code cannot be all zeros")
		if (retVal==true)
		{
			s.focus();
			return false;
		}	
	}
	s1=s.value
	tt=s.value.length
	if (tt>0)
	{
		if (isBlank(s,message))
		{
			s.focus();
			s.select();
			return false;
		}
		for (i = 0; i < tt; i++)
		{   
			// Check that current character is number.
			// only accept digits else alert i.e error
			var c = s1.charAt(i);
			if (!((c >= "0") && (c <= "9")))
			{
				alert("Invalid entry, only digits are allowed.\nPlease re-enter");
				s.focus();
   				s.select();
				return false;
			} 
  		}
	}
	return true;
}


function isNumericDigit(c)
{
    if (c>="0" && c<="9")
     {
       return true;     
	 }
   return false;
}


//only accepts character and number
function IsLettersNumber(c)
{
    if ((c>="0" && c<="9" ) || (c>="a" && c<="z")  || ( c>="A" && c<="Z" ) )
     {
       return true     
	 }

   return false
}


function isSpecialChar(s,message1)
{
      s1=s.value
      tt=s.value.length
      for (i = 0; i < tt; i++)
	   {
	    var c = s1.charAt(i);
	    if (!( ((c >= "0") && (c <= "9")) || ((c >= "A") && (c <= "Z")) || ((c >= "a") && (c <= "z"))  ))
	     {
          alert(message1);
          s.focus();
   		  s.select();
		  return false;
	     } 
  	   }
return true
}



function isAllZeros(s,message)
{
	count=0
    slen=s.value.length
	for(i=0;i<=slen-1;i++)
	{
		if (s.value.charAt(i)=="0")
	    { 
			count=count+1
	    }
	}
	if (count!=slen)
	{
		return false
	}
	else 
	{
		alert(message);
	    s.focus();
  	    s.select();
 	    return true;	    
	}
    return false;	    
}



//only characters, digits, braces and dots are allowed.
function isLetterDigitSpace(s,message,n,f)
{

 	 s1=s.value
     tt=s.value.length
     f=f*1
	if (f)
	{
		if (isBlank(s,message))
		{
			s.focus();
			s.select();
			return false;
		}
	}
     for (i = 0; i < tt; i++)
	   {   
	    var c = s1.charAt(i);
	    if (!( (c == " ") || ((c >= "A") && (c <= "Z")) || ((c >= "a") && (c <= "z")) || ((c >= 0) && (c <= 9)) || (c == ".") || (c == "(") || (c == ")")   ))
	     {
		  alert("Invalid entry, only alphabets, digits, braces and dots are allowed.\nPlease re-enter");
          s.focus();
   		  s.select();
		  return false;
	     } 
  	   }
    
	 return true;
}




function isBlank(s,message)
{
	if ((s.value.length > 0) && (s.value != null) && (s.value != "") && (s.value != " "))
	{
	    if ( isAllSpaces(s,message))
	         return true;	    
		else
		     return false;	    

	}
	alert(message);
	s.focus();
	s.select();
	return true;
}



// trim leading and trailing spaces
function trim(text)				// trim leading and trailing spaces
{ 
    while (text.substring(0,1) == ' ')
	{
        text = text.substring(1, text.length);
	}
    while (text.substring(text.length-1,text.length) == ' ') 
	{
        text = text.substring(0, text.length-1);
	}	return text;
}




function isEmail(s,message)
{
	var i,ii;
	var j;
	var k,kk;
    var jj;
    var len;
    

	if (isBlank(s,message))
	{
		s.focus();
		s.select();
		return false;
	}

    if (s.value.length >0){
		i=s.value.indexOf("@");
		ii=s.value.indexOf("@",i+1);
		j=s.value.indexOf(".",i);
		k=s.value.indexOf(",");
		kk=s.value.indexOf(" ");
		jj=s.value.lastIndexOf(".")+1;
		len=s.value.length;
		if ((i>0) && (j>(1+1)) && (k==-1) && (ii==-1) && (kk==-1) &&
           (len-jj >=2) && (len-jj<=3)) {}
		else {
	 		 	alert("Please enter valid E-mail id")
	 		 	s.focus();
	 		 	s.select();
				return false;
		}
	}
    return true;
}


//only digits and decimal are allowed
function isNumberDecimal(s,message,n,f)
{
   f=f*1
   if (f)
   {
	if (isBlank(s,message))
	{
		s.focus();
		return false;
	}
   }
     for (i = 0; i < s.value.length; i++)
	  {   
		var c = s.value.charAt(i);
			if ( !(isNumericDigit(c) || isDecimal(c) )   )
			{
				 alert("Invalid entry, only digits and decimal are allowed.\nPlease re-enter.");
				 s.focus();
				 s.select();
				return false;
			}

      }
    return true
}



function isDesignation(s,message,n,f)
{ 
   f=f*1
	if (f)
	{
	  if (isBlank(s,message))
	  {
		s.focus();
		s.select();
		return false;
	  }
    }

	s1=s.value
    tt=s.value.length
    if (tt>0)
    {
	  for (i = 0; i < tt; i++)
	   {   
	    var c = s1.charAt(i);
	    if (!(  ((c >= "A") && (c <= "Z")) || ((c >= "a") && (c <= "z")) || (c == " ") ||(c==".") || (c=="/") ))
	     {
		  alert("Invalid entry, only alphabets,forward slash and dots are allowed.\nPlease re-enter");
          s.focus();
   		  s.select();
		  return false;
	     } 
  	  }
    }
    return true

}




function isPhone(s,message,n,f)
{ 
   f=f*1
	if (f)
	{
	  if (isBlank(s,message))
	  {
		s.focus();
		s.select();
		return false;
	  }
    }

	s1=s.value
    tt=s.value.length
    if (tt>0)
    {
	  for (i = 0; i < tt; i++)
	   {   
	    var c = s1.charAt(i);
	    if (!(  ((c >= "0") && (c <= "9")) || (c == " ") ||(c==",")  || (c=="/") ))
	     {
		  alert("Invalid entry, only digits,forward slash and commas are allowed.\nPlease re-enter");
          s.focus();
   		  s.select();
		  return false;
	     } 
  	  }
    }
    return true

}


//only digits and spaces are allowed.
function isdigits(s,message,n,f)
{
   f=f*1
   if (f)
   {
	if (isBlank(s,message))
	{
		s.focus();
		return false;
	}
   }
     for (i = 0; i < s.value.length; i++)
	  {   
		var c = s.value.charAt(i);
		if (c !=" ")
		{
			if (!(isNumericDigit(c))  )
			{
				 alert("Invalid entry, only digits are allowed.\nPlease re-enter.");
				 s.focus();
				 s.select();
				return false;
			}
        }
      }
    return true
}




//only characters, digits, braces and dots are allowed.
function isCompany(s,message,n,f)
{

 	 s1=s.value
     tt=s.value.length
     f=f*1
	if (f)
	{
		if (isBlank(s,message))
		{
			s.focus();
			s.select();
			return false;
		}
	}
     for (i = 0; i < tt; i++)
	   {   
	    var c = s1.charAt(i);
	    if (!( (c == " ") || ((c >= "A") && (c <= "Z")) || ((c >= "a") && (c <= "z")) || (c == ".") || (c == "(") || (c == ")")   ))
	     {
		  alert("Invalid entry, only alphabets, braces and dots are allowed.\nPlease re-enter");
          s.focus();
   		  s.select();
		  return false;
	     } 
  	   }
    
	 return true;
}

function isDecimal(c)
{
    if (c==".")
     {
       return true     
	 }
   return false
}


//only characters, digits, braces and dots are allowed.
function isWebsite(s,message,n,f)
{

 	 s1=s.value
     tt=s.value.length
     f=f*1
	if (f)
	{
		if (isBlank(s,message))
		{
			s.focus();
			s.select();
			return false;
		}
	}
     for (i = 0; i < tt; i++)
	   {   
	    var c = s1.charAt(i);
	    if (!( (c == " ") || ((c >= "A") && (c <= "Z")) || ((c >= "a") && (c <= "z")) || (c == ".") || (c == "(") || (c == ")")   ))
	     {
		  alert("Invalid entry, only alphabets, braces and dots are allowed.\nPlease re-enter");
          s.focus();
   		  s.select();
		  return false;
	     } 
  	   }
    
	 return true;
}



function isBc(s,message,f)
{
	var i,ii;
	var j;
	var k,kk;
    var jj;
    var len;
    var a;
 f=f*1
	if (f)
	{
	if (isBlank(s,message))
	{
		s.focus();
		s.select();
		return false;
	}
	}
	if (s.value.length >0){
		i=s.value.indexOf("@");
		ii=s.value.indexOf("@",i+1);
		j=s.value.indexOf(".",i);
		k=s.value.indexOf(",");
		kk=s.value.indexOf(" ");
		a=s.value.indexOf("/");
		jj=s.value.lastIndexOf(".")+1;
		len=s.value.length;
		if ((i>0) && (j>(i+1)) && (k==-1) && (ii==-1) && (kk==-1) &&
            (a==-1) && (len-jj >=2) && (len-jj<=3)) {}
		else {
	 		 	alert("Please enter valid E-mail id")
	 		 	s.focus();
	 		 	s.select();
				return false;
		}
	}
    return true;
}

function validate(dateField, errMsg, fmt)
{

      var ds = dateField.value;
      // bail if the date parameter is empty
      if (ds == "")
         return true;

      // declare local variables
      var n = 10;   // the Y2K offset in years
      var today = new Date();
      var err = 0;  // error flag
      var month = "";
      var d;
      var m;
      var y;
      var p1 = 0;
      var p2 = 0;
      var dd = 0;
      var mm = 0;
      var yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear();

      var e = errMsg;
      if (errMsg == "")
	  {
         // default error message if second parameter is empty
         e = "Invalid date! Please re-enter using dd/mm/yyyy format";
      }
      // strip leading and trailing spaces
      while (ds.charAt(0) == " ")
	  {
            ds = ds.substring(1,ds.length);
            dateField.value = ds;
      }
      while (ds.charAt(ds.length-1) == " ")
	  {
            ds = ds.substring(0,ds.length-1);
            dateField.value = ds;
      }

      // handle common data-entry shortcuts
      if (ds == "t" || ds == "today" || ds == "0")
	  {
            dd = today.getDate();
            mm = today.getMonth() + 1;
            ds =  dd + "/" + mm + "/" + yy;
      }
      else if (ds.length < 3 && isNum(ds)) {
         // try as a date in the current month and year
         if (parseInt(ds) < 32)
		 {
            dd = ds;
            mm = today.getMonth() + 1;
            ds =  dd + "/" + mm + "/" + yy;
         }
      }
      else if (ds.length == 3 && monthToNum(ds) > 0) {
         dd = 1;
         mm = monthToNum(ds);
         ds =  dd + "/" + mm + "/" + yy;

      }
      else if (ds.length == 4 && isNum(ds)) {
         if (parseInt(ds) > 1231) {
            // assume it's a year [yyyy], set date to 1st January
            dd = 1;
            mm = 1;
            yy = ds;
         	ds =  dd + "/" + mm + "/" + yy;
         }
		 else
		 {
            // assume it's a month and day [mmdd], set year as current
            mm = ds.substring(2);
            dd = ds.substring(0,2);
			ds =  dd + "/" + mm + "/" + yy;
         }
      }
      else if (ds.length>4 && ds.length<7 && monthToNum(ds.substring(0,3))>0 && ds.indexOf(" ",0)>0) {
         // assume it's a month and day (mmm d[d]), set year as current
         p1 = ds.indexOf(" ");   // position of space
         mm = ds.substring(p1+1,ds.length);
         dd = monthToNum(ds.substring(0,3));
         ds =  dd + "/" + mm + "/" + yy;
      }
      else if (ds.length>2 && ds.length<6 && ds.indexOf("/",0)>0 && ds.indexOf("/",0)==ds.lastIndexOf("/")) {
         // assume it's a month and day (mm/dd), set year as current
         p1 = ds.indexOf("/");   // position of slash
         dd = ds.substring(0,p1);
         mm = ds.substring(p1+1,p1+3);

         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
			ds =  dd + "/" + mm + "/" + yy;
      }
      else if (ds.length>2 && ds.length<6 && ds.indexOf(" ",0)>0 && ds.indexOf(" ",0)==ds.lastIndexOf(" ")) {
         // assume it's a month and day (mm dd), set year as current
         p1 = ds.indexOf(" ");   // position of space
         dd = ds.substring(0,p1);
         mm = ds.substring(p1+1,p1+3);
		 if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
			ds =  dd + "/" + mm + "/" + yy;
      }
      else if (ds.length>2 && ds.length<6 && ds.indexOf("-",0)>0 && ds.indexOf("-",0)==ds.lastIndexOf("-")) {
         // assume it's a day and month (dd-mm), set year as current
         p1 = ds.indexOf("-");   // position of dash
         dd = ds.substring(0,p1);
         mm = ds.substring(p1+1,ds.length);

		 if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
			ds =  dd + "/" + mm + "/" + yy;
      }

////////////////////////       second flow        ////////////////////////////////////////

      if (ds.indexOf("-",0)>0 && ds.indexOf("-",0)<3)
	  {
         // test for DD-MMM-YYYY standard format
         if (ds.length == 11 && ds.indexOf("-",0) == 2 && ds.lastIndexOf("-") == 6)
		 {
            dd = ds.substring(0,2);
            mm = monthToNum(ds.substring(3,6));
            yy = ds.substring(7,11);
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            if (isNum(mm+dd+yy))
			{
			  ds = dd + "/" + mm + "/" + yy;
			}
            else 
			{
               mm = 0;
               dd = 0;
               yy = 0;
            }
         }
         // test for DD-MMM-YY abbreviated format
         else if (ds.length == 9 && ds.indexOf("-",0) == 2 && ds.lastIndexOf("-") == 6)
		 {
            dd = ds.substring(0,2);
            mm = monthToNum(ds.substring(3,6));
            yy = (parseInt(ds.substring(7,9))<n) ? ("20" + ds.substring(7,9)) : ("19" + ds.substring(7,9));
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            if (isNum(mm+dd+yy))
			{
			  	 ds = dd + "/" + mm + "/" + yy;
            }
            else
			{
               mm = 0;
               dd = 0;
               yy = 0;
            }
         }
         // test for DD-MM-YY[YY] format
         else
		 {
            p1 = ds.indexOf("-");   // position of first dash
            dd = ds.substring(0,p1);
            p2 = ds.lastIndexOf("-");   // position of last dash
            mm = ds.substring(p1+1,p2);
            yy = ds.substring(p2+1,ds.length);
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            if (mm.charAt(0) == "0") mm = mm.substring(1,2);
            if (yy.length > 4) yy = yy.substring(0,4);
            if (dd==0 || mm==0)
			{
                  mm = 0;
                  dd = 0;
                  yy = 0;
            }
            else
			{
               if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
               while (yy.substring(0,1)=="0")
			   {
                  yy = yy.substring(1,yy.length);  // remove leading zeroes
               }
               if (yy == "") yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear();
               if (isNum(mm+dd+yy))
			   {
                  if (yy > 0 && yy < 100)
				  {
                     yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
                  }
               //ds = mm + "/" + dd + "/" + yy;
			  ds = dd + "/" + mm + "/" + yy;

               }
               else
			   {
                     mm = 0;
                     dd = 0;
                     yy = 0;
               }
            }
         }
      }

       // test for MMDDYY patterned formats
	  //// test for DDMMYY patterned formats
      else if (ds.length == 6 && isNum(ds))
	  {

		 // DDMMYY patterned formats			
         mm = ds.substring(2,4);
         dd = ds.substring(0,2);
         yy = ds.substring(4,6);
			
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         if (yy.charAt(0) == "0") yy = yy.substring(1,2);

         if (yy == "0" || yy == "00") yy = "2000";
         if (yy > 0 && yy < 100)
		 {
            yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
         }
		  	 ds = dd + "/" + mm + "/" + yy;
      }

			 // test for MMDDYYYY patterned formats
      // test for DDMMYYYY patterned formats
      else if (ds.length == 8  && isNum(ds))
	  {
      
	     // test for DDMMYYYY patterned formats
         mm = ds.substring(2,4);
         dd = ds.substring(0,2);
         yy = ds.substring(4,8);

         if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
               //ds = mm + "/" + dd + "/" + yy;
			  ds = mm + "/" + dd + "/" + yy;

      }

      // convert year 2K+ for MM/DD/YY[YY] pattern formats
      else if (ds.indexOf("/",0) > 0 && (ds.length-ds.lastIndexOf("/")) < 6)
	  {
		 p1 = ds.indexOf("/");   // position of first slash
         dd = ds.substring(0,p1);
         p2 = ds.lastIndexOf("/");   // position of last slash
         mm = ds.substring(p1+1,p2);
		 yy = ds.substring(p2+1,ds.length);
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         if (yy.length > 4) yy = yy.substring(0,4);
         if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
         while (yy.substring(0,1)=="0") {
            yy = yy.substring(1,yy.length);  // remove leading zeroes
         }
         if (yy == "") yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear();
         if (isNum(mm+dd+yy)) {
            if (yy > 0 && yy < 100) {
               yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
            }
  		  	 ds = dd + "/" + mm + "/" + yy;

         }
         else {
               mm = 0;
               dd = 0;
               yy = 0;
         }
      }
	  ////.........................start
     // convert year 2K+ for DD/MM/YY[YY] pattern formats
      else if (ds.indexOf("/",0) > 0 && (ds.length-ds.lastIndexOf("/")) < 11)
	  {
         p1 = ds.indexOf("/");   // position of first slash
         mm = ds.substring(0,p1);
         p2 = ds.lastIndexOf("/");   // position of last slash
         dd = ds.substring(p1+1,p2);
         yy = ds.substring(p2+1,ds.length);
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         if (yy.length > 4) yy = yy.substring(0,4);
         if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
         while (yy.substring(0,1)=="0")
		 {
            yy = yy.substring(1,yy.length);  // remove leading zeroes
         }
         if (yy == "") yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear();
         if (isNum(mm+dd+yy))
		 {
            if (yy > 0 && yy < 100)
			{
               yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
            }
  			ds = dd + "/" + mm + "/" + yy;
         }
         else
		 {
               mm = 0;
               dd = 0;
               yy = 0;
         }
      }
	  ////.........................end 
      // convert year 2K+ for MM.DD.YY[YY] pattern formats
      else if (ds.indexOf(".",0) > 0 && (ds.length-ds.lastIndexOf(".")) < 6) {
         p1 = ds.indexOf(".");   // position of first dot
         mm = ds.substring(0,p1);
         p2 = ds.lastIndexOf(".");   // position of last dot
         dd = ds.substring(p1+1,p2);
         yy = ds.substring(p2+1,ds.length);
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         if (yy.length > 4) yy = yy.substring(0,4);
         if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
         while (yy.substring(0,1)=="0") {
            yy = yy.substring(1,yy.length);  // remove leading zeroes
         }
         if (yy == "") yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear();
         if (isNum(mm+dd+yy)) {
            if (yy > 0 && yy < 100) {
               yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
            }
               //ds = mm + "/" + dd + "/" + yy;
			  	 ds = dd + "/" + mm + "/" + yy;

         }
         else {
               mm = 0;
               dd = 0;
               yy = 0;
         }
      }

      // validate the standard space-delimited formats
      else if (ds.indexOf(" ",0)>0 && (ds.length-ds.lastIndexOf(" "))<6)
	  {

         if (ds.indexOf(",",0) > 0) {
            // validate 'mmm[...] dd, yy[yy]' type formats
            
			p1 = ds.indexOf(" ");   // position of first space
            mm = monthToNum(ds.substring(0,3));
            dd = ds.substring(p1+1,ds.indexOf(",",0));
            p2 = ds.lastIndexOf(" ");   // position of last space

            yy = ds.substring(p2+1,ds.length);
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            if (yy.length > 4) yy = yy.substring(0,4);
            if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
            while (yy.substring(0,1)=="0")
			{
               yy = yy.substring(1,yy.length);  // remove leading zeroes
            }
            if (yy == "") yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear();
            if (isNum(mm+dd+yy))
			{
               if (yy > 0 && yy < 100)
			  {
                  yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
               }
               //    ds = mm + "/" + dd + "/" + yy;
			  	     ds = dd + "/" + mm + "/" + yy;

            }
            else
			{
               mm = 0;
               dd = 0;
               yy = 0;
            }
         }

         else if (monthToNum(ds.substring(ds.indexOf(" ")+1,ds.indexOf(" ")+4))>0)
		 {

			// validate 'dd mmm[...] yy[yy]' type formats
            p1 = ds.indexOf(" ");   // position of first space
            dd = ds.substring(0,p1);
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            p2 = ds.lastIndexOf(" ");   // position of last space
            mm = monthToNum(ds.substring(p1+1,p1+4));   // extract 3 bytes for month
            yy = ds.substring(p2+1,ds.length);
            if (yy.length > 4) yy = yy.substring(0,4);
            if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
            while (yy.substring(0,1) == "0") {
               yy = yy.substring(1,yy.length);  // remove leading zeroes
            }
            if (yy == "") yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear();
            if (isNum(mm+dd+yy)) {
               if (yy > 0 && yy < 100) {
                  yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
               }
               //ds = mm + "/" + dd + "/" + yy;
			  	 ds = dd + "/" + mm + "/" + yy;

            }
            else {
               mm = 0;
               dd = 0;
               yy = 0;
            }
         }

         // validate 'MM DD YY[YY]' formats
         else {
            p1 = ds.indexOf(" ");   // position of first space
            dd = ds.substring(0,p1);
            p2 = ds.lastIndexOf(" ");   // position of last space
            mm = ds.substring(p1+1,p2);

			yy = ds.substring(p2+1,ds.length);
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            if (mm.charAt(0) == "0") mm = mm.substring(1,2);
            if (yy.length > 4) yy = yy.substring(0,4);
            if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
            while (yy.substring(0,1)=="0") {
               yy = yy.substring(1,yy.length);  // remove leading zeroes
            }
            if (yy == "") yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear();
            if (isNum(mm+dd+yy)) {
               if (yy > 0 && yy < 100) {
                  yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
               }
               //ds = mm + "/" + dd + "/" + yy;
			  	 ds = dd + "/" + mm + "/" + yy;

            }
            else {
               mm = 0;
               dd = 0;
               yy = 0;
            }
         }
      }



////////////////////////       third flow        ////////////////////////////////////////

      // attempt to parse any other dates with valid IETF formats
      if (dd==0 && mm==0 && yy==0)
	  {

         d = new Date(Date.parse(ds));
         dd = d.getDate();
         mm = (d.getMonth() + 1);
         // Netscape returns last 2 digits of years 1900-1999,
         // and the full year (4 char) string for dates > 2000 or < 1900;
         // IE returns 1900 minus the current year in all cases,
         // <duh> except IE3, when the year is earlier than 1970 </duh>
         if (d.getYear() > 2000)
		 {
            yy = d.getYear();  // Netscape
         }
         else if (d.getYear() < 1900 && d.getYear() > 200) 
		 {
            yy = d.getYear();  // Netscape, date prior to 1900
         }
         else
		 {
            yy = d.getYear() + 1900;
         }
         if (dd == 31 && mm == 12 && yy == 1969) {
            // IE's start-epoch date
            mm = 0;
            dd = 0;
            yy = 0;
         }
               //ds = mm + "/" + dd + "/" + yy;
			  	 ds = dd + "/" + mm + "/" + yy;

      }

      // verify the date components
      if (parseInt(dd)>0 && parseInt(mm)>0 && parseInt(yy)+1>0)
	  {

		 if (mm < 1 || mm > 12) err = 1;
         if (dd < 1 || dd > 31) err = 1;
         if (yy < 1000 || yy > 9999) err = 1;

         // check the months with 30 days
         if (mm == 4 || mm == 6 || mm == 9 || mm == 11) {
            if (dd == 31) {
               dd = 1;  // flick it forward a day
               mm = mm + 1;
            }
         }
         // check February and leap years
         if (mm == 2) {
            if (dd > 29) err = 1;
            if (dd == 29 && ((yy/4) != parseInt(yy/4))) {
               dd = 1;  // flick it forward a day
               mm = 3;
            }
         }
      }


      // finally, test whether the input string can be Date.parsed

	   ddmmyy=ds.split("/")
	   ds=ddmmyy[1]+"/"+ddmmyy[0]+"/"+ddmmyy[2]
      
	   
	   d = new Date(Date.parse(ds));


      if (!d.getDate()) 
		{
		  err = 1;
		}


	if (err==1 || dd==0 || mm==0)
	  {
		 alert(e);
		 dateField.select();
         dateField.focus();
         return false;
      }
       // we have a valid IETF date, so convert it to
      // the specified standard format for database entry
      if (parseInt(dd)<10 && (fmt < 4 || fmt > 6))
         dd = "0" + dd;   // add leading zero to days 1-9

      // convert month numeric to string
      if (mm == 1)
         month = "Jan";
      else if (mm == 2)
         month = "Feb";
      else if (mm == 3)
         month = "Mar";
      else if (mm == 4)
         month = "Apr";
      else if (mm == 5)
         month = "May";
      else if (mm == 6)
         month = "Jun";
      else if (mm == 7)
         month = "Jul";
      else if (mm == 8)
         month = "Aug";
      else if (mm == 9)
         month = "Sep";
      else if (mm == 10)
         month = "Oct";
      else if (mm == 11)
         month = "Nov";
      else if (mm == 12)
         month = "Dec";
      else month == "";
      // add leading zero to months 1-9 for mm formats
      if (fmt > 6 && mm < 10) mm = "0" + mm;

      // re-test the date components
      if (dd==0 || dd=="" || month=="" || mm==0 || mm=="" || yy=="")
	  {
         alert(e);
         dateField.select();
         dateField.focus();
         return false;
      }

      dateField.value = dd*1 + "/" + mm*1 + "/" + yy*1;
      return true;
   }


function monthToNum(monthStr) {
      if (monthStr=="")
         return false;
      var m = monthStr;
      if (monthStr.length>3)
         var m = monthStr.substring(0,2);
      if (m=="jan" || m=="Jan" || m=="JAN")
         return 1;
      else if (m=="feb" || m=="Feb" || m=="FEB")
         return 2;
      else if (m=="mar" || m=="Mar" || m=="MAR")
         return 3;
      else if (m=="apr" || m=="Apr" || m=="APR")
         return 4;
      else if (m=="may" || m=="May" || m=="MAY")
         return 5;
      else if (m=="jun" || m=="Jun" || m=="JUN")
         return 6;
      else if (m=="jul" || m=="Jul" || m=="JUL")
         return 7;
      else if (m=="aug" || m=="Aug" || m=="AUG")
         return 8;
      else if (m=="sep" || m=="Sep" || m=="SEP")
         return 9;
      else if (m=="oct" || m=="Oct" || m=="OCT")
         return 10;
      else if (m=="nov" || m=="Nov" || m=="NOV")
         return 11;
      else if (m=="dec" || m=="Dec" || m=="DEC")
         return 12;
      else
         return 0;
   }


function isNum(arg) {
      if (arg == "")
         return false;
      for (i=0; i < arg.length; i++) {
         if (arg.charAt(i) < "0" || arg.charAt(i) > "9") {
       
            return false;
         }
      }
      return true;
   }
   
   
   
function checkdate()
{
 	if (document.form.PickDate.value=="")
	{
		alert("Please enter date of payment mode");
		document.form.PickDate.focus();
		return (false);
	} 
	  
	var systemdate=new Date()
	var systemdate55=new Date()
	var sysdate
	sysdate=new Date(systemdate).valueOf()
	hondatedmy=document.form.PickDate.value.split("/")
	hondate=hondatedmy[1]+"/"+hondatedmy[0]+"/"+hondatedmy[2]
	h_ondate=new Date(hondate).valueOf()
	vsystemdate55=(systemdate55.getYear()<200)?systemdate55.getYear()+1900:systemdate55.getYear()
	var dt=(systemdate55.getMonth()+1)+"/"+systemdate55.getDate()+"/"+vsystemdate55;
	var	tempcheck=sysdate - (60*24*60*60*1000)
	var sysdate1
	sysdate1=sysdate + (60*24*60*60*1000)
	if (h_ondate > sysdate1)
	{
		alert("Payment mode date should not exceed 60 days from today's date")
		return (false);
    }
    if (h_ondate < tempcheck)
	{
		alert("Payment date cannot be less than 60 days from todate")
		return (false);
	}
return true
}


