function dt(vname,addyear,lessyear)
{
    today = new Date();
    thismonth = today.getMonth()+1;
    thisyear = today.getYear();
    if (thisyear < 999 )
        thisyear = today.getYear()+1900;
    thisday = today.getDate();
    maxyear=thisyear + addyear;
    minyear=thisyear - lessyear;
    days=vname + "days";
    months=vname + "months";
    years=vname + "years";

    //Display days

    document.write(" <select name=");
    document.write(days);
    document.write(" size=1 style=width:50>");
    for (var theday = 1; theday <= 31; theday++) {
        var theday = "" + theday;
        if (theday.length == 1) {
            theday = "0" + theday;
        }
        document.write("<option value='" + theday + "' ");
        if (theday == thisday) document.write(" selected");
        document.write(">");
        document.write(theday);
    }
    document.write("</select>");

    //display month

    document.write(" <select name=");
    document.write(months);
    document.write(" size=1 style=width:50>");
    for (var themn = 1; themn <= 12; themn++) {
        var themn = "" + themn;
        if (themn.length == 1) {
            themn = "0" + themn;
        }
        document.write("<option value='" + themn + "' ");
        if (themn == thismonth) document.write(" selected");
        document.write(">");
        document.write(themn);
    }
    document.write("</select>");


    //display year

    document.write(" <select name=");
    document.write(years);
    document.write(" size=1 style=width:70>");
    for (var theyr = minyear; theyr <= maxyear; theyr++) {
        document.write("<option value='" + theyr + "' ");
        if (theyr == thisyear) document.write(" selected");
        document.write(">");
        document.write(theyr);
    }
    document.write("</select>");

}    //end of function
// this function used when not refreshed your combo box
function dt_notrefresh(vname,addyear,lessyear,day,month,year)
{
  	today = new Date();
    thismonth = today.getMonth()+1;
    thisyear = today.getYear();
    if (thisyear < 999 )
        thisyear = today.getYear()+1900;
    thisday = today.getDate();
    maxyear=thisyear + addyear;
    minyear=thisyear - lessyear;
    days=vname + "days";
    months=vname + "months";
    years=vname + "years";

    //Display days

    document.write(" <select name=");
    document.write(days);
    document.write(" size=1 style=width:50>");
    day=""+day;
	if (day.length == 1) {
		day = "0" + day;
	}
	for (var theday = 1; theday <= 31; theday++) {
        var theday = "" + theday;
        if (theday.length == 1) {
            theday = "0" + theday;
        }
        document.write("<option value='" + theday + "' ");
        if (theday == day){
			document.write(" selected");
		}
		document.write(">");
        document.write(theday);
    }
    document.write("</select>");

    //display month

    month=""+month;
	if (month.length == 1) {
		month = "0" + month;
	}

	document.write(" <select name=");
    document.write(months);
    document.write(" size=1 style=width:50>");
    for (var themn = 1; themn <= 12; themn++) {
        var themn = "" + themn;
        if (themn.length == 1) {
            themn = "0" + themn;
        }
        document.write("<option value='" + themn + "' ");
        if (themn == month){ 
		document.write(" selected");
		}
		document.write(">");
        document.write(themn);
    }
    document.write("</select>");


    //display year

    document.write(" <select name=");
    document.write(years);
    document.write(" size=1 style=width:70>");
    for (var theyr = minyear; theyr <= maxyear; theyr++) {
        document.write("<option value='" + theyr + "' ");
        if (theyr == year) document.write(" selected");
        document.write(">");
        document.write(theyr);
    }
    document.write("</select>");
	
}    //end of function


// this will compare two dates 
//and return false if first date is greater than to second
function date_compare_new(frm,startdt,enddt)
{
	//var cur_date=new Date();
	var firstdt = new Date(frm.elements[startdt+"years"].value,(frm.elements[startdt+"months"].value - 1),frm.elements[startdt+"days"].value);
    var seconddt = new Date(frm.elements[enddt+"years"].value,(frm.elements[enddt+"months"].value - 1),frm.elements[enddt+"days"].value);
	return (firstdt<=seconddt);
       
}
function date_compare_new1(frm,startdt,enddt)
{
	//var cur_date=new Date();
	var firstdt = new Date(frm.elements[startdt+"years"].value,frm.elements[startdt+"months"].value);
    var seconddt = new Date(frm.elements[enddt+"years"].value,frm.elements[enddt+"months"].value);
	return (firstdt<=seconddt);
       
}
function compare_date(frm,startdt,enddt)
{
	var firstdt = new Date(frm.elements[startdt+"years"].value,(frm.elements[startdt+"months"].value - 1),frm.elements[startdt+"days"].value);
    var seconddt = new Date(frm.elements[enddt+"years"].value,(frm.elements[enddt+"months"].value - 1),frm.elements[enddt+"days"].value);
	return (firstdt<seconddt);
}
/* RETURN TRUE IF TODAY IS GREATER THAN CURRENT DATE */
function check_to_date(frm,tdt)
{
    var cur_date=new Date();
	var cur_year=cur_date.getYear();
	if(cur_year<999)
		cur_year+=1900;
	var cur_month=cur_date.getMonth();
	var cur_day=cur_date.getDate();
	var cdate=new Date(cur_year,cur_month,cur_day);
	var todt = new Date(frm.elements[tdt+"years"].value,(frm.elements[tdt+"months"].value - 1),frm.elements[tdt+"days"].value);
	return (todt>cdate);
}
function valid_date(frm,tdt)
{
	
	var mn=frm.elements[tdt+"months"].value;
	var day=frm.elements[tdt+"days"].value;
	var yr=frm.elements[tdt+"years"].value;
       //alert(mn+"-"+day+"-"+yr);
	if((mn==02) && (day>28)){	
		if ((((yr % 4 == 0) && (yr % 100 != 0)) || (yr % 400 == 0)) && (day < 30))
			return false;
		else
			return true;
	}
	else if((mn==04 || mn==06 || mn==09 || mn==11) && (day>30))
		return true;
	else
		return false;
}

var count=0;
function counter(frm)
{
	count++;
	if(count==1)
		return true;
	else 
		return false;
}

//THIS WILL VALIDATE THE DATE 
//ALSO PROMPT IF DATE IS GREATER THAN SYSTEM CURRENT DATE
function validate_date(frm,tdt)
{
 //alert("in to script");
	if(valid_date(frm,tdt))
	{
		alert("Please enter valid date.");
		frm.elements[tdt+"days"].focus();
		return false;
	}
	else if(check_to_date(frm,tdt))
	{
		alert("Date should not be greater than  current date.");
		frm.elements[tdt+"days"].focus();
		return false;
	}
	return true;
}
function dtyears(vname,addyear,lessyear)
{
	today = new Date();
	thisyear = today.getYear();
	if (thisyear < 999 )
        thisyear = today.getYear()+1900;

	maxyear=thisyear + addyear;
    	minyear=thisyear - lessyear;
	years=vname + "years";
	document.write(" <select name=");
    	document.write(years);
	document.write(" size=1 style=width:70 id="+years+">");
    for (var theyr = minyear; theyr <= maxyear; theyr++) {
        document.write("<option value='" + theyr + "' ");
        if (theyr == thisyear) document.write(" selected");
        document.write(">");
        document.write(theyr);
    }
    document.write("</select>");
}
function dtmonths(vname)
{
	today = new Date();
	thismonth = today.getMonth()+1;
	months=vname + "months";
	var mon=new Array(12);
	mon[01]="Jan";mon[02]="Feb";mon[03]="March";mon[04]="April";
	mon[05]="May";mon[06]="June";mon[07]="July";mon[08]="Aug";
	mon[09]="Sep";mon[10]="Oct";mon[11]="Nov";mon[12]="Dec";
	document.write("<select name=");
	document.write(months);
	document.write(" style=width:70 id="+months+">");
	
	for(var i=1;i<=12;i++)
	{
		
		document.write("<option value='" + i + "' ");
		if(i==thismonth)document.write(" selected");
		document.write(">");
		document.write(mon[i]);
			
	}
	document.write("</select>");
	//alert(document.write(thismonth));
	return ;
}

function dtmonths_yrs(vname)
{
	today = new Date();
	thismonth = today.getMonth()+1;
	thisyear = today.getYear();
	if(thisyear < 999)	// netscape browser compatibilty
		thisyear += 1900;
	months=vname + "months";
	var mon=new Array(12);
	mon[01]="Jan";mon[02]="Feb";mon[03]="March";mon[04]="April";
	mon[05]="May";mon[06]="June";mon[07]="July";mon[08]="Aug";
	mon[09]="Sep";mon[10]="Oct";mon[11]="Nov";mon[12]="Dec";
	document.write("<select name=");
	document.write(months);
	document.write("  id="+months+">");
	for(var j=(thisyear - 2); j <=thisyear; j++)
	{
		for(var i=1;i<=12;i++)
		{
			if(i <10)
				document.write("<option value='" + j + "-0" + i +"' ");
			else				
				document.write("<option value='" + j + "-" + i + "' ");				
			if(i==thismonth && j==thisyear) document.write(" selected");
			document.write(">");
			document.write(mon[i]+ "-"+ j);
		}
	}
	document.write("</select>");
	//alert(document.write(thismonth));
	return ;
}

function dtmonthsqur(vname)
{
	today = new Date();
	thismonth = today.getMonth()+1;
	months=vname + "months";
	var mon=new Array(12);
	mon[01]="Jan-Mar";mon[02]="Apr-June";mon[03]="July-Sep";mon[04]="Oct-Dec";
	document.write("<select name=");
	document.write(months);
	document.write(" style=width:150 id="+months+">");
	document.write("<option value='ALL'>--Select Period--");
	for(var i=1;i<=4;i++)
	{
		document.write("<option value='" + mon[i] + "' ");
		//if(i==thismonth)document.write(" selected");
		document.write(">");
		document.write(mon[i]);
			
	}
	document.write("</select>");
	//alert(document.write(thismonth));
	return;
}

//this function is used for restiction of current month selection
function Check_Cur_Month(frm,f)
{
	var fyear=frm.elements[f+"years"].value;
	var fmonth=frm.elements[f+"months"].value;
	
	today = new Date();
	thismonth = today.getMonth()+1;
	thisyear = today.getYear();
	if (thisyear < 999 )
	thisyear = today.getYear()+1900;
	
	if(thisyear==fyear)
	{		
		if(fmonth==thismonth)
		{
			alert("Current month can not be selected.");
			return false;
		}
	}
	return true;
}//end of function


function Check_to_Month(frm,f,t)
{
	var fyear=frm.elements[f+"years"].value;
	var fmonth=frm.elements[f+"months"].value;

	var tyear=frm.elements[t+"years"].value;
	var tmonth=frm.elements[t+"months"].value;
	
	
	if(tyear<fyear)
	{
		alert("From Period can not be greater than To Period.");
		return false;
	}
	
	if(tyear==fyear)
	{ 
		if(fmonth > tmonth)
		{
			alert("From Period can not be greater than To Period.");
			return false;
		}
	}
	
	return true;
}//end of function

function trimAll(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

