var xmlhttp = getHTTPObject();
var CalendarHttp = getCalendarObject();
var CalendarHttp2 = getCalendarObject2();

function handleHttpUpdatedate(){
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
	document.getElementById('vino_week').innerHTML=xmlhttp.responseText;
	loadCalendar();
} else {
	alert("您所請求的頁面有異常1。");
	}
}
}
function handleHttpCalendarDate(){
if(CalendarHttp.readyState == 4){
if(CalendarHttp.status == 200){
	document.getElementById('calendar_action_day').innerHTML=CalendarHttp.responseText;
} else {
	alert("您所請求的頁面有異常2。");
	}
}
}
function handleHttpUpdatedate2(){
if(CalendarHttp2.readyState == 4){
if(CalendarHttp2.status == 200){
	document.getElementById('calendar_name').innerHTML=CalendarHttp2.responseText;
} else {
	alert("您所請求的頁面有異常3。");
	}
}
}
function handleHttpResponse(){
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
	document.getElementById('calendar_name').innerHTML=xmlhttp.responseText;
} else {
	alert("您所請求的頁面有異常4。");
	}
}
}
 function updateCalendar(c_id,sub_id){
 select_m=document.getElementById('select_month').value;
 select_y=document.getElementById('select_year').value;
 xmlhttp.open("GET","http://"+window.location.host+"/big5/calendar.asp?c_id="+c_id+"&sub_id="+sub_id+"&s_year="+select_y+"&s_month="+ select_m+"",true);
 xmlhttp.onreadystatechange = handleHttpResponse;
 xmlhttp.send(null); 
 }
 function loadCalendar(c_id){
 select_m=document.getElementById('select_month').value;
 select_y=document.getElementById('select_year').value;
 xmlhttp.open("GET","http://"+window.location.host+"/big5/calendar.asp?s_year="+select_y+"&s_month="+ select_m+"" ,true);
 xmlhttp.onreadystatechange = handleHttpResponse;
 xmlhttp.send(null); 
 }

function loaddate(){
 select_m=document.getElementById('select_month').value;
 select_y=document.getElementById('select_year').value;
 if(select_y<=document.getElementById('min_year').value){
			document.getElementById('arrow_year_prve').innerHTML="<img src='common/images/arrow_month_prve_on.gif' />";
		    document.getElementById('arrow_month_next').innerHTML="<a href='' onClick='updatedate(0,-1);return false' ><img src='common/images/arrow_month_next.gif' /></a>";
			if(document.getElementById('calendar_op').value==1){document.getElementById('calendar_action_year_arrow2').innerHTML="&nbsp;";}
			if(document.getElementById('calendar_op').value==2){document.getElementById('calendar_action_year_arrow2').innerHTML="&nbsp;";}
if (select_m<=1){
			document.getElementById('arrow_month_prve').innerHTML="<img src='common/images/arrow_month_prve_on.gif' />";
			}else{
			document.getElementById('arrow_month_prve').innerHTML="<a href='' onClick='updatedate(0,1);return false'><img src='common/images/arrow_month_prve.gif' /></a>";
			}
	}else{
			 if(document.getElementById('calendar_op').value==1){document.getElementById('calendar_action_year_arrow2').innerHTML="<a href='' onClick='updatedate(1,0);return false' ><img src='common/images/icon/arrow2.jpg' /></a>";}
			 if(document.getElementById('calendar_op').value==2){document.getElementById('calendar_action_year_arrow2').innerHTML="<a href='' onClick='updatedate(1,0);return false' ><img src='common/images/calendar/prve/"+(parseInt(select_y)-1)+".jpg' /></a>";}

			document.getElementById('arrow_year_prve').innerHTML="<a href='' onClick='updatedate(1,0);return false' ><img src='common/images/arrow_month_prve.gif' /></a>";
		}
		
		
	 if(select_y>=document.getElementById('big_year').value){
		 
	 document.getElementById('arrow_year_next').innerHTML="<img src='common/images/arrow_month_next_on.gif' />";
     if(document.getElementById('calendar_op').value==1){document.getElementById('calendar_action_year_arrow').innerHTML="&nbsp;";}
     if(document.getElementById('calendar_op').value==2){document.getElementById('calendar_action_year_arrow').innerHTML="&nbsp;";}
if (select_m>=12){
	 document.getElementById('arrow_month_next').innerHTML="<img src='common/images/arrow_month_next_on.gif' />";
	 }else{
     document.getElementById('arrow_month_next').innerHTML="<a href='' onClick='updatedate(0,-1);return false' ><img src='common/images/arrow_month_next.gif' /></a>";
	 }
	 }else{
	 if(document.getElementById('calendar_op').value==1){document.getElementById('calendar_action_year_arrow').innerHTML="<a href='' onClick='updatedate(-1,0);return false' ><img src='common/images/icon/arrow.jpg' /></a>";}

	 if(document.getElementById('calendar_op').value==2){document.getElementById('calendar_action_year_arrow').innerHTML="<a href='' onClick='updatedate(-1,0);return false' ><img src='common/images/calendar/next/"+(parseInt(select_y)+1)+".jpg' /></a>";}

document.getElementById('arrow_year_next').innerHTML="<a href='' onClick='updatedate(-1,0);return false' ><img src='common/images/arrow_month_next.gif' /></a>";
		}
		
 document.getElementById('now_select_year').innerHTML="<img src='common/images/year/"+select_y+".gif'/>";
 document.getElementById('now_select_month').innerHTML="<img src='common/images/month/"+select_m+".gif'/>";
 
 if(document.getElementById('calendar_op').value==1){
	 for(i=1;i<=12;i++){
		 if(i==select_m){
 document.getElementById('month'+i).innerHTML="<img src='common/images/calendar/month/"+i+"_a.jpg'/>";
	 }else{
 document.getElementById('month'+i).innerHTML="<a href='' onclick='updatedate2("+i+");return false'><img src='common/images/calendar/month/"+i+".jpg'/></a>";
		 }
	 }
 CalendarHttp.open("GET","http://"+window.location.host+"/big5/calendar_date.asp" ,true);
 CalendarHttp.onreadystatechange = handleHttpCalendarDate;
 CalendarHttp.send(null); 

}

 if(document.getElementById('calendar_op').value==2){
	 	 for(i=1;i<=12;i++){
		 if(i==select_m){
 document.getElementById('month'+i).innerHTML="<img src='common/images/select/"+i+".jpg'/>";
	 }else{
 document.getElementById('month'+i).innerHTML="<a href='' onclick='updatedate2("+i+");return false'><img src='common/images/noselect/"+i+".jpg'/></a>";
		 }
	 }

	 document.getElementById('calendar_action_month_arrow2').innerHTML="<a href='' onClick='updatedate(0,-1);return false' ><img src='common/images/icon/arrow.jpg' /></a>";
	 document.getElementById('calendar_action_month_arrow').innerHTML="<a href='' onClick='updatedate(0,1);return false' ><img src='common/images/icon/arrow2.jpg' /></a>";
	 document.getElementById('calendar_action_month').innerHTML="<img src='common/images/calendar/month/"+select_m+".jpg'/>";
	 
 CalendarHttp.open("GET","http://"+window.location.host+"/big5/calendar_date2.asp" ,true);
 CalendarHttp.onreadystatechange = handleHttpCalendarDate;
 CalendarHttp.send(null); 

}

xmlhttp.open("GET","http://"+window.location.host+"/big5/select_date.asp" ,true);
 xmlhttp.onreadystatechange = handleHttpUpdatedate;
 xmlhttp.send(null); 
 }

 function updatedate(year_num,month_num){
	 select_m=document.getElementById('select_month').value-month_num;
     select_y=document.getElementById('select_year').value-year_num;
	 if (select_m<1){
		select_m=12
		select_y=select_y-1
	 }
	 if (select_m>12){
		select_m=1
		select_y=select_y+1
	 }
			
	 if(select_y<=document.getElementById('min_year').value){
			document.getElementById('arrow_year_prve').innerHTML="<img src='common/images/arrow_month_prve_on.gif' />";
		    document.getElementById('arrow_month_next').innerHTML="<a href='' onClick='updatedate(0,-1);return false' ><img src='common/images/arrow_month_next.gif' /></a>";
			 if(document.getElementById('calendar_op').value==1){document.getElementById('calendar_action_year_arrow2').innerHTML="&nbsp;";}

			 if(document.getElementById('calendar_op').value==2){document.getElementById('calendar_action_year_arrow2').innerHTML="&nbsp;";}

            if (select_m<=1){
			document.getElementById('arrow_month_prve').innerHTML="<img src='common/images/arrow_month_prve_on.gif' />";
			}else{
			document.getElementById('arrow_month_prve').innerHTML="<a href='' onClick='updatedate(0,1);return false'><img src='common/images/arrow_month_prve.gif' /></a>";
			}
	}else{
			document.getElementById('arrow_year_prve').innerHTML="<a href='' onClick='updatedate(1,0);return false' ><img src='common/images/arrow_month_prve.gif' /></a>";
			 if(document.getElementById('calendar_op').value==1){document.getElementById('calendar_action_year_arrow2').innerHTML="<a href='' onClick='updatedate(1,0);return false' ><img src='common/images/icon/arrow2.jpg' /></a>";
}

			 if(document.getElementById('calendar_op').value==2){document.getElementById('calendar_action_year_arrow2').innerHTML="<a href='' onClick='updatedate(1,0);return false' ><img src='common/images/calendar/prve/"+(parseInt(select_y)-1)+".jpg' /></a>";
}
}
	 if(select_y>=document.getElementById('big_year').value){
			document.getElementById('arrow_year_next').innerHTML="<img src='common/images/arrow_month_next_on.gif' />";
            if(document.getElementById('calendar_op').value==1){document.getElementById('calendar_action_year_arrow').innerHTML="&nbsp;";}

            if(document.getElementById('calendar_op').value==2){document.getElementById('calendar_action_year_arrow').innerHTML="&nbsp;";}
if (select_m>=12){
	        document.getElementById('arrow_month_next').innerHTML="<img src='common/images/arrow_month_next_on.gif' />";
	        }else{
		    document.getElementById('arrow_month_next').innerHTML="<a href='' onClick='updatedate(0,-1);return false' ><img src='common/images/arrow_month_next.gif' /></a>";
		     }
		}else{
            if(document.getElementById('calendar_op').value==1){		 document.getElementById('calendar_action_year_arrow').innerHTML="<a href='' onClick='updatedate(-1,0);return false' ><img src='common/images/icon/arrow.jpg' /></a>";
}
            if(document.getElementById('calendar_op').value==2){		 document.getElementById('calendar_action_year_arrow').innerHTML="<a href='' onClick='updatedate(-1,0);return false' ><img src='common/images/calendar/next/"+(parseInt(select_y)+1)+".jpg' /></a>";
}
document.getElementById('arrow_year_next').innerHTML="<a href='' onClick='updatedate(-1,0);return false' ><img src='common/images/arrow_month_next.gif' /></a>";
		}
		
 document.getElementById('select_month').value=select_m;
 document.getElementById('select_year').value=select_y;
 document.getElementById('now_select_year').innerHTML="<img src='common/images/year/"+select_y+".gif'/>";
 document.getElementById('now_select_month').innerHTML="<img src='common/images/month/"+select_m+".gif'/>";
 
 if(document.getElementById('calendar_op').value==1){
		
 document.getElementById('calendar_action_year').innerHTML="<img src='common/images/calendar/year/"+select_y+".jpg'/>";
 	 for(i=1;i<=12;i++){
		 if(i==select_m){
 document.getElementById('month'+i).innerHTML="<img src='common/images/calendar/month/"+i+"_a.jpg'/>";
	 }else{
 document.getElementById('month'+i).innerHTML="<a href='' onclick='updatedate2("+i+");return false'><img src='common/images/calendar/month/"+i+".jpg'/></a>";
		 }
	 }
 CalendarHttp.open("GET","http://"+window.location.host+"/big5/calendar_date.asp?year="+select_y+"&month="+select_m+"" ,true);
 CalendarHttp.onreadystatechange = handleHttpCalendarDate;
 CalendarHttp.send(null);
 
}


 if(document.getElementById('calendar_op').value==2){
		
 document.getElementById('calendar_action_year').innerHTML="<img src='common/images/calendar/year/"+select_y+".jpg'/>";
	 document.getElementById('calendar_action_month_arrow2').innerHTML="<a href='' onClick='updatedate(0,-1);return false' ><img src='common/images/icon/arrow.jpg' /></a>";
	 document.getElementById('calendar_action_month_arrow').innerHTML="<a href='' onClick='updatedate(0,1);return false' ><img src='common/images/icon/arrow2.jpg' /></a>";
	 document.getElementById('calendar_action_month').innerHTML="<img src='common/images/calendar/month/"+select_m+".jpg'/>";
	 
 document.getElementById('calendar_action_year').innerHTML="<img src='common/images/calendar/year/"+select_y+".jpg'/>";
 	 for(i=1;i<=12;i++){
		 if(i==select_m){
 document.getElementById('month'+i).innerHTML="<img src='common/images/select/"+i+".jpg'/>";
	 }else{
 document.getElementById('month'+i).innerHTML="<a href='' onclick='updatedate2("+i+");return false'><img src='common/images/noselect/"+i+".jpg'/></a>";
		 }
	 }

CalendarHttp.open("GET","http://"+window.location.host+"/big5/calendar_date2.asp?year="+select_y+"&month="+select_m+"" ,true);
 CalendarHttp.onreadystatechange = handleHttpCalendarDate;
 CalendarHttp.send(null);
 
}

 xmlhttp.open("GET","http://"+window.location.host+"/big5/select_date.asp?year="+select_y+"&month="+ select_m+"" ,true);
 xmlhttp.onreadystatechange = handleHttpUpdatedate;
 xmlhttp.send(null); 
 CalendarHttp2.open("GET","http://"+window.location.host+"/big5/calendar.asp?s_year="+select_y+"&s_month="+select_m+"" ,true);
 CalendarHttp2.onreadystatechange = handleHttpUpdatedate2;
 CalendarHttp2.send(null); 

 }
 function updatedate2(month_num){
 select_m=month_num;
 select_y=document.getElementById('select_year').value;
 document.getElementById('select_month').value=select_m;
  if(document.getElementById('calendar_op').value==1){

 document.getElementById('now_select_month').innerHTML="<img src='common/images/month/"+select_m+".gif'/>";
 for(i=1;i<=12;i++){
		 if(i==select_m){
 document.getElementById('month'+i).innerHTML="<img src='common/images/calendar/month/"+i+"_a.jpg'/>";
	 }else{
 document.getElementById('month'+i).innerHTML="<a href='' onclick='updatedate2("+i+");return false'><img src='common/images/calendar/month/"+i+".jpg'/</a>";
		 }
	 }
  }else{
 for(i=1;i<=12;i++){
		 if(i==select_m){
 document.getElementById('month'+i).innerHTML="<img src='common/images/select/"+i+".jpg'/>";
	 }else{
 document.getElementById('month'+i).innerHTML="<a href='' onclick='updatedate2("+i+");return false'><img src='common/images/noselect/"+i+".jpg'/</a>";
		 }
	 }	 
	 }
 CalendarHttp.open("GET","http://"+window.location.host+"/big5/calendar_date.asp?year="+select_y+"&month="+select_m+"" ,true);
 CalendarHttp.onreadystatechange = handleHttpCalendarDate;
 CalendarHttp.send(null); 

 xmlhttp.open("GET","http://"+window.location.host+"/big5/select_date.asp?year="+select_y+"&month="+ select_m+"" ,true);
 xmlhttp.onreadystatechange = handleHttpUpdatedate;
 xmlhttp.send(null); 
 }
function getHTTPObject(){
 var xmlhttp =false; 
 
if(window.XMLHttpRequest)
{	
	xmlhttp = new XMLHttpRequest();
if(xmlhttp.overrideMimeType)
{
xmlhttp.overrideMimeType('text/xml');
}
}
else{
	var arrXmlDomTypes = [];
    // assume IE6 or older
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                     "MSXML2.XMLHTTP.5.0",
                                     "MSXML2.XMLHTTP.4.0",
                                     "MSXML2.XMLHTTP.3.0",
                                     "MSXML2.XMLHTTP",
                                     "Microsoft.XMLHTTP");
    // try every prog id until one works
    for (var i=0; i<XmlHttpVersions.length && !xmlhttp; i++) 
    {
      try 
      { 
        // try to create XMLHttpRequest object
        xmlhttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
 }
 return xmlhttp;
 }
 
 
function getCalendarObject(){
 var CalendarHttp =false; 
 
if(window.XMLHttpRequest)
{
	
CalendarHttp = new XMLHttpRequest();
if(CalendarHttp.overrideMimeType)
{
CalendarHttp.overrideMimeType('text/xml');
}
}
else{
    // assume IE6 or older
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    // try every prog id until one works
    for (var i=0; i<XmlHttpVersions.length && !CalendarHttp; i++) 
    {
      try 
      { 
        // try to create XMLHttpRequest object
        CalendarHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
 }
 return CalendarHttp;
 }
 
 
 function getCalendarObject2(){
 var CalendarHttp2 =false; 
 
if(window.XMLHttpRequest)
{
	
CalendarHttp2 = new XMLHttpRequest();
if(CalendarHttp2.overrideMimeType)
{
CalendarHttp2.overrideMimeType('text/xml');
}
}
else{
    // assume IE6 or older
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    // try every prog id until one works
    for (var i=0; i<XmlHttpVersions.length && !CalendarHttp2; i++) 
    {
      try 
      { 
        // try to create XMLHttpRequest object
        CalendarHttp2 = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
 }
 return CalendarHttp2;
 }

 
 //圖層隱藏
function show_detailed(t_id){
document.getElementById("detailed" + t_id).style.display = "";
}

function hide_detailed(t_id){
document.getElementById("detailed" + t_id).style.display = "none";
}
function show_sub_detailed(t_id){
document.getElementById("sub_detailed" + t_id).style.display = "";
}

function hide_sub_detailed(t_id){
document.getElementById("sub_detailed" + t_id).style.display = "none";
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
