//$.getScript('/mu/images/jQuery.cookies.js');


if(!$.isFunction(jQuery.cookie))
{
$.ajax({
    type:"GET",
    cache:true,
    url:'/mu/images/jQuery.cookies.js',
    async: false,
    dataType:'script'
    });
}

function clearerrorkeydown(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;
        }    }
}

function include(id,url)
{
    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);
            $('#header_changecity').hide();
        }
    });
}

var max = new Date();
max.setFullYear(max.getFullYear()+1);
var min = new Date();
var	op = {
    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
};

var 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    
};

function initmenu(Menu,SubMenu)
{
	$(".mainmenu").jMainMenu({actionType:"mouseover",defaultSelectedMenu:Menu,defaultSelectedSubMenu:SubMenu});
}

function initsearch(type)
{
	$(".flight_status_search").jFlightStatusSearchBox({defaultSwitchType:type});
}

jQuery.fn.outerHTML = function()
{
    return jQuery('<div></div>').append(this.clone()).html();
}

jQuery.dom = function(id)
{
    return document.getElementById(id);
}

if(!$.isFunction(formSubmit))
{
    var formSubmit = function(val)
    {
        if(window.document.forms.length===0)
        {
            $('body').append('<form></form>');
        }
        var oldactionvalue = window.document.forms[0].action;
        var actionvalue = oldactionvalue.split("/");
    
        if (actionvalue[1] == 'muecard')
        {
            if (actionvalue[1] != null)
            {
                //alert("/" + actionvalue[1] + val);
                window.document.forms[0].action = "/" + actionvalue[1] + val;
                window.document.forms[0].submit();
            }
            else
            {
                alert("The request path is error!");
            }
        }
        else
        {
            //If we are user the ROOT directory,do not add any prefix
            window.document.forms[0].action = val;
            window.document.forms[0].submit();
        }
    }
}


function openurlnotfull(url)
{
    var width = 870;
    var height = 650;
    var left = screen.width > 800 ? 100 : 0;
    var top = 0;
    window.open(url, "_parent", "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + "");
}

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');	
                }
            }); 
       });
    }
}

$(document).ready(function()
{
    $('#header_changecity').hide();
    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',clearerrorkeydown);
    WCM.init();  
});


//对JavaScript基础类的扩展
String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.formtest = function(r,e,f)
{
    if(typeof r === 'string')
    {
        r = new RegExp(r);
    }
    try
    {
        if(r.test(this))
        {
            alert(e);
            if(typeof f!=='undefined')
            {
                f.focus();
            }
            return false;
        }
        else
        {
            return true;
        }
    }
    catch(ce)
    {
        alert(ce.message);
        return null;
    }
}
//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;
}
