var alertVar = 0;

function nothing(){}

function verifyInput_allNumbers( theInput ){


        if (alertVar == 1){
                alert("verifyInput_allNumbers begin");
        }

        var str = "0123456789";
        var n = theInput.length;
        var itMatches = 0;

        for (var i=0;i<n;i++){
                itMatches = 0;
                for (var j=0;j<str.length;j++){
                        if ( theInput.charAt(i) == str.charAt(j) ){
                                itMatches=1;
                        }
                }
                if (itMatches==0){
                        i=n;
                }
        }

        if ( itMatches == 0 ) {
                return false;
        }
        else{
                return true;
        }

}

function parseInput( theInput , dFormat ){

        if (alertVar == 1){
                alert("parseInput begin");
        }

        i11 = theInput.substring(0,2)*1;
        i22 = (theInput.substring(2,4)*1);

        if (dFormat==2||dFormat==4){
                iiDay=i22;
                iiMonth=i11-1;
        }
        else{
                iiDay=i11;
                iiMonth=i22-1;
        }


        iiYear = theInput.substring(4,8)*1;
        if (theInput.length==12){
                iiHour = theInput.substring(8,10)*1;
                iiMinute = theInput.substring(10,12)*1;
                sTodayIs = "Now";
        }
        else{
                sTodayIs = "Hoje";
        }


        if (alertVar == 1){
                alert("iiDay: ."+iiDay+".");
                alert("iiMonth: ."+iiMonth+".");
                alert("iiYear: ."+iiYear+".");
                alert("iiHour: ."+iiHour+".");
                alert("iiMinute: ."+iiMinute+".");
        }

        if ( verifyInput_DateTime( iiDay, iiMonth, iiYear, iiHour, iiMinute
)==0 ){
                setTimeNow();
        }

        if (alertVar == 1){
                alert("parseInput end");
        }
}

function verifyInput_DateTime( iiDay, iiMonth, iiYear, iiHour, iiMinute ){

        if (alertVar == 1){
                alert("verifyInput_DateTime begin");
        }
        returnBoolean = 0;

        iVal = parseInt(iiMonth);
        var num = ++iVal;

        if (alertVar == 1){
                alert("bakılan " + num);
        }

        switch ( num ){

                case  1:
                case  3:
                case  5:
                case  7:
                case  8:
                case 10:
                case 12:

                        if (iiDay<=31){
                                returnBoolean = 1;
                        }
                        break;

                case  4:
                case  6:
                case  9:
                case 11:

                        if (iiDay<=30){
                                returnBoolean = 1;
                        }
                        break;

                case  2:
                        if (isLeapYear(iiYear)){
                                if (iiDay<=29){
                                        returnBoolean = 1;
                                }
                        }
                        else{
                                if (iiDay<=28){
                                        returnBoolean = 1;
                                }
                        }
                        break;
        }


        if (iiHour!=""){
                if (iiHour>23||iiMinute>59){
                        returnBoolean = 0;
                }
        }

        if (alertVar == 1){
                alert("verifyInput_DateTime : " +returnBoolean);
        }
        return returnBoolean;

}


function setTimeNow(){

        if (alertVar == 1){
                alert("setTimeNow begin");
        }
        d = new Date();
        iiDay = d.getDate();
        iiMonth = d.getMonth();
        iiYear = d.getYear();
        iiHour = d.getHours();
        iiMinute = d.getMinutes();


        if (alertVar == 1){
                alert("iiDay: ."+iiDay+".");
                alert("iiMonth: ."+iiMonth+".");
                alert("iiYear: ."+iiYear+".");
                alert("iiHour: ."+iiHour+".");
                alert("iiMinute: ."+iiMinute+".");

                alert("setTimeNow end");
        }
}


function onafterload_c( iiDay, iiMonth, iiYear, iiHour, iiMinute ){

        if (alertVar == 1){
                alert("onafterload_c begin");
        }
        iSelDay = iiDay;
        iMonth = iiMonth;
        iYear = iiYear;
        iHour = iiHour;
        iMinute = iiMinute;

        clearAllDays();
        setCurrentDate(iYear, iMonth, iSelDay, iHour, iMinute);

        if (alertVar == 1){
                alert("onafterload_c end");
        }
}


function onafterload(iNextMonthDayPressed){
   setCurrentDate(iYear, iMonth, iNextMonthDayPressed, iHour, iMinute);
}



function controlAndOpen_calendar(theObj,dFormat){
        if ( document.getElementById('calendar').style.visibility ==
'hidden' ){
                showCalendar(theObj,'txtDate',dFormat);
        }
        else{
                hideCalendar();
        }
}
function controlAndOpen_DropDown(num){

        if (num==0){
                if (isOpen_DropDownMonth == 1){
                        popDownYear(0);
                        popUpMonth();
                }
                else{
                        popDownMonth(0);
                }
        }
        else{
                if (isOpen_DropDownYear == 1){
                        popDownMonth(1);
                        popUpYear();
                }
                else{
                        popDownYear(1);
                }
        }

}

function isLeapYear(y)
{
        return (y%4!=0) ? false : (y%100!=0) ? true : (y%400!=0) ? false :true;
}

function addDay(iDay)
{
        if(iMaxY==6)
                {iMaxY = 0; iMaxX++;}
        else
                iMaxY ++;
        document.getElementById("cell_" + iMaxX + "_" + iMaxY).innerHTML =String(iDay);
        document.getElementById("cell_" + iMaxX + "_" + iMaxY).onclick =function(){tdclick(this)};
}

function makeDaySelected(iDay)
{
        for(var x=0; x<=5; x++)
                for(var y=0; y<=6; y++)
                {
                        if(document.getElementById("cell_" + x + "_" +y).style.color=="")
                                if(document.getElementById("cell_" + x + "_"+ y).innerHTML==String(iDay))
                                        document.getElementById("cell_" + x + "_" + y).style.backgroundColor = "#cccccc";
                }
}

function getDaysNumberForMonth(iMonth, iYear)
{

        switch (iMonth+1)
        {
                case  1:
                case  3:
                case  5:
                case  7:
                case  8:
                case 10:
                case 12:
                        return(31);
                        break;
                case  4:
                case  6:
                case  9:
                case 11:
                        return(30);
                        break;
                case  2:
                        if (isLeapYear(iYear))
                                return(29)
                        else
                                return(28);
                        break;
        }
}

function checkToday()
{
        if((todayDate.getUTCFullYear() == iYear)&&(todayDate.getUTCMonth()+1 == monthName[iMonth]))
        {
                for(var x=0; x<=5; x++)
                        for(var y=0; y<=6; y++)
                                if((document.getElementById("cell_" + x + "_" + y).innerHTML == String(todayDate.getUTCDate()))&&(document.getElementById("cell_" + x + "_" + y).style.color != "gray"))
                                {
                                        document.getElementById("cell_" + x+ "_" + y).innerHTML += "<img src='imagens/select.gif'>";
                                        break;
                                }
        }
}

function gotoToday()
{
        d = new Date();
        d.setUTCMonth(todayDate.getUTCMonth());
        d.setUTCFullYear(todayDate.getUTCFullYear());
        iSelDay = d.getUTCDate();
        iMonth = d.getUTCMonth();
        iYear = d.getUTCFullYear();

        iHour = d.getHours();
        iMinute = d.getMinutes();

        clearAllDays();
        onafterload(todayDate.getUTCDate());

}

function fnShowPic(obj, mode)
{
        if (mode == 1)
                document.getElementById(obj).style.filter=''
        else
                document.getElementById(obj).style.filter='gray(),alpha(opacity=50)';
}

function setCurrentDate(iYear, iMonth, iDay, iHour, iMinute)
{
        var s;
        var iLastDayOfMonth;
        var tempDateObj = new Date();

  document.getElementById("spanMonth").innerHTML = "&nbsp;" + monthName[iMonth] + "&nbsp;<IMG id='changeMonth' style='filter: gray(),alpha(opacity=50);' SRC='imagens/dropcal.gif' BORDER=0 onmouseover='fnShowPic(\"changeMonth\",1)' onmouseout='fnShowPic(\"changeMonth\",0)'>";

        document.getElementById("spanYear").innerHTML ="&nbsp; <IMG id='changeYear' style='filter: gray(), alpha(opacity=50);' SRC='imagens/dropcal2.gif' BORDER=0 onmouseover='fnShowPic(\"changeYear\",1)' onmouseout='fnShowPic(\"changeYear\",0)'>" + "&nbsp;" + iYear;crossMonthObj=(dom)?document.getElementById("selectMonth").style :ie?document.all.selectMonth:document.selectMonth;crossYearObj=(dom)?document.getElementById("selectYear").style:ie?document.all.selectYear:document.selectYear;tempDateObj.setUTCFullYear(iYear, iMonth, 1);iLastDayOfMonth = getDaysNumberForMonth(iMonth, iYear);
        document.getElementById("txtToday").innerHTML = "<img src=\"imagens/select.gif\"><FONT SIZE=1>" + sTodayIs + "</FONT>";
        document.getElementById("txtToday").onclick =function(){gotoToday()};


        var iDisabledDayBefore = 0;
        var iPrevMonth;

        var iPrevYear = iYear;
        var iDaysInPrevMonth;
        if(tempDateObj.getUTCDay()>0)
                for(var x=0; x<tempDateObj.getUTCDay(); x++)
                {
                        iDisabledDayBefore++;
                }
        switch (iMonth)
        {
                case 0:
                        iPrevMonth = 11;
                        iPrevYear--;
                        break;
                default:
                        iPrevMonth = iMonth-1;
                        break;
        }
        iDaysInPrevMonth = getDaysNumberForMonth(iPrevMonth, iPrevYear);
        var arrTemp = new Array();

        if(tempDateObj.getUTCDay()>0)
        {
                for(var i=iDaysInPrevMonth-iDisabledDayBefore+1;i<=iDaysInPrevMonth;i++)
                {
                        arrTemp[arrTemp.length] = i;
                }
                for(var x=0; x<tempDateObj.getUTCDay(); x++)
                {
                        document.getElementById("cell_0_" + x).innerHTML =arrTemp[x];
                        document.getElementById("cell_0_" + x).onclick =function(){changeDate(2, this)};
                        document.getElementById("cell_0_" + x).style.color ="gray";
                        iMaxY++;
                }
        }
        else
        {
                for(var i=iDaysInPrevMonth-6; i<=iDaysInPrevMonth;i++)
                {
                        arrTemp[arrTemp.length] = i;
                }
                for(var x=0; x<=6; x++)
                {
                        document.getElementById("cell_0_" + x).innerHTML =arrTemp[x];
                        document.getElementById("cell_0_" + x).onclick =function(){changeDate(2, this)};
                        document.getElementById("cell_0_" + x).style.color ="gray";
                }

                iMaxX++;
                iMaxY = 0;
        }

        document.getElementById("cell_" + iMaxX + "_" + iMaxY).innerHTML ="1";
        document.getElementById("cell_" + iMaxX + "_" + iMaxY).onclick =function(){tdclick(this)};

        for(var iCurrentDay = 2; iCurrentDay <= iLastDayOfMonth;iCurrentDay++)
                addDay(iCurrentDay)
                makeDaySelected(iDay);

        var iNextDays = 1;
        for(var i=iMaxY+1; i<=6; i++)
        {
                document.getElementById("cell_" + iMaxX + "_" + i).innerHTML= iNextDays;
                document.getElementById("cell_" + iMaxX + "_" + i).onclick =function(){changeDate(3, this)};
                document.getElementById("cell_" + iMaxX + "_" + i).style.color = "gray";
                iNextDays++;
        }
        if(iMaxX<5)
        {
                iMaxX++;
                iMaxY=0;
                for(var i=iMaxY; i<=6; i++)
                {
                        document.getElementById("cell_" + iMaxX + "_" + i).innerHTML = iNextDays;
                        document.getElementById("cell_" + iMaxX + "_" + i).onclick = function(){changeDate(3, this)};
                        document.getElementById("cell_" + iMaxX + "_" + i).style.color = "gray";
                        iNextDays++;
                }
        }
        bIsLoaded = true;


        if (sTodayIs.indexOf("Now")!=-1){

                if(iHour<10){
                        self.document.frmCalendar.txt_hh.value="0"+iHour;
                }
                else{
                        self.document.frmCalendar.txt_hh.value=iHour;
                }

                if(iMinute<10){
                        self.document.frmCalendar.txt_mm.value="0"+iMinute;
                }
                else{
                        self.document.frmCalendar.txt_mm.value=iMinute;
                }

                self.document.frmCalendar.txt_hh.focus();
        }
        else{
                self.document.frmCalendar.txt_hh.value="";
                self.document.frmCalendar.txt_mm.value="";
        }

        checkToday();
}


function changeDate(mode, obj)
{	
        var iNextMonthDayPressed = null;
        if(bIsLoaded)
        {
                switch (mode)
                {
                        case 0:
                                d.setUTCMonth(obj);
                                break;
                        case 1:
                                d.setUTCFullYear(obj);
                                break;
                        case 2:
                                if(obj != null) 
				{
					iNextMonthDayPressed =obj.innerHTML;
				}
                                switch (d.getUTCMonth())
                                {
                                        case 0:
                                                d.setUTCMonth(11); 
						d.setUTCFullYear(d.getUTCFullYear()-1);
                                                break;
                                        default: 
						d.setUTCMonth(d.getUTCMonth()-1);
                                                break;
                                }
                                break;
                        case 3:
                                if(obj != null) iNextMonthDayPressed =obj.innerHTML;
                                switch (d.getUTCMonth())
                                {
                                        case 11:
                                                d.setUTCMonth(0); 
						d.setUTCFullYear(d.getUTCFullYear()+1);
                                                break;
                                        default: 
						d.setUTCMonth((d.getUTCMonth()+1));
                                                break;
                                }
                                break;
                }
                iMonth = d.getUTCMonth();
                iYear = d.getUTCFullYear();
                clearAllDays();
                iSelDay = iNextMonthDayPressed;
                onafterload(iNextMonthDayPressed);
        }
}

function clearAllDays()
{
        setAllCellsNoColor();
        for(var x=0; x<=5; x++)
                for(var y=0; y<=6; y++)
                {
                        document.getElementById("cell_" + x + "_" + y).innerHTML = "";
                        document.getElementById("cell_" + x + "_" + y).onclick = "";
                        document.getElementById("cell_" + x + "_" + y).style.color = "";
                        document.getElementById("cell_" + x + "_" + y).background = "";
                }
        iMaxX = 0;
        iMaxY = 0;
}

function setAllCellsNoColor()
{
        for(var x=0; x<=5; x++)
                for(var y=0; y<=6; y++)
                {
                        document.getElementById("cell_" + x + "_" + y).style.backgroundColor = "";
                }
}

function tdclick(obj)
{
        setAllCellsNoColor()
        if(obj.innerHTML!="")
        {
                obj.style.backgroundColor = "cccccc";
                iSelDay = obj.innerHTML;
        }
        fnRetVal();hideCalendar();
}

function fnRetVal()
{
        var retval = "";
        var sSeparator, hourSeparator, separatorBoth;
        var data = document.frmCalendar;
        sSeparator = "/";
        hourSeparator = "/";
        separatorBoth = "/";
        if(iSelDay==null) iSelDay=0;
        var sMonth = String(iMonth+1);
        var sSelDay = iSelDay;
        if(String(iMonth+1).length==1) sMonth = "0" + sMonth;
        if(String(sSelDay).length==1) sSelDay = "0" + sSelDay;
        var sHH = document.getElementById("txt_hh").value+"";
        var sMM = document.getElementById("txt_mm").value+"";

        if ( !(sHH.indexOf(" ")!=-1 || sHH.indexOf("  ")!=-1 || sMM.indexOf(" ")!=-1 || sMM.indexOf("  ")!=-1) ){
                if(sHH.length==1){
                        sHH="0"+sHH;
                }

                if(sMM.length==1){
                        sMM="0"+sMM;
                }
        }
        else{
                sHH="";
                sMM="";
        }

        switch (lngFormat)
        {
                case 1:
                        if(iSelDay!=0)
                                retval += sSelDay + sSeparator + sMonth + sSeparator + iYear;
                        else
                                retval = -1;
                        break;
                case 2:
                        if(iSelDay!=0)
                                retval += sMonth + sSeparator + sSelDay + sSeparator + iYear;
                        else
                                retval = -1;
                        break;
                case 3:
                        if(iSelDay!=0)
                                retval += sSelDay + sSeparator + sMonth + sSeparator + iYear + separatorBoth + sHH + hourSeparator + sMM;
                        else
                                retval = -1;
                        break;
                case 4:
                        if(iSelDay!=0)
                                retval += sMonth + sSeparator + sSelDay + sSeparator + iYear  + separatorBoth + sHH + hourSeparator + sMM;
                        else
                                retval = -1;
                        break;
        }
        if(retval!=-1) {document.getElementById(objRetName).value = retval;}
}

function hideElement( elmID, overDiv )
{
        if(ie)
        {
                for( i = 0; i < document.all.tags(elmID).length; i++ )
                {
                        obj = document.all.tags(elmID)[i];
                        if( !obj || !obj.offsetParent )        continue;
                        objLeft = obj.offsetLeft;
                        objTop = obj.offsetTop;
                        objParent = obj.offsetParent;
            while( objParent.tagName.toUpperCase() != "BODY" )
                        {
                                objLeft += objParent.offsetLeft;
                                objTop  += objParent.offsetTop;
                                objParent = objParent.offsetParent;
                        }
            objHeight = obj.offsetHeight;
                        objWidth = obj.offsetWidth;
            if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
                        else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
                        else if( overDiv.offsetTop >= ( objTop + objHeight));
                        else if( overDiv.offsetLeft >= ( objLeft + objWidth));
                        else
                        {
                                if(obj.id!="selMonth"&&obj.id!="selYear")
				obj.style.visibility = "hidden";
                        }
                }
        }
}

function swapImage(srcImg, destImg)
{
        if (ie)        {
document.getElementById(srcImg).setAttribute("src",imgDir + destImg) }
}

function showElement( elmID )
{
        if(ie)
        {
                for( i = 0; i < document.all.tags(elmID).length; i++ )
                {
                        obj = document.all.tags( elmID )[i];
            if( !obj || !obj.offsetParent ) continue;
                    obj.style.visibility = "";
                }
        }
}

function showCalendar(obj, RetName, dFormat)
{
        isOpen_calendar = -isOpen_calendar;
        var leftpos = 0;
        var toppos = 0;
        aTag = new Object(obj);
        lngFormat = dFormat;
        objRetName = RetName;

        if (dFormat==3||dFormat==4)
	document.getElementById("div_time").style.display = "block";

        var crossobj = document.getElementById("calendar").style;

        do
        {
                aTag = aTag.offsetParent;
                leftpos += aTag.offsetLeft;
                toppos += aTag.offsetTop;
        }
        while(aTag.tagName!="BODY");

        crossobj.left = fixedX==-1 ? obj.offsetLeft + leftpos :fixedX;
        crossobj.top = fixedY==-1 ? obj.offsetTop + toppos +obj.offsetHeight +2 : fixedY;
        crossobj.visibility=(dom||ie)? "visible" : "show";
        hideElement( 'SELECT', document.getElementById("calendar") );
        hideElement( 'APPLET', document.getElementById("calendar") );

        var theInput = obj.value;

        if (alertVar == 1){
                alert("theInput: ." + theInput + ".");
        }

        if (theInput!=""){

                if (alertVar == 1){
                        alert("length: ." + theInput.length + ".");
                }

                if ( (theInput.length==8||theInput.length==12) && verifyInput_allNumbers( theInput ) ){
                        if (alertVar == 1){
                                alert("correct");
                        }
                        parseInput( theInput, dFormat );
                }
                else{
                        if (alertVar == 1){
                                alert("incorrect");
                        }
                        setTimeNow();
                }

                onafterload_c( iiDay, iiMonth, iiYear, iiHour, iiMinute );
        }
        else{
                sTodayIs = "Hoje";
                if (alertVar == 1){
                        alert("empty theInput: ." + theInput + ".");
                }
        }



}

function hideCalendar()
{
        isOpen_calendar = -isOpen_calendar;
    showElement( 'SELECT' );
        showElement( 'APPLET' );
        crossMonthObj.visibility = "hidden";
        crossYearObj.visibility = "hidden";
        document.getElementById("calendar").style.visibility = "hidden";

}

function constructMonth()
{
        popDownYear(0);
        document.onselectstart=new Function ("return false")	
        if (!monthConstructed)
        {
                sHTML = ""
                for (i=0; i<12; i++)
                {
                        sName = monthName[i];
                        if (i==iMonth){
                                sName = "<B>" + sName + "</B>"
                        }
                        sHTML += "<tr><td id='m" + i + "'style='cursor:default' onmouseout='this.style.backgroundColor=\"\";this.style.color=\"black\"' onclick='monthConstructed=false;monthSelected=" + i +";popDownMonth(0);event.cancelBubble=true;changeDate(0, " + i + ");'>&nbsp;" + sName + "&nbsp;</td></tr>"
                }
                document.getElementById("selectMonth").innerHTML = "<table style='font-family:verdana; font-size:9px; border-width:1; border-style:solid; border-color:#000080;' bgcolor='#FFFFFF' cellspacing=0 onmouseover='clearTimeout(timeoutID2)' onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownMonth(1)\",100)' " + sHTML + "</table>"
                monthConstructed=true
        }

}

function popUpMonth()
{
        isOpen_DropDownMonth=-1;
        var crossobj1 = document.getElementById("spanMonth");

        constructMonth()
        crossMonthObj.visibility = (dom||ie)? "visible" : "show";
        crossMonthObj.left = parseInt(crossobj1.offsetWidth);
        crossMonthObj.top =         parseInt(crossobj1.offsetHeight);

        hideElement( 'SELECT', document.getElementById("selectMonth") );
        hideElement( 'APPLET', document.getElementById("selectMonth") );
        fnShowPic("changeMonth",1);
}

function popDownMonth(fromWhere)
{

        if (fromWhere==1){
                document.onselectstart=new Function ("return false");
        }
        else{
                document.onselectstart=new Function ("return true");
        }

        isOpen_DropDownMonth=1;
        crossMonthObj.visibility = "hidden";
        fnShowPic("changeMonth",0);
}

function incYear()
{
        for        (i=0; i<7; i++)
        {
                newYear        = (i+nStartingYear)+1
                if (newYear==iYear)
                        txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;"
                else
                        txtYear = "&nbsp;" + newYear + "&nbsp;";
                document.getElementById("y"+i).innerHTML = txtYear;
        }
        nStartingYear ++;
        bShow=true
}

function incYear10()
{
        for        (i=0; i<7; i++)
        {
                newYear        = (i+nStartingYear)+10;
                if (newYear==iYear)
                        txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;"
                else
                        txtYear = "&nbsp;" + newYear + "&nbsp;";
                document.getElementById("y"+i).innerHTML = txtYear;
        }
        nStartingYear = nStartingYear + 10;
        bShow=true
}

function decYear()
{
        for        (i=0; i<7; i++)
        {
                newYear        = (i+nStartingYear)-1;
                if (newYear==iYear)
                        txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;"
                else
                        txtYear = "&nbsp;" + newYear + "&nbsp;"
                document.getElementById("y"+i).innerHTML = txtYear;
        }
        nStartingYear --;
        bShow=true
}

function decYear10()
{
        for        (i=0; i<7; i++)
        {
                newYear        = (i+nStartingYear)-5;
                if (newYear==iYear)
                        txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;"
                else
                        txtYear = "&nbsp;" + newYear + "&nbsp;"

                document.getElementById("y"+i).innerHTML = txtYear;
        }
        nStartingYear = nStartingYear - 5;
        bShow=true
}

function selectYear(nYear)
{
        yearSelected = parseInt(nYear+nStartingYear);
        yearConstructed = false;
        popDownYear(1);
        changeDate(1,yearSelected);
}

function popDownYear(fromWhere)
{

        if (fromWhere==0){
                document.onselectstart=new Function ("return false");
        }
        else{
                document.onselectstart=new Function ("return true");
        }

        isOpen_DropDownYear=1;
        crossYearObj.visibility= "hidden";
}

function constructYear()
{
        popDownMonth(1);
        sHTML =        "";
        if (!yearConstructed)
        {
                sHTML ="<tr><td align='center'style='cursor:default'onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\"\"'onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval(intervalID1)'>-1</td>" +"<td align='center' style='cursor:default'onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\"\"'onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear10()\",1)' onmouseup='clearInterval(intervalID1)'>-10</td></tr>"

                j =        0;
                nStartingYear = iYear-3;
                for        (i=(iYear-3); i<=(iYear+3); i++)
                {
                        sName =        i;
                        if (i==iYear)
                        {
                                sName =        "<B>" +        sName +"</B>";
                        }

                        sHTML += "<tr><td colspan=2 id='y" + j + "'style='cursor:default'onmouseout='this.style.backgroundColor=\"\";this.style.color=\"black\"'onclick='selectYear("+j+");event.cancelBubble=true'>&nbsp;" + sName +"&nbsp;</td></tr>";
                        j ++;
                }

                sHTML += "<tr><td align='center' style='cursor:default'onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\"\"'style='cursor:pointer'onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear()\",30)'        onmouseup='clearInterval(intervalID2)'>+1</td>" +"<td align='center' style='cursor:default'onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\"\"'style='cursor:pointer'onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear10()\",1)'        onmouseup='clearInterval(intervalID2)'>+10</td></tr>"

                document.getElementById("selectYear").innerHTML        ="<table style='font-family:verdana; font-size:9px; border-width:1; border-style:solid; border-color:#000080;' bgcolor='#FFFFFF'onmouseover='clearTimeout(timeoutID2)'onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownYear(1)\",100)' cellspacing=0>" + sHTML + "</table>"

                yearConstructed        = true;
        }
}


function popUpYear()
{
        isOpen_DropDownYear=-1;
        var crossobj2 = document.getElementById("spanYear");
        var leftOffset;
        constructYear();
        crossYearObj.visibility        = (dom||ie)? "visible" : "show";
        leftOffset = parseInt(crossobj2.offsetWidth) +
document.getElementById("spanYear").offsetLeft;
        if (ie)
        {
                leftOffset += 6;
        }
        crossYearObj.left = parseInt(crossobj2.offsetWidth) +        65;
        crossYearObj.top = parseInt(crossobj2.offsetHeight);
}


var isOpen_calendar = 1;
var isOpen_DropDownMonth = 1;
var isOpen_DropDownYear = 1;

var iiDay = "";
var iiMonth = "";
var iiYear = "";
var iiHour = "";
var iiMinute = "";

var fixedX = -1
var fixedY = -1
var imgDir = "images"
var monthConstructed = false;
var yearConstructed = false;

var yearSelected;
var crossMonthObj, crossYearObj;
var intervalID1,timeoutID2,intervalID2,timeoutID1;
var nStartingYear;

var iMinYear = 1900;
var iMaxYear = 2100;
var iMaxX = 0;
var iMaxY = 0;
var bIsLoaded = false;
var iSelDay = 0;

var lngFormat = 1;
var objRetName;

var d = new Date();
var iMonth = d.getMonth();
var iYear = d.getFullYear();
var iHour = d.getHours();
var iMinute = d.getMinutes();
var todayDate = new Date();
var sTodayIs = "Hoje";

var ie=document.all;
var dom=document.getElementById;

var monthName = new Array("Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro")

document.write(""+"<div onclick='bShow=true' id='calendar' style='z-index:+999;position:absolute;visibility:hidden;'>"+ "<FORM name=\"frmCalendar\" method=\"post\">" + "<TABLE width=180 cellSpacing=0 cellPadding=0 border=0 style='BORDER-RIGHT: #a0a0a0 1px solid; BORDER-TOP: #a0a0a0 1px solid; FONT-SIZE: 11px; BORDER-LEFT: #a0a0a0 1px solid; BORDER-BOTTOM: #a0a0a0 1px solid; FONT-FAMILY: arial' align=center valign=middle bgColor=white>" + "<TR>"+ "<TD align=left class=\"buttons\" onclick=\"changeDate(2,null);\" onmouseover=\"document.getElementById('arL').style.filter='';\" onmouseout=\"document.getElementById('arL').style.filter='gray(), alpha(opacity=50)';\">&nbsp;&nbsp;<img id='arL' style=\"filter: 'gray(), alpha(opacity=50)'\" src='imagens/left.gif'></TD>"+"<TD width=150><span id='spanMonth' style='cursor:pointer' onmouseover='fnShowPic(\"changeMonth\",1);window.status=\"Click to select a month.\"' onmouseout='fnShowPic(\"changeMonth\",0);window.status=\"\"' onclick='controlAndOpen_DropDown(0)'></span>&nbsp;<div id='selectMonth' style='z-index:+999;position:absolute;visibility:hidden;'></div></TD>"+"<TD nowrap><span id='spanYear' style='cursor:pointer' onmouseover='fnShowPic(\"changeYear\",1);window.status=\"Click to select a year.\"' onmouseout='fnShowPic(\"changeYear\",0);window.status=\"\"' onclick='controlAndOpen_DropDown(1)'></span><div id='selectYear' style='z-index:+999;position:absolute;visibility:hidden;'></div>&nbsp;</TD>"+"<TD nowrap class=\"buttons\" onclick=\"changeDate(3,null);\" onmouseover=\"document.getElementById('arR').style.filter='';\" onmouseout=\"document.getElementById('arR').style.filter='gray(), alpha(opacity=50)';\"><img id='arR' style=\"filter: 'gray(), alpha(opacity=50)'\" src='imagens/right.gif'>&nbsp;</TD>"+"</TR>"+"<TR>"+"<TD colspan=4>"+"<TABLE style=\"WIDTH: 100%\" cellSpacing=0 cellPadding=0 width=\"100%\" align=center border=0>"+"<TR>"+"<TD class=\"WEEKEND\">DOM</TD>"+ "<TD class=\"DAYOFWEEK\">SEG</TD>"+"<TD class=\"DAYOFWEEK\">TER</TD>"+"<TD class=\"DAYOFWEEK\">QUA</TD>"+"<TD class=\"DAYOFWEEK\">QUI</TD>"+"<TD class=\"DAYOFWEEK\">SEX</TD>"+"<TD class=\"WEEKEND\">SAB</TD>"+"</TR>"+"<TR>"+"<TD colspan=7><HR></TD>"+"</TR>");


for(var a = 0; a <=5; a++)
{
        document.write(""+

                "<TR id=\"cell_" + String(a) + "\">");

        for(var b = 0; b<=6; b++)
        {
                document.write(""+"<TD id=\"cell_" + String(a) + "_" + String(b) + "\"class=\"ALLDAYS\" onmouseover=\"this.className='ALLDAYSUP'\"onmouseout=\"this.className='ALLDAYS'\" onclick=\"tdclick(this)\"></TD>");

        }
        document.write(""+"</TR>");

}

document.write(""+"</TABLE>"+"</TD>"+ "</TR>"+ "</TABLE>"+"<TABLE width=180 cellSpacing=0 cellPadding=0 border=0 style='BORDER-RIGHT: #a0a0a0 1px solid; BORDER-TOP: #a0a0a0 1px solid; BORDER-LEFT: #a0a0a0 1px solid; BORDER-BOTTOM: #a0a0a0 1px solid;' align=center valign=middle bgColor=white>" +"<TR>"+ "<TD colspan=2><div id=\"txtToday\"style='cursor:default'></div><div id='div_time'style='display:none'>HH<input type='text' class='hhmm' id='txt_hh' size='1'maxlength='2' onkeyup='if(isNaN(this.value)||this.value>23||this.value<0)this.value=\"\"'onchange='if(isNaN(this.value)||this.value>23||this.value<0)this.value=\"\"'>MM<input type='text' class='hhmm' id='txt_mm' size='1'maxlength='2' onkeyup='if(isNaN(this.value)||this.value>59||this.value<0)this.value=\"\"'onchange='if(isNaN(this.value)||this.value>59||this.value<0)this.value=\"\"'></div></TD>"+"<TD class=\"ALLDAYS\"></TD>"+"<TD class=\"ALLDAYS\"><span onclick=\"hideCalendar();\"id='img_2'><FONT FACE=Times New Roman SIZE=1>Cancelar</FONT></span></TD>"+"</TR>"+"</TABLE>"+"</FORM>"+"</DIV>");

onafterload(null);

