function check_search(theForm)
{	var today = new Date();
	DMonth = today.getMonth() + 1;
	DDate = today.getDate();
	DYear = today.getFullYear();
	DD=DYear+"-"+DMonth+"-"+DDate;
  if(theForm.flytype[1].checked == true) //来回程
	{	if(theForm.txtDepPort.value == theForm.txtArrPort.value)
		  {	alert("出发城市与目的城市不能相同!\n请您重新选择!");
			theForm.txtArrPort.focus();
			return (false);
		  }

		if(!check_text(theForm.txtDepDate, '请您输入出发日期！')){return (false);}
		if(!CheckDate(theForm.txtDepDate.value, "出发日期")) {return (false);}
		if(!check_text(theForm.txtBackDate, '请您输入返程日期！')){return (false);}
		if(!CheckDate(theForm.txtBackDate.value, "返程日期")) {return (false);}
		if(!compareDate(theForm.txtDepDate.value,DD))
		{
			alert("出发日期不能早于今天！");
			return (false);
		}
		if(!compareDate(theForm.txtBackDate.value,theForm.txtDepDate.value))
		{
			alert("返程日期不能早于出发日期！");
			return (false);
		}
		if((!compareDate(theForm.txtBackDate.value,theForm.txtDepDate.value)) && (theForm.txtBackTime.value < theForm.txtDepTime.value))
		{
			alert("返程日期时间不能早于出发日期时间！");
			return (false);
		}
	}
	else 
	{ //单程；
		if(theForm.txtDepPort.value == theForm.txtArrPort.value)
		  {	alert("出发城市与目的城市不能相同!\n请重新选择!");
			theForm.txtArrPort.focus();
			return (false);
		  }

		if(!check_text(theForm.txtDepDate, '请您输入出发日期!')){return (false);}
		if(!CheckDate(theForm.txtDepDate.value, "出发日期")) {return (false);}
		if(!compareDate(theForm.txtDepDate.value,DD))
		  {	alert("出发日期不能早于今天!");
			 return (false);
		  }
	}//单程
waiting.style.visibility="visible";
theForm.submit();
}

function select_flytype(ftype)
{
	if(document.getElementsByTagName("*"))
	{
		switch (ftype)
			{
			case 1:/*来回航程*/
			document.getElementById("back_date_name").style.display = "";
            document.getElementById("back_date_pd").style.display = "";
			break;
		    default:/*单程航程*/
			document.getElementById("back_date_name").style.display = "none";
			document.getElementById("back_date_pd").style.display = "none";
			}

	}
	else
	{
		switch (ftype)
		{
			case 1:
			document.getElementById("back_date_name").style.display = "";
			document.getElementById("back_date_pd").style.display = "";
			break;
		    default:
			document.getElementById("back_date_name").style.display = "none";
			document.getElementById("back_date_pd").style.display = "none";
		}
   }
}
//-->
function check_text(who,display)
{
	if(who.value == "")
	{
		alert(display);
		who.focus();
		return (false);
	}
	return (true);
}

function change_city(city_value,obj)
{
	obj.value=city_value;
	//update();
}
function check_city(city_value,obj)
{
	var i;
	obj.value="";
	city_value=city_value.toUpperCase( );
	for (i=0;i<obj.options.length;i++){
		if (city_value==obj.options[i].value){
			obj.value=city_value;
		}
	}
	if (obj.value==""){
		obj.value="non";
		alert("请输入正确的城市代码！");
	}
	//update();
}
function update(){
	tempdate=document.all('txtDepDate').value;
    //tempdate=document.forms["FormGnFlight"].txtDepDate.value;
	GetInputDate(tempdate);

}

function setdv(formobj,v){
	for (i=0; i<formobj.length; i++){
		if (formobj.options[i].value.substr(0,3)==v) {
			formobj.options[i].selected = true;
			break;
		}
	}
}

function init_city(formobj)
{
	setdv(formobj.txtDepPort, "SHA");
	setdv(formobj.txtArrPort, "PEK");
}

function sinit_city(formobj,sstr,estr)
{
	setdv(formobj.txtDepPort, sstr);
	setdv(formobj.txtArrPort, estr);
}
function inter_initcity(formobj){
	setdv(formobj.txtDepPort,"SHA");
	setdv(formobj.txtArrPort,"HKG");
}
//init_city(document.forms["FormGnFlight"]);
//inter_initcity(document.FormGj);
function openWindow(url, name, rs, w, h){
	var resize = "";
	if (rs){resize = "resizable,";}
	popupWin = window.open(url, name, 'scrollbars,' + resize +
	'width=' + w + ',height=' + h);
	window.name = 'opener';
}

var gIntMonth = 0;
var gIntDate = 0;
var gIntYear = 0;

function gCFD(sDate, sOff)
{
	var dDate = new Date(sDate);
	if(isNaN(dDate)) {dDate = new Date();}
	var sOff = String(sOff);
	var aO = sOff.split("-");
	var iYO = parseInt(aO[0]);
	var iMO = parseInt(aO[1]);
	var iDO = parseInt(aO[2]);
	var dNew = new Date(dDate);

	dNew.setDate(dNew.getDate() + iDO);
	dNew.setMonth(dNew.getMonth() + iMO);

	if (dNew.getYear() < 100)
	{
		dNew.setYear(dNew.getYear() + 2000 + iYO);
	}
	else
	{
		dNew.setYear(dNew.getFullYear() + iYO);
	}

	var sFD = String(dNew.getFullYear())+ "-" + String(dNew.getMonth() + 1) + "-" + String(dNew.getDate());
	return(sFD);
}

function GetDaysInMonth(intMonth, intYear)
{
	var arrDaysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	var intCount = arrDaysInMonth[intMonth-1];
	if(intMonth == 2) {	if((intYear%4) == 0 ) {	/* post-2000 leap year - ignore 2100 etc.*/	intCount++;	}}
	return intCount;
}

function IsValidDate(intDate, intMonth, intYear)
{
	if( (intYear > 2050) || (intYear < 1900) ) {return false;}
	if( (intMonth > 12) || (intMonth < 1) ) {return false;}
	if(intDate < 1) {return false;}
	var intMaxDate = GetDaysInMonth(intMonth, intYear);
	if(intDate > intMaxDate) {return false;}
	return true;
}

function GetInputDate(strDate)
{
	var lenDateString = strDate.length;
	if(lenDateString == 0) {return(false);}

	arrDate = strDate.split("-");
	if(arrDate.length < 3) {return(false);}

	var intYear = cleanDigits(arrDate[0]);
	var intMonth = cleanDigits(arrDate[1]);
	var intDate = cleanDigits(arrDate[2]);

	if (intYear.length < 4){intYear = parseint("20" + string(intYear))}

	if(IsValidDate(intDate, intMonth, intYear)) {
		gIntMonth = intMonth;
		gIntDate = intDate;
		gIntYear = intYear;
	}else{
		var dToday = new Date();
		gIntMonth = dToday.getMonth() + 1;
		gIntDate = dToday.getDate();
		gIntYear = dToday.getFullYear();
	}
	return(true);
}
function cleanDigits(strDigits)
{
	var strResult = "0";
	for(var i = 0; i < strDigits.length; i++){
		var strC = strDigits.charAt(i);
		if(isDigit(strC)) {	strResult += "" + strC;	}
	}
	var iResult = parseInt(strResult,10);
	return(iResult);
}

function isDigit(ch)
{
	return(ch >= '0' && ch <= '9');
}

function datetran(strdate)
{
	var dd = String(strdate);
	var aO = dd.split("-");
	var iYO = parseInt(aO[0]);
	var iMO = parseInt(aO[1]);
	var iDO = parseInt(aO[2]);
	var Newdate = (iMO + "-" + iDO + "-" + String(iYO) );
	return(Newdate);
}

function updateDependentDate(oBox2,sDate1,sOffset)
{ 	GetInputDate(sDate1);
	var d1 = new Date(datetran(sDate1));
	var d2 = new Date(datetran(oBox2.value));
	if(isNaN(d1)) {	return;	}
	var sNew = gCFD(d1, sOffset);
	alert(d1);
	alert(sNew);
	if(isNaN(d2)) {
		oBox2.value = sNew;
		return;
	}
	if(d1 >= d2) {
		oBox2.value = sNew;
		return;
	}
}

function Ticket_TF(type,side)
{
	switch(type)
	{
		case "edit":
			//document.getElementById("pic_gaiqian_"+side).style.display="none";
			//document.getElementById("pic_gaiqian_"+side+"_red").style.display="";
			document.getElementById("pic_feipiao_"+side).style.display="";
			document.getElementById("pic_feipiao_"+side+"_red").style.display="none";
			document.getElementById("pic_tuipiao_"+side).style.display="";
			document.getElementById("pic_tuipiao_"+side+"_red").style.display="none";
			//document.getElementById("gaiqian_"+side).style.display="";
			document.getElementById("feipiao_"+side).style.display="none";
			document.getElementById("tuipiao_"+side).style.display="none";
			break;
		case "discard":
			//document.getElementById("pic_gaiqian_"+side).style.display="";
			//document.getElementById("pic_gaiqian_"+side+"_red").style.display="none";
			document.getElementById("pic_feipiao_"+side).style.display="none";
			document.getElementById("pic_feipiao_"+side+"_red").style.display="";
			document.getElementById("pic_tuipiao_"+side).style.display="";
			document.getElementById("pic_tuipiao_"+side+"_red").style.display="none";
			//document.getElementById("gaiqian_"+side).style.display="none";
			document.getElementById("feipiao_"+side).style.display="";
			document.getElementById("tuipiao_"+side).style.display="none";
			break;
		case "return":
			//document.getElementById("pic_gaiqian_"+side).style.display="";
			//document.getElementById("pic_gaiqian_"+side+"_red").style.display="none";
			document.getElementById("pic_feipiao_"+side).style.display="";
			document.getElementById("pic_feipiao_"+side+"_red").style.display="none";
			document.getElementById("pic_tuipiao_"+side).style.display="none";
			document.getElementById("pic_tuipiao_"+side+"_red").style.display="";
			//document.getElementById("gaiqian_"+side).style.display="none";
			document.getElementById("feipiao_"+side).style.display="none";
			document.getElementById("tuipiao_"+side).style.display="";
			break;
	}
}
