// JavaScript Document
function $(id){return document.getElementById(id);}
function $T(id){return document.getElementsByTagName?document.getElementsByTagName(id):new Array()}
//var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
//var days = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
//var mtend = [31,28,31,30,31,30,31,31,30,31,30,31];
var TxtMoth=['','一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
function MyDategoDown(length){
	var where = $('ListDateShow').scrollTop + (length);
	if(where<0) 
		where=0;
	$('ListDateShow').scrollTop = where;
	return false;
}
function getLastDay(year,month)// 获取一月最后一天
{
	var new_year = year;    //取当前的年份
	var new_month = month++;//取下一个月的第一天，方便计算（最后一天不固定）
	if(month>12)            //如果当前大于12月，则年份转到下一年
	{
	new_month -=12;        //月份减
	new_year++;            //年份增
	}
	var new_date = new Date(new_year,new_month,1);                //取当年当月中的第一天
	return (new Date(new_date.getTime()-1000*60*60*24)).getDate();//获取当月最后一天日期
}
function WriteDivNone(Num){//线路页价格日历生成空白格
	var Rhtm='';
	for(var a=1;a<=Num;a++){
		Rhtm=Rhtm+"<div style=\"height:26px;\">&nbsp;</div>";
	}
	return Rhtm;
}
function WriteDivNone1(Num){//地区页可移动价格日历生成空白格
	var Rhtm='';
	for(var a=1;a<=Num;a++){
		Rhtm=Rhtm+"<div style=\"height:43px;\">&nbsp;</div>";
	}
	return Rhtm;
}
function scroll_top(){    
    var scrollPos;    
    if (typeof window.pageYOffset != 'undefined') {    
         scrollPos = window.pageYOffset;    
     }    
    else if (typeof document.compatMode != 'undefined' &&    
         document.compatMode != 'BackCompat') {    
         scrollPos = document.documentElement.scrollTop;    
     }    
    else if (typeof document.body != 'undefined') {    
         scrollPos = document.body.scrollTop;    
     }    
    return scrollPos;    
} 
function ReplacePrice(cz,MyPrice,MyEtPrice,MyScPrice,MyDate,DateInnerHTML,qz){
	qz = typeof(qz)=='undefined' ? '' : qz;
	if(!$("ShowDatePrice")){
		$(cz).innerHTML='<div id="ShowDatePrice"><table border="0" align="left" cellpadding="4" cellspacing="0"><tr><td width="36" bgcolor="#F1F9FF" class="title">类型</td><td bgcolor="#F1F9FF" class="title">价格</td></tr><tr><td width="36" class="td">九游汇</td><td class="td" id="ShowDatePrice_JYH">&nbsp;</td></tr><tr><td width="36" class="td">市场</td><td class="td" id="ShowDatePrice_SC">&nbsp;</td></tr><tr><td class="td" width="36">儿童</td><td class="td" id="ShowDatePrice_ET">&nbsp;</td></tr><tr><td colspan="2" align="center" class="td" id="ShowDatePrice_SJ">&nbsp;</td></tr></table></div>';
	}
	//var JDate=new Date();
	var CPdate=new Date();
	//alert(CPdate.getTime());
	for(var i=0;i<MyDate.length;i++){
		var Ad=MyDate[i].split("-");
		var PDate=new Date(Ad[0],Ad[1],Ad[2]);
		//var PTdate=new Date(parseInt(Ad[0]),parseInt(Ad[1])-1,parseInt(Ad[2]),0,0,0);
		//alert(MyDate[i]+"---"+JDate.getYear()+"-"+JDate.getMonth()+"-"+JDate.getDate());
//if((Ad[0]<=JDate.getYear() && Ad[1]<=JDate.getMonth()+1 && Ad[2]>=JDate.getDate()) || (Ad[0]<=JDate.getYear() && Ad[1]>JDate.getMonth()+1))
		if(PDate > CPdate)
		if($(qz+''+MyDate[i])){
			eval("var D"+MyDate[i].replace(/[-]/g,"")+"=['"+MyPrice[i]+"','"+MyEtPrice[i]+"','"+MyScPrice[i]+"','"+MyDate[i]+"'];")
			$(qz+''+MyDate[i]).style.cursor="pointer";
			$(qz+''+MyDate[i]).innerHTML="<span>"+$(qz+''+MyDate[i]).innerHTML+" "+DateInnerHTML+MyPrice[i]+"元</span>";
			$(qz+''+MyDate[i]).onclick=function(){
				//alert(eval("D"+this.title.toString().replace(/[-]/g,"")+"[3]"));
				switch(cz){
					case 'Line':
						$('starttime').value=eval("D"+this.title.toString().replace(/[-]/g,"")+"[3]");
						$('people').focus();
						//window.location.href='#Ordering';
						$("ShowAjaxDate").style.display="none";
						break;
					case 'AjaxDatePrice':
						alert(eval("D"+this.title.toString().replace(/[-]/g,"")+"[3]"));
						break;
				}
			}
			$(qz+''+MyDate[i]).onmouseout=function(){
				$('ShowDatePrice').style.display='none';
			}
			$(qz+''+MyDate[i]).onmousemove=function(evt){
				var t="D"+this.title.toString().replace(/[-]/g,"");
				var evt=evt || window.event;
				if(evt.pageX){
				xPos=evt.pageX;
				yPos=evt.pageY;
				} else {
					//alert(document.body.scrollTop);
				xPos=evt.clientX+document.body.scrollLeft-document.body.clientLeft;
				yPos=scroll_top()+evt.clientY+document.body.scrollTop-document.body.clientTop;
				//yPos=document.body.scrollHeight-yPos;
				//alert(document.body.offsetHeight);
				}
				$('ShowDatePrice').style.left=xPos+10+'px';
				$('ShowDatePrice').style.top=yPos+10+'px';
				$('ShowDatePrice').style.display='block';
				$(cz).style.display='block';
				$(cz).style.height=0+"px";
				$('ShowDatePrice_SJ').innerHTML=eval("D"+this.title.toString().replace(/[-]/g,"")+"[3]");
				$('ShowDatePrice_SC').innerHTML=eval("D"+this.title.toString().replace(/[-]/g,"")+"[2]");
				$('ShowDatePrice_ET').innerHTML=eval("D"+this.title.toString().replace(/[-]/g,"")+"[1]");
				$('ShowDatePrice_JYH').innerHTML=eval("D"+this.title.toString().replace(/[-]/g,"")+"[0]");
			}
		}
	}
}

function ShowLine_Date(obj,MyPrice,MyEtPrice,MyScPrice,MyDate){    //不可移动日历
	var CDate = new Date();
	var Year = CDate.getFullYear();
	var Month = CDate.getMonth()+1;
	var ToDay = CDate.getDate();
	var Week = CDate.getDay();
	//document.write(new Date(2009,05,01).getDay());  //月份需要-1
	Rv='';
	for(var n=Month;n<=Month+2;n++){
		if(n>=13){
			Year=Year+1;
			Month=Month+2 - n;
			n=1;
		}		
		var MaxDay = getLastDay(Year,n);
		Rv=Rv+"<div class=\"ListDateLfet\">"+Year+"<br>"+TxtMoth[n]+"</div>\r\n";
		Rv=Rv+"<div class=\"ListDateCenter\">\r\n";
		for(var i=1;i<=MaxDay;i++){
			if(i==1){
				var tWeek=parseInt(new Date(Year,n-1,1).getDay())+1;
				//if(tWeek != 1)Rv=Rv+""+WriteDivNone(tWeek-1);
				if(tWeek == 0 )Rv=Rv+""+WriteDivNone(6);
				if(tWeek != 1 && tWeek != 0)Rv=Rv+""+WriteDivNone(tWeek-1);
			}
			var MyN=n.toString();
			var MyI=i.toString();
			if(MyN.length==1)MyN='0'+n;
			if(MyI.length==1)MyI='0'+i;
			if(Month==n && ToDay==i){  //#f7fafd
				Rv=Rv+"<div id=\"A"+Year+"-"+MyN+"-"+MyI+"\" title=\""+Year+"-"+MyN+"-"+MyI+"\" style=\"background:#ecf3fb\">"+MyI+"</div>\r\n";
			}else{
				if(Month==n && ToDay>i){
					Rv=Rv+"<div id=\"A"+Year+"-"+MyN+"-"+MyI+"\" title=\""+Year+"-"+MyN+"-"+MyI+"\" style=\"background:#ffffff\">"+MyI+"</div>\r\n";
				}else{
					Rv=Rv+"<div id=\"A"+Year+"-"+MyN+"-"+MyI+"\" title=\""+Year+"-"+MyN+"-"+MyI+"\" style=\"background:#F4F4F4\">"+MyI+"</div>\r\n";
				}
			}
			if(i==MaxDay){
				var eWeek=new Date(Year,n-1,i).getDay();
				if(eWeek <= 6 && eWeek!=0)Rv=Rv+""+WriteDivNone(6-eWeek);
			}
		}
		Rv=Rv+"</div>\r\n";		
	}
	$(obj).innerHTML=Rv;
	Rv='';
	ReplacePrice("Line",MyPrice,MyEtPrice,MyScPrice,MyDate,'','A');
}

function AjaxDateShow(Year,Month,MyPrice,MyEtPrice,MyScPrice,MyDate,ShowPrice,thisId){   //  可移动日历  
	//alert(0);
	Month=parseInt(Month);
	Year=parseInt(Year);
	$("ShowAjaxDateT").innerHTML=Year+"年&nbsp;"+(Month)+"月&nbsp;&nbsp;&nbsp;关闭";
	var o=$(thisId);
	var x=0;
	var y=0
	if(o!=null){
		x=o.offsetLeft;
		y=o.offsetTop;
		while(o=o.offsetParent){
			x+=o.offsetLeft;
			y+=o.offsetTop;
		}
	}
	var webW=parseInt(document.body.scrollWidth);
	if(x+480 > webW){
		x=webW-480;
	}
	$("ShowAjaxDate").style.display="block";
	$("ShowAjaxDate").style.top=y+parseInt($(thisId).style.height)+"px";
	$("ShowAjaxDate").style.left=x+"px";
	$("ShowAjaxDateT").title="关闭";
	$("ShowAjaxDateT").style.cursor="pointer";
	$("ShowAjaxDateT").onclick=function(){$('ShowAjaxDate').style.display="none";}
	var toDate=new Date();
	var toYear=parseInt(toDate.getFullYear());
	var toMonth=parseInt(toDate.getMonth())+1;
	var toDay=parseInt(toDate.getDate());
	var StartWeek=new Date(Year,Month-1,1).getDay();  	//  第一天星期几
	var LastDate=getLastDay(Year,Month);				//  最后一天
	var LastDay=new Date(Year,Month-1,LastDate).getDay();// 最后一天星期几
	var Rhtml='';
	for(var i=1;i<=LastDate;i++){
		if(i==1){
			if(StartWeek == 0 )Rhtml=Rhtml+""+WriteDivNone1(6);
			if(StartWeek != 1 && StartWeek != 0)Rhtml=Rhtml+""+WriteDivNone1(StartWeek-1);
		}
		Si=i.toString();
		if(Si.length==1)Si='0'+i;
		SMonth=Month.toString();
		if(SMonth.length==1)SMonth='0'+SMonth;
		var ShowId=Year+"-"+SMonth+"-"+Si;   //Year+"-"+Month+"-"+Si;
		var ShowTitle=Year+"-"+SMonth+"-"+Si;
		if(Year==toYear && Month==toMonth && toDay==i){
			Rhtml=Rhtml+"<div id=\""+ShowId+"\" style=\"background:#efefef;height:43px;\" title=\""+ShowTitle+"\">"+Si+"&nbsp;<span style=\"font-size:9px;font-weight:normal;line-height:0px;height:12px\">今天</span></div>";
		}else if(Year <= toYear && Month <= toMonth){
			if(Year == toYear && Month == toMonth && i > toDay){
				Rhtml=Rhtml+"<div id=\""+ShowId+"\" onmousemove=\"this.style.background='#DBDBDB';\" onmouseout=\"this.style.background='#FFFFFF';\" style=\"background:#ffffff;height:43px;\" title=\""+ShowTitle+"\">"+Si+"</div>";
			}else if(Year <= toYear && Month <= toMonth){
				Rhtml=Rhtml+"<div id=\""+ShowId+"\" onmousemove=\"this.style.background='#DBDBDB';\" onmouseout=\"this.style.background='#F5F5F5';\" style=\"background:#F5F5F5;height:43px;\" title=\""+ShowTitle+"\">"+Si+"</div>";
			}
		}else{
			Rhtml=Rhtml+"<div id=\""+ShowId+"\" style=\"height:43px;\" onmousemove=\"this.style.background='#DBDBDB';\" onmouseout=\"this.style.background='#ffffff';\" title=\""+ShowTitle+"\">"+Si+"</div>";
		}
		if(i==LastDate){
			if(LastDay <= 6 && LastDay != 0 )Rhtml=Rhtml+""+WriteDivNone1(7-LastDay);
		}
	}
	$("ShowAjaxWrite").innerHTML=Rhtml;
	Rhtml='';
	$("ShowAjaxDateT_2").onclick=function(){
		if(Month+1 >= 13){AjaxDateShow(Year+1,1,MyPrice,MyEtPrice,MyScPrice,MyDate,ShowPrice,thisId);}
		else{AjaxDateShow(Year,Month+1,MyPrice,MyEtPrice,MyScPrice,MyDate,ShowPrice,thisId);}
	}
	$("ShowAjaxDateT_1").onclick=function(){
		if(Month-2<=1){AjaxDateShow(Year-1,12,MyPrice,MyEtPrice,MyScPrice,MyDate,ShowPrice,thisId);}
		else{AjaxDateShow(Year,Month-1,MyPrice,MyEtPrice,MyScPrice,MyDate,ShowPrice,thisId);}
	}
	if(ShowPrice!='')ReplacePrice(ShowPrice,MyPrice,MyEtPrice,MyScPrice,MyDate,'<br>');
}
