/**
 * 公共模块
 *
 * @version 0.5
 * @author lbj
 */
var onSelectChanged = function (s1,s2id,s3id) {
	if (s3id!='')
	{
		var s3options = MAP2[s1.options[s1.selectedIndex].value];
		var s3 = document.getElementById(s3id);
		s3.options.length = 0;
	    for (var i = 0; i < s3options.length; i++) {
	        s3.options[i] = new Option;
	        s3.options[i].value = s3options[i].value;
	        s3.options[i].text = s3options[i].text;
	    }		
	}
    var s2options = MAP1[s1.options[s1.selectedIndex].value];
    var s2 = document.getElementById(s2id);
    s2.options.length = 0;
    for (var i = 0; i < s2options.length; i++) {
        s2.options[i] = new Option;
        s2.options[i].value = s2options[i].value;
        s2.options[i].text = s2options[i].text;
    }
}
var login = function(){
	if ($('#username').val()=="")
	{
		$('#username').focus();
		return;
	}
	if ($('#password').val()=="")
	{
		$('#password').focus();
		return;
	}
	$('#agentLogin').submit();
}
var _alert = function (id,msg) {
	if ($('#'+id).val()=="")
	{
		alert(msg);
		$('#'+id).focus();
		return false;
	}
	else
		return true;
}
var _alertAirLine = function () {
	if ($('#air_line1').attr("checked"))
	{
		return (
			_alert("arrival_flight_no","Please check the arrival flight no") &&
			_alert("arrival_flight_date","Please check the arrival flight date") &&  
			_alert("arrival_flight_time","Please check the arrival flight time") &&
			_alert("departure_flight_no","Please check the departure flight no") &&
			_alert("departure_flight_date","Please check the departure flight date") &&
			_alert("departure_flight_time","Please check the departure flight time")
		);
	}
	else if ($('#air_line2').attr("checked"))
	{
		return (
			_alert("arrival_air_line_request","Please check the arrival air line request")
		);
	}
	else
	{
		alert("Please check the air line");
		return false;
	}
}
var formA = function () {
	return (
	_alert("tour_name","Please check the tour name") &&
	_alert("tour_code","Please check the tour code") &&  
	_alert("travelling_date","Please check the travelling date") &&
	_alert("no_of_adult","Please check the no of adult") &&
	//_alert("no_of_child_with_bed","Please check the no of child with bed") &&
	//_alert("no_of_child_no_bed","Please check the no of child no bed") &&
	//_alert("no_of_child_with_bed","Please check the no of child with bed") &&
	_alert("guest_title","Please check the title") &&
	_alert("surname","Please check the surname") &&
	_alert("given_name","Please check the given name") &&
    //_alert("nationality","Please check the nationality") &&	
    _alert("contact_no","Please check the contact no") &&
    _isEmail($('#email_address').val()) &&
    _alert("departure","Please check the departure") &&
    _alert("return","Please check the return") 
    //_alert("hotel_used","Please check the hotel used") &&
    //_alertAirLine()    
    );
}
var formB = function () {
	return (
	_alert("company_name","Please check the company name") &&
	_alert("contact_number","Please check the contact number") &&  
	_alert("fax_number","Please check the fax number") &&
	_alert("email_address","Please check the e-mail address")
    );
}
var _isEmail = function(strEmail) {
	if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
	{
		alert("E-mail is not properly formatted");
		$('#email').val("");
		$('#email').focus();		
		return false;
	}
}
var _checkPwd = function() {
	if ($('#password').val()==$('#repeat_password').val())
		return true;
	else
	{
		alert("Password and Confirm Password inconsistency");
		$('#repeat_password').val("");
		$('#repeat_password').focus();
		return false;
	}
}
var formC = function () {
	return (
	_alert("name","Please check the name") &&
	//_alert("passport_number","Please check the passport number") &&  
	//_alert("passport_nationality","Please check the passport nationality") &&
	_alert("emergency_contact","Please check the emergency contact") &&
	_alert("email_address","Please check the e-mail address") &&
	_isEmail($('#email_address').val()) &&
	_alert("agent_name","Please check the agent name") &&
	_alert("contact_number","Please check the contact number") &&
	_alert("fax_number","Please check the fax number") &&
	_alert("agent_email_address","Please check e-mail address") &&
	_isEmail($('#agent_email_address').val()) &&
	//_alert("arrival_date","Please check the arrival date") &&
	//_alert("departure_date","Please check the departure date") &&
	_alert("adults","Please check the adults") 
	//_alert("children","Please check the children") &&
	//_alert("hotel_used","Please check the hotel require")
    );
}
var formD = function () {
	return (
	_alert("username","Please check the user name") &&
	_alert("password","Please check the password") &&  
	_alert("repeat_password","Please check the repeat password") &&
	_checkPwd() &&
	_alert("name","Please check the name") &&
	_alert("agent_name","Please check the agent name") &&
	_alert("company_number","Please check the company registration number") &&
	_alert("company_address1","Please check the company address") &&
	_alert("contact","Please check the contact number(office)") &&
	_alert("fax","Please check the fax number") &&
	_alert("group","Please check the agent group") &&
	_alert("email","Please check the e-mail address") &&
	_isEmail($('#email').val())
    );
}