﻿function setdv(formobj,v){
//	oldv = formobj.options[formobj.selectedIndex].value;
//	if (oldv=="non"){
		for (i=0; i<formobj.length; i++){
			if (formobj.options[i].value==v) {
				formobj.options[i].selected = true;
				break;
			}
		}	
//	}
}
function mkyearobj(objname){
	if (objname == 'back_year'){
		document.write("<select style='visibility:hidden;' name='",objname,"' size=1 class=itm>");
	}
	else{
		document.write("<select name='",objname,"' size=1 class=itm>");	
	}
	yeart=0;
	yearv=0;
	year1="";
	today=new Date();
	yeart = today.getYear();
	if (yeart<=137 && yeart>=100) {
		yeart = yeart + 1900;
	}
	if (yeart<=2037 && yeart>=2000) {
		yearv = yeart - 2000;
		if (yearv<10) {
			year1 = "0" + yearv;	
		}
		document.write("<option value=",yeart," selected>",yeart,"年</option>"); 
		yeart = yeart + 1;
		if (yeart<=2037 && yeart>=2000){
			yearv = yearv + 1;
			if (yearv<10) {
				year1 = "0" + yearv;
			}
			document.write("<option value=",yeart,">",yeart,"年</option>"); 
		}
	}
	document.write("</select>");
}
function mkmonthobj(objname){
	if (objname == 'back_month'){
		document.write("<select style='visibility:hidden;' name='",objname,"' size=1 class='itm'>");
	}
	else{
		document.write("<select name='",objname,"' size=1 class='itm'>");		
	}
	document.write("<option value='01'>1月</option>");
	document.write("<option value='02'>2月</option>");
	document.write("<option value='03'>3月</option>");
	document.write("<option value='04'>4月</option>");
	document.write("<option value='05'>5月</option>");
	document.write("<option value='06'>6月</option>");
	document.write("<option value='07'>7月</option>");
	document.write("<option value='08'>8月</option>");
	document.write("<option value='09'>9月</option>");
	document.write("<option value='10'>10月</option>");
	document.write("<option value='11'>11月</option>");
	document.write("<option value='12'>12月</option>");
	document.write("</select>");
}

function mkdayobj(objname){
	if (objname == 'back_date'){
		document.write("<select style='visibility:hidden;' name='",objname,"' size=1 class='itm'>");
	}
	else{
		document.write("<select name='",objname,"' size=1 class='itm'>");		
	}
	var datei = 1;
	for(datei = 1; datei <= 31; datei++)
	{
		if (datei<10){
			document.write("<option value=0",datei,">",datei,"日</option>"); 
		}
		else{
			document.write("<option value=",datei,">",datei,"日</option>"); 
		}	
	}
	document.write("</select>");
}
function getdatenum(year,mon,day){
ret = 0;
year = remkyear(year);
ret = Date.parse(year+"/"+mon+"/"+day)
return ret;
}
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;
	year = remkyear(year);
	bufDate = new Date(year,mon,0);
	bufday = bufDate.getDate();
	if (day > bufday){rec = false;}
	return rec;
}

function remkyear(year){
	if (year<1000){if (year<=37 && year>=0){year = year + 2000;}
	else{if (year<=99 && year>=80){year = year + 1900;}}}
	return year;
}

function detectonedate(formobj){
	recstr = "成功";
	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(parseInt(by),bm,getdaynum(bd))) {
		bdate = getdatenum(parseInt(by,10),bm,getdaynum(bd));
		if ( bdate< detecttoday() ){
			recstr = "日期应晚于或等于当日 , 请重新填写！";
		}
		else{
			recstr = "成功";
		}
	}
	else{recstr = "日期填写有误, 请重新填写 ! !";}
	return recstr;
}

function detecttwodate(formobj,vstr1,vstr2){
	recstr = "成功";
	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(parseInt(by),getmonthnum(bm),getdaynum(bd))) {
		if (ey!="non" && em!="non" && ed!="non" && detectmondayok(parseInt(ey),getmonthnum(em),getdaynum(ed))) {
			bdate = getdatenum(parseInt(by,10),bm,getdaynum(bd));	
			if ( bdate< detecttoday()){
				recstr = vstr1 + "应晚于或等于当日 , 请重新填写 ! !";
			}
			else{
				edate = getdatenum(parseInt(ey,10),em,getdaynum(ed));
				if (edate<bdate) {recstr = vstr1 + "应早于或等于" + vstr2 + " , 请重新填写 ! !";}
				else{recstr = "成功";}
			}
		}
		else{recstr = vstr2 + "填写有误, 请重新填写 ! !";}
	}
	else{recstr = vstr1 + "填写有误, 请重新填写 ! !";}
	return recstr;
}

function detecttwowhere(formobj,vstr1,vstr2){
	recstr = "成功";
	dw = formobj.org.options[formobj.org.selectedIndex].value;
	rw = formobj.dst.options[formobj.dst.selectedIndex].value;
	if (dw==rw) {recstr = vstr1 + "与" + vstr2 + "不应一致, 请重新填写 ! ! ";}
	return recstr;
	}
	function detectthreewhere(formobj,vstr1,vstr2,vstr3){
	recstr = "成功";
	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 = vstr1+"与"+vstr2+"不应一致, 请重新填写 ! ! ";}
	if (vw==rw) {recstr = vstr2+"与"+vstr3+"不应一致, 请重新填写 ! ! ";}
	//if (dw==rw) {recstr = vstr1+"与"+vstr3+"不应一致, 请重新填写 ! ! ";}
	return recstr;
}
function detectfourwhere(formobj,vstr1,vstr2,vstr3,vstr4){
	recstr = "成功";
	dw = formobj.org.options[formobj.org.selectedIndex].value;
	vw = formobj.via.options[formobj.via.selectedIndex].value;
	vw1 = formobj.via1.options[formobj.via1.selectedIndex].value;
	rw = formobj.dst.options[formobj.dst.selectedIndex].value;
	if (dw==vw) {recstr = vstr1+"与"+vstr2+"不应一致, 请重新填写 ! ! ";}
	if (vw1==rw) {recstr = vstr3+"与"+vstr4+"不应一致, 请重新填写 ! ! ";}
	return recstr;
}
function tktkindset(formobj,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11){
		formobj.viacity.value =v1;
		formobj.dstcity.value = v2;
		formobj.fsttime.value = v3;
		formobj.sectime.value = v4;
		formobj.go_air.value = v5;
		formobj.back_air.value = v6;
		formobj.via.style.visibility = v7;
		formobj.back_year.style.visibility = v8;
		formobj.back_month.style.visibility = v9;
		formobj.back_date.style.visibility = v10;
		formobj.back_airline.style.visibility = v11;
}
function kindset(formobj){
	vstr="";
	for (var i=0;i<formobj.elements.length;i++){
		var e = formobj.elements[i];
	       	if (e.name=="bookkind1"){if (e.checked){vstr=e.value;break;}}
	}
	for (i=0; i<formobj.bookkind.length; i++){
		if (formobj.bookkind.options[i].value==vstr) {
			formobj.bookkind.options[i].selected = true;
			break;
		}
	}	
	//kindselectsch(formobj);
	kindselect(formobj);
}

function inter_initcity(formobj){
	setdv(formobj.org,"PEK");
	setdv(formobj.via,"LAX");
	setdv(formobj.dst,"NYC");
}
