//... 13/04/2004	
var fixedX = -1, fixedY =-1	
var startAt = 1		
var showWeekNumber = 1
var showToday = 1
var imgDir="Images/"
var countDW= 6
var txtFW="", txtLW=""
var txtName=""
var FirstW, LastW
var format="dd/mm/yyyy"
var formatEN="mm/dd/yyyy"
var optionCal
var Language

var gotoString = "Choose this month"
var todayString = "Today is "				
var weekString = "Week"			
var scrollLeftMessage = "Choose previous month."
var scrollRightMessage = "Choose next month."
var selectMonthMessage = "Choose month."
var selectYearMessage = "Choose year."
var selectDateMessage2 = "Week from: [date1] -->" // do not replace [date], it will be replaced by date.
var selectDateMessage1 = " [date2]"	
var selectDateMessage = "Day: [date]" // do not replace [date], it will be replaced by date.

var	crossobj, crossMonthObj, crossYearObj, monthSelected, yearSelected, dateSelected, omonthSelected, oyearSelected, odateSelected, monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2, ctlToPlaceValue, ctlNow, dateFormat, nStartingYear;
var BD,BM,BY; 
var NgayClient=new Date(); 
var month_prev,year_prev,on_prev;
var month_next,year_next,ok_next;
var ok;

var	bPageLoaded=false
var	ie=document.all
var	dom=document.getElementById	

var	ns4=document.layers
var	today =	new	Date()
var	dateNow	 = today.getDate() 
var	monthNow = today.getMonth()
var	yearNow	 = today.getYear()
var dateChoose = 0, monthChoose = 0, yearChoose = 0

var	imgsrc = new Array("C_Drop1.gif","C_Drop2.gif","C_Left1.gif","C_Left2.gif","C_Right1.gif","C_Right2.gif")
var	img	= new Array()

var bShow = false;

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 obj.style.visibility = "hidden";
        }
    }
}
function showElement_CLD(elmID){
    if(ie){
        for(i_CLDS=0;i_CLDS<document.all.tags(elmID).length;i_CLDS++){
            obj = document.all.tags(elmID)[i_CLDS];
            if(!obj||!obj.offsetParent) continue;
            obj.style.visibility = "";
        }
    }
}
function HolidayRec(d,m,y,desc){
    this.d = d
    this.m = m
    this.y = y
    this.desc = desc
}
var HolidaysCounter = 0
var Holidays = new Array()
function addHoliday(d,m,y,desc){
    Holidays[HolidaysCounter++] = new HolidayRec(d,m,y,desc)
}
if(dom){
    for(i_CLD=0;i_CLD<imgsrc.length;i_CLD++){
        img[i_CLD] = new Image
        img[i_CLD].src = imgDir + imgsrc[i_CLD]
    }
    document.write("<div onclick='bShow=true' id='Calendar'	style='z-index:+999;position:absolute;visibility:hidden;'><table width="+((showWeekNumber==1)?250:220)+" style='font-family:arial;font-size:11px;border-width:1;border-style:solid;border-color:#000000;font-family:arial; font-size:11px}' bgcolor='#ffffff'><tr bgcolor='#4682B4'><td><table width='"+((showWeekNumber==1)?248:218)+"'><tr><td style='padding:2px;font-family:arial; font-size:11px;'><font color='#ffffff'><B><span id='caption'></span></B></font></td><td align=right><a onclick='hideCalendar()'><IMG SRC='"+imgDir+"C_Close.gif' WIDTH='15' HEIGHT='13' BORDER='0' ALT='Close the Calendar'></a></td></tr></table></td></tr><tr><td style='padding:5px' bgcolor=#DBF1F5><span id='content'></span></td></tr>")
    if (showToday==1) document.write("<tr bgcolor=#4682B4><td style='padding:5px' align=center><span id='lblToday'></span></td></tr>")
    document.write("</table></div><div id='selectMonth' style='z-index:+999;position:absolute;visibility:hidden;'></div><div id='selectYear' style='z-index:+999;position:absolute;visibility:hidden;'></div>");
}
var	monthName =	new	Array("January","February","March","April","May","June","July","August","September","October","November","December")
var	monthNumber =new Array("01","02","03","04","05","06","07","08","09","10","11","12")
var	dayNumber=new Array("00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31")
if (startAt==0){
    dayName = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
    fullDayName = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")		
}else{
    dayName = new Array("Mon","Tue","Wed","Thu","Fri","Sat","Sun")
    fullDayName = new Array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday", "Sunday")
}
function Convert_Language(language){
    if(language=='en'){
        monthName =	new	Array("January","February","March","April","May","June","July","August","September","October","November","December")
        monthNumber =new Array("01","02","03","04","05","06","07","08","09","10","11","12")
        dayNumber=new Array("00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31")
        if(startAt==0){
            dayName = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
            fullDayName = new Array("Sun","Mon","Tue","Wed","Thur","Fri","Sat")
        }else{
            dayName = new Array("Mon","Tue","Wed","Thu","Fri","Sat","Sun")				
            fullDayName = new Array("Mon","Tue","Wed","Thur","Fri","Sat","Sun")
        }
        gotoString = "Choose this month"
        todayString = "Today is "				
        weekString = "Week"			
        scrollLeftMessage = "Choose previous month."
        scrollRightMessage = "Choose next month."
        selectMonthMessage = "Choose month."
        selectYearMessage = "Choose year."
        selectDateMessage2 = "Week from: [date1] -->"
        selectDateMessage1 = " [date2]"			
        selectDateMessage = "Day: [date]"
    }	
}
var	styleAnchor="text-decoration:none;color:#FFFFFF;"
var	styleLightBorder="border-style:solid;border-width:1px;border-color:#b0a0a0;background-color: none;"

function swapImage(srcImg, destImg){
    if(ie) document.getElementById(srcImg).setAttribute("src",imgDir+destImg) 
}
function init(){
    Convert_Language(Language);	
    if(!ns4){
        if(!ie){ yearNow += 1900 }
        crossobj=(dom)?document.getElementById("Calendar").style : ie? document.all.Calendar : document.Calendar
        hideCalendar()
        crossMonthObj=(dom)?document.getElementById("selectMonth").style : ie? document.all.selectMonth	: document.selectMonth
        crossYearObj=(dom)?document.getElementById("selectYear").style : ie? document.all.selectYear : document.selectYear
        monthConstructed=false;
        yearConstructed=false;
        if (showToday==1)
            if (Language=='vi') document.getElementById("lblToday").innerHTML =	"<font style='color:#FFFFFF'>"+todayString + fullDayName[(today.getDay()-startAt==-1)?6:(today.getDay()-startAt)]+", " + monthName[monthNow] + " " + dayNumber[dateNow] + ", " +	yearNow	+ "</font>"
            else document.getElementById("lblToday").innerHTML =	"<font style='color:#FFFFFF'>"+todayString + fullDayName[(today.getDay()-startAt==-1)?6:(today.getDay()-startAt)]+", " + monthNumber[monthNow] + "/" + dayNumber[dateNow] + "/" + yearNow	+ "</font>"
            sHTML1="<span id='spanLeft'	style='border-style:solid;border-width:1;border-color:#FFFFFF;cursor:pointer' onmouseover='swapImage(\"changeLeft\",\"c_left2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+scrollLeftMessage+"\"' onclick='javascript:decMonth()' onmouseout='clearInterval(intervalID1);swapImage(\"changeLeft\",\"c_left1.gif\");this.style.borderColor=\"#FFFFFF\";window.status=\"\"' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartDecMonth()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'>&nbsp<IMG id='changeLeft' SRC='"+imgDir+"c_left1.gif' width=10 height=11 BORDER=0>&nbsp</span>&nbsp;"
            sHTML1+="<span id='spanRight' style='border-style:solid;border-width:1;border-color:#FFFFFF;cursor:pointer'	onmouseover='swapImage(\"changeRight\",\"c_right2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+scrollRightMessage+"\"' onmouseout='clearInterval(intervalID1);swapImage(\"changeRight\",\"c_right1.gif\");this.style.borderColor=\"#FFFFFF\";window.status=\"\"' onclick='incMonth()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartIncMonth()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'>&nbsp<IMG id='changeRight' SRC='"+imgDir+"c_right1.gif' width=10 height=11 BORDER=0>&nbsp</span>&nbsp"
            sHTML1+="<span id='spanMonth' style='border-style:solid;border-width:1;border-color:#FFFFFF;cursor:pointer'	onmouseover='swapImage(\"changeMonth\",\"c_drop2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+selectMonthMessage+"\"' onmouseout='swapImage(\"changeMonth\",\"c_drop1.gif\");this.style.borderColor=\"#FFFFFF\";window.status=\"\"' onclick='popUpMonth()'></span>&nbsp;"
            sHTML1+="<span id='spanYear' style='border-style:solid;border-width:1;border-color:#FFFFFF;cursor:pointer' onmouseover='swapImage(\"changeYear\",\"c_drop2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+selectYearMessage+"\"'	onmouseout='swapImage(\"changeYear\",\"c_drop1.gif\");this.style.borderColor=\"#FFFFFF\";window.status=\"\"'	onclick='popUpYear()'></span>&nbsp;"
            document.getElementById("caption").innerHTML  =	sHTML1
            bPageLoaded=true
           
    }
}
function hideCalendar(){
   if (crossobj!=null) crossobj.visibility="hidden";
    if(crossMonthObj!=null){crossMonthObj.visibility="hidden"}
    if(crossYearObj!=null){crossYearObj.visibility="hidden"}
    showElement_CLD('SELECT');
    showElement_CLD('APPLET');
}
function padZero(num){
    return (num<10)? '0' + num : num ;
}
function constructDate(d,m,y){
    sTmp = dateFormat;
    sTmp = sTmp.replace("dd","<e>");
    sTmp = sTmp.replace("d","<d>");
    sTmp = sTmp.replace("<e>",padZero(d));
    sTmp = sTmp.replace("<d>",d);
    sTmp = sTmp.replace("mmm","<o>");
    sTmp = sTmp.replace("mm","<n>");
    sTmp = sTmp.replace("m","<m>");
    sTmp = sTmp.replace("<m>",m+1);
    sTmp = sTmp.replace("<n>",padZero(m+1));
    sTmp = sTmp.replace("<o>",monthName[m]);
    return sTmp.replace("yyyy",y);
}
function constructDateEN(d,m,y) {
    
    sTmp = formatEN;
    sTmp = sTmp.replace("dd","<e>");
    sTmp = sTmp.replace("d","<d>");
    sTmp = sTmp.replace("<e>",padZero(d));
    sTmp = sTmp.replace("<d>",d);
    sTmp = sTmp.replace("mmm","<o>");
    sTmp = sTmp.replace("mm","<n>");
    sTmp = sTmp.replace("m","<m>");
    sTmp = sTmp.replace("<m>",m+1);
    sTmp = sTmp.replace("<n>",padZero(m+1));
    sTmp = sTmp.replace("<o>",monthName[m]);
    return sTmp.replace("yyyy",y);
}
function StartDecMonth(){
    intervalID1=setInterval("decMonth()",80)
}
function StartIncMonth(){
    intervalID1=setInterval("incMonth()",80)
}
function incMonth(){
    monthSelected++
    if(monthSelected>11){
        monthSelected=0
        yearSelected++
    }
    constructCalendar()
}
function decMonth(){
    monthSelected--
    if(monthSelected<0){
        monthSelected=11
        yearSelected--
    }
    constructCalendar()
}
function constructMonth(){
    popDownYear()
    if(!monthConstructed){
        sHTML =	""
        for(i=0;i<12;i++){
            sName =	monthName[i];
            if(i==monthSelected) sName = "<B>" +	sName +	"</B>"
            sHTML += "<tr><td id='m" + i + "' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='monthConstructed=false;monthSelected=" + i + ";constructCalendar();popDownMonth();event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
        }
        document.getElementById("selectMonth").innerHTML = "<table width=103 style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#a0a0a0;' bgcolor='#FFFFDD' cellspacing=0 onmouseover='clearTimeout(timeoutID1)'	onmouseout='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"popDownMonth()\",100);event.cancelBubble=true'>" +sHTML +"</table>"
        monthConstructed=true
    }
}
function popUpMonth(){
    constructMonth()
    crossMonthObj.visibility = (dom||ie)? "visible"	: "show"
    crossMonthObj.left = parseInt(crossobj.left) + 50
    crossMonthObj.top =	parseInt(crossobj.top) + 26
    hideElement('SELECT',document.getElementById("selectMonth"));
    hideElement('APPLET',document.getElementById("selectMonth"));			
}
function popDownMonth(){
    crossMonthObj.visibility= "hidden"
}
function incYear(){
    for(i=0;i<7;i++){
        newYear	= (i+nStartingYear)+1
        if(newYear==yearSelected) txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;" 
        else txtYear = "&nbsp;" + newYear + "&nbsp;"
        document.getElementById("y"+i).innerHTML = txtYear
    }
    nStartingYear ++;
    bShow=true
}
function decYear(){
    for(i=0;i<7;i++){
        newYear	= (i+nStartingYear)-1
        if(newYear==yearSelected) txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;" 
        else txtYear = "&nbsp;" + newYear + "&nbsp;" 
        document.getElementById("y"+i).innerHTML = txtYear
    }
    nStartingYear --;
    bShow=true
}
function selectYear(nYear){
    yearSelected=parseInt(nYear+nStartingYear);
    yearConstructed=false;
    constructCalendar();
    popDownYear();
}
function constructYear(){
    popDownMonth()
    sHTML =	""
    if(!yearConstructed){
        sHTML =	"<tr><td align='center'	onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\"\"' style='cursor:pointer'	onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval(intervalID1)'>-</td></tr>"
        j =	0
        nStartingYear =	yearSelected-3
        for(i=(yearSelected-3);i<=(yearSelected+3);i++){
            sName =	i;
            if(i==yearSelected) sName =	"<B>" +	sName +	"</B>"
            sHTML += "<tr><td id='y" + j + "' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='selectYear("+j+");event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
            j ++;
        }
        sHTML += "<tr><td align='center' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear()\",30)'	onmouseup='clearInterval(intervalID2)'>+</td></tr>"
        document.getElementById("selectYear").innerHTML	= "<table width=44 style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#a0a0a0;'	bgcolor='#FFFFDD' onmouseover='clearTimeout(timeoutID2)' onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownYear()\",100)' cellspacing=0>"	+ sHTML	+ "</table>"
        yearConstructed	= true
    }
}
function popDownYear(){
    clearInterval(intervalID1)
    clearTimeout(timeoutID1)
    clearInterval(intervalID2)
    clearTimeout(timeoutID2)
    crossYearObj.visibility= "hidden"
}
function popUpYear(){
    var	leftOffset
    constructYear()
    crossYearObj.visibility	= (dom||ie)? "visible" : "show"
    leftOffset = parseInt(crossobj.left) + document.getElementById("spanYear").offsetLeft
    if(ie) leftOffset += 6
    crossYearObj.left =	leftOffset
    crossYearObj.top = parseInt(crossobj.top) +	26
}
function WeekNbr(n){
    year = n.getFullYear();
    month = n.getMonth() + 1;
    if(startAt==0) day = n.getDate() + 1;
    else day = n.getDate();
    a = Math.floor((14-month)/12);
    y = year + 4800 - a;
    m = month + 12 * a - 3;
    b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400);
    J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;
    d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
    L = Math.floor(d4 / 1460);
    d1 = ((d4 - L) % 365) + L;
    week = Math.floor(d1/7) + 1;
    return week;
}
function Getnumdays(day1){// d: datetime
    var Numday=0;
    var Numdays = Array(31,0,31,30,31,30,31,31,30,31,30,31);
    var	M = day1.getMonth();
    var	Y = day1.getYear();	
    if(M==2){
        D = new Date(Y,M,1);
        D = new Date(D - (24*60*60*1000));
        Numday = D.getDate();			
    }else Numday = Numdays[M-1];
    return Numday; 	
}
function Adddate(date1,n){
    return new Date(date1.getTime() + (n * 86400000));
}    
function y2k(number){ return (number < 1000) ? number + 1900 : number; }
function format_date(adate){
    return adate.getDate() + '/' + (adate.getMonth()+1) + '/' + y2k(adate.getYear());
}
function Firstweek(Ngay){	 	
    var thu = Ngay.getDay();     	
    var sthu=(Ngay.getDay() == 0) ? -6 : (1-Ngay.getDay());
    return Adddate(Ngay,sthu)
}
function constructCalendar(){
    var aNumDays = Array(31,0,31,30,31,30,31,31,30,31,30,31)
    var dateMessage
    var startDate =	new	Date(yearSelected,monthSelected,1)		
    var endDate, endDate1
    var dt_month_prev=monthSelected; 
    var sd_month_prev;
    var dt_month_next=monthSelected+2; 
    if(monthSelected==1){
        endDate	= new Date(yearSelected,monthSelected+1,1);
        endDate	= new Date(endDate	- (24*60*60*1000));
        numDaysInMonth = endDate.getDate()			
    }else numDaysInMonth = aNumDays[monthSelected];
    if(monthSelected==0){
        ok_prev=1;
        year_prev=yearSelected-1;
        month_prev=12;
        dt_month_prev=month_prev;
    }else{
        year_prev=yearSelected;
        ok_prev=0;			
    }
    if(dt_month_prev==2){
        endDate1 = new Date(yearSelected,dt_month_prev,1);
        endDate1 = new Date(endDate1 - (24*60*60*1000));
        sd_month_prev = endDate1.getDate()			
    }else sd_month_prev = aNumDays[dt_month_prev-1];
    if(monthSelected==11){
        ok_next=1;
        year_next=yearSelected+1;
        month_next=1;
        dt_month_next=month_next;
    }else{
        year_next=yearSelected;
        ok_next=0;			
    }		
    datePointer	= 0
    dayPointer = startDate.getDay() - startAt
    if(dayPointer<0) dayPointer = 6
    styleAnchor="text-decoration:none;color:#FFFFFF;"
    styleLightBorder="border-style:solid;border-width:1px;border-color:#D0070F;background-color:#BFEFDF;"
    if((optionCal==1)||(optionCal==3)){
        sHTML =	"<table	 border=0 style='font-family:verdana;font-size:10px;color:#003366;'><tr>"
        if(showWeekNumber==1)
            sHTML += "<td width=27><b>" + weekString + "</b></td><td width=1 rowspan=7 bgcolor='#92DAB6' style='padding:0px'><img src='"+imgDir+"divider.gif' width=1></td>"
            for(i=0;i<7;i++)
                sHTML += "<td width='27' align='right'><B>"+ dayName[i]+"</B></td>"
                sHTML +="</tr><tr>"
                if(showWeekNumber==1) sHTML += "<td align=right>" + WeekNbr(startDate) + "&nbsp;</td>"
                var day_prev;
                if(dayPointer!=0) month_prev=dt_month_prev;
                else month_prev=0;
                for(var i=1;i<=dayPointer;i++){
                    day_prev=sd_month_prev+i-dayPointer;		
                    sHTML += "<td align=right>"
                    sStyle=styleAnchor+"cursor: hand;color:#669999;"					
                    if((day_prev==odateSelected) && ((month_prev-1)==omonthSelected) && (year_prev==oyearSelected))
                    { sStyle+=styleLightBorder }
                    dateSelected=dt_month_prev;
                    sHint = ""
                    for(k=0;k<HolidaysCounter;k++){
                        if((parseInt(Holidays[k].d)==datePointer)&&(parseInt(Holidays[k].m)==(monthSelected+1))){
                            if((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==yearSelected)&&(parseInt(Holidays[k].y)!=0))){
                                sStyle+="background-color:#ff0000;"
                                sHint+=sHint==""?Holidays[k].desc:"\n"+Holidays[k].desc
                            }
                        }
                    }
                    var regexp= /\"/g
                    sHint=sHint.replace(regexp,"&quot;")
                    dateMessage = "onmousemove='window.status=\""+selectDateMessage.replace("[date]",constructDate(day_prev,month_prev-1,year_prev))+"\"' onmouseout='window.status=\"\"' "
                    if((day_prev==dateNow)&&((month_prev-1)==monthNow)&&(year_prev==yearNow)) 
                        sHTML += "<b><a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' onclick='ok=1;dateSelected="+day_prev+";closeCalendar();'><font color=#ff0000>&nbsp;" + day_prev+ "</font>&nbsp;</a></b>"
                    else if(i % 7 == (startAt * -1)+1)
                        sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' onclick='ok=1;dateSelected="+day_prev+ ";closeCalendar();'>&nbsp;<font color=#FF0000>" + day_prev+ "</font>&nbsp;</a>" 
                    else sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' onclick='ok=1;dateSelected="+day_prev+ ";closeCalendar();'>&nbsp;" + day_prev+ "&nbsp;</a>" 
                }
                for(datePointer=1;datePointer<=numDaysInMonth;datePointer++){
                    dayPointer++;
                    sHTML += "<td align=right>"
                    sStyle=styleAnchor+"cursor: hand;color:#000000;"				
                    styleLightBorder1="border-style:solid;border-width:1px;border-color:#DEB887;background-color:#BFEFDF;"
                    if ((datePointer==odateSelected) &&	(monthSelected==omonthSelected)	&& (yearSelected==oyearSelected))
                        sStyle+=styleLightBorder1
                        if ((datePointer==dateNow) && (monthSelected==monthNow) && (yearSelected==yearNow))
                            sStyle+=styleLightBorder
                            sHint = ""
                            for (k=0;k<HolidaysCounter;k++){
                                if ((parseInt(Holidays[k].d)==datePointer)&&(parseInt(Holidays[k].m)==(monthSelected+1))){
                                    if ((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==yearSelected)&&(parseInt(Holidays[k].y)!=0))){
                                        sStyle+="background-color:#FFDDDD;"
                                        sHint+=sHint==""?Holidays[k].desc:"\n"+Holidays[k].desc
                                    }
                                }
                            }
                            var regexp= /\"/g
                            sHint=sHint.replace(regexp,"&quot;")
                            dateMessage = "onmousemove='window.status=\""+selectDateMessage.replace("[date]",constructDate(datePointer,monthSelected,yearSelected))+"\"' onmouseout='window.status=\"\"' "
                            if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow)) 
                                sHTML += "<b><a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' onclick='ok=0;dateSelected="+datePointer+";closeCalendar();'><font color=#ff0000>&nbsp;" + datePointer + "</font></b>&nbsp;</a>"
                            else if(dayPointer % 7 == (startAt * -1)+1)
                                sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' onclick='ok=0;dateSelected="+datePointer + ";closeCalendar();'>&nbsp;<font color=#FF0000>" + datePointer + "</font>&nbsp;</a>" 
                            else sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' onclick='ok=0;dateSelected="+datePointer + ";closeCalendar();'>&nbsp;" + datePointer + "&nbsp;</a>" 
                            sHTML += ""
                            if ((dayPointer+startAt) % 7 == startAt){ 
                                sHTML += "</tr><tr>" 
                                if ((showWeekNumber==1)&&(datePointer<numDaysInMonth))
                                    sHTML += "<td align=right>" + (WeekNbr(new Date(yearSelected,monthSelected,datePointer+1))) + "&nbsp;</td>"
                            }
                }
                endDate_next = new Date(yearSelected,monthSelected,numDaysInMonth);			
                numCell=7-endDate_next.getDay();		
                var thu;
                if(numCell!=7){
                    month_next=dt_month_next;
                    for(var i=1;i<=numCell;i++){
                        day_prev=i;	
                        thu= new Date(year_next,dt_month_next-1,day_prev);	
                        sHTML += "<td align=right>"
                        sStyle=styleAnchor+"cursor: hand;color:#669999;"
                        if((day_prev==odateSelected)&&((dt_month_next-1)==omonthSelected)&&(year_next==oyearSelected)) 
                            sStyle+=styleLightBorder
                            sHint = ""
                            for(k=0;k<HolidaysCounter;k++){
                                if((parseInt(Holidays[k].d)==day_prev)&&(parseInt(Holidays[k].m)==(monthSelected+1))){
                                    if((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==yearSelected)&&(parseInt(Holidays[k].y)!=0))){
                                        sStyle+="background-color:#ff0000;"
                                        sHint+=sHint==""?Holidays[k].desc:"\n"+Holidays[k].desc
                                    }
                                }
                            }	
                            var regexp= /\"/g
                            sHint=sHint.replace(regexp,"&quot;")
                            dateMessage = "onmousemove='window.status=\""+selectDateMessage.replace("[date]",constructDate(day_prev,dt_month_next-1,year_next))+"\"' onmouseout='window.status=\"\"' "
                            if((day_prev==dateNow)&&((dt_month_next-1)==monthNow)&&(year_next==yearNow)) 
                                sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' onclick='ok=2;dateSelected="+day_prev+";closeCalendar();'><b><font color=#ff0000>&nbsp;" + day_prev+ "</font></b>&nbsp;</a>"
                            else sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' onclick='ok=2;dateSelected="+day_prev+ ";closeCalendar();'>&nbsp;" + day_prev+ "&nbsp;</a>" 
                    }					
                }else month_next=0;
    }
    document.getElementById("content").innerHTML   = sHTML		
    document.getElementById("spanMonth").innerHTML = "&nbsp;" +	monthName[monthSelected] + "&nbsp;<IMG id='changeMonth' SRC='"+imgDir+"c_drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
    document.getElementById("spanYear").innerHTML =	"&nbsp;" + yearSelected	+ "&nbsp;<IMG id='changeYear' SRC='"+imgDir+"c_drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
}
document.onkeypress=function hidecal1(e){
    var isIE = document.all;    
    if(isIE) window.event.returnValue = true;
    var keyCode = (isIE)?(window.event.keyCode):(e.which);
    //    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if(keyCode==27) hideCalendar()
}
document.onclick=function hidecal2(){ 		
    if(!bShow) hideCalendar()
    bShow=false
}

if(document.all) 
	init()
else{
    window.onload=init
}
function popUpCalendar(language,option,ctl,txtnameFW,txtnameLW,numWeek){
    optionCal = option;
    Language  = language;	
    strClient=document.all(txtnameFW).value;		
    if(strClient!="") {
        var arrDay = strClient.split('/');
        if (arrDay.length == 3) {
            if (Language=="vi"){					
                NgayClient = new Date(arrDay[2],arrDay[1]-1,arrDay[0]);					
            }else{
                NgayClient = new Date(arrDay[2],arrDay[0]-1,arrDay[1]);	
            }
        }
    }		
    init();
    if((option==1)||(option==3)){
        if(option==1) txtName = txtnameFW;
        var	leftpos=0
        var	toppos=0				
        if(bPageLoaded){
            if(crossobj.visibility=="hidden"){				
                dateFormat=format;
                formatChar = " "				
                aFormat	= dateFormat.split(formatChar)				
                if(aFormat.length<3){
                    formatChar = "/"
                    aFormat	= dateFormat.split(formatChar)
                    if(aFormat.length<3){
                        formatChar = "."
                        aFormat	= dateFormat.split(formatChar)
                        if(aFormat.length<3){
                            formatChar = "-"
                            aFormat	= dateFormat.split(formatChar)
                            if(aFormat.length<3)// invalid date	format
                                formatChar=""
                        }
                    }
                }
                if(formatChar==""){
                    alert('Chuoi dinh dang ngay khong hop le')
                    return false;					
                }
                tokensChanged =	0				
                if((tokensChanged!=3)||isNaN(dateSelected)||isNaN(monthSelected)||isNaN(yearSelected)){
                    dateChoose  = NgayClient.getDate();							
                    monthChoose = NgayClient.getMonth()
                    yearChoose  = NgayClient.getYear()
                    dateSelected = dateChoose
                    monthSelected =	monthChoose
                    //yearSelected = yearChoose
                    yearSelected = y2k(yearChoose);
                }
                odateSelected=dateSelected
                omonthSelected=monthSelected
                oyearSelected=yearSelected
                aTag = ctl
                do{
                    aTag = aTag.offsetParent;
                    leftpos	+= aTag.offsetLeft;
                    toppos += aTag.offsetTop;
                }while(aTag.tagName!="BODY");	
                
                crossobj.left = (fixedX == -1) ? ctl.offsetLeft + leftpos : fixedX;				
                crossobj.top = (fixedY == -1) ? ctl.offsetTop + toppos : fixedY;
                leftCal= (fixedX == -1) ? ctl.offsetLeft + leftpos : fixedX;				
                topCal=(fixedY == -1) ? ctl.offsetTop + toppos : fixedY;
                // xử lý vị trí hiển thị lịch																		
                if ((screen.availHeight-(topCal+148))<148)
                    crossobj.top=(fixedY == -1) ? ctl.offsetTop + toppos-148 : fixedY;
                    if ((screen.availWidth-(leftCal+234))<174)
                        crossobj.left=(fixedX == -1) ? ctl.offsetLeft + leftpos-234 : fixedX;
                        //kết thúc xử lý vị trí					
                        constructCalendar(1, monthSelected, yearSelected);
                        crossobj.visibility=(dom||ie)? "visible" : "show"
                        hideElement('SELECT',document.getElementById("Calendar"));
                        hideElement('APPLET',document.getElementById("Calendar"));			
                        bShow = true;
            }else{
                hideCalendar()
                if(ctlNow!=ctl){popUpCalendar(language,option,ctl,txtnameFW)}
            }
            ctlNow = ctl
        }
    }					
}	
function closeCalendar(){	
    var NgayBD,NgayKT;
    if(optionCal==1){
        hideCalendar();			
        if (Language=="vi")
            document.all(txtName).value=Viewday();
        else{
            document.all(txtName).value=ViewdayEN();
        }
    }		
}	
function Viewday(){
    var dayTemp;
    if(ok==0) dayTemp=constructDate(dateSelected,monthSelected,yearSelected);
    if(ok==1)//previous month
        if(ok_prev==0) dayTemp=constructDate(dateSelected,month_prev-1,yearSelected);			
        else dayTemp=constructDate(dateSelected,month_prev-1,year_prev);
    if(ok==2)//next month		
        if(ok_next==0) dayTemp=constructDate(dateSelected,month_next-1,yearSelected);			
        else dayTemp=constructDate(dateSelected,month_next-1,year_next);
    return dayTemp;
}
function ViewdayEN() {
    var dayTemp;
    if (ok==0) dayTemp=constructDateEN(dateSelected,monthSelected,yearSelected);
    if (ok==1)//previous month
        if (ok_prev==0) dayTemp=constructDateEN(dateSelected,month_prev-1,yearSelected);			
        else dayTemp=constructDateEN(dateSelected,month_prev-1,year_prev);				
    if (ok==2)//next month	
        if (ok_next==0) dayTemp=constructDateEN(dateSelected,month_next-1,yearSelected);			
        else dayTemp=constructDateEN(dateSelected,month_next-1,year_next);				
    return dayTemp;
}

