$(function(){
    //初始化客服样式
    $('div.services').commonBoxSmalls();
    $('div.services p a').commonLink();
    //初始化登陆框
    $('input[type=text]').commonTexts();
    $('input[type=password]').commonTexts();
    $('div.common_box_user_1 a.forget_password').commonLinks({
        color:'#666'
    });
    $('div.common_box_user_1 a.register').commonHighlightLinks();
    $('div.common_box_user_2 li.generic a').commonLinks();
    //初始化用户中心面板
    $('div.menu_levels').commonBoxSmall();
    //点击services弹出框页面
    /*  */
    $('div.services li.online_service').click(function(){
        window.open('serviceChat.do?operator_id=' + $(this).find('span').text(), 'service_chat', 'height=353, width=412, top=300, left=400, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
    });
});
/**
 * min 最小长度
 * max 最大长度
 * isNull 是否可以为空，true 可以为空,false不可以为空
 * return 0：正确；1：长度过短；2：长度过长；
 **/
String.prototype.checkLength = function(min,max,isNull){
    if((!this || this.length == 0) && isNull){
        return 0;
    }
    else if(!this){
        return 1;
    }
    if(min > 0 && this.length < min){
        return 1;
    }
    if(max > 0 && this.length > max){
        return 2;
    }
    return 0;
}
String.prototype.replaceAll  = function(s1,s2){
    return this.replace(new RegExp(s1,"gm"),s2);
}
String.prototype.trim= function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.isChinese = function(){
    var reg = /^[\u4E00-\u9FA5]+$/;
    for(var i = 0;i < this.length;i ++){
        if(!reg.test(this.substr(i, i+1))){
            return false;
        }
    }

    return true;
}
String.prototype.hasChinese = function(){
    var reg = /^[\u4E00-\u9FA5]+$/;
    for(var i = 0;i < this.length;i ++){
        var value = this.substring(i,i+1);
        if(reg.test(value)){
            return true;
        }
    }
    return false;
}
function isChinese(str){
    var reg = /^[\u4E00-\u9FA5]+$/;
    if(!reg.test(str)){
        return false;
    }
    return true;
}
String.prototype.isNumber = function(){
    var reg = /^[0-9]+$/;
    if(reg.test(this)){
        return true;
    }
    return false;
}
String.prototype.isLetter = function(){
    var reg = /^[a-zA-Z]+$/;
    if(reg.test(this)){
        return true;
    }
    return false;
}
String.prototype.isLowerCase = function(){
    var reg = /^[a-z]+$/;
    if(!reg.test(this)){
        return false;
    }
    return true;
}
String.prototype.exchange = function(){
    var value = parseInt(this);
    if(isNaN(value)){
        return '（数值错误）';
    }
    var NUMBER_CN = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
    var UNIT_CN = [' ', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿'];
    var str = null;
    if(this == 0){
        str = '0';
    }else{
        str = this.replace(/^[0]+/g, '').reverse().replaceAll(',', '');
    }
    var now = 0;
    var result = '';
    for (var i = 0; i < str.length; i++) {
        now = str.charAt(i) - '0';
        if(isNaN(now)){
            return '（数值错误）';
        }
        if(i > UNIT_CN.length){
            return '（数值超出范围）';
        }
        result = NUMBER_CN[now] + '' + UNIT_CN[i] + result;
    }
    result = result.replaceAll("零仟", "零");
    result = result.replaceAll("零佰", "零");
    result = result.replaceAll("零拾", "零");
    result = result.replaceAll("零亿", "亿");
    result = result.replaceAll("零万", "万");
    result = result.replaceAll(" ", "");
    result = result.replaceAll("零零", "零");
    result = result.replaceAll("零亿", "亿");
    result = result.replaceAll("零零", "零");
    result = result.replaceAll("零万", "万");
    result = result.replaceAll("零零", "零");
    result = result.replaceAll("亿万", "亿");
    result = result.replaceAll("零$", "");
    if(result.length == 0){
        result = '零';
    }
    return result;
}
String.prototype.isUpperCase = function(){
    var reg = /^[A-Z]+$/;
    if(!reg.test(this)){
        return false;
    }
    return true;
}
String.prototype.reverse = function(){
    var result = '';
    for(var i = this.length - 1;i > -1;i --){
        result += this.charAt(i);
    }
    return result;
}
