function capturedate_func()
{
if((navigator.appName=="Netscape"))
	{

	window.onKeyPress=func;
	window.captureEvents(Event.KEYPRESS);
	}
}

function releasedate_func()
{
	if((navigator.appName=="Netscape"))
	{
		window.releaseEvents(Event.KEYPRESS);
	}
}

function func(e)
{
	
	
	var ch=0;
	if(navigator.appName=="Netscape")
	{
		ch=e.which;
			
		if(((ch<47) || (ch>57)) && (ch!=8))
			return false;
	}
	else
	{
		ch=event.keyCode;
		if(((ch<47) || (ch>57)) )
			event.returnValue=false;
	}
	
}//func(e)

//*****************
function dateformat(obj1,datevalue,nlyear,ngyear,tempdate,dfrmt) {
var message;
if(datevalue.length>0)
{
//
if(dfrmt == 2)
message = "Invalid Date !\nPlease enter a valid date in \n   'MM/DD/YYYY' format";
if(dfrmt == 1)
message = "Invalid Date !\nPlease enter a valid date in \n   'DD/MM/YYYY' format";
 a=datevalue.indexOf("/");
 b=datevalue.lastIndexOf("/");
 //******************
 var ravicount=0;
for(i=0;i<datevalue.length;i++)
   {
    if(datevalue.substr(i,1)=='/')
      ravicount=ravicount+1;
     
   }
if(ravicount>2)
{
alert(message);
		   obj1.value="";
		   obj1.focus();
		   return false;
}
 //**********************
 //new code to avoid entering '//'  
  if(datevalue.indexOf('//')!=-1)
	     {
		   alert(message);
		   obj1.value="";
		   obj1.focus();
		   return false;
		 }
		 //*******************
	 if(a==b)
	 {
		alert(message);
		obj1.value="";
		obj1.focus();
	 }
	 else
	 if((a+1)==b)
	 {
		alert(message);
		obj1.value="";
		obj1.focus();
	 }//
	 else
if ((datevalue.length < 8) || (datevalue.length>10)) 
{
alert(message);
obj1.value="";
obj1.focus();
}

else
{

var stryear;
var mmonth;
var mDay;
var mYear;

 flg=true;
 bflg=true;

	if(nlyear.length==4)
			stryear=nlyear;
	else
			stryear=1900;
	
	ind1=datevalue.indexOf('/');
	ind2=datevalue.lastIndexOf('/');
	if((ind1==1) || (ind1==2) || (ind2==4) || (ind2==5) || (ind2 == 3))
	{
		if(dfrmt == 1)
		{
		mDay = datevalue.substr(0,ind1);
			
		if(((ind1==2) && (ind2==5)) || ((ind1==2) && (ind2==4)))
			mmonth=datevalue.substr(ind1+1,ind2-3);
		if(((ind1==1) && (ind2==3)) || ((ind1==1) && (ind2==4)))
			mmonth=datevalue.substr(ind1+1,ind2-2);
		}
	    if(dfrmt == 2)
		{
		 mmonth = datevalue.substr(0,ind1);
		
		 if(((ind1==2) && (ind2==5)) || ((ind1==2) && (ind2==4)))
			mDay=datevalue.substr(ind1+1,ind2-3);
	     if(((ind1==1) && (ind2==3)) || ((ind1==1) && (ind2==4)))
			mDay=datevalue.substr(ind1+1,ind2-2);
		}	
		 mYear = datevalue.substr(ind2+1,datevalue.length);
		 

		if ((mYear.length < 4) || (mYear<stryear))
			{
			if(mYear<stryear)
			{
				alert("Date less than the year "+stryear+" is not permitted");
				obj1.value="";
				obj1.focus();
				bflg=false;
			}
			else
			{
				alert(message);
				obj1.value="";
				obj1.focus();
				bflg=false;
			}
			}
		else {//else for if(mYear1)
		if(mmonth<1 || mmonth>12)
		{
			alert(message);
			obj1.value="";
			obj1.focus();
			bflg=false;
			}
		else {//else for if(mmonth)
		if(mmonth==2)
		{
			if(LeapYear(mYear))
			{
				if(mDay<1 || mDay>29)
				{
				alert(message);
				obj1.value="";
				obj1.focus();
				bflg=false;
				}
			}
			else
			{
				if(mDay<1 || mDay>28)
				{
				alert(message);
				obj1.value="";
				obj1.focus();
				bflg=false;
				}
			}
		}//if(mmonth==2)
		if(mmonth==1 || mmonth==3 || mmonth==5 || mmonth==7 || mmonth==8 || mmonth==10 || mmonth==12)
		{
			if(mDay<1 || mDay>31)
			{
				alert(message);
				obj1.value="";
				obj1.focus();
				bflg=false;
			}
		}//if(mmonth)
		if(mmonth==4 || mmonth==6 || mmonth==9 || mmonth==11)
		{
			if(mDay<1 || mDay>30)
				{
				alert(message);
				obj1.value="";
				obj1.focus();
				bflg=false;
				}
		}//if(mmonth)
		}//end of else if(mmonth)
   }//end of else(if(mYear))
   }//end of if(ind1==1 || ind2==4)
   else
	{
	alert(message);
	obj1.value="";
	obj1.focus();
	bflg=false;
	}
	if((flg)&&(bflg))
	{
		
		fflg=true;		
		//sdate=new Date();
		sdate=tempdate;
		
		//strdd=sdate.getDate();
		//strmm=sdate.getMonth();
		//strmm++;
		
		//stryy=sdate.getFullYear();

		//strsysdate=strdd+"/"+strmm+"/"+stryy;
		int1=sdate.indexOf('/');
	int2=sdate.lastIndexOf('/');
	if((int1==1) || (int1==2) || (int2==4) || (int2==5) || (int2 == 3))
	{
		 strdd = sdate.substr(0,int1);
			
		if(((int1==2) && (int2==5)) || ((int1==2) && (int2==4)))
			strmm=sdate.substr(int1+1,int2-3);
		if(((int1==1) && (int2==3)) || ((int1==1) && (int2==4)))
			strmm=sdate.substr(int1+1,int2-2);
			
		 stryy = sdate.substr(int2+1,sdate.length);
		 }
		if(strdd.indexOf("0")==0)
			strdd=strdd.substr(1,strdd.length);
		if(strmm.indexOf("0")==0)
			strmm=strmm.substr(1,strmm.length);
		strsysdate=strdd+"/"+strmm+"/"+stryy;
		//strsysdate=sdate;
		
		//this is for notlessthan 
		
		if(nlyear=="sysdate")
		{

			fflg=datefunc(Number(mDay),Number(mmonth),Number(mYear),Number(strdd),Number(strmm),Number(stryy),strsysdate,obj1);
		}
		else
			if(nlyear.length>4)//this case is for a given date
			{
				
				if(nlyear.indexOf("/")>0)
				{
					inti = nlyear.indexOf("/");
					intj = nlyear.lastIndexOf("/");
			if((inti==1) || (inti==2) || (intj==4) || (intj==5) || (intj == 3))
			{
				 nldate = nlyear.substr(0,inti);
			
				if(((inti==2) && (intj==5)) || ((inti==2) && (intj==4)))
					nlmonth=nlyear.substr(inti+1,intj-3);
				if(((inti==1) && (intj==3)) || ((inti==1) && (intj==4)))
					nlmonth=nlyear.substr(inti+1,intj-2);
			
					 nly = nlyear.substr(intj+1,nlyear.length);
			}
					if(nldate.indexOf("0")==0)
					{
						nldate=nldate.substr(1,1);
						
					}
					if(nlmonth.indexOf("0")==0)
					{
						nlmonth=nlmonth.substr(1,1);
						
					}
				fflg=datefunc(Number(mDay),Number(mmonth),Number(mYear),Number(nldate),Number(nlmonth),Number(nly),nlyear,obj1);
				}//if this is a given date
				else
				if(nlyear.indexOf("days")>0)
				{
							
					var strp;
					dday=nlyear.substr(0,nlyear.indexOf("days"));
					//here dday is 30
					if(strdd > dday)
					{
						strp="1/"+strmm+"/"+stryy;
						fflg=datefunc(Number(mDay),Number(mmonth),Number(mYear),Number(1),Number(strmm),Number(stryy),strp,obj1);
					}
					else
					{
						dd=dday-strdd;
						if((strmm==1))
						{
							dd = 31-dd;
							strp=dd+"/12/"+(stryy-1);
							fflg=datefunc(Number(mDay),Number(mmonth),Number(mYear),Number(dd),Number(12),Number(Number(stryy)-1),strp,obj1);
						}
						else
						if((strmm==5) || (strmm==7) || (strmm==8) || (strmm==10) || (strmm==12))
						{
							dd = 30-dd;
							strp=dd+"/"+(strmm-1)+"/"+stryy;
						fflg=datefunc(Number(mDay),Number(mmonth),Number(mYear),Number(dd),Number(Number(strmm)-1),Number(stryy),strp,obj1);
						}
						else
						if((strmm==2) || (strmm==4) || (strmm==6) || (strmm==9) || (strmm==11))
						{
							dd = 31-dd;
							strp=dd+"/"+(strmm-1)+"/"+stryy;
							
						fflg=datefunc(Number(mDay),Number(mmonth),Number(mYear),Number(dd),Number(Number(strmm)-1),Number(stryy),strp,obj1);
						}
						else
						if(strmm==3)
						{
						
							if(LeapYear(stryy))
							{
								if(dd<29)
								{
									dd=29-dd;
									strmm=strmm-1;
								}
								else
								{
									dd=dd-29;
									dd=31-dd;
									strmm=1;
								}

							}//ifLeapYear
							else
							{
								if(dd<28)
								{
									dd=28-dd;
									strmm=strmm-1;
								}
								else
								{
									dd=dd-28;
									dd=31-dd;
									strmm=1;
								}
							}//else if LeapYear()
						strp=dd+"/"+strmm+"/"+stryy;
						fflg=datefunc(Number(mDay),Number(mmonth),Number(mYear),Number(dd),Number(strmm),Number(stryy),strp,obj1);
						}//if(strmm==3)
					}//else 

				}// if nlyear(indexof("days"))
				else//this case is no.of days lessthan sysdate
				if(nlyear.indexOf("months")>0)
				{
					strp=strdd+"/"+strmm+"/"+(stryy-1);
					fflg=datefunc(Number(mDay),Number(mmonth),Number(mYear),Number(strdd),Number(strmm),(Number(stryy)-1),strp,obj1);
				}//if(nlyear.indexOf("months"))
			}//if nlyear.length>4
		
			
				
			

		
	//}//if flg()
//}//end of else

//not greater than
		
		if(fflg)
		{
		if(ngyear=="sysdate")
		{
			
			datefunc_g(Number(mDay),Number(mmonth),Number(mYear),Number(strdd),Number(strmm),Number(stryy),strsysdate,obj1);
		}
		else
			if(ngyear.length>4)//this case is for a given date
			{
				
				if(ngyear.indexOf("/")>0)
				{
					inti = ngyear.indexOf("/");
					intj = ngyear.lastIndexOf("/");
			if((inti==1) || (inti==2) || (intj==4) || (intj==5) || (intj == 3))
			{
				 ngdate = ngyear.substr(0,inti);
			
				if(((inti==2) && (intj==5)) || ((inti==2) && (intj==4)))
					ngmonth=ngyear.substr(inti+1,intj-3);
				if(((inti==1) && (intj==3)) || ((inti==1) && (intj==4)))
					ngmonth=ngyear.substr(inti+1,intj-2);
			
					 ngy = ngyear.substr(intj+1,ngyear.length);
			}
					if(ngdate.indexOf("0")==0)
					{
						ngdate=ngdate.substr(1,1);
						
					}
					if(ngmonth.indexOf("0")==0)
					{
						ngmonth=ngmonth.substr(1,1);
						
					}
					datefunc_g(Number(mDay),Number(mmonth),Number(mYear),Number(ngdate),Number(ngmonth),Number(ngy),ngyear,obj1);
				
				}//if for a given date
				else
				if(ngyear.indexOf("days")>0)
				{
					var strp;
					var ndays;
					dday=ngyear.substr(0,ngyear.indexOf("days"));
					if((strmm==1) || (strmm==3) || (strmm==5) || (strmm==7) || (strmm==8) || (strmm==10) || (strmm==12))
						ndays = 31;
					else 
					if((strmm==4) || (strmm==6) || (strmm==9) || (strmm==11))
						ndays = 30;
					else
					if(strmm==2)
					{
						if(LeapYear(stryy))
							ndays = 29;
						else
							ndays = 28;
					}


					//here dday is 30
					intcntdays=Number(strdd)+Number(dday);
					
					if(intcntdays <= ndays)
					{
						strp=intcntdays+"/"+strmm+"/"+stryy;
					datefunc_g(Number(mDay),Number(mmonth),Number(mYear),Number(intcntdays),Number(strmm),Number(stryy),strp,obj1);
					}
					else
					{
						
						dd = dday-(Number(ndays)-Number(strdd));
						
						
						if((strmm==12))
						{
							
							strp=dd+"/1/"+(stryy+1);
							datefunc_g(Number(mDay),Number(mmonth),Number(mYear),Number(dd),Number(1),Number(Number(stryy)+1),strp,obj1);
						}
						else
						if(strmm==1)
						{
								if(LeapYear(stryy))
								{
									if(dd > 29)
									{
										dd = dd-29;
										strp=dd+"/3/"+stryy;
								datefunc_g(Number(mDay),Number(mmonth),Number(mYear),Number(dd),Number(3),Number(stryy),strp,obj1);	}//if (dd>28)
									else
									{
										strp=dd+"/2/"+stryy;
								datefunc_g(Number(mDay),Number(mmonth),Number(mYear),Number(dd),Number(2),Number(stryy),strp,obj1);	
									}//else if(dd > 28)
								}//if leapyear
								else
								{
									if(dd>28)
									{
									dd=dd-28;
									strp=dd+"/3/"+stryy;
								datefunc_g(Number(mDay),Number(mmonth),Number(mYear),Number(dd),Number(3),Number(stryy),strp,obj1);	
									}
									else
									{
									strp=dd+"/2/"+stryy;
								datefunc_g(Number(mDay),Number(mmonth),Number(mYear),Number(dd),Number(2),Number(stryy),strp,obj1);	
									}
								}//else if leapyear
							
						}//if(strmm==1)
						else
						if((strmm==2) || (strmm==3) || (strmm==4) || (strmm==5) || (strmm==6) || (strmm==7) || (strmm==8) || (strmm==9) || (strmm==10) || (strmm==11) || (strmm==12))
						{
							
							
							strp=dd+"/"+(Number(strmm)+1)+"/"+stryy;

							datefunc_g(Number(mDay),Number(mmonth),Number(mYear),Number(dd),(Number(strmm)+1),Number(stryy),strp,obj1);
						}
						
					}//else 

				}// if ngyear(indexof("days"))
				else//this case is no.of days greaterthan sysdate
				if(ngyear.indexOf("months")>0)
				{
					strp=strdd+"/"+strmm+"/"+(stryy+1);
					datefunc_g(Number(mDay),Number(mmonth),Number(mYear),Number(strdd),Number(strmm),(Number(stryy)+1),strp,obj1);
				}//if(nlyear.indexOf("months"))
			}//if(ngyear>4)
			
		}//if(fflg)	
	}//if flg()
}//end of else
}//end of if(datevalue.length>0)

//*******************

}//end of func

//**************

function LeapYear(mYear)
{
if(mYear%100==0)
{
	if(mYear%400==0) 
		return true;
}
else
	if(mYear%4==0)
		return true;
return false;
}//end of func

//***********

function datefunc(d1,m1,y1,d2,m2,y2,cdate,obj1)
{
	
			if(y1<y2)
			{
				alert("Date should not be less than '"+cdate+"'");
				obj1.value="";
				obj1.focus();
				return false;
			}
			else
			//if((Number(m1)<Number(m2))&&(y1==y2))
			if((m1<m2)&&(y1==y2))
			{
				//alert(m1+" m2 : "+m2);
				alert("Date should not be less than '"+cdate+"'");
				obj1.value="";
				obj1.focus();
				return false;
			}
			else
			if((d1<d2)&&(m1==m2)&&(y1==y2))
			{
				alert("Date should not be less than '"+cdate+"'");
				obj1.value="";
				obj1.focus();
				return false;
			}
			else
				return true;
}//end of datefunc();
//***************


function datefunc_g(d1,m1,y1,d2,m2,y2,cdate,obj1)
{
	
	
			if(y1>y2)
			{
				alert("Date should not be greater than '"+cdate+"'");
				obj1.value="";
				obj1.focus();
			}
			else
			if((m1>m2) && (y1==y2))
			{
				alert("Date should not be greater than '"+cdate+"'");
				obj1.value="";
				obj1.focus();
			}
			else
			if((d1>d2) && (m1==m2) && (y1==y2))
			{
				alert("Date should not be greater than '"+cdate+"'");
				obj1.value="";
				obj1.focus();
			}
}//end of datefunc_g();

//****************


//*********** Numbers & alphabets(upper&lower) & spaces *************//


function capture_numchar_func()
{

if((navigator.appName=="Netscape"))
	{

	window.onKeyPress=numchar_func;
	window.captureEvents(Event.KEYPRESS);
	}
}


function numchar_func(e)
{
		
	var ch=0;
	if(navigator.appName=="Netscape")
	{
			ch=e.which;
		
	if(((ch<48) || (ch>57)) && (ch!=8) && ((ch<65)||(ch>90)) && ((ch<97)||(ch>122)) && (ch!=32))
	return false;
			
	}
	else
	{
		ch=event.keyCode;
		if(((ch<48) || (ch>57)) && (ch!=8) && ((ch<65)||(ch>90)) && ((ch<97)||(ch>122))&& (ch!=32))
	 event.returnValue=false;
		
	}
}//func(e)


function capture_num_func()
{
if((navigator.appName=="Netscape"))
	{

	window.onKeyPress=num_func;
	window.captureEvents(Event.KEYPRESS);
	}
}


function num_func(e)
{
	
	
	var ch=0;
	if(navigator.appName=="Netscape")
	{
		ch=e.which;
			
		if(((ch<48) || (ch>57)) && (ch!=8))
			return false;
	}
	else
	{
		ch=event.keyCode;
		if(((ch<48) || (ch>57)) )
			event.returnValue=false;
	}
	
}//func(e)

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

function capture_numdec_func()
{
if((navigator.appName=="Netscape"))
	{

	window.onKeyPress=numdec_func;
	window.captureEvents(Event.KEYPRESS);
	}
}


function numdec_func(e)
{
	
	
	var ch=0;
	if(navigator.appName=="Netscape")
	{
		ch=e.which;
			
		if(((ch<48) || (ch>57)) && (ch!=8) && (ch!=46))
			return false;
	}
	else
	{
		ch=event.keyCode;
		if(((ch<48) || (ch>57)) && (ch!=46) )
			event.returnValue=false;
	}
	
}//func(e)


function numdec_funcheck(obj,bval,aval,pcur)
{
			numdecflag=true;
			i=obj.value.indexOf(".");
			j=obj.value.lastIndexOf(".");
				if(i<0)
				{
					if(obj.value.length>bval)
					{
						alert("Maximum digits are restricted to "+bval);
						obj.focus();
						numdecflag=false;
					}
				}
				else
				if((i==j) && (i==0))
				{
					alert("If the value is less than 1 prefix the decimal with 0 \n for ex. 0.78");
						obj.focus();
						numdecflag=false;
				}
			
			else
			if((i>0)&&(i==j))
			{
					if(obj.value.substring(0,i).length>bval)
					{	
						if(pcur=="a")
							alert("Max digits before decimal are restricted to "+bval);
						else
							alert("Invalid Percentage. \n Max digits before decimal is restricted to "+bval);
						obj.focus();
						numdecflag=false;
					}
				
					else
					if(obj.value.substring(i+1,obj.value.length).length>aval) 
					{
							if(pcur=="a")
								alert("Max digits after decimal are restricted to "+aval);
							else
								alert("Invalid Percentage. \n Max digits after decimal are restricted to "+aval);								
							obj.focus();
							numdecflag=false;
					}

					else
					if(obj.value.substring(i+1,obj.value.length).length<1)
					{
							alert("There should be at least one digit after the decimal");
							obj.focus();
							numdecflag=false;
					}
				}//if(i==j)&&(i>0)
				
				else
				if(i!=j)
				{
					alert("There can not be multiple decimal points");
					obj.focus();
					numdecflag=false;
				}
				
		return numdecflag;
			
}//function numdec_funcheck()



