var JsCommon = {
    // 设置根路径
    root: '',
    setRoot: function(root) {
        JsCommon.root = root;
    },
    // 字体调整大
    fontSizeBig: function(id) {
        $('#' + id).css("font-size", "28px");
    },
    // 字体调整中
    fontSizeMedium: function(id) {
        $('#' + id).css("font-size", "20px");
    },
    // 字体调整小
    fontSizeNano: function(id) {
        $('#' + id).css("font-size", "12px");
    },
    // 首页面广告的图片切换
    changeFlashImage: function(obj) {
        // 停止自动切换图片
        endAutoChangeFlashImage();
        $('a[name=changeFlashImageButton]').removeClass("on");
        obj.className = "on";
        $("#changeFlashImageImgID").fadeOut(1200, function(){
            this.src = obj.getAttribute("imageSrc");
            $('#changeFlashImageAID').attr("href", obj.getAttribute("imageHref"));
        });
        $("#changeFlashImageImgID").fadeIn(1200, function(){}); 
        // 开始自动切换图片
        startAutoChangeFlashImage();
    },
    // 切换内容是否显示
    changeConDivShow: function(showLiId, notShowLiId, showDivId, notShowDivId) {
        $('#' + showLiId).addClass("on");
        $('#' + notShowLiId).removeClass("on");
        
        $('#' + showDivId).removeClass("displayNone");
        $('#' + notShowDivId).addClass("displayNone");
    },
    // 切换显示店铺图片
    changeShbaLogoShow: function(obj) {
        var parentElement = obj.parentNode;
        var parentObj = parentElement.childNodes;
        for(var i = 0; i < parentObj.length; i++) {
            if(parentObj[i].nodeType == '1') {
                if(parentObj[i].nodeName == 'LI' || parentObj[i].nodeName == 'li') {
                    parentObj[i].className = '';
                }
            }
        }
        obj.className = 'first';
    },
    // 进入登录页面
    loginForward: function() {
        document.location.href = JsCommon.root + '/news/userManagerAction.app?method=loginForward';
        return false;
    },
    // 退出
    logout: function() {
        document.location.href = JsCommon.root + '/news/userManagerAction.app?method=logout';
        return false;
    },
    // 到注册页面
    registerForward: function() {
        document.location.href = JsCommon.root + '/news/userManagerAction.app?method=registerForward';
        return false;
    },
    // 到个人中心页面
    centerIndex: function() {
        document.location.href = JsCommon.root + '/userCenter/accountManagerAction.app?method=index';
        return false;
    },
    // 新闻首页
    contentIndex: function() {
        document.location.href = JsCommon.root + '/news/contentIndexAction.app?method=contentIndex';
        return false;
    },
    // 到商品详细页面
    goodDetail: function(gobaId) {
        document.location.href = JsCommon.root + '/shop/goodsSearchAction.app?method=detail&gobaId=' + gobaId;
        return false;
    },
    // 查询店铺页面
    findShop: function(shbaId) {
        document.location.href = JsCommon.root + '/shop/shopBaseAction.app?method=find&shbaId=' + shbaId;
        return false;
    },
    // 商城首页
    shopIndex: function() {
        document.location.href = JsCommon.root + '/shop/shopIndexAction.app?method=shopIndex';
        return false;
    },
    // 市场行情专题
    marketSpecial: function() {
        document.location.href = JsCommon.root + '/news/contentAction.app?method=marketSpecial';
        return false;
    },
    // 行业信息专题
    tradeInfoSpecial: function() {
        document.location.href = JsCommon.root + '/news/contentAction.app?method=tradeInfoSpecial';
        return false;
    },
    // 行业分析专题
    tradeAnalysisSpecial: function() {
        document.location.href = JsCommon.root + '/news/contentAction.app?method=tradeAnalysisSpecial';
        return false;
    },
    // 宏观经济专题
    macroEconomySpecial: function() {
        document.location.href = JsCommon.root + '/news/contentAction.app?method=macroEconomySpecial';
        return false;
    },
    // 世界能源专题
    worldPowerSpecial: function() {
        document.location.href = JsCommon.root + '/news/contentAction.app?method=worldPowerSpecial';
        return false;
    },
    // 政策法规专题
    policyLawSpecial: function() {
        document.location.href = JsCommon.root + '/news/contentAction.app?method=policyLawSpecial';
        return false;
    },
    // 供求信息专题
    sudeContentSpecial: function() {
        document.location.href = JsCommon.root + '/news/sudeContentAction.app?method=sudeContentSpecial';
        return false;
    },
    // 发表评论ajax登录
    publishConCommonAjaxLogin: function() {
        
        // 登录名.
        if(!StringHelper.checkStrLength('usbaNameID', 1, 50)) {
            alert("请输入用户名");
            ElementHelper.focus('usbaNameID');
            return false;
        }
        // 密码.
        if(!StringHelper.checkStrLength('usbaPasswordID', 1, 50)) {
            alert("请输入密码");
            ElementHelper.focus('usbaPasswordID');
            return false;
        }
        // 验证码.
        if(!StringHelper.checkStrLength('usbaValidateCodeID', 5, 5)) {
            alert("请输入验证码");
            ElementHelper.focus('usbaValidateCodeID');
            return false;
        }
        
        // 屏蔽发布按钮
        $('#publishConCommonUserLoginButtonID').attr("disabled", "true");
        
        $.ajax({
	        url:JsCommon.root + '/news/userManagerAction.app',
            type:'post',
            dataType:'xml', 
            data:'method=ajaxLogin&usbaName=' + $('#usbaNameID').val() + '&usbaPassword=' + $('#usbaPasswordID').val() + '&usbaValidateCode=' + $('#usbaValidateCodeID').val(),   
            success: function(data, textStatus) {
                // 得到 opMsg 属性.
                var opMsg = data.getElementsByTagName('op-msg')[0];
                // 得到编码.
                var code = opMsg.getAttribute('code');
                // 得到编码说明.
                var description = opMsg.getAttribute('description');
                if(code == 'ok') {
                    // 刷新当前页面
                    document.location.href = document.location.href;
                    return false;
                }else if(code == 'error') {
                    alert(description);
                    // 清除用户名，密码和验证码
				    StringHelper.clear(['usbaNameID', 'usbaPasswordID', 'usbaValidateCodeID',]);
				    // 要重新刷新验证码
				    flushImageToken();
				    // 显示发布按钮
			        $('#publishConCommonUserLoginButtonID').attr("disabled", "");
			        return false;
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert("网络故障请重试！");
                // 清除用户名，密码和验证码
			    StringHelper.clear(['usbaNameID', 'usbaPasswordID', 'usbaValidateCodeID',]);
			    // 要重新刷新验证码
			    flushImageToken();
			    // 显示发布按钮
		        $('#publishConCommonUserLoginButtonID').attr("disabled", "");
		        return false;
            }
	    });
    }
};