﻿var id_hash= new Array();
var el_hash = new Array();
	
	var $gl = function(id){
		return el_hash[id] || (el_hash[id] = document.getElementById(id_hash[id] || id));
	};
	
	var $alert = (function(fn){
		return function(){
			var arg=Array.prototype.slice.call(arguments,0);
			arg[1]=$s2t(arg[1]);
			fn.apply(_,arg);
			return false;
		};
	})(window.$alert);
	
	var form = document.forms[0];	
	function switchAgeType(){
		//$gl('age_type_tip').style.display = ageType.value == 'CHD' ? '' : 'none';
	}

	
	//private
	function getValue(el){
		if(el.options) return el.value;
		for(var i = 0; i < el.length; i++) if(el[i].checked) return el[i].value;
	}
	function setValue(el, val){
		if(el.options) el.value = val;
		else for(var i = 0; i < el.length; i++) if(el[i].value == val) el[i].checked = true;
	}
	function addEvent(el, fn){
		if(el.options) el.onchange = fn;
		else for(var i = 0; i < el.length; i ++) el[i].onclick = fn;
	}

	//校验
	window.validateQuery = function(){
		//出发城市
		var el = $gl('home_city');
		if(el.isNull()) return $alert(el, '请选择出发城市');
		var ct1 = el.value;

		//出发日期
		var el = $gl('depart_date_1');
		if(el.isNull()) return $alert(el, '请选择出发日期');
		var dt1 = el.value.isDateTime();
		if(!dt1) return $alert(el, '日期格式有误，请检查');
		if(dt1 < new Date().dateValue()) return $alert(el, '对不起，出发日期不能在今天之前');

		//目的城市
		var el = $gl('dest_city_1');
		if(el.isNull()) return $alert(el, '请选择目的城市');
		var ct2 = el.value.replace(/\(.+$/g,'');
		if(ct2 == ct1) return $alert(el, '您选择的目的城市和出发城市相同，请重新选择');
		//if(isDomesticCity(ct1) && isDomesticCity(ct2)) return $alert(el, '出发城市和目的城市不能同为国内城市，请检查');

		//返回日期
		var el = $gl('depart_date_2');
		if(el.style.display=="block")
		{
		    if(el.isNull()) return $alert(el, '请选择出发日期');
			var dt2 = el.value.isDateTime();
			if(!dt2) return $alert(el, '日期格式有误，请检查');
			if(dt2 < dt1) return $alert(el, '对不起，返回日期不能早于出发日期');
	    }

		//送票城市
		/*var el = $gl('ticket_city');
		if(el.isNull()){
			el.value = $gl('home_city').value;
			if (el.module.notice)
				el.module.notice.check();
			document.getElementById(el.getAttribute('mod_address_reference')).value = 
			document.getElementById($gl('home_city').getAttribute('mod_address_reference')).value;
			//el.module.address.reference.value = $gl('home_city').module.address.reference.value;
		}*/

		//by cdchu
		/*if (submitBtn)
			setTimeout(function(){
				submitBtn.disabled=true;
			},1);
		if (scheduleBtn)
			setTimeout(function(){
				scheduleBtn.disabled=true;
			},1);
		$r("beforeunload",function(){
			if (submitBtn)
				submitBtn.disabled=false;
			if (scheduleBtn)
				scheduleBtn.disabled=true;
		});*/
		//end
		
	   changegj(0);count();search_ticket(1);
		return true;
	}
		window.validateQuerygj = function(){
		//出发城市
		var el = $gl('home_citygj');
		if(el.isNull()) return $alert(el, '请选择出发城市');
		var ct1 = el.value;

		//出发日期
		var el = $gl('depart_dategj_1');
		if(el.isNull()) return $alert(el, '请选择出发日期');
		var dt1 = el.value.isDateTime();
		if(!dt1) return $alert(el, '日期格式有误，请检查');
		if(dt1 < new Date().dateValue()) return $alert(el, '对不起，出发日期不能在今天之前');

		//目的城市
		var el = $gl('dest_citygj_1');
		if(el.isNull()) return $alert(el, '请选择目的城市');
		var ct2 = el.value.replace(/\(.+$/g,'');
		if(ct2 == ct1) return $alert(el, '您选择的目的城市和出发城市相同，请重新选择');
		//if(isDomesticCity(ct1) && isDomesticCity(ct2)) return $alert(el, '出发城市和目的城市不能同为国内城市，请检查');

		//返回日期
		var el = $gl('depart_dategj_2');
		if(el.style.display=="block")
		{
		    if(el.isNull()) return $alert(el, '请选择出发日期');
			var dt2 = el.value.isDateTime();
			if(!dt2) return $alert(el, '日期格式有误，请检查');
			if(dt2 < dt1) return $alert(el, '对不起，返回日期不能早于出发日期');
	    }
       changegj(1);count();search_ticket(2);
		return true;
	}