jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {domain:null,path:'/'};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = "";
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

function CommonError(ans) {
    CleanMessage();
    for (var i = 0; i < ans.error.length; i++) {
        var node = $("#" + ans.error[i]["ErrorControlID"]), type = node.attr("nodeName").toLowerCase();
        if (type == "span" || type == "div") {
            node.next(".font14b").eq(0).remove();
            node.prev(".font14b").eq(0).remove();
            node.html(ans.error[i]["ErrorMessage"]);
            node.parents(".leftitbor").show();
        }
        else {
            node.after("<span class='error'>" + ans.error[i]["ErrorMessage"] + "</span>");
        }
    }
}


/*日期start*/

Date.dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];

Date.abbrDayNames = ['日', '一', '二', '三', '四', '五', '六'];

Date.monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];

Date.abbrMonthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];

Date.firstDayOfWeek = 1;

Date.format = 'yyyy-mm-dd';
//Date.format = 'mm/dd/yyyy';
//Date.format = 'yyyy-mm-dd';
//Date.format = 'dd mmm yy';

/**
 * The first two numbers in the century to be used when decoding a two digit year. Since a two digit year is ambiguous (and date.setYear
 * only works with numbers < 99 and so doesn't allow you to set years after 2000) we need to use this to disambiguate the two digit year codes.
 *
 * @name format
 * @type String
 * @cat Plugins/Methods/Date
 * @author Kelvin Luck
 */
Date.fullYearStart = '20';

function ToDate(stringDate) {
    var r = stringDate.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
    if (r == null) {
        return false;
    }
    return new Date(r[1], r[3] - 1, r[4]);
}

(function() {

    function add(name, method) {
        if (!Date.prototype[name]) {
            Date.prototype[name] = method;
        }
    };
    
    add("isLeapYear", function() {
        var y = this.getFullYear();
        return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
    });
    
    add("isWeekend", function() {
        return this.getDay() == 0 || this.getDay() == 6;
    });
    
    add("isWeekDay", function() {
        return !this.isWeekend();
    });
    
    add("getDaysInMonth", function() {
        return [31, (this.isLeapYear() ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][this.getMonth()];
    });
    
    add("getDayName", function(abbreviated) {
        return abbreviated ? Date.abbrDayNames[this.getDay()] : Date.dayNames[this.getDay()];
    });
    
    add("getMonthName", function(abbreviated) {
        return abbreviated ? Date.abbrMonthNames[this.getMonth()] : Date.monthNames[this.getMonth()];
    });
    
    add("getDayOfYear", function() {
        var tmpdtm = new Date("1/1/" + this.getFullYear());
        return Math.floor((this.getTime() - tmpdtm.getTime()) / 86400000);
    });
    
    add("getWeekOfYear", function() {
        return Math.ceil(this.getDayOfYear() / 7);
    });
    
    add("setDayOfYear", function(day) {
        this.setMonth(0);
        this.setDate(day);
        return this;
    });
    
    add("addYears", function(num) {
        this.setFullYear(this.getFullYear() + num);
        return this;
    });
    
    add("addMonths", function(num) {
        var tmpdtm = this.getDate();
        
        this.setMonth(this.getMonth() + num);
        
        if (tmpdtm > this.getDate()) 
            this.addDays(-this.getDate());
        
        return this;
    });
    
    add("addDays", function(num) {
        //this.setDate(this.getDate() + num);
        this.setTime(this.getTime() + (num * 86400000));
        return this;
    });
    
    add("addHours", function(num) {
        this.setHours(this.getHours() + num);
        return this;
    });
    
    add("addMinutes", function(num) {
        this.setMinutes(this.getMinutes() + num);
        return this;
    });
    
    add("addSeconds", function(num) {
        this.setSeconds(this.getSeconds() + num);
        return this;
    });
    
    add("zeroTime", function() {
        this.setMilliseconds(0);
        this.setSeconds(0);
        this.setMinutes(0);
        this.setHours(0);
        return this;
    });
    
    add("asString", function(format) {
        var r = format || Date.format;
        return r.split('yyyy').join(this.getFullYear()).split('yy').join((this.getFullYear() + '').substring(2)).split('mmmm').join(this.getMonthName(false)).split('mmm').join(this.getMonthName(true)).split('mm').join(_zeroPad(this.getMonth() + 1)).split('dd').join(_zeroPad(this.getDate())).split('hh').join(_zeroPad(this.getHours())).split('min').join(_zeroPad(this.getMinutes())).split('ss').join(_zeroPad(this.getSeconds()));
        
    });
    
    add("equalDate", function(date) {
        return this.getFullYear() == date.getFullYear() && this.getMonth() == date.getMonth() && this.getDate() == date.getDate();
    });
    add("equalMonth", function(date) {
        return this.getFullYear() == date.getFullYear() && this.getMonth() == date.getMonth();
    });
    Date.fromString = function(s, format) {
        var f = format || Date.format;
        var d = new Date('01/01/1977');
        
        var mLength = 0;
        
        var iM = f.indexOf('mmmm');
        if (iM > -1) {
            for (var i = 0; i < Date.monthNames.length; i++) {
                var mStr = s.substr(iM, Date.monthNames[i].length);
                if (Date.monthNames[i] == mStr) {
                    mLength = Date.monthNames[i].length - 4;
                    break;
                }
            }
            d.setMonth(i);
        }
        else {
            iM = f.indexOf('mmm');
            if (iM > -1) {
                var mStr = s.substr(iM, 3);
                for (var i = 0; i < Date.abbrMonthNames.length; i++) {
                    if (Date.abbrMonthNames[i] == mStr) 
                        break;
                }
                d.setMonth(i);
            }
            else {
                d.setMonth(Number(s.substr(f.indexOf('mm'), 2)) - 1);
            }
        }
        
        var iY = f.indexOf('yyyy');
        
        if (iY > -1) {
            if (iM < iY) {
                iY += mLength;
            }
            d.setFullYear(Number(s.substr(iY, 4)));
        }
        else {
            if (iM < iY) {
                iY += mLength;
            }
            // TODO - this doesn't work very well - are there any rules for what is meant by a two digit year?
            d.setFullYear(Number(Date.fullYearStart + s.substr(f.indexOf('yy'), 2)));
        }
        var iD = f.indexOf('dd');
        if (iM < iD) {
            iD += mLength;
        }
        if (iD > -1) {
            d.setDate(Number(s.substr(iD, 2)));
        }
        if (isNaN(d.getTime())) {
            return false;
        }
        return d;
    };
    
    // utility method
    var _zeroPad = function(num) {
        var s = '0' + num;
        return s.substring(s.length - 2)
        //return ('0'+num).substring(-2); // doesn't work on IE :(
    };
    
})();
/*日期end*/

var CommonErrorMessage;
$(function() {
    BaseScript.TranslatePage();
    BaseScript.BindChangeLanguage();
    CommonErrorMessage = $(".leftitbor").filter(function(index) {
        return $(this).css("display") == "none";
    });
})
function CleanMessage() {
    $(".error").remove();
    CommonErrorMessage.hide();
}

var BaseScript = 
{
    TranslatePage: function() {
        $("[SXLang]").each(function() {
            var $this = $(this);
            if ($this.val()&&$this.attr("nodeName").toLowerCase()!="option") {
                $this.val(Lang[$this.attr("SXLang")]);
            }
            else {
                $this.html(Lang[$this.attr("SXLang")]);
            }
        })
    },
    BindChangeLanguage:function(){
      $(".language a[name='chinese']").click(function(){
        $.cookie("Language","zh-cn",{domain:null,path:'/',expires:500})
        location.reload();
      })
      $(".language a[name='english']").click(function(){
        $.cookie("Language","en",{domain:null,path:'/',expires:500})
        location.reload();
      })
    }
}

function AddOverLayLoding(time) {
    var t = 1000;
    if (time != null || typeof time != "undefined") {
        t = time;
    }
    layloding = true;
    if (t < 1000) {
        $("body").append("<div class='overlayAjax'></div><div id='pageloading' class='LoadingAjax'>"+ Lang.ReadData +"</div>");
    }
    else {
        setTimeout(function() {
            if (layloding) {
                $("body").append("<div class='overlayAjax'></div><div id='pageloading' class='LoadingAjax'>"+ Lang.ReadData +"</div>");
            }
        }, t);
    }
    
}

var layloding = true;
function RemoveOverLayLoding() {
    layloding = false;
    $("body .overlayAjax").remove()
    $(".LoadingAjax").remove();
}

function getQueryStringRegExp(name) {
    var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
    if (reg.test(location.href)) 
        return unescape(RegExp.$2.replace(/\+/g, " "));
    return "";
}

(function($) {
    $.ajaxJson = function(settings) {
        this.defaults = 
        {
            url: "",
            data: {},
            type: "post",
            cache: false,
            success: function() {
            },
            time: 1000
        };
        var config = $.extend(this.config, this.defaults, settings);
        AddOverLayLoding(config.time);
        $.ajax(
        {
            url: config.url,
            dataType: 'json',
            type: config.type,
            data: config.data,
            cache: config.cache,
            success: function(ans) {
                RemoveOverLayLoding();
                config.success(ans);
            }
        });
    }
})(jQuery);

function AddReturnUrl() {
    var link = location.href;
    var f = "/pages/";
    return "returnUrl=" + link.substring(link.toLowerCase().indexOf(f) + f.length, link.length);
}

function GetReturnUrl() {
    var link = location.href;
    var f = "/pages/";
    return link.substring(0, link.toLowerCase().indexOf(f) + f.length) + getQueryStringRegExp("returnUrl");
}




