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){
document.write("<select name='",objname,"' size=1 class=itm>");
document.write("<option selected value=non>&nbsp</option>");
				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=",year1,">",yeart,"</option>"); 
					yeart = yeart + 1;
					if (yeart<=2037 && yeart>=2000){
						yearv = yearv + 1;
						if (yearv<10) {
							year1 = "0" + yearv;
						}
						document.write("<option value=",year1,">",yeart,"</option>"); 
					}
				}
document.write("</select>");
}
function mkmonthobj(objname){
document.write("<select name='",objname,"' size=1 class='itm'>");
document.write("<option value='non' selected>&nbsp</option>");
document.write("<option value='jan'>01</option>");
document.write("<option value='feb'>02</option>");
document.write("<option value='mar'>03</option>");
document.write("<option value='apr'>04</option>");
document.write("<option value='may'>05</option>");
document.write("<option value='jun'>06</option>");
document.write("<option value='jul'>07</option>");
document.write("<option value='aug'>08</option>");
document.write("<option value='sep'>09</option>");
document.write("<option value='oct'>10</option>");
document.write("<option value='nov'>11</option>");
document.write("<option value='dec'>12</option>");
document.write("</select>");
}
function mkdayobj(objname){
document.write("<select name='",objname,"' size=1 class=itm>");
document.write("<option selected value=non>&nbsp</option>");
var datei = 1;
for(datei = 1; datei <= 31; datei++)
{
	if (datei<10){
		document.write("<option value=0",datei,">0",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 = "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(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 detecttwodate(formobj,vstr1,vstr2){
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(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),getmonthnum(bm),getdaynum(bd));	
		if ( bdate< detecttoday()){recstr = vstr1 + "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 = vstr1 + "must be equal or earlier than" + vstr2 + " , Please input again!!";}
			else{recstr = "ok";}
		}
	}
	else{recstr = vstr2 + " Wrong date input,please input again!!";}
}
else{recstr = vstr1 + " Wrong date input,please input again!!";}
return recstr;
}
function detecttwowhere(formobj,vstr1,vstr2){
recstr = "ok";
dw = formobj.org.options[formobj.org.selectedIndex].value;
rw = formobj.dst.options[formobj.dst.selectedIndex].value;
if (dw==rw) {recstr = vstr1 + " and " + vstr2 + " must not be same, Please input again!!";}
return recstr;
}
function detectthreewhere(formobj,vstr1,vstr2,vstr3){
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 = vstr1+" and "+vstr2+" must not be same, Please input again!!";}
if (vw==rw) {recstr = vstr2+" and "+vstr3+" must not be same, Please input again!!";}
if (dw==rw) {recstr = vstr1+" and "+vstr3+" must not be same, Please input again!!";}
return recstr;
}
function tktkindset(formobj,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11){
		formobj.via.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 initcity(formobj){
	setdv(formobj.org,"PEK");
	setdv(formobj.via,"SHA");
	setdv(formobj.dst,"CAN");
}
function inter_initcity(formobj){
	setdv(formobj.org,"PEK");
	setdv(formobj.via,"LAX");
	setdv(formobj.dst,"NYC");
}
