jQuery.dom = function(id)
{
    return document.getElementById(id);
};
//对JavaScript基础类的扩展
String.prototype.trim = function()
{ 
    return this.replace(/(^\s*)|(\s*$)/g, "");
};
String.prototype.realLength = function() 
{ 
  return this.replace(/[^\x00-\xff]/ig,"**").length; 
};
//1000->1,000
Number.prototype.toStr3 = function()
{
    return (this == 0 ? '': Math.abs(this) / this).toString().replace('1', '') + this.toString().match(/\d/g).reverse().join('').match(/\d{1,3}/g).join(',').match(/./g).reverse().join('');
};
//Date->2010-01-19
Date.prototype.to_Str = function()
{
    return this.getFullYear().toString() + '-' + (this.getMonth() < 9 ? '0': '') + (this.getMonth() + 1).toString() + '-' + (this.getDate() < 10 ? '0': '') + this.getDate().toString();
};
//Date->20100119
Date.prototype.getShortDateStr = function()
{
    var str = this.getFullYear().toString();
    if (this.getMonth() < 9) str += "0";
    str += (this.getMonth() + 1).toString();
    if (this.getDate() < 10) str += "0";
    str += this.getDate().toString();
    return str;
}

var max = new Date();
max.setFullYear(max.getFullYear() + 1);
var min = new Date();

var expoMaxInPublic = new Date();
var maxDiffDateInPublic = 7;
expoMaxInPublic.setDate(Number(expoMaxInPublic.getDate()) + maxDiffDateInPublic);
expoMaxInPublic.setFullYear(expoMaxInPublic.getFullYear() + 1);

var expoMinInPublic = new Date();
var minDiffDateInPublic = 7;
expoMinInPublic.setDate(Number(expoMinInPublic.getDate()) + minDiffDateInPublic);



var Shared = {
    "include": function(id, url,callback)
    {
        var cache = true;
        if (url.indexOf('.jsp') > 0 || url.indexOf('.shtml') > 0)
        {
            cache = false;
        }
        $.ajax({
            type: 'GET',
            url: url,
            cache: cache,
            async: false,
            success: function(data)
            {
                $(id).replaceWith(data);
                if(typeof callback != 'undefined')
                {
                    callback();
                }
            }
        });
    },
    "dateconfig_1Months": {
        dateFormat: 'yy-mm-dd',
        showButtonPanel: true,
        buttonImage: '/mu/images/icon_calendar.gif',
        buttonImageOnly: true,
        numberOfMonths: 1,
        closeText: "关闭",
        currentText: '今天',
        monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
        monthNamesShort: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'],
        dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
        dayNamesShort: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
        dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
        duration: 0,
        showAnim: 'show',
        minDate: min,
        maxDate: max
    },
    "dateconfig_2Months": {
        dateFormat: 'yy-mm-dd',
        showButtonPanel: true,
        buttonImage: '/mu/images/icon_calendar.gif',
        buttonImageOnly: true,
        numberOfMonths: 2,
        closeText: "关闭",
        currentText: '今天',
        monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
        monthNamesShort: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'],
        dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
        dayNamesShort: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
        dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
        duration: 0,
        showAnim: 'show',
        minDate: min,
        maxDate: max
    },
    "dateConfigForExpoInPublic": {
        dateFormat: 'yy-mm-dd',
        showButtonPanel: true,
        buttonImage: '/mu/images/icon_calendar.gif',
        buttonImageOnly: true,
        numberOfMonths: 2,
        closeText: "关闭",
        currentText: '今天',
        monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
        monthNamesShort: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'],
        dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
        dayNamesShort: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
        dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
        duration: 0,
        showAnim: 'show',
        minDate: expoMinInPublic,
        maxDate: expoMaxInPublic
    },
    "initmenu": function(Menu, SubMenu)
    {
        $(".mainmenu").jMainMenu({
            "actionType": "mouseover",
            "defaultSelectedMenu": Menu,
            "defaultSelectedSubMenu": SubMenu
        });
    },
    "initsearch": function(type)
    {
        $(".flight_status_search .title_red_small").addClass(type);
        if(type==='close')
        {
            $(".flight_status_search .flight_search").hide();
            $(".flight_status_search .title_red_small").removeClass('open').addClass('close');
        }
        $(".flight_status_search .title_red_small").live('click',function()
        {
             if($(this).hasClass('open'))
             {
                 $(this).next().hide();
                 $(this).removeClass('open').addClass('close');
             }
             else
             {
                 $(this).next().show();
                 $(this).removeClass('close').addClass('open');                 
             }
        });
    },
    "clearerrorkeydown": function(event)
    {
        switch (event.keyCode)
        {
        case 188:
            //<
        case 190:
            //>
        case 51:
            //#
        case 52:
            //$
        case 55:
            //&
            {
                if (event.shiftKey == true)
                {
                    return false;
                }
                break;
            }
        case 222:
            //',"
            {
                return false;
            }
        }
    },
    "expo_menu":function()
    {
        $("#logon").jLoginPopUp();
        $("li[id^=menu_]").live('mouseover.menu',function()
        {
    	    $("li[id^=menu_].active").removeClass("active");
    	    $("div[id^=menu_nav_]:visible").hide();
    	    $(this).addClass('active');
    	    $('#menu_nav_'+$(this).attr('id').replace(/[^\d]/g,'')).show();
        });

    },
    "left_expo":function()
    {
        $(".menu_child [class*=child_menu_]").live('click.expo',function()
        {
            if($('.menu_child h2:visible')[0] !== $(this).next("h2")[0])
            {
                $('.menu_child h2:visible').slideUp('normal');
                $(this).next("h2").slideDown('normal');                
            }
        });
    }
};



var WCM = new function()
{
    this.init = function()
    {
        var _3CODE = $.cookie('_3CODE');
        $('iframe[wcm]').each(function()
        {
            var url = $(this).attr('wcm');
            if (_3CODE !== null && _3CODE !== 'null' && _3CODE !== 'NULL')
            {
                url = url.replace('main', _3CODE.toLowerCase());
            }
            $(this).attr('src', url);
            $(this).removeAttr('wcm');
            //动态高度
            $(this).bind('load',
            function()
            {
                var totalHeight = 0;
                $(this).contents().find('body>div').each(function()
                {
                    totalHeight = totalHeight + $(this).height();
                });
                $(this).height(totalHeight);
                if ($(this).width() < 300)
                {
                    $(this).width('219px');
                }
            });
        });
    };
};
$(function()
{
    var _3CODE = $.cookie('_3CODE');
    var city = $.cookie('city');
    if (_3CODE == null || _3CODE == 'null')
    {
        city = '主站';
        $.cookie('city', '主站', {
            expires: 365,
            path: '/'
        });
        $.cookie('_3CODE', 'NULL', {
            expires: 365,
            path: '/'
        });
    }
    $('#header_changecity_lable').text(city + '：');
    $('input[type="text"]').live('keydown', Shared.clearerrorkeydown);
    WCM.init();
});

