﻿
// JavaScript Document

var languageName="cn"  //内容显示的语言 value:"cn" "en"

var currentMonth,currentYear

var nextMonth,nextMonthYear

var nowDate,nowMonth,nowYear

var selInputId

var  dateForm

var index

var totalNum



d=new Date();

nowDate=d.getDate()

nowMonth=d.getMonth()

nowYear=d.getFullYear()

currentMonth=nowMonth

currentYear=nowYear

nextMonth=currentMonth+1

nextMonthYear=currentYear

if (nextMonth>11) {nextMonth=0;nextMonthYear++}


arrWeekCaption_cn = new Array("日","一","二","三","四","五","六")

arrMonthCaption_cn= new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月")




function selectdate(){

    output='<table  border="0" cellpadding="0" cellspacing="1"  width="300">'

    //output='<table cellpadding=0 cellspacing=1 style="border:1 solid #0099ff;width:150;cursor:default" id="tblMonthView" onselectstart="return false" bgcolor="#FFFFFF">'

    output+='<tr>'

    output+=' <td bgcolor="#FFFFFF" align="center" width="150" valign="top">'

    // output='<table width="98%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF">'

    // output+='<tr>'

    //output+=' <td>'	

	output+='        <table width="100%" cellpadding=0 cellspacing=0 bgcolor="#ADE0FC" >'

    output+='            <tr style="padding-top:2;padding-bottom:2;"  id="trCaption">'

    output+='                <td align="center" width="20%"> <a href="javascript:showCurrentDate(\'preview\')"><img src="/images/gongyong/leftarrow.gif" width="20" height="20" border="0"></a></td>'

    output+='                <td align="center" width="60%"><span style="padding-left:10;font-size:12" id="spanCurrentYear"></span>年<span id="spanCurrentMonth" style="font-size:12;"></span></td>'

    output+='                <td align="center" width="20%"></td>'

    output+='            </tr>'

    output+='        </table>'

    //output+='      </td>'

    //output+='    </tr>'

    //output+='    <tr>'

    //output+='      <td>'

    output+='        <table width="98%" cellpadding=0 cellspacing=3 id="tblShowDay" name="tblShowDay" style="font-size:12"  bgcolor="#FFFFFF">'

    output+='            <tr align="center"><td style="color:#FF0000;"></td><td></td><td></td><td></td><td></td><td></td><td style="color:#FF0000"></td></tr>'

    output+='            <tr ><td colspan=7 height="1" style="background:#7DBEFF" id="tdLine"></td></tr>'

    output+='            <tr ><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>'

    output+='        </table>'

    //output+='      </td>'

    //output+='    </tr>'

    //output+='    <tr>'

    //output+='      <td>'

	output+='    </td>'
	
	
	
	
	
    output+=' <td bgcolor="#FFFFFF" align="center"  width="150" valign="top">'

    // output='<table width="98%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF">'

    // output+='<tr>'

    //output+=' <td>'	

	output+='        <table width="100%" cellpadding=0 cellspacing=0 bgcolor="#ADE0FC" >'

    output+='            <tr style="padding-top:2;padding-bottom:2;"  id="trCaptionNext">'

    output+='                <td align="center" width="20%"></td>'

    output+='                <td align="center" width="60%"><span style="padding-left:10;font-size:12" id="spanNextMonthYear"></span>年<span id="spanNextMonth" style="font-size:12;"></span></td>'

    output+='                <td align="center" width="20%"><a href="javascript:showCurrentDate(\'next\')"><img src="/images/gongyong/rightarrow.gif" width="20" height="20" border="0"></a></td>'

    output+='            </tr>'

    output+='        </table>'

    //output+='      </td>'

    //output+='    </tr>'

    //output+='    <tr>'

    //output+='      <td>'

    output+='        <table width="98%" cellpadding=0 cellspacing=3 id="tblShowDayNext" name="tblShowDayNext" style="font-size:12"  bgcolor="#FFFFFF">'

    output+='            <tr align="center"><td style="color:#FF0000;"></td><td></td><td></td><td></td><td></td><td></td><td style="color:#FF0000"></td></tr>'

    output+='            <tr ><td colspan=7 height="1" style="background:#7DBEFF" id="tdLine"></td></tr>'

    output+='            <tr ><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>'

    output+='        </table>'

    //output+='      </td>'

    //output+='    </tr>'

    //output+='    <tr>'

    //output+='      <td>'


	output+='    </td>'


    output+='   </tr>'

    
	output+='   <tr>'		
	output+='    <td colspan="2">'
    output+='        <table width="100%" cellpadding=0 cellspacing=2 id="tblToday" style="font-size:12"  bgcolor="#FFFFFF">'
    output+='            <tr><td align=center><a style="text-decoration:none" href="javascript:closeDate()"  onclick="window.focus()">关闭</a></td></tr>'
    output+='        </table>'
    output+='    </td>'
    output+='   </tr>'	

    output+='</table>'

	//output+='    </td>'

    //output+='   </tr>'

    //output+='</table>'


    document.write (output);
    setCurrentCaption();
    setWeekCaption();
    bulidDay("tblShowDay",currentMonth,currentYear,"1");
    bulidDay("tblShowDayNext",nextMonth,nextMonthYear,"2");
}



function closeDate(){

   document.getElementById("dateselect").style.visibility="hidden"

}



//酒店日期

function opendate(imgid,inputid,ind,totalnum,dateform){

  //var t

  //var l

  totalNum=totalnum

  selInputId=inputid

  dateForm=dateform
  
  index=parseInt(ind)

  var e=document.getElementById(imgid)

  var t=e.offsetTop;

  var l=e.offsetLeft;

  while(e=e.offsetParent){

		t+=e.offsetTop;

		l+=e.offsetLeft;

  }

  t=t+33+index*52;
  l=l-67;

  document.getElementById("dateselect").style.top=t+"px"

  document.getElementById("dateselect").style.left=l+"px"

  document.getElementById("dateselect").style.visibility="visible"

}



function opendate1(imgid,inputid,ind,totalnum,dateform){

  //var t

  //var l

  totalNum=totalnum

  selInputId=inputid

  dateForm=dateform
  
  index=parseInt(ind)

  var e=document.getElementById(imgid)

  var t=e.offsetTop;

  var l=e.offsetLeft;

  while(e=e.offsetParent){

		t+=e.offsetTop;

		l+=e.offsetLeft;

  }

  t=t+23+index*52;
  
  document.getElementById("dateselect").style.top=t+"px"

  document.getElementById("dateselect").style.left=l+"px"

  document.getElementById("dateselect").style.visibility="visible"

}



//设置年月
function setCurrentCaption(){

    document.getElementById("spanCurrentYear").innerHTML=currentYear
    document.getElementById("spanCurrentMonth").innerHTML=arrMonthCaption_cn[currentMonth]
    document.getElementById("spanNextMonthYear").innerHTML=nextMonthYear
    document.getElementById("spanNextMonth").innerHTML=arrMonthCaption_cn[nextMonth]
}



function setWeekCaption(){ 

    arrCaption=arrWeekCaption_cn

    for (var i=0; i<arrCaption.length; i++){        
        document.getElementById("tblShowDay").rows[0].cells[i].innerHTML=arrCaption[i]
        document.getElementById("tblShowDayNext").rows[0].cells[i].innerHTML=arrCaption[i]
    }

}



function bulidDay(DayID,CurMonth,CurYear,ActNo){
          
    arrMonthCount=new Array(31,28,31,30,31,30,31,31,30,31,30,31)

    if ((CurYear % 400 ==0) || ((CurYear % 100==0)&&(CurYear % 4==0))){

        arrMonthCount[1]=29

    }

    rowDay=2

    while ( document.getElementById(DayID).rows.length>rowDay){

       document.getElementById(DayID).deleteRow(rowDay)

    }    

    firstDay=new Date(CurYear,CurMonth,1);

    tempRow=document.getElementById(DayID).insertRow(-1);

    //*********填充当月1号以前的日期*********

    for (var j=0 ;j<firstDay.getDay();j++){

        tempCell=tempRow.insertCell(-1);

    }

    //*************************************

    for (var i=1 ;i<=arrMonthCount[CurMonth]; i++){

        tempCell=tempRow.insertCell(-1)

        tempCell.style.textAlign="center"

		if(nowYear==CurYear && nowMonth==CurMonth){

		  if(i<nowDate){

           tempCell.style.color="#CCCCCC"

		  }

		  else if(nowDate==i){

           tempCell.style.color="#FF0000"

		   tempCell.style.cursor="pointer"

		   if(ActNo==1)
		      tempCell.onclick=action
		   else
		      tempCell.onclick=action1

		  }

		  else{

		   tempCell.style.color="#3333FF"

		   tempCell.style.cursor="pointer"
		   
		   if(ActNo==1)
		      tempCell.onclick=action
		   else
		      tempCell.onclick=action1

		  } 

		}

		else if(CurYear==nowYear && CurMonth>nowMonth){

		   tempCell.style.color="#3333FF"

		   tempCell.style.cursor="pointer"

		   if(ActNo==1)
		      tempCell.onclick=action
		   else
		      tempCell.onclick=action1

		}

		else if(CurYear>nowYear){

		   tempCell.style.color="#3333FF"

		   tempCell.style.cursor="pointer"

		   if(ActNo==1)
		      tempCell.onclick=action
		   else
		      tempCell.onclick=action1

		}

		else{

		  tempCell.style.color="#CCCCCC"

		}

        tempCell.innerHTML=i

       if ((i+firstDay.getDay()) %7 == 0 && i!=arrMonthCount[CurMonth]){tempRow=document.getElementById(DayID).insertRow(-1)}

    }
	
}



function showCurrentDate(direction){

    if (direction=="preview"){

        currentMonth=currentMonth-2
        if (currentMonth<0) {currentMonth=11 ;currentYear--}
		

    }

    if (direction=="next"){

        currentMonth=currentMonth+2

        if (currentMonth>11) {currentMonth=0 ;currentYear++}

    }

	nextMonth=currentMonth+1
	nextMonthYear=currentYear;
    if (nextMonth>11) {nextMonth=0 ;nextMonthYear++}
    

    setCurrentCaption()

    bulidDay("tblShowDay",currentMonth,currentYear,"1")
	bulidDay("tblShowDayNext",nextMonth,nextMonthYear,"2")
}





function action(){


    var linkchar1="-";

	var linkchar2="-";

    if(currentMonth<9)

	 linkchar1="-0";

	if(this.innerHTML<10)

	 linkchar2="-0";

     MonthView_value=currentYear+linkchar1+(currentMonth+1)+linkchar2+this.innerHTML

	if(totalNum>1){

         window.document.forms[dateForm].elements[selInputId][index].value=MonthView_value

	}

	else{

         window.document.forms[dateForm].elements[selInputId].value=MonthView_value

	}

	closeDate()

	if(selInputId=="st"){

	  opendate('et','et',index,totalNum,dateForm)

	}
	
	if(selInputId=="st2"){

	  opendate('et2','et2',index,totalNum,dateForm)

	}
}

function action1(){


    var linkchar1="-";

	var linkchar2="-";

    if(nextMonth<9)

	 linkchar1="-0";

	if(this.innerHTML<10)

	 linkchar2="-0";

     MonthView_value=nextMonthYear+linkchar1+(nextMonth+1)+linkchar2+this.innerHTML

	if(totalNum>1){

         window.document.forms[dateForm].elements[selInputId][index].value=MonthView_value

	}

	else{

         window.document.forms[dateForm].elements[selInputId].value=MonthView_value

	}

	closeDate()

	if(selInputId=="st"){

	  opendate('et','et',index,totalNum,dateForm)

	}
	
	if(selInputId=="st2"){

	  opendate('et2','et2',index,totalNum,dateForm)

	}
}
