﻿function binderWeather(obj) {
	for (var k in obj) {
		var kdiv = document.getElementById("Weather" + k);
		if (kdiv) {
			if ("Image" == k) { kdiv.src = obj[k]; } else { kdiv.innerHTML = obj[k]; }
		}
	}
}
function AjaxMethod(url, params, success, failure) {
	Ext.Ajax.request({ url: url, success: success, failure: failure, params: params });
};
function _event(a,b,g){
	var d="on"+b;
	if(a.addEventListener)a.addEventListener(b,g,false);
	else if(a.attachEvent)a.attachEvent(d,g);
	else{var e=a[d];a[d]=function(){var c=e.apply(this,arguments),j=g.apply(this,arguments);return c==undefined?j:j==undefined?c:j&&c}}
}
var p = new function () {
	var _onckcss = 'chk', _t = this, _share = {}, swap = function (nd, i) {
		if (_share[i]) {
			_share[i].className = "";
			disp(_share[i].getAttribute("by"), "none");
		}
		nd.className = _onckcss;
		disp(nd.getAttribute("by"), "block");
		_share[i] = nd;
	}, disp = function (id, bl) {
		var byid = _t.$(id);
		if (byid) byid.style.display = bl;
	};
	this.writerswf = function (swf_width, swf_height, files) {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + swf_width + '" height="' + swf_height + '">');
		document.write('<param name="movie" value="bcastr.swf"><param name="quality" value="high">');
		document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
		document.write('<param name="FlashVars" value="bcastr_xml_url=' + files + '">');
		document.write('<embed src="bcastr.swf" wmode="opaque" FlashVars="bcastr_xml_url=' + files + '" menu="false" quality="high" width="' + swf_width + '" height="' + swf_height + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
		document.write('</object>');
	}
	this.qs = function (p) { var _urlreg = new RegExp('[?|&]' + p + '=([^&]+)', 'i'); var match = top.location.href.match(_urlreg); return match ? match[1] : ""; };
	this.$ = function (s) { return document.getElementById(s); };
	this.share = function (s, tag, ckcss) {
		if (ckcss) _onckcss = ckcss;
		var nds = this.$(s).getElementsByTagName(tag);
		_share[s] = nds[0]; nds[0].className = _onckcss;
		for (var i = 0; i < nds.length; i++) {
			nds[i].onmouseover = function () { swap(this, s); }
			this.$(nds[i].getAttribute("by")).style.display = "none";
		}
		swap(nds[0], s);
	}
	//------------------------------------------------------
	var _roomdiv = "", _hid, _dfmt = "Y-m-d", extcons;
	function getDate1() { return extcons[0].getValue().format(_dfmt); }
	function getDate2() { return extcons[1].getValue().format(_dfmt); }
	function binderHotelRooms() {
		AjaxMethod("/js/HotelRooms.aspx", { hid: _hid, tm1: getDate1(), tm2: getDate2() }, function (resp) {
			_t.$(_roomdiv).innerHTML = resp.responseText;
		}, function (resp) { });
	}
	function openurl(url) { try { window.open(url, ""); } catch (e) { location.href = url; } }
    this.format = function (d) { return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate(); }
    this.parseDate = function (v) { var ks = v.split('-'); return new Date(ks[0], parseInt(ks[1]) - 1, ks[2]); }
	//this.changeroomdiv = function (p, hid) { _roomdiv = p; _hid = hid; }
	this.binderDateControl = function (p1, p2) {
		var date = this.getdate();
		extcons = [
			new Ext.form.DateField({ format: "Y 年 m 月 d 日", el: p1, width: 138, enableKeyEvents: true, value: this.parseDate(date.d1) }),
			new Ext.form.DateField({ format: "Y 年 m 月 d 日", el: p2, width: 138, enableKeyEvents: true, value: this.parseDate(date.d2) })
		];
		for (var i = 0; i < extcons.length; i++) extcons[i].render();
		//binderHotelRooms();
	}
	this.onchangehoteldate = function (fm) {
		var d1 = getDate1(), d2 = getDate2(), d3 = this.getcurrentdate();
		var _d1 = this.parseDate(d1), _d2 = this.parseDate(d2), _d3 = this.parseDate(d3.d1);
		if (_d2 <= _d1 || _d1 < _d3) {
			Ext.MessageBox.alert("提示:", "错误的时间范围!");
			return;
		}
		this.setcheckdate(d1, d2);
		binderHotelRooms();
	}
	this.lookmap = function (hid, cid, key) { openurl('/Hotel-search.html?t=3&hid=' + hid + '&cid=' + (cid ? cid : '') + '&key=' + (key ? key : '')); }
	this.order = function (rid) { openurl('/HotelOrder.aspx?hid=' + _hid + "&rid=" + rid); }
	this.getcurrentdate = function () {
		var d = new Date(), d1 = new Date(d.getFullYear(), d.getMonth(), d.getDate() + 2), d2 = new Date(d.getFullYear(), d.getMonth(), d.getDate() + 4);
		return ({ 'd1': this.format(d1), 'd2': this.format(d2) });
	}
	this.setcheckdate = function (d1, d2) {
		var d = new Date();
		Ext.util.Cookies.set("hoteldate1", d1, new Date(d.getFullYear(), d.getMonth(), d.getDate() + 5));
		Ext.util.Cookies.set("hoteldate2", d2, new Date(d.getFullYear(), d.getMonth(), d.getDate() + 5));
	}
	this.getdate = function () {
		var res = this.getcurrentdate();
		var s1 = Ext.util.Cookies.get("hoteldate1"), s2 = Ext.util.Cookies.get("hoteldate2");
		if (s1 && s2) {
			var d1 = this.parseDate(s1), d2 = this.parseDate(s2);
			var resd1 = this.parseDate(res.d1);
			if (d1 > resd1) res = { 'd1': this.format(d1), 'd2': this.format(d2) }
		} else {
			this.setcheckdate(res.d1, res.d2);
		}
		return res;
	}
}
_event(window, "load", function () {
	var cdate = p.getdate(), dti = p.$('dateIn'), dto = p.$('dateOut'), dtn = p.$('dateNum');
	if (dti) dti.innerHTML = cdate.d1;
	if (dto) dto.innerHTML = cdate.d2;
	if (dtn) {
		var d1 = p.parseDate(cdate.d1), d2 = p.parseDate(cdate.d2), n = 0;
		while (d1 < d2) {
			n++;
			d1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate() + 1);
		}
		dtn.innerHTML = n;
	}
});
function __key(s) {
	function __decode(vl) { try { return escape(decodeURI(vl)); } catch (e) { return vl; } }
	var ks = ['q', 'wd', 'kw', 'query', 'p', 'w'];
	for (var i = 0; i < ks.length; i++) {
		if (res = s.match(new RegExp('[?|&]' + ks[i] + '=([^&]*)'))) return __decode(res[1]);
	}return "";
}
//document.write('<script type="text/javascript" src="/monitor/AddVisitor.ashx?ref=' + escape(document.referrer) + '&key=' + escape(__key(document.referrer)) + '"><' + '/script>');
