if (typeof PassengerInfoAction === 'undefined')
{
    $.ajax({
        type: "GET",
        url: '/mu/dwr/interface/PassengerInfoAction.js',
        async: false,
        dataType: 'script'
    });
}
function selectSeat()
{
    var scrollT = document.getElementById("buttons");
}

function setSeatClk()
{
    $('#button1').attr('disabled', false);
    $('#button2').attr('disabled', true);
}

function setCalClk()
{
    $('#button1').attr('disabled', true);
    $('#button2').attr('disabled', false);
}
//值机
var checkin = new function()
{
    this.formsubmittest = function(url,func)
    {
        var reg = new RegExp('(?:^$)|(?:^'+JS_Resource.js.cuss.info.error+'$)', '');
        if ($("#querypassName").val().formtest(reg, JS_Resource.js.cuss.passenger.empty.error, $('#querypassName')) 
        && $("#queryidNo").val().formtest(reg, JS_Resource.js.cuss.cardno.empty.error, $('#queryidNo'))
        && $("#queryidNo").val().formtest('[^0-9a-zA-Z]', JS_Resource.js.cuss.cardno.type.error, $('#queryidNo')) 
        && $("#querymobileNo").val().formtest(reg, JS_Resource.js.cuss.phone.empty.error, $('#querymobileNo'))
        && $("#querymobileNo").val().formtest('[^\\d]',JS_Resource.js.cuss.phone.num.error,$("#querymobileNo"))
        && $("#fromcity").attr('_3CODE').formtest('^$',JS_Resource.js.cuss.depcity.empty.error,$("#fromcity"))
        && checkAge()
        && validatePaxName())
        {
            var old = $("#fromcity").val();
            $("#fromcity").val($("#fromcity").attr('_3CODE'));
            func(url);
            $("#fromcity").val(old);
            return true;
        }
        return false;
    }
}
function sFormSubmitOne(url)
{
    $('#checkin_data').show();
    $('#checkin_cancel').hide();
    $('#history_data').hide();
    $('#seat_Select').hide();
    $('#cuss_cancel').hide();
    return checkin.formsubmittest(url,startRequestCussPa);
}
//取消值机
function sFormSubmitTwo(url)
{
    $('#checkin_data').hide();
    $('#checkin_cancel').show();
    $('#history_data').hide();
    $('#seat_Select').hide();
    $('#cuss_cancel').hide();
    return checkin.formsubmittest(url,startRequestCussPw);
}
//历史查询
function sFormSubmitThree(url)
{
    
    var pageClicked = $("#button6").attr("pageClicked");
    if (pageClicked == '' || pageClicked == null || pageClicked != "y") {
        $('#history_data').empty();
    	$("#currentPage").val(1);
    }
    $("#button6").removeAttr("pageClicked");
    
    $('#checkin_data').hide();
    $('#checkin_cancel').hide();
    $('#history_data').show();
    $('#seat_Select').hide();
    $('#cuss_cancel').hide();
    return checkin.formsubmittest(url,startRequestFront);
}
//select seat
function sFormSubmitSeat(url)
{
    if ($("#qmobileNo").val().formtest('^$',JS_Resource.js.cuss.phone.empty.error,$("#qmobileNo"))
    && $("#qmobileNo").val().formtest('[^\\d]',JS_Resource.js.cuss.phone.num.error,$("#qmobileNo"))
    && isVCardNo($('#ffpNo').val(),$('#ffpairline').val()))
    {
        if ($("input[name='items']:checked").size() == 0)
        {
            alert(JS_Resource.js.cuss.flight.empty.error);
            return false;
        }
        $('#seat_Select').empty().show();
        var old = $("#fromcity").val();
        $("#fromcity").val($("#fromcity").attr('_3CODE'));
        startRequestSeat(url);
        $("#fromcity").val(old);
        return true;
    }
    return false;
}
//cancle checkin
function sFormSubmitCal()
{
    $('#checkin_cancel_text3').show();
    $('#checkin_text3').hide();
}

function sFormSubmitCussPa(url)
{

    if ($("#button1").attr('disabled') == true)
    {
        alert(JS_Resource.js.cuss.repeat.error);
        return false;
    }

    if ($('#seat_no').val() == '')
    {
        alert(JS_Resource.js.cuss.choose.seat.error);
        return false;
    }
    if ($("input[name='checkbox1']:checkbox:checked").size() == 0)
    {
        alert(JS_Resource.js.cuss.confirm.condition);
        return;
    }
    $("#button1").attr('disabled', 'true');
    formSubmit(url);
}

function check()
{
    
    var butt4 = document.getElementById("button3");
    if($('#checkbox1').attr("checked") == true)
    {
        $('#button3').attr('disabled',false);
    }
    else
    {
        $('#button3').attr('disabled',true);
    }
}

function setBoardingCheck()
{
    $("#recno").val($("input[name='boardingCheck']:checked").val());
}

function setCussPwCal()
{
    $('#cuss_cancel').hide();
}

function cancle(url, msg)
{
    confirmSubmit(url, msg);
}

function startRequestCussPa(urll)
{
    var $get = $('#checkin_data');
    $get.empty();
    $get.append('<img src="/mu/images/indicator_snake.gif"/>loading.....');
    var url = urll + "?querypassName=" + encodeURIComponent($('#querypassName').val()) + "&queryidNo=" + $('#queryidNo').val() + "&querymobileNo=" + $('#querymobileNo').val() + "&fromcity=" + $('#fromcity').val();
    $.ajax({
        type:'POST',
        url:url,
        cache:false,
        success:function(data)
        {
            $get.empty();
            $get.append(data);
            $('#qmobileNo').val($('#querymobileNo').val());
        }
    });
}

function setMessage(message)
{
    $('#checkin_data').replaceAll('<font color=red>' + message + ' </font>');
}

function startRequestCussPw(urll)
{
    var $get = $('#checkin_cancel');
    $get.empty();
    $get.append('<img src="/mu/images/indicator_snake.gif"/>loading.....');
    var url = urll + "?querypassName=" + encodeURIComponent($('#querypassName').val()) + "&queryidNo=" + $('#queryidNo').val() + "&querymobileNo=" + $('#querymobileNo').val() + "&fromcity=" + $('#fromcity').val();
    $.ajax({
        type:'POST',
        url:url,
        cache:false,
        success:function(data)
        {
            $get.empty();
            $get.append(data);
        }
    });
}


function startRequestFront(urll)
{   //alert($("#currentPage").val());
    var $get = $('#history_data');
    //$get.empty();
    //$get.hide();
    $('#fly_info3').empty();
    $get.append('<img src="/mu/images/indicator_snake.gif"/>loading.....');
    var url = urll + "?querypassName=" + encodeURIComponent($('#querypassName').val()) + "&queryidNo=" + $('#queryidNo').val() + "&querymobileNo=" + $('#querymobileNo').val() + "&fromcity=" + $('#fromcity').val()+"&pageNo="+$("#currentPage").val();
    $.ajax({
        type:'POST',
        url:url,
        cache:false,
        success:function(data)
        {
            $get.empty();
            $get.append(data);
            //$('#fly_info3').TablePage();
            //$get.show();
        }
    });
}

function startRequestSeat(urll)
{
    var $get = $('#seat_Select');
    $get.empty();
    $get.append('<div id="checkin_text3"><img src="/mu/images/indicator_snake.gif"/>loading.....</div>');
    var url = urll + "?passName=" + encodeURIComponent($('#passName').val()) + "&userId=" + $('#userId').val() + "&org=" + $('#org').val() + "&airline=" + $('#airline').val() + "&segIndex=" + $('#segIndex').val() + "&tktno=" + $('#tktno').val();
    $.ajax({
        type:'POST',
        url:url,
        cache:false,
        success:function(data)
        {
            $get.empty();
            $get.append(data);
        }
    });
}

function startRequestPwDo(urll)
{
    if ($("input[name='recno_cal']:checked").size() == 0)
    {
        alert(JS_Resource.js.cuss.cancel.flight);
        return false;
    }
    var $get = $('#cuss_cancel');
    $get.show();
    $get.empty();
    $get.append('<img src="/mu/images/indicator_snake.gif"/>loading.....');
    var url = urll; //+"?passName="+encodeURIComponent($('#passName').val())+"&userId="+$('#userId').val()+"&org="+$('#org').val()+"&airline="+$('#airline').val()+"&segIndex="+$('#segIndex').val()+"&tktno="+$('#tktno').val();
    $.ajax({
        type:'POST',
        url:url,
        cache:false,
        success:function(data)
        {
            $get.empty();
            $get.append(data);
        }
    });
}
function doSendCode(urll)
{
    var url = urll + "?" + $("input[name='recno_cal']:checked").val();
    $.ajax({
        type:'POST',
        url:url,
        cache:false,
        success:function(data)
        {
            if (data == "ok")
            {
                alert(JS_Resource.js.cuss.sendmsg.success);
            }
            else
            {
                alert(JS_Resource.js.cuss.sendmsg.fail + data);
            }
        }
    });
}
function doCussCancel(urll)
{
    if ($("#button2").attr('disabled') == true)
    {
        alert(JS_Resource.js.cuss.repeat.error);
        return false;
    }
    if ($("input[name='recno_cal']:checked").size() == 0)
    {
        alert(JS_Resource.js.cuss.cancel.flight);
        return false;
    }
    if ($("#verifyNo").val() == "")
    {
        alert(JS_Resource.js.cuss.msg.empty.error);
        return false;
    }
    var url = urll + "?" + $("input[name='recno_cal']:checked").val() + "&verifyNo=" + $("#verifyNo").val();
    $.get(url,function(data)
    {
        if (data == "ok")
        {
           alert(JS_Resource.js.cuss.cancel.success);
           $("#button8").attr('disabled', 'true');
        }
        else
        {
           alert(JS_Resource.js.cuss.cancel.fail + getReasonByCode(data));
        }
    });
}

function getReasonByCode(data){
   if(data == '') return JS_Resource.js.cuss.use.busy ;
   else if(data =='04001') return JS_Resource.js.cuss.use.busy ;
   else if(data =='04002') return JS_Resource.js.cuss.param.error ;
   else if(data =='04003') return JS_Resource.js.cuss.handing ;
   else if(data =='04004') return JS_Resource.js.cuss.cancel.msg.error ;
   else if(data =='04005') return JS_Resource.js.cuss.cancel.self.fail ;
   else  return JS_Resource.js.cuss.use.busy ;
}

function setSeatPar()
{
    $('#seat_Select').hide();
    var item1 = $("input[name='items']:checked").val();
    var item2 = $("input[name='items']:checked").parent().next().text();
    var item3 = $("input[name='items']:checked").parent().next().next().text();
    var item4 = $("input[name='items']:checked").parent().next().find("input").val();
    var item3a = $("input[name='items']:checked").parent().next().next().find("input").val();

    $('#org').val(item1);
    $('#tktno').val(item2);
    $('#airline').val(item3a);
    $('#segIndex').val(item4);
}

var seatnum = 0;
var maxseatnum = 1000;

$(function()
{
    $('#fly_picture .start_t .free').live('click',function()
    {
        $('#fly_picture .start_t .freesel').removeClass('freesel').addClass('free');
        $(this).removeClass('free').addClass('freesel');
        $('#label_seat_no').text($(this).val()).show();
        $('#seat_no').val($(this).val());
    });
    $('#fly_picture .start_t input[name=special]').live('click',function()
    {
        $('#fly_picture .start_t .freesel').removeClass('freesel').addClass('free');
        var str = '';
        var str1 = '';
        switch($(this).val())
        {
            case 'W':
            {
                str = JS_Resource.js.cuss.window;
                str1 ='W';
                break;
            }
            case 'I':
            {
                str = JS_Resource.js.cuss.way;
                str1 ='I';
                break;
            }
            case 'F':
            {
                str = JS_Resource.js.cuss.front;
                str1 ='F';
                break;
            }
            case 'A':
            {
                str = JS_Resource.js.cuss.back;
                str1 ='A';
                break;
            }
            case 'L':
            {
                str = JS_Resource.js.cuss.left;
                str1 = 'L';
                break;
            }
            case 'R':
            {
                str = JS_Resource.js.cuss.right;
                str1 = 'R';
                break;
            }
        }
        $('#seat_no').val(str1);
        $('#label_seat_no').text(str).show();
    });
});

//判断常客卡号
function isVCardNo(cardNo, airline)
{

    var form = document.cussForm;
    if (airline != "" && cardNo == "")
    {
        alert(JS_Resource.js.cuss.card.empty.error);
        form.ffpNo.focus();
        return false;
    }
    if (airline == "" && cardNo != "")
    {
        alert(JS_Resource.js.cuss.card.ofcompany);
        form.ffpairline.focus();
        return false;
    }
    if (airline == "MU")
    {
        var pattern = /^[0-9]{9}$|^[0-9]{12}$/;
        if (!pattern.test(cardNo))
        {
            alert(JS_Resource.js.cuss.ceair.card.error);
            form.ffpNo.focus();
            return false;
        }
    }
    if (airline == "CX")
    {
        var pattern = /^([0-9]{10})$/;
        if (!pattern.test(cardNo))
        {
            alert(JS_Resource.js.cuss.guotai.card.error);
            form.ffpNo.focus();
            return false;
        }
    }
    if (airline == "CI")
    {
        var pattern = /^([Ww][Bb][0-9]{7})$/;
        if (!pattern.test(cardNo))
        {
            alert(JS_Resource.js.cuss.china.card.error);
            form.ffpNo.focus();
            return false;
        }
    }
    return true;
}
function checkAge()
{
    var certNo = $('#queryidNo').val();
    var checkStatus = "Ok";
    var isNumber = true;
    var needCheck = false;
    if (certNo != "" && (certNo.length == 15 || certNo.length == 18))
    {
        if (CheckIDCard(certNo))
        {
            needCheck = true;
        }
        else
        {
            alert(JS_Resource.js.cuss.checkId.error);
            return false;
        }
    }
    if (needCheck)
    {
        var cussTime = new Date();
        var birthdayDate = new Date(birthday);

        birthdayDate.setUTCFullYear(birthdayDate.getUTCFullYear() + 12);

        if (cussTime < birthdayDate)
        {
            alert(JS_Resource.js.cuss.child.error);
            return false;
        }
    }
    return true;
}

//身份证号码校验,并从中拆分出出生年月日和性别
var yyyy;
var mm;
var dd;
var birthday;
var sex;

//校验身份证号码
function CheckIDCard(idCard)
{
    return true;
    var id = idCard;
    var id_length = id.length;

    if (id_length == 0)
    {
        return false;
    }

    if (id_length != 15 && id_length != 18)
    {
        return false;
    }

    if (id_length == 15)
    {
        yyyy = "19" + id.substring(6, 8);
        mm = id.substring(8, 10);
        dd = id.substring(10, 12);

        if (mm > 12 || mm <= 0)
        {
            return false;
        }

        if (dd > 31 || dd <= 0)
        {
            return false;
        }

        birthday = yyyy + "/" + mm + "/" + dd;

        if ("13579".indexOf(id.substring(14, 15)) != -1)
        {
            sex = "1";
        }
        else
        {
            sex = "2";
        }
    }
    else if (id_length == 18)
    {
        if (id.indexOf("X") > 0 && id.indexOf("X") != 17 || id.indexOf("x") > 0 && id.indexOf("x") != 17)
        {
            return false;
        }

        yyyy = id.substring(6, 10);
        if (yyyy > 2200 || yyyy < 1900)
        {
            return false;
        }

        mm = id.substring(10, 12);
        if (mm > 12 || mm <= 0)
        {
            return false;
        }

        dd = id.substring(12, 14);
        if (dd > 31 || dd <= 0)
        {
            return false;
        }

        if (id.charAt(17) == "x" || id.charAt(17) == "X")
        {
            if ("x" != GetVerifyBit(id) && "X" != GetVerifyBit(id))
            {
                return false;
            }

        }
        else
        {
            if (id.charAt(17) != GetVerifyBit(id))
            {
                return false;
            }
        }

        birthday = id.substring(6, 10) + "/" + id.substring(10, 12) + "/" + id.substring(12, 14);
        if ("13579".indexOf(id.substring(16, 17)) > -1)
        {
            sex = "1";
        }
        else
        {
            sex = "2";
        }
    }

    return true;
}

//15位转18位中,计算校验位即最后一位
function GetVerifyBit(id)
{
    var result;
    var nNum = eval(id.charAt(0) * 7 + id.charAt(1) * 9 + id.charAt(2) * 10 + id.charAt(3) * 5 + id.charAt(4) * 8 + id.charAt(5) * 4 + id.charAt(6) * 2 + id.charAt(7) * 1 + id.charAt(8) * 6 + id.charAt(9) * 3 + id.charAt(10) * 7 + id.charAt(11) * 9 + id.charAt(12) * 10 + id.charAt(13) * 5 + id.charAt(14) * 8 + id.charAt(15) * 4 + id.charAt(16) * 2);
    nNum = nNum % 11;
    switch (nNum)
    {
    case 0:
        result = "1";
        break;
    case 1:
        result = "0";
        break;
    case 2:
        result = "X";
        break;
    case 3:
        result = "9";
        break;
    case 4:
        result = "8";
        break;
    case 5:
        result = "7";
        break;
    case 6:
        result = "6";
        break;
    case 7:
        result = "5";
        break;
    case 8:
        result = "4";
        break;
    case 9:
        result = "3";
        break;
    case 10:
        result = "2";
        break;
    }
    return result;
}

function onloadCussQuery()
{
    var query = location.search.substring(1);
    var querypassName, queryidNo, querymobileNo, fromcity, city3Code, pos;
    var url = '/mu/front/cuss/cuss!doSearchCussPa.shtml';

    if ("" != query && query.indexOf("cussQueryFromIndex") >= 0)
    {
        var values = query.split("&");
        for (var i = 1; i < values.length; i++)
        {
            pos = values[i].indexOf("=");
            switch (i)
            {
            case 1:
                querypassName = decodeURIComponent(values[i].substring(pos + 1));
                break;
            case 2:
                queryidNo = values[i].substring(pos + 1);
                break;
            case 3:
                querymobileNo = values[i].substring(pos + 1);
                break;
            case 4:
                fromcity = decodeURIComponent(values[i].substring(pos + 1));
                break;
            case 5:
            	city3Code = values[i].substring(pos + 1);
            }
        }
        $("#querypassName").val(querypassName);
        $("#queryidNo").val(queryidNo);
        $("#querymobileNo").val(querymobileNo);
        $("#fromcity").val(fromcity);
        $("#fromcity").attr("_3CODE",city3Code);
        sFormSubmitOne(url);
    }
}

function doClickPa(str)
{
    if (str == "etdz")
    {
        $.dom('button4').click();
    }
}
function doSelect(select){
     
   var currentPage = $('#currentPage').val();
   
   switch(select)
    {
      case 'select':
      {
        $("#currentPage").val($("#selectPage").val());
        break;
      }
      case 'first':
      {
        $("#currentPage").val('1');
        break;
      }
      case 'back':
      {
        $("#currentPage").val(parseInt(currentPage) - parseInt("1"));
        break;
      }
      case 'next':
      {
        $("#currentPage").val(parseInt(currentPage) + parseInt("1"));
        break;
      }
      case 'last':
      {
        $("#currentPage").val($("#totalPage").val());
        break;
      }
    }
 
   $("#button6").attr("pageClicked","y");
 
   $.dom('button6').click();
}

$(function()
{
    $("#fromcity").jSelectCity({
        tips: "支持中文/拼音"
    });
    var str = $('body').attr('etdz');
    if (str == "etdz")
    {
        $.dom('button4').click();
    }
    onloadCussQuery();
    $('#fly_info3').TablePage();
});

$(document).ready(function()
{
    var addblur = function(jqueryselect)
    {
        if ($(jqueryselect).val() == '')
        {
            $(jqueryselect).val(JS_Resource.js.cuss.info.error);
            $(jqueryselect).blur(function()
            {
                if ($(this).val() == '')
                {
                    $(this).val(JS_Resource.js.cuss.info.error);
                }
            });
            $(jqueryselect).focus(function()
            {
                if ($(this).val() == JS_Resource.js.cuss.info.error)
                {
                    $(this).val('');
                }
            });
        }
    }
    addblur('#querypassName');
    addblur('#queryidNo');
    addblur('#querymobileNo');
});

//add by wuyang 2010-03-31 -start-
function validatePaxName(){
	DWREngine.setAsync(false);
    var result;
    PassengerInfoAction.getLegalName($("#querypassName").val(),function(data)
    {
    	result=data;
    });
    DWREngine.setAsync(true);
    if(result.indexOf("?")>=0)
    {
    	alert(JS_Resource.js.cuss.passenger.name+result+JS_Resource.js.cuss.name.remark);
    	return false;
    }
    
    return true;
}
//add by wuyang 2010-03-31 -end-

