function show_e(s_emsg,o_input){
	o_from = document.cbErrorMsg;
	o_e = eval("o_from."+s_emsg)
	document.getElementById("cb_emsg").innerHTML = o_e.value;
	o_input.focus();
	document.getElementById("cb_e").style.display = "block";
	if(isMac&&isIE5)if(document.getElementById("cbNav"))document.getElementById("cbNav").style.visibility = "hidden";
	o_input.className+=" cb_efield";
	(o_input.type=='text') ? o_input.onkeypress = function (){this.className=''} : o_input.onclick = function (){this.className=''}
}
function close_e(){
	document.getElementById("cb_e").style.display = "none";
	if(isMac&&isIE5)if(document.getElementById("cbNav"))document.getElementById("cbNav").style.visibility = "visible";
}
//check 1
function e_checklength(o_input,i_min,i_max){
	b_valid = true;
	if(o_input.value.length < i_min || o_input.value.length > i_max){
		show_e('e_length',o_input)
		b_valid = false;
	}
	return b_valid;	
}
//check 2
function e_checkspace(o_input){
	b_valid = true;
	if(o_input.value.charCodeAt(0)==32){
		show_e('e_space',o_input)
		b_valid = false;
	}
	return b_valid;
}
//check 3
function e_checkchar(o_input){
	b_valid = true;
	b_charCodeError=false;
	s_checkvalue = o_input.value
	s_checkvalue = s_checkvalue.toLowerCase();
	for(var i=0;i<s_checkvalue.length;i++)if(s_checkvalue.charCodeAt(i)!=46&&s_checkvalue.charCodeAt(i)!=44&&s_checkvalue.charCodeAt(i)!=32&&s_checkvalue.charCodeAt(i)!=39&&(s_checkvalue.charCodeAt(i)<97||s_checkvalue.charCodeAt(i)>122))b_charCodeError=true;
	if(b_charCodeError){
		show_e('e_char',o_input)
		b_valid = false;
	}
	return b_valid;	
}
//check 4
function e_same(o_inputT,o_inputF){
	b_valid = true;
	if(o_inputT.value==o_inputF.value) {
		show_e('e_same',o_inputT)
		b_valid = false;
	}
	return b_valid;
}
//check 5
function e_children(o_select, s_idbit){
	b_valid = true;
	if(o_select.selectedIndex>0){
		minorAges = document.getElementById("cb"+s_idbit+"childages").getElementsByTagName("select")
		for(var i=0;i < o_select.selectedIndex;i++){
			if(minorAges[i].selectedIndex==0){
				show_e('e_child',minorAges[i]);
				b_valid = false;
				i = minorAges.length
			}
		}
	}
	return b_valid;
}
//check 6
function e_dates(o_fromM,o_toM, o_fromD, o_toD){
	b_valid = true;
	if(o_fromM.selectedIndex==o_toM.selectedIndex){
		if(o_fromD.selectedIndex>o_toD.selectedIndex){
			show_e('e_date',o_toD)
			b_valid = false;
		}
	}else if((o_fromM.selectedIndex-o_toM.selectedIndex)==1){
		show_e('e_date',o_toM)
		b_valid = false;
	}
	return b_valid;
}
//check 7
function e_validdate(o_date){
	b_valid = true;	s_odate=o_date.value;
	s_delimitor = (s_odate.indexOf("/")>-1) ? "/" : (s_odate.indexOf(".")>-1) ? "." : (s_odate.indexOf("-")>-1) ? "-" : (s_odate.indexOf(",")>-1) ? "," : "/";
	a_sodate = s_odate.split(s_delimitor);
	if(a_sodate.length!=3)b_valid=false;
	for(var i=0;i< a_sodate.length;i++)if(isNaN(a_sodate[i])||a_sodate[i]=="") b_valid=false;
	if(!b_valid) show_e('e_validdate',o_date)
	return b_valid;
}
function checkform(){
	a_arguments = checkform.arguments;
	o_form = a_arguments[0];
	a_form = o_form.name.split("form");
	s_type = a_form[1];
	s_type2 = s_type;
	s_airflex = 0;
	s_airbit = "";
	b_submit = true;
	for(var i= 1;i<a_arguments.length;i++){
		switch (a_arguments[i]){
			case 1:
				if(document.getElementById(s_type+"_from")) b_submit = e_checklength(document.getElementById(s_type+"_from"),3,25);		
				if(b_submit) if(document.getElementById(s_type+"_to")) b_submit = e_checklength(document.getElementById(s_type+"_to"),3,25);
			break;
			case 2:
				if(document.getElementById(s_type+"_from")) b_submit = e_checkspace(document.getElementById(s_type+"_from"));				
				if(b_submit) if(document.getElementById(s_type+"_to")) b_submit = e_checkspace(document.getElementById(s_type+"_to"));
			break;
			case 3:
				if(document.getElementById(s_type+"_from")) b_submit = e_checkchar(document.getElementById(s_type+"_from"));				
				if(b_submit) if(document.getElementById(s_type+"_to")) b_submit = e_checkchar(document.getElementById(s_type+"_to"));
			break;
			case 4:
				b_submit = e_same(document.getElementById(s_type+"_from"),document.getElementById(s_type+"_to"))
			break;
			case 5:
				if(document.getElementById(s_type+"_children")){if(document.getElementById(s_type+"_children").selectedIndex>0)b_submit = e_children(document.getElementById(s_type+"_children"), s_type);}
				if(document.getElementById(s_type+"_child1")){if(document.getElementById(s_type+"_child1").selectedIndex>0)b_submit = e_children(document.getElementById(s_type+"_child1"), s_type);}
			break;
			case 6:
				if(document.getElementById(s_type+"_tomonth")) b_submit = e_dates(document.getElementById(s_type+"_frommonth"),document.getElementById(s_type+"_tomonth"),document.getElementById(s_type+"_fromdate"),document.getElementById(s_type+"_todate"));
			break;
			case 7:
				if(document.getElementById(s_type+"_adults")){
					if(document.getElementById(s_type+"_adults").selectedIndex==0&&document.getElementById(s_type+"_children").selectedIndex==0&&document.getElementById(s_type+"_seniors").selectedIndex==0) {
						show_e('e_pass',document.getElementById(s_type+"_adults"))
						b_submit =false;
					}
				}
				if(document.getElementById(s_type+"_adult1")){
					if(document.getElementById(s_type+"_adult1").selectedIndex==0&&document.getElementById(s_type+"_child1").selectedIndex==0&&document.getElementById(s_type+"_senior1").selectedIndex==0) {
						show_e('e_pass',document.getElementById(s_type+"_adult1"))
						b_submit =false;
					}
				}
			break;
			case 8:
				if(!s_airflex){
					b_oneway = 0;
					if(document.getElementById(s_type2+"_fromdate")){
						b_submit = e_validdate(document.getElementById(s_type2+"_fromdate"));
					} else if(document.getElementById(s_type2.toLowerCase()+"-fromdate")){
						b_submit = e_validdate(document.getElementById(s_type2.toLowerCase()+"-fromdate"));
					}
					if(s_airbit=="multicity"||s_airbit=="oneway")b_oneway = 1;
					if(document.getElementById(s_type2+"_todate")&&b_submit&&!b_oneway){
						b_submit = e_validdate(document.getElementById(s_type2+"_todate"));
					} else if(document.getElementById(s_type2.toLowerCase()+"-todate")&&b_submit&&!b_oneway){
						b_submit = e_validdate(document.getElementById(s_type2.toLowerCase()+"-todate"));
					}
				}else{
					b_submit=true;
				}
			break;
			default:
		}
		if(!b_submit) i=a_arguments.length;
	}
	return b_submit;
}

