function init(formobj){
year_v="";
b_year_v="";
year_v=formobj.year.options[formobj.year.selectedIndex].value;
b_year_v=formobj.back_year.options[formobj.back_year.selectedIndex].value;
today=new Date();
yearind = today.getFullYear();
if (yearind<=2037 && yearind>=2000){yearind = yearind - 2000;}
else{if (yearind<=1999 && yearind>=1980){yearind = yearind - 1900;}}
if (formobj.year.length > 0){
	for (i=0; i<formobj.year.length; i++){
		if (parseInt(formobj.year.options[i].value,10)==yearind) {
			if (year_v=="non"){formobj.year.options[i].selected=true;}
			if (b_year_v=="non"){formobj.back_year.options[i].selected=true;}	
			break;
		}
	}
}
if (year_v=="non") {	
	formobj.month.options[today.getMonth()+ 1].selected=true;
	formobj.date.options[today.getDate()].selected=true;
}
if (b_year_v=="non") {	
	formobj.back_month.options[today.getMonth()+ 1].selected=true;
	formobj.back_date.options[today.getDate()].selected=true;  
}
kindselect(formobj)
formobj.h_ok.value = "";
}

function goaction(formobj){
	var kind = "";
	kind = formobj.bookkind.options[formobj.bookkind.selectedIndex].value;
	switch (kind) {
	case "1": 
		//formobj.action="/servlet/english.onewaysch.SearchServlet";
		formobj.action="/english/englishQueryFlight.do";
		formobj.actionkind.value="oneway";
		goactiononeway(formobj); 
		break;
	case "2": 
		//formobj.action="/servlet/english.returnair.SearchReturnAir";
		formobj.action="/english/englishQueryFlight.do";
		formobj.actionkind.value="airreturn";
		goactionairreturn(formobj); 
		break;
	case "3": 
		if (formobj.name == "formbook"){
		//formobj.action="/servlet/english.multi.MultiSearchTicketServlet";
		formobj.action="/english/englishQueryFlight.do";
		formobj.actionkind.value="muti";
	    goactionmuti(formobj);
	    }
		if (formobj.name == "inter_formbook")
		{//formobj.action="/servlet/english.mutiinter.SearchMultiInter"; 
		 formobj.action="/english/englishInterQueryFlight.do";
		 formobj.actionkind.value="muti";
		 goactionintermuti(formobj);
		 }
		break;
	default: 
		//formobj.action="/servlet/english.onewaysch.SearchServlet";
		formobj.action="/english/englishQueryFlight.do";
		formobj.actionkind="oneway";
		goactiononeway(formobj); 
		break;
	}
}

function goaction_inter(bookformobj,airformobj)
{
//alert("here!");
           var kind = "";
           
           kind=bookformobj.bookkind.options[bookformobj.bookkind.selectedIndex].value;
         
           switch (kind) {
	       case "1": 
           airformobj.airkind.value="oneway";
        	break;
			case "2": 
		   airformobj.airkind.value="airreturn";
		   break;
		   	case "3": 
		   	 airformobj.airkind.value="muti";
		   break;
		   default:
			 airformobj.airkind.value="oneway";
			 break;
			}
			
		//	alert("here2!")
			 
			airformobj.org.value = bookformobj.org.options[bookformobj.org.selectedIndex].value;
			airformobj.via.value = bookformobj.via.options[bookformobj.via.selectedIndex].value;
			airformobj.dst.value = bookformobj.dst.options[bookformobj.dst.selectedIndex].value;
			
			airformobj.goyear.value = bookformobj.year.options[bookformobj.year.selectedIndex].value;
			airformobj.gomonth.value = bookformobj.month.options[bookformobj.month.selectedIndex].value;
			airformobj.godate.value = bookformobj.date.options[bookformobj.date.selectedIndex].value;
		//	airformobj.timego.value = bookformobj.timego.options[bookformobj.timego.selectedIndex].value;
			
			airformobj.backyear.value = bookformobj.back_year.options[bookformobj.back_year.selectedIndex].value;
			airformobj.backmonth.value = bookformobj.back_month.options[bookformobj.back_month.selectedIndex].value;
			airformobj.backdate.value = bookformobj.back_date.options[bookformobj.back_date.selectedIndex].value;
		//	airformobj.backtimego.value = bookformobj.backtimego.options[bookformobj.backtimego.selectedIndex].value;
			
			airformobj.airline.value = bookformobj.airline.options[bookformobj.airline.selectedIndex].value;
			//airformobj.direct.value = "";
		
		
			var actionkind="";
			actionkind = airformobj.airkind.value;
			
		//	alert("actionkind:"+actionkind);
			switch (actionkind) {
			case "oneway": 
				newgoactiononeway(bookformobj,airformobj); 
				break;
			case "airreturn": 
				newgoactionairreturn(bookformobj,airformobj); 
				break;
			case "muti": 
				newgoactionmuti(bookformobj,airformobj); 
				break;
			default: 
				newgoactiononeway(bookformobj,airformobj); 
				break;
			}



}




function newgoactiononeway(formobj,airformobj){
//alert("here!")

recstr = "";
	recstr = detectdateoneway(formobj);
	if (recstr=="ok") {
		
	//	alert(recstr);
		recstr = detecthwereoneway(formobj);
		if (recstr=="ok") {
		
//		alert(recstr);
				airformobj.submit();
			
		}
		else{alert(recstr);}	
	}
	else{alert(recstr);}
}
function newgoactionairreturn(formobj,airformobj){
recstr = "";
	recstr = detectdatereturnair(formobj);
	if (recstr=="ok") {
		recstr = detecthwerereturnair(formobj);
		if (recstr=="ok") {
				airformobj.submit();
				
		}
		else{alert(recstr);}	
	}
	else{alert(recstr);}
}
function newgoactionmuti(formobj,airformobj){
recstr = "";
	recstr = detectdatemuti(formobj);
	if (recstr=="ok") {
		recstr = detecthweremuti(formobj);
		if (recstr=="ok") {
				airformobj.submit();
			
		}
		else{alert(recstr);}	
	}
	else{alert(recstr);}
}


function goactiononeway(formobj){
recstr = "";
	recstr = detectdateoneway(formobj);
	if (recstr=="ok") {
		recstr = detecthwereoneway(formobj);
		if (recstr=="ok") {
			formobj.h_org.value = formobj.org.options[formobj.org.selectedIndex].text;
			formobj.h_dst.value = formobj.dst.options[formobj.dst.selectedIndex].text;
			formobj.h_orgdate.value = formobj.year.options[formobj.year.selectedIndex].text + "-" +formobj.month.options[formobj.month.selectedIndex].text + "-" + formobj.date.options[formobj.date.selectedIndex].text;
			formobj.submit();
		}
		else{
			alert(recstr);
		}	
	}
	else{
		alert(recstr);
	}
}

function goactionairreturn(formobj){
recstr = "";
	recstr = detectdatereturnair(formobj);
	if (recstr=="ok") {
		recstr = detecthwerereturnair(formobj);
		if (recstr=="ok") {
			formobj.h_org.value = formobj.org.options[formobj.org.selectedIndex].text;
			formobj.h_dst.value = formobj.dst.options[formobj.dst.selectedIndex].text;
			formobj.h_orgdate.value = formobj.year.options[formobj.year.selectedIndex].text + "-" + formobj.month.options[formobj.month.selectedIndex].text + "-" + formobj.date.options[formobj.date.selectedIndex].text;
			formobj.h_backdate.value = formobj.back_year.options[formobj.back_year.selectedIndex].text + "-" + formobj.back_month.options[formobj.back_month.selectedIndex].text + "-" + formobj.back_date.options[formobj.back_date.selectedIndex].text;
			formobj.submit();
		}
		else{
			alert(recstr);
		}	
	}
	else{
		alert(recstr);
	}
}

function goactionmuti(formobj){
recstr = "";
	recstr = detectdatemuti(formobj);
	if (recstr=="ok") {
		recstr = detecthweremuti(formobj);
		if (recstr=="ok") {
			formobj.h_org.value = formobj.org.options[formobj.org.selectedIndex].text;
			formobj.h_via.value = formobj.via.options[formobj.via.selectedIndex].text;
			formobj.h_dst.value = formobj.dst.options[formobj.dst.selectedIndex].text;
			formobj.h_orgdate.value = formobj.year.options[formobj.year.selectedIndex].text + "-" +formobj.month.options[formobj.month.selectedIndex].text + "-" + formobj.date.options[formobj.date.selectedIndex].text;
			formobj.h_chgdate.value = formobj.back_year.options[formobj.back_year.selectedIndex].text + "-" + formobj.back_month.options[formobj.back_month.selectedIndex].text + "-" + formobj.back_date.options[formobj.back_date.selectedIndex].text;
			formobj.submit();
		}
		else{
			alert(recstr);
		}	
	}
	else{
		alert(recstr);
	}
}

function goactionintermuti(formobj){
recstr = "";
	recstr = detectdateintermuti(formobj);
	if (recstr=="ok") {
		recstr = detecthwereintermuti(formobj);
		if (recstr=="ok") {
			formobj.h_org.value = formobj.org.options[formobj.org.selectedIndex].text;
			formobj.h_via.value = formobj.via.options[formobj.via.selectedIndex].text;
			formobj.h_dst.value = formobj.dst.options[formobj.dst.selectedIndex].text;
			formobj.h_orgdate.value = formobj.year.options[formobj.year.selectedIndex].text + "-" + formobj.month.options[formobj.month.selectedIndex].text + "-" + formobj.date.options[formobj.date.selectedIndex].text;
			formobj.h_chgdate.value = formobj.back_year.options[formobj.back_year.selectedIndex].text + "-" + formobj.back_month.options[formobj.back_month.selectedIndex].text + "-" + formobj.back_date.options[formobj.back_date.selectedIndex].text;
			formobj.submit();
		}
		else{
			alert(recstr);
		}	
	}
	else{
		alert(recstr);
	}
}
function getdatenum(year,mon,day){
ret = 0;
if (year<=37 && year>=0){year = year + 2000;}
else{if (year<=99 && year>=80){year = year + 1900;}}
ret = Date.parse(year+"/"+mon+"/"+day)
return ret;	
}
function detectdateoneway(formobj){
recstr = "ok";
bdate = 0 ;
by = 0;
bm = 0;
bd = 0;
by = formobj.year.options[formobj.year.selectedIndex].value;
bm = formobj.month.options[formobj.month.selectedIndex].value;
bd = formobj.date.options[formobj.date.selectedIndex].value;

if (by!="non" && bm!="non" && bd!="non" && detectmondayok(2000+parseInt(by),getmonthnum(bm),getdaynum(bd))) {
	bdate = getdatenum(parseInt(by,10),getmonthnum(bm),getdaynum(bd));
	if ( bdate< detecttoday()){
		recstr = "Date you just input must be equal or later than today, Please input again!!";
	}
	else{
		recstr = "ok";
	}
}
else{
	recstr = "Wrong date input,please input again!!";
}
return recstr;
}
function detecthwereoneway(formobj){
recstr = "ok";
dw = formobj.org.options[formobj.org.selectedIndex].value;
rw = formobj.dst.options[formobj.dst.selectedIndex].value;
if (dw==rw) {
	recstr = "Departure city and arrival city are not same,please input again!!";	
}
return recstr;
}
function detectdatereturnair(formobj){
recstr = "ok";
bdate = 0 ;
edate = 0;
by = 0;
bm = 0;
bd = 0;
ey = 0;
em = 0;
ed = 0;
by = formobj.year.options[formobj.year.selectedIndex].value;
bm = formobj.month.options[formobj.month.selectedIndex].value;
bd = formobj.date.options[formobj.date.selectedIndex].value;
ey = formobj.back_year.options[formobj.back_year.selectedIndex].value;
em = formobj.back_month.options[formobj.back_month.selectedIndex].value;
ed = formobj.back_date.options[formobj.back_date.selectedIndex].value;

if (by!="non" && bm!="non" && bd!="non" && detectmondayok(2000+parseInt(by),getmonthnum(bm),getdaynum(bd))) {
	if (ey!="non" && em!="non" && ed!="non" && detectmondayok(2000+parseInt(ey),getmonthnum(em),getdaynum(ed))) {
		bdate = getdatenum(parseInt(by,10),getmonthnum(bm),getdaynum(bd));	
		if ( bdate< detecttoday()){
			recstr = "Departure date you just input must be equal or later than today, Please input again!!";
		}
		else{
			edate = getdatenum(parseInt(ey,10),getmonthnum(em),getdaynum(ed));
			if (edate<bdate) {
				recstr = "Departure date must be equal or earlier than return date,please input again!!";
			}
			else{
				recstr = "ok";
			}
		}
	}
	else{
		recstr = "Wrong return date input,please input again!!";
	}
}
else{
	recstr = "Wrong departure date input,please input again!!";
}
return recstr;
}
function detecthwerereturnair(formobj){
recstr = "ok";
dw = formobj.org.options[formobj.org.selectedIndex].value;
rw = formobj.dst.options[formobj.dst.selectedIndex].value;
if (dw==rw) {
	recstr = "Departure city and arrival city are not same,please input again!!";	
}
return recstr;
}
/*
function detectdatemuti(formobj){
recstr = "ok";
bdate = 0 ;
by = 0;
bm = 0;
bd = 0;
by = formobj.year.options[formobj.year.selectedIndex].value;
bm = formobj.month.options[formobj.month.selectedIndex].value;
bd = formobj.date.options[formobj.date.selectedIndex].value;

if (by!="non" && bm!="non" && bd!="non" && detectmondayok(2000+parseInt(by),getmonthnum(bm),getdaynum(bd))) {
	bdate = getdatenum(parseInt(by,10),getmonthnum(bm),getdaynum(bd));
	if ( bdate< detecttoday()){
		recstr = "Date you just input must be equal or later than today, Please input again!!";
	}
	else{
		recstr = "ok";
	}
}
else{
	recstr = "Wrong date input,please input again!!";
}
return recstr;
}

*/
function detectdatemuti(formobj){
recstr = "ok";
bdate = 0 ;
edate = 0;
by = 0;
bm = 0;
bd = 0;
ey = 0;
em = 0;
ed = 0;
by = formobj.year.options[formobj.year.selectedIndex].value;
bm = formobj.month.options[formobj.month.selectedIndex].value;
bd = formobj.date.options[formobj.date.selectedIndex].value;
ey = formobj.back_year.options[formobj.back_year.selectedIndex].value;
em = formobj.back_month.options[formobj.back_month.selectedIndex].value;
ed = formobj.back_date.options[formobj.back_date.selectedIndex].value;

if (by!="non" && bm!="non" && bd!="non" && detectmondayok(2000+parseInt(by),getmonthnum(bm),getdaynum(bd))) {
	if (ey!="non" && em!="non" && ed!="non" && detectmondayok(2000+parseInt(ey),getmonthnum(em),getdaynum(ed))) {
		bdate = getdatenum(parseInt(by,10),getmonthnum(bm),getdaynum(bd));	
		if ( bdate< detecttoday()){
			recstr = "Date you just input must be equal or later than today, Please input again!!";
		}
		else{
			edate = getdatenum(parseInt(ey,10),getmonthnum(em),getdaynum(ed));
			if (edate<bdate) {
				recstr = "Departure date must be equal or earlier than change date,please input again!!";
			}
			else{
				recstr = "ok";
			}
		}
	}
	else{
		recstr = "Wrong change date input,please input again!!";
	}
}
else{
	recstr = "Wrong departure date input,please input again!!";
}
return recstr;
}

function detecthweremuti(formobj){
recstr = "ok";
dw = formobj.org.options[formobj.org.selectedIndex].value;
vw = formobj.via.options[formobj.via.selectedIndex].value;
rw = formobj.dst.options[formobj.dst.selectedIndex].value;
if (dw==vw) {
	recstr = "Departure city and change city are not same,please input again!!";	
}
if (vw==rw) {
	recstr = "Change city and arrival city are not same,please input again!!";	
}
if (dw==rw) {
	recstr = "Departure city and arrival city are not same,please input again!!";	
}

return recstr;
}
function detectdateintermuti(formobj){
recstr = "ok";
bdate = 0 ;
edate = 0;
by = 0;
bm = 0;
bd = 0;
ey = 0;
em = 0;
ed = 0;
by = formobj.year.options[formobj.year.selectedIndex].value;
bm = formobj.month.options[formobj.month.selectedIndex].value;
bd = formobj.date.options[formobj.date.selectedIndex].value;
ey = formobj.back_year.options[formobj.back_year.selectedIndex].value;
em = formobj.back_month.options[formobj.back_month.selectedIndex].value;
ed = formobj.back_date.options[formobj.back_date.selectedIndex].value;

if (by!="non" && bm!="non" && bd!="non" && detectmondayok(2000+parseInt(by),getmonthnum(bm),getdaynum(bd))) {
	if (ey!="non" && em!="non" && ed!="non" && detectmondayok(2000+parseInt(ey),getmonthnum(em),getdaynum(ed))) {
		bdate = getdatenum(parseInt(by,10),getmonthnum(bm),getdaynum(bd));	
		if ( bdate< detecttoday()){
			recstr = "Departure Date you just input must be equal or later than today, Please input again!!";
		}
		else{		
			edate = getdatenum(parseInt(ey,10),getmonthnum(em),getdaynum(ed));
			if (edate<bdate) {
				recstr = "出发日期应早于或等于中转出发日期 , 请重新填写 ! !";
			}
			else{
				recstr = "ok";
			}
		}
	}
	else{
		recstr = "Wrong change date input,please input again!!";
	}
}
else{
	recstr = "Wrong departure date input,please input again!!";
}
return recstr;
}
function detecthwereintermuti(formobj){
recstr = "ok";
dw = formobj.org.options[formobj.org.selectedIndex].value;
vw = formobj.via.options[formobj.via.selectedIndex].value;
rw = formobj.dst.options[formobj.dst.selectedIndex].value;
if (dw==vw) {
	recstr = "出发地与中转地不应一致, 请重新填写 ! ! ";	
}
if (vw==rw) {
	recstr = "中转地与到达地不应一致, 请重新填写 ! ! ";	
}
if (dw==rw) {
	recstr = "出发地与到达地不应一致, 请重新填写 ! ! ";	
}

return recstr;
}


function detecttoday(){
daynum=0;
year_v=0;
month_v=0;
day_v=0;
today=new Date();
year_v = today.getFullYear();
month_v = today.getMonth() + 1;
day_v = today.getDate();
daynum = Date.parse(year_v+"/"+month_v+"/"+day_v)
return daynum;
}

function getmonthnum(monv){
retnum=0;
switch (monv) {
case "jan": retnum=1; break;
case "feb": retnum=2; break;
case "mar": retnum=3; break;
case "apr": retnum=4; break;
case "may": retnum=5; break;
case "jun": retnum=6; break;
case "jul": retnum=7; break;
case "aug": retnum=8; break;
case "sep": retnum=9; break;
case "oct": retnum=10; break;
case "nov": retnum=11; break;
case "dec": retnum=12; break;
default: retnum=0; break;
}
return retnum;
}
function getdaynum(monv){
retnum=0;
if (!parseInt(monv,10)){retnum=0;}
else{retnum=parseInt(monv,10);}
return retnum;
}
function detectmondayok(year,mon,day){
	rec = true;
	bufDate = new Date(year,mon,0);
	bufday = bufDate.getDate();
	if (day > bufday){rec = false;}
	return rec;
}

function kindselect(formobj){
var kind = "";
var str1 = "";
kind = formobj.bookkind.options[formobj.bookkind.selectedIndex].value;
switch (kind) {
case "1": 
		formobj.viacity.value ="";
		formobj.dstcity.value = "Arrival city:";
		formobj.fsttime.value = "Departure Date:";
		formobj.sectime.value = "";
		formobj.go_air.value = "Airlines:";
		formobj.back_air.value = "";
		formobj.via.style.visibility = "hidden";
		formobj.back_year.style.visibility = "hidden";
		formobj.back_month.style.visibility = "hidden";
		formobj.back_date.style.visibility = "hidden";
		formobj.back_airline.style.visibility = "hidden";
	        break;
case "2": 
		formobj.viacity.value ="";
		formobj.dstcity.value = "Arrival city:";
		formobj.fsttime.value = "Departure Date:";
		formobj.sectime.value = "Return Date:";
		formobj.go_air.value = "Dpt Airlines:";
		formobj.back_air.value = "Ret Airlines:";
		formobj.via.style.visibility = "hidden";
		formobj.back_year.style.visibility = "visible";
		formobj.back_month.style.visibility = "visible";
		formobj.back_date.style.visibility = "visible";
		formobj.back_airline.style.visibility = "visible";
	        break;
case "3": 
		if (formobj.name == "formbook"){
			formobj.viacity.value ="Change city:";
			formobj.dstcity.value = "Arrival city:";
			formobj.fsttime.value = "Departure Date:";
			formobj.sectime.value = "Chg Dpt Date:";
			formobj.go_air.value = "Airlines:";
			formobj.back_air.value = "";
			formobj.via.style.visibility = "visible";
		//	formobj.back_year.style.visibility = "hidden";
		//	formobj.back_month.style.visibility = "hidden";
		//	formobj.back_date.style.visibility = "hidden";
		    formobj.back_year.style.visibility = "visible";
			formobj.back_month.style.visibility = "visible";
			formobj.back_date.style.visibility = "visible";
			formobj.back_airline.style.visibility = "hidden";
		}
		if (formobj.name == "inter_formbook"){
			formobj.viacity.value ="Change city:";
			formobj.dstcity.value = "Arrival city:";
			formobj.fsttime.value = "Departure Date:";
			formobj.sectime.value = "Chg Dpt Date:";
			formobj.go_air.value = "Dpt Airlines:";
			formobj.back_air.value = "Chg Airlines:";
			formobj.via.style.visibility = "visible";
			formobj.back_year.style.visibility = "visible";
			formobj.back_month.style.visibility = "visible";
			formobj.back_date.style.visibility = "visible";
			formobj.back_airline.style.visibility = "visible";
		}
	        break;
default: 
		formobj.kind.options[0].selected=true;
		formobj.viacity.value ="";
		formobj.dstcity.value = "Arrival city:";
		formobj.fsttime.value = "Departure Date:";
		formobj.sectime.value = "";
		formobj.go_air.value = "Airlines:";
		formobj.back_air.value = "";
		formobj.via.style.visibility = "hidden";
		formobj.back_year.style.visibility = "hidden";
		formobj.back_month.style.visibility = "hidden";
		formobj.back_date.style.visibility = "hidden";
		formobj.back_airline.style.visibility = "hidden";
	        break;
}
}

