﻿// JScript 檔

 var months = new Array("一", "二", "三","四", "五", "六", "七", "八", "九","十", "十一", "十二");
 var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31);
 var days = new Array("日","一", "二", "三","四", "五", "六");
 var classTemp;
 var today=new getToday();
 var year=today.year;
 var month=today.month;
 var newCal;
 obj="";

 function getCurrentTime(){
 	var currentdate=new Date();
	this.getCurrentYear=function(){
		return currentdate.getFullYear();
	}
	this.getCurrentMonth=function(){
		return currentdate.getMonth()+1;
	}
	this.getCurrentDay=function(){
		return currentdate.getDate();
	}
	this.getCurrentHour=function(){
	    return currentdate.getHours();
	}
	this.getCurrentMinute=function(){
	    return currentdate.getMinutes();
	}
	this.getCurrentSecond=function(){
	    return currentdate.getSeconds();
	}
 }
 function getDays(month, year) {
  if (1 == month) return ((0 == year % 4) && (0 != (year % 100))) ||(0 == year % 400) ? 29 : 28;
  else return daysInMonth[month];
 }

 function getToday() {
  this.now = new Date();
  this.year = this.now.getFullYear();
  this.month = this.now.getMonth();
  this.day = this.now.getDate();
 }

 function Calendar(objcaltable,objcalendar,objyear,objhiddenYear,objmonth,displayMonth) {
  newCal = new Date(year,month,1);
  today = new getToday();   
  var day = -1;
  var startDay = newCal.getDay();
  var endDay=getDays(newCal.getMonth(), newCal.getFullYear());
  var daily = 0;
  if ((today.year == newCal.getFullYear()) &&(today.month == newCal.getMonth()))
  {
   day = today.day;
  }
  var caltable = objcalendar;
  var intDaysInMonth =getDays(newCal.getMonth(), newCal.getFullYear());
  for (var intWeek = 0; intWeek < caltable.rows.length;intWeek++)
  for (var intWeek = 0; intWeek < caltable.rows.length;intWeek++)
   for (var intDay = 0;intDay < caltable.rows[intWeek].cells.length;intDay++)
   {
    var cell = caltable.rows[intWeek].cells[intDay];
    var montemp=(newCal.getMonth()+1)<10?("0"+(newCal.getMonth()+1)):(newCal.getMonth()+1);         
    if ((intDay == startDay) && (0 == daily)){ daily = 1;}
    var daytemp=daily<10?("0"+daily):(daily);
    var d="<"+newCal.getFullYear()+"-"+montemp+"-"+daytemp+">";
    if(day==daily) cell.className="DayNow";
	cell.className ="Day";
	if(year==test.getCurrentYear()){
		if((month+1)==test.getCurrentMonth()){
			if(daily<test.getCurrentDay() || daily==0 || daily==32){
			    cell.className="disablecolor";
                cell.style.backgroundColor='';
                cell.style.color='';
	            cell.onmouseover=function(event){
	            }
	            cell.onmouseout=function(event){
	            }
	            cell.onclick=function(event){
	            }
			}else if(daily==test.getCurrentDay()){
			    if(test.getCurrentHour()>=17){
			        //=======20080918修正，當天17:00後不擋==========================================
			        /*
			        if(test.getCurrentMinute()>=0){
			            if(test.getCurrentSecond()>=0){
			                cell.className="disablecolor";
                            cell.style.backgroundColor='';
                            cell.style.color='';
	                        cell.onmouseover=function(event){
	                        }
	                        cell.onmouseout=function(event){
	                        }
	                        cell.onclick=function(event){
	                        }
	                    }
	                }
	                */
	                
	                cell.className="Day";
				    cell.onmouseover=function(event){
				        buttonOver(event);
				    }
				    cell.onmouseout=function(event){
				        buttonOut(event);
				    }
				    cell.onclick=function(event){
				        buttonClick(event,objcalendar);  
				    }
				    /**/
				    
	                //=======20080918修正，當天17:00後不擋==========================================
			   }else{
				    cell.className="Day";
				    cell.onmouseover=function(event){
				        buttonOver(event);
				    }
				    cell.onmouseout=function(event){
				        buttonOut(event);
				    }
				    cell.onclick=function(event){
				        buttonClick(event,objcalendar);
				    }
				}  
			}else{
				cell.className="Day";
				cell.onmouseover=function(event){
				    buttonOver(event);
				}
				cell.onmouseout=function(event){
				    buttonOut(event);
				}
				cell.onclick=function(event){
				    buttonClick(event,objcalendar);
				}
			}
		}else if((month+1)<test.getCurrentMonth()){
			cell.className="disablecolor";
            cell.style.backgroundColor='';
            cell.style.color='';
	        cell.onmouseover=function(event){
	        }
	        cell.onmouseout=function(event){
	        }
	        cell.onclick=function(event){
	        }
		}else{
			cell.className="Day";
			cell.onmouseover=function(event){
			    buttonOver(event);
			}
			cell.onmouseout=function(event){
			    buttonOut(event);
			}
			cell.onclick=function(event){
			    buttonClick(event,objcalendar);
			}
		}
	}else if(year<test.getCurrentYear()){
		cell.className="disablecolor";
        cell.style.backgroundColor='';
        cell.style.color='';
        cell.onmouseover=function(event){
        }
        cell.onmouseout=function(event){
        }
        cell.onclick=function(event){
        }
	}else if(year>test.getCurrentYear()){
		cell.onmouseover=function(event){
		    buttonOver(event);
		}
		cell.onmouseout=function(event){
		    buttonOut(event);
		}
		cell.onclick=function(event){
		    buttonClick(event,objcalendar);
		}
    }
    if ((daily > 0) && (daily <= intDaysInMonth))
    {
     cell.innerHTML = daytemp;
     daily++;
    } else
    {
        cell.className="CalendarTD";
        cell.innerHTML = "";
        cell.style.backgroundColor='';
        cell.style.color='';
	    cell.onmouseover=function(event){
	    }
	    cell.onmouseout=function(event){
	    }
	    cell.onclick=function(event){
	    }
    }
  }
  objyear.value=year;
  objhiddenYear.value=year;
  if((parseInt(month)+1)<10)
  {
  	displayMonth.value="0"+(parseInt(month)+1);
  }else{
    displayMonth.value=parseInt(month)+1;
  }
  objmonth.value=parseInt(month)+1;
}

 function subMonth(objcaltable,objcalendar,objyear,objhiddenYear,objmonth,displayMonth)
 {  
  year=parseInt(objhiddenYear.value);
  s_flag=displayMonth.value.substring(0,1);
  if(s_flag=='0')
    month=parseInt(displayMonth.value.substring(1,2))-1;
  else
    month=parseInt(displayMonth.value)-1;    
  if ((month-1)<0)
  {
   month=11;
   year=year-1;
  } else
  {
   month=month-1;
  }
  Calendar(objcaltable,objcalendar,objyear,objhiddenYear,objmonth,displayMonth);
 }

 function addMonth(objcaltable,objcalendar,objyear,objhiddenYear,objmonth,displayMonth)
 {
  year=parseInt(objhiddenYear.value);
  s_flag=displayMonth.value.substring(0,1);
  if(s_flag=='0')
    month=parseInt(displayMonth.value.substring(1,2))-1;
  else
    month=parseInt(displayMonth.value)-1;
    
  if((month+1)>11)
  {
   month=0;
   year=year+1;
  } else
  {
   month=month+1;
  }
  Calendar(objcaltable,objcalendar,objyear,objhiddenYear,objmonth,displayMonth);
 }

 function setDate(objcaltable,objcalendar,objyear,objhiddenYear,objmonth) 
 {
  if (objmonth.value<1||objmonth.value>12)
  {
   alert("月的有效範圍在1-12之間!");
   return;
  }
  year=Math.ceil(objyear.value);
  month=Math.ceil(objmonth.value-1);
  Calendar(objcaltable,objcalendar,objyear,objhiddenYear,objmonth);
 }
 

//------------------------------------------------------------
 
function buttonOver(evt)
{
    if(navigator.appName!='Netscape'){
        evtValue=event.srcElement;
    }else{
        evtValue=evt.target;
    }
    //******start2008/01/09
    evtValue.style.backgroundColor='#8ab0bd';
    //******end2008/01/09
    evtValue.style.color='white';
    evtValue.style.cursor='pointer';     
}

function buttonOut(evt)
{
    if(navigator.appName!='Netscape'){
        evtValue=event.srcElement;
    }else{
        evtValue=evt.target;
    }
    evtValue.style.backgroundColor='';
    evtValue.style.color='';
    evtValue.style.ursor='pointer';
}

//******start2008/09/23bylivia--------------------------------
//修改前：當點了一個日期後，想要改選其他日期時，會造成本來的日期無法再被選擇 (PS：之前是專門這樣設計的)
//修改後：當點了一個日期後，想要改選其他日期時，本來的日期可以再被選擇
function buttonClick(evt,objcalendar)
{
   if(navigator.appName!='Netscape'){
        obj1=event.srcElement;
    }else{
        obj1=evt.target;
    }
    //******start2008/07/02bylivia
 obj1.style.backgroundColor="#8ab0bd";
 /*obj1.style.color="white";*/
 
 obj1.onmouseover=function(){
    buttonOver(event);
 }
 obj1.onmouseout=function(){
    buttonOut(event);
 }
 obj1.onclick=function(){
    buttonClick(event,objcalendar);
 } 
 /*
 obj1.className="disablecolor";
 obj1.style.backgroundColor='';
 obj1.style.color='';
 obj1.style.cursor='';
 */
 //******end2008/07/02bylivia
 
 if(obj==""){
	obj=obj1;
 }else{
 	obj.style.backgroundColor="";
 	obj.style.color="";
 }
 
 obj=obj1;
 
 if(objcalendar.id=="calendarIN")
    getDiaryIN(evt);
 else if(objcalendar.id=="calendarOut")
    getDiaryOut(evt);
 test1= new Date();
   s_flag=obj1.innerHTML.substring(0,1);
  if(s_flag=='0')
    day=parseInt(obj1.innerHTML.substring(1,2));
  else
    day=parseInt(obj1.innerHTML);

	if(year==test.getCurrentYear()){
	    ////******start2008/07/02bylivia
		if((month+1)==test.getCurrentMonth()){
		//******end2008/07/02bylivia
			if(day==test.getCurrentDay()){
			//=======20080918修正，當天17:00後不擋==========================================
			/*
                if(test1.getHours()<17){
                }else{
                    if(objcalendar.id=="calendarIN"){
                       TrimIn(evt);
                    }else{
                       TrimOut(evt);
                    }
                    alert('抱歉，已逾當日訂房訂購時間');                    
                    obj1.className="disablecolor";
                    obj1.style.backgroundColor='';
                    obj1.style.color='';
                    obj1.onmouseover=function(event){
                        buttonOver(event);
                    }
                    obj1.onmouseout=function(event){
                        buttonOut(event);
                    }
                    obj1.onclick=function(event){
                        buttonClick(event,objcalendar);
                    }
                }
            */
            
                /*
                obj1.className="disablecolor";
                obj1.style.backgroundColor='';
                obj1.style.color='';
                */
                obj1.onmouseover=function(event){
                    buttonOver(event);
                }
                obj1.onmouseout=function(event){
                    buttonOut(event);
                }
                obj1.onclick=function(event){
                    buttonClick(event,objcalendar);
                }
            /**/    
            //=======20080918修正，當天17:00後不擋==========================================    
            }else if(day<test.getCurrentDay()){
                /*
                obj1.className="disablecolor";
                obj1.style.backgroundColor='';
                obj1.style.color='';
                */
                obj1.onmouseover=function(event){
                    buttonOver(event);
                }
                obj1.onmouseout=function(event){
                    buttonOut(event);
                }
                obj1.onclick=function(event){
                    buttonClick(event,objcalendar);
                }
            }
         }else if((month)<test.getCurrentMonth()){
            /*
            obj1.className="disablecolor";
            obj1.style.backgroundColor='';
            obj1.style.color='';
            */
            obj1.onmouseover=function(event){
                buttonOver(event);
            }
            obj1.onmouseout=function(event){
                buttonOut(event);
            }
            obj1.onclick=function(event){
                buttonClick(event,objcalendar);
            }
          }    
      }else if(year<test.getCurrentYear()){ 
        /*
        obj1.className="disablecolor";
        obj1.style.backgroundColor='';
        obj1.style.color='';
        */
        obj1.onmouseover=function(event){
            buttonOver(event);
        }
        obj1.onmouseout=function(event){
            buttonOut(event);
        }
        obj1.onclick=function(event){
            buttonClick(event,objcalendar);
        }
      }    
}
//******end2008/09/23bylivia--------------------------------

function TrimIn(evt){
    document.getElementById("ctl01_ContentPlaceHolder1_Uc_BSingleProd_Order1_txtDateIN").value='';
}
function TrimOut(evt){
    document.getElementById("ctl01_ContentPlaceHolder1_Uc_BSingleProd_Order1_txtDateOut").value='';
}
var test=new getCurrentTime();