var winrow=new Array();
var winno='';
var curdt=new Date();
var curye=curdt.getFullYear();
var curmt=curdt.getMonth()+1;
var curda=curdt.getDate();
var ptd=/^20\d{2}-[01]?\d{1}-[0-3]?\d{1}$/,shu=/^[1-9]+\d*$/;
var tpye,tpmt,tpda,thye,thmt,thda;
function $(id)
{
	return document.getElementById(id);
}
function get_request()
{
	var http_request = false;
	if(window.XMLHttpRequest)
	{
		http_request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		try 
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	}
	if (!http_request)
	{
		window.alert("不能创建XMLHttpRequest对象实例.");
		return false;
	}
	return http_request;
}
function ob_hid(id,flag)
{
	if($(id)) $(id).style.display=(flag)?'none':'block';
}
function getpos(ob)
{
	var add=(document.layers) ? 2 : 0;
	var obtp=ob;
	var top=0;
	var left=0;
	do 
	{
		obtp=obtp.offsetParent;
		left+=obtp.offsetLeft;
		top+=obtp.offsetTop;
	}
	while(obtp.tagName!="BODY" && obtp.tagName!="HTML");
	
	var temp=new Array();
	
	temp[0]=ob.offsetLeft+left;
		
	temp[1]=ob.offsetTop+top+ob.offsetHeight+add;
	return temp;
}
function hidwin()
{
	for(x in winrow)
	ob_hid(winrow[x],1);
	if(winno)ob_hid(winno);
	winno='';
}
function getcy(e)
{
	e=(e)?e:window.event;
	ob=(e.target)?e.target:e.srcElement;
	if(!$('cydiv'))
	{
		var bd=document.getElementsByTagName('body').item(0);
		var itm=document.createElement('div');
		
		itm.setAttribute('id','cydiv');
		
		itm.className='city';
		
		itm.onclick=function(e)
		{
			e=(e)?e:window.event;
			e.cancelBubble=true;
		}		
		winrow[winrow.length]='cydiv';		
		
		bd.appendChild(itm);		

		$('cydiv').innerHTML='<ul><li class="right" onclick="ob_hid(\'cydiv\',1)">关闭</li><li><select id="pro" onchange="add2(this,\'cityr\')"><option value="0">选择省直辖市</option></select></li></ul><ul id="cityr"><li>请先选择省直辖市</li><ul>';

		for(x in pro)
		{
			if(x!='clear')
			addse('pro',x,pro[x]);
		}
	}
	var row=getpos(ob);	
	$('cydiv').style.left=row[0]+'px';			
	$('cydiv').style.top=row[1]+'px';	
	ob_hid('cydiv');	
	winno='cydiv';
	
	//e.cancelBubble=true;
}

function showd(id,e)
{
	e=(e)?e:window.event;
	ob=(e.target)?e.target:e.srcElement;
	if(!$(id+'_0'))
	{
		var bd=document.getElementsByTagName('body').item(0);
		var itm=document.createElement('div');
		
		itm.setAttribute('id',id+'_0');
		
		itm.className='date';
		
		itm.onclick=function(e)
		{
			e=(e)?e:window.event;
			e.cancelBubble=true;
		}
		
		var row=getpos(ob);
		
		winrow[winrow.length]=id+'_0';
		
		bd.appendChild(itm);
		
		itm.style.left=row[0]+'px';

		itm.style.top=row[1]+'px';

	}
	
	var yst=trim(ob.value);
	var ptd=/^(20\d{2})-([01]?\d{1})-([0-3]?\d{1})$/;
	tpye=curye;
	tpmt=curmt;
	tpda=curda;
	var row=ptd.exec(yst)
	if(row && row[2]>0 && row[2]<13)
	{
		tpye=row[1];
		tpmt=row[2];tpmt++;tpmt--;
		tpda=row[3];
	}
	thye=tpye;thmt=tpmt;thda=tpda;
	
	$(id+'_0').innerHTML='<div id="'+id+'_1"><ul class="top"><li onclick="ob_hid(\''+id+'_0\',1)">关闭</li></ul><ul class="mid"><li onclick="mpre(\''+id+'\',1)">&lt;&lt;</li><li id="'+id+'_2" class="hdno">'+tpye+'.'+tpmt+'</li><li  onclick="mpre(\''+id+'\',-1)">&gt;&gt;</li></ul></div><div id="'+id+'_3" class="end"></div>';
	
	mpre(id,0);
	
	ob_hid(id+'_0');
	
	winno=id+'_0';
	//e.cancelBubble=true;
}

function chdt(id,ye,mon,ob)
{
	$(id).value=ye+'-'+((mon<10)?'0'+mon:mon)+'-'+ob.innerHTML;
	//alert(id);
	ob_hid(id+'_0',1);
}

function mpre(id,flag)
{
	if(flag==1) {if(tpmt==1){tpmt=12;tpye--;}else tpmt--;}
	if(flag==-1) {if(tpmt==12){tpmt=1;tpye++;}else tpmt++;}
	
	var num=32;
	if(tpmt==4 || tpmt==6 || tpmt==9 || tpmt==11) num=31;
	if(tpmt==2)
	{
		num=29;
		if(tpye%400==0 || (tpye%4==0 && tpye%100!=0)) num=30;
	}
	
	var temp=new Array();
	
	var n=0;
	
	for(var i=1;i<num;i++)
	{
		var tmdt=new Date(tpye,tpmt-1,i);
		var xin=tmdt.getDay();
		
		if(typeof(temp[n])=='undefined') temp[n]=new Array();		
		temp[n][tmdt.getDay()]=i;
		
		if(xin==6) n++;
	}
	var str='<ul class="xq"><li>日</li><li>一</li><li>二</li><li>三</li><li>四</li><li>五</li><li>六</li></ul>';
	for(var i=0;i<=n;i++)
	{
		str+='<ul>';
		for(var x=0;x<7;x++)
		{			
			if((typeof(temp[i])!='undefined' && typeof(temp[i][x])!='undefined'))
			{
				var cls='';
				if(temp[i][x]==curda && tpye==curye && tpmt==curmt) cls+='cur';
				if(temp[i][x]==thda && tpye==thye && tpmt==thmt) cls+=(cls)?' chs':'chs';
				cls=(cls)?' class="'+cls+'"':'';
				str+='<li'+cls+' onclick="chdt(\''+id+'\','+tpye+','+tpmt+',this)">'+((temp[i][x]<10)? '0'+temp[i][x]:temp[i][x])+'</li>';
			}
			else str+='<li class="hdno">&nbsp;</li>';
		}
		str+='</ul>';
	}
	$(id+'_3').innerHTML=str;
	//alert(str);
	$(id+'_2').innerHTML=tpye+'.'+((tpmt<10)?'0'+tpmt:tpmt);
}


function addse(id,val,txt)
{
	$(id).options.add(new Option(txt,val));
}
function add2(ob,ctid)
{
	var id=ob.value;
	
	var str='';
	
	if(id==0)
	{str='<li>请先选择省直辖市</li>';}
	else
	{
		var row2=cit[id].split(',');
		for(i=0;i<row2.length;i++)
		{
			var row3=row2[i].split('-');
			str+='<li class="ocity" onclick="chcity(\''+row3[1]+'\',\''+row3[0]+'\')">'+row3[1]+'</li>';
		}
	}
	$(ctid).innerHTML=str;
	
}
var pro=new Array();
var cit=new Array();
var row=cstr.split('|');
for(i=0;i<row.length;i++)
{
	row1=row[i].split(':');
	pro[i+1]=row1[0];
	cit[i+1]=row1[1];
}

function checkf(form,i)
{
	var x=(i)?i:'';
	//var std=form.CheckInDate;
	//var edd=form.CheckOutDate;
	//var std=form.elements['CheckInDate'+x];
	//var edd=form.elements['CheckOutDate'+x];
	var std=eval('form.CheckInDate'+x);
	var edd=eval('form.CheckOutDate'+x);
	//var ctn=$('city'+x);
	var pnm=form.PersonNum;
	var rnm=form.RoomNum;
	
	var tel="请填写 20??-??-?? 格式的日期,不能填写过大及过去的日期";
	var tl2='必须填写正整数';
	
	if(!ptd.exec(trim(std.value)))
	{
		alert(tel);
		std.focus();
		return false;
	}
	if(!trim(edd.value).match(ptd))
	{
		alert(tel);
		edd.focus();
		return false;
	}
	var row1=trim(std.value).split('-');
	var row2=trim(edd.value).split('-');
	
	var date1=new Date(row1[0],row1[1]-1,row1[2]);
	var date2=new Date(row2[0],row2[1]-1,row2[2]);
	var cur=new Date(curye,curmt-1,curda);

	if(date1.getTime()<cur.getTime())
	{
		alert('入店时间不能小于当前时间');
		std.focus();
		return false;
	}
	
	if(date1.getTime()>=date2.getTime())
	{
		alert('离店时间必须大于入店时间');
		edd.focus();
		return false;
	}
	
	if(!trim(pnm.value).match(shu))
	{
		alert('人数'+tl2);
		pnm.focus();
		return false;
	}
	if(!shu.exec(trim(rnm.value)))
	{
		alert('房间数'+tl2);
		rnm.focus();
		return false;
	}
	if(form.price.value==-1 && form.Star.value==-1 && !form.HotelName.value)
	{
		window.location.href='http://'+$('city'+x).value+'.869d.com/';
		return false;
	}
	//alert(form.action)
	form.action='http://'+$('city'+x).value+'.869d.com/search.php';
	return true;
}
function trim(s)
{
	var blk=/^\s*|\s*$/g;
	return s.replace(blk,'');
}

function chcity(name,id)
{
	$('cname').value=name;
	$('city').value=id;
	//alert($('city').value);
	ob_hid('cydiv',1);
}
if(document.attachEvent) document.attachEvent('onclick',hidwin);
else if(document.addEventListener) document.addEventListener('click',hidwin,false);
else document.onclick=hidwin;

var pare='',sp=Array(),fun='',fcs=Array();
function C_chge(head,num,cl1,cl2,mid)
{
	this.head=head;
	this.num=num;
	this.th=1;
	this.cl1=cl1;
	this.cl2=cl2;
	this.mid=mid;
	pare=this;
	
	for(var i=1;i<=this.num;i++)
	{
		$(this.head+i).onmouseover=function(){if($(pare.head+pare.th)!=this) this.className=pare.mid;};
		$(this.head+i).onmouseout=function(){if($(pare.head+pare.th)!=this) this.className=pare.cl2;};
	}
	
	/*this.unmid=function()
	{
		alert(this.th);
		alert(this);
	}*/
		
	this.show=function(x)
	{
		for(var i=1;i<=this.num;i++)
		{
			$(this.head+'_'+i).style.display='none';
			$(this.head+i).className=this.cl2;
		}
		$(this.head+'_'+x).style.display='block';
		$(this.head+x).className=this.cl1;
		this.th=x;
		for(n in sp)
		{
			if(x==sp[n] && fun)
			{
				fun(fcs[sp[n]]);
				break;
			}
		}
	}
}
function fmdate(mt)
{
	var dt=new Date(mt);
	var ty=dt.getFullYear(),tm=dt.getMonth()+1,td=dt.getDate();
	tm=(tm<10)?'0'+tm:tm;td=(td<10)?'0'+td:td;
	return ty+'-'+tm+'-'+td;
}
function readcookie(name)
{
	var re='';
	var mycc=document.cookie;
	var ex=new RegExp(name+"=([^;]*)");
	if(ex.test(mycc))
	{
		re=unescape(RegExp.$1);
	}
	return re;
}
function ob_hid(id,flag)
{
	if($(id)) $(id).style.display=(flag)?'none':'block';
}
document.write('<script type="text/javascript" src="http://www.8684.cn/js/wj.js"></script>');