var DomainValidateHelper = {
     value : function(id) {
         return $('#' + id).val();
     },
     length : function(id) {
         return $('#' + id).val().length;
     },
     focus : function(id) {
         $('#' + id).focus();
     },
     // 域名非空验证 如果不为 '' 返回 true，如果为 '' 返回 false
     prefixIsNotNull : function(prefixId) {
         if(DomainValidateHelper.value(prefixId) == null || 
             DomainValidateHelper.value(prefixId) == '') {
             showDivErr('请输入域名！', 'result');return false;
         }
         return true;
     },
     // 英文域名验证
     prefixEnValidate : function(prefixId) {
        if(!myIsDomain( DomainValidateHelper.value(prefixId) ) || 
            IsChDomain( DomainValidateHelper.value(prefixId) )) {
	        showDivErr('输入域名格式错误，请重新输入！', 'result');return false;
	    }
        return true;
     },
     // 中文域名验证
     prefixCnValidate : function(prefixId) {
        if(!myIsDomain( DomainValidateHelper.value(prefixId) ) || 
            !IsChDomain( DomainValidateHelper.value(prefixId) )) {
	        showDivErr('输入域名格式错误，请重新输入！', 'result');return false;
	    }
        return true;
     },
     // 无线域名验证
     prefixWxValidate : function(prefixId) {
        
        return true;
     },
     // 区域域名验证
     prefixAreaValidate : function(prefixId) {
        if(!myIsDomain( DomainValidateHelper.value(prefixId) ) || 
            IsChDomain( DomainValidateHelper.value(prefixId) )) {
	        showDivErr('输入域名格式错误，请重新输入！', 'result');return false;
	    }
        return true;
     },
     // domflo_schres 页面域名验证
     domfloSchresValidate : function(
                        ctx,
                        prefixId,
                        domainSuffixTypeName,
                        validateCodeId,
                        validateCodeImageId,
                        condition,
                        formId,
                        formActionUrl,
                        domainSuffixTypeEn, domainSuffixTypeCn, domainSuffixTypeWx, domainSuffixTypeArea) {
                        
                        // 域名非空验证
                        // 1. 验证域名是否填入
                        if(!DomainValidateHelper.prefixIsNotNull(prefixId)) { return false;}
                        // 2. 是否选择了域名后缀
                        var domainSuffixTypeRadio = $("input[type=radio][name="+domainSuffixTypeName+"][checked=true]");
                        var suffixCheckboxObj = $("input[type=checkbox][name=suffix][checked=true][domainSTC=" +domainSuffixTypeRadio.val()+ "]");
                        if(suffixCheckboxObj.length == 0) {
                            showDivErr('请至少选择一个域名后缀！', 'result');return false;
                        }
                        // 得到域名类型.
                        var suffixTypeRadioObj = $("input[type=radio][name=domainSuffixType][checked=true]");
                        // 如果是英文域名.
                        if(suffixTypeRadioObj.val() == domainSuffixTypeEn) {
                            if(!DomainValidateHelper.prefixEnValidate(prefixId)) { return false;}
                        }
                        // 如果是中文域名.
                        if(suffixTypeRadioObj.val() == domainSuffixTypeCn) {
                            if(!DomainValidateHelper.prefixCnValidate(prefixId)) { return false;}
                        }
                        // 如果是无线域名.
                        if(suffixTypeRadioObj.val() == domainSuffixTypeWx) {
                            if(!DomainValidateHelper.prefixWxValidate(prefixId)) { return false;}
                        }
                        // 如果是区域域名.
                        if(suffixTypeRadioObj.val() == domainSuffixTypeArea) {
                            if(!DomainValidateHelper.prefixAreaValidate(prefixId)) { return false;}
                        }
                        // 验证码验证.
                        if(DomainValidateHelper.value(validateCodeId) == '') {
                            showDivErr('请输入验证码！', 'result');return false;
                        }
                        var name = "name=" + $('#' + prefixId).val();
                        var suffix = "";
                        for( var i = 0; i < suffixCheckboxObj.length; ++i )
                        {
                            suffix += "&suffix=" + suffixCheckboxObj[i].value;
                        }

                        DomainValidateHelper.validateCodeValidate(ctx, validateCodeId, validateCodeImageId, condition, formId, formActionUrl, name+suffix);
     },
     validateCodeValidate : function(ctx, validateCodeId, validateCodeImageId, condition, formId, formActionUrl, postData) {
         if(condition == null || condition == '') {
             condition = '1';
         }
         
         showDivErr('请稍候...', 'result');
         $('#postDomain').css("display","none");

         $.ajax({
            url:ctx,
            type: 'post',
            data: postData,
			success: function(text){
			    var texts = text.split("&");
			    var show = "";
			    for(var i = 0; i < texts.length; ++i)
			    {
			        if(texts[i].search("name") != -1)
			        {
			            var domaim = texts[i].split("=");
			            show += "<p>www." + domaim[1];
			        }
			        else if(texts[i].search("chk") != -1)
			        {
			            var enable = texts[i].split("=");
			            if(enable[1]=="100")
			            {
			                show += "可注册</p>";
			            }
			            else
			            {
			                show += "不可注册</p>";
			            }
			        }
			    }
			    $(result).html(show);
			    $('#postDomain').css("display","inline");
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
                showCheckDiv("服务器繁忙，请稍后再试。",validateCodeId);
			    $('#postDomain').css("display","inline");
            }
		 });

     },
     
     CheckDomain : function(ctx, validateCodeId, validateCodeImageId, condition, formId, formActionUrl) {
         if(condition == null || condition == '') {
             condition = '1';
         }
        $.post(ctx, { Action: "post", name: "asdfasdfasdf", enc : "E", suffix : ".com", suffix : ".net", suffix : ".cn" },
		        function (data, textStatus){
			        // data 可以是 xmlDoc, jsonObj, html, text, 等等.
			        //this; // 这个Ajax请求的选项配置信息，请参考jQuery.get()说到的this
			        alert(data.result);
		        }, "json");

     }

};

var SelectDomainHelper = {
    // 显示域名后缀
    checkSuffix : function(
                      domainSuffixTypeValue,
                      domainSuffixTypeEn, domainSuffixTypeCn, domainSuffixTypeWx, domainSuffixTypeArea) {
                      var trEnObj = $("tr[suffixType='domainSuffixTrEn']");
					  var trCnObj = $("tr[suffixType='domainSuffixTrCn']");
					  var trWxObj = $("tr[suffixType='domainSuffixTrWx']");
					  var trAreaObj = $("tr[suffixType='domainSuffixTrArea']");
					  
					  if(domainSuffixTypeValue == domainSuffixTypeEn) {
					      // 显示
				          trEnObj.css("display","");
				          trCnObj.css("display","none");
				          trWxObj.css("display","none");
				          trAreaObj.css("display","none");
				          // 多选框是否可选
				          $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeEn+"]").attr("disabled", "");
				          $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeCn+"]").attr({disabled:"true", checked: false});
				          $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeWx+"]").attr({disabled:"true", checked: false});
				          $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeArea+"]").attr({disabled:"true", checked: false});
				          // 初始化值
				          $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeEn+"]").each(function() {
			                  if(this.value == '.com') { this.checked = 'true'; }
			                  if(this.value == '.cn') { this.checked = 'true'; }
			                  if(this.value == '.cc') { this.checked = 'true'; }
			                  if(this.value == '.me') { this.checked = 'true'; }
			              });
			              
			              $('#indexDomainCheckFormID').removeAttr("action");
					        $('#ssffSpanID').css("display", "");
					        $('#searchButtonSpanID').css("display", "none");
					        
				          return;
					   }
					    
					   if(domainSuffixTypeValue == domainSuffixTypeCn) {
					       // 显示
					       trEnObj.css("display","none");
					       trCnObj.css("display","");
					       trWxObj.css("display","none");
					       trAreaObj.css("display","none");
					       // 多选框是否可选
					       $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeEn+"]").attr({disabled:"true", checked: false});
				           $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeCn+"]").attr("disabled", "");
				           $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeWx+"]").attr({disabled:"true", checked: false});
				           $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeArea+"]").attr({disabled:"true", checked: false});
					       
					       // 初始化值
					       $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeCn+"]").each(function() {
			                   if(this.value == '.中国') { this.checked = 'true'; }
			                   if(this.value == '.cc') { this.checked = 'true'; }
			                   if(this.value == '.com') { this.checked = 'true'; }
			               });
			               $('#indexDomainCheckFormID').removeAttr("action");
					        $('#ssffSpanID').css("display", "");
					        $('#searchButtonSpanID').css("display", "none");
					      
					       return;
					    }
					    
					    if(domainSuffixTypeValue == domainSuffixTypeWx) {
					        // 显示
					        trEnObj.css("display","none");
					        trCnObj.css("display","none");
					        trWxObj.css("display","");
					        trAreaObj.css("display","none");
					        // 多选框是否可选
					        $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeEn+"]").attr({disabled:"true", checked: false});
				            $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeCn+"]").attr({disabled:"true", checked: false});
				            $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeWx+"]").attr("disabled", "");
				            $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeArea+"]").attr({disabled:"true", checked: false});
					        
					        $('#indexDomainCheckFormID').attr("action", jsCtx + "/domain/check.do?method=domfloSchres");
					        $('#ssffSpanID').css("display", "none");
					        $('#searchButtonSpanID').css("display", "");
					        return;
					    }
					    
					    if(domainSuffixTypeValue == domainSuffixTypeArea) {
					        // 显示
					        trEnObj.css("display","none");
					        trCnObj.css("display","none");
					        trWxObj.css("display","none");
					        trAreaObj.css("display","");
					        // 多选框是否可选
					        $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeEn+"]").attr({disabled:"true", checked: false});
				            $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeCn+"]").attr({disabled:"true", checked: false});
				            $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeWx+"]").attr({disabled:"true", checked: false});
				            $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeArea+"]").attr("disabled", "");
					        
					        $('#indexDomainCheckFormID').removeAttr("action");
					        $('#ssffSpanID').css("display", "");
					        $('#searchButtonSpanID').css("display", "none");
					      
					        return;
					    }
    
    },
    // 全选
    qxSuffixCheckbox : function(id) {
                          var suffixCheckboxObj = $("input[type=checkbox][name=suffix][regSuffix=regSuffix]");
                          var chooseSuffixObj = $("#" + id);
    
                          suffixCheckboxObj.attr("checked", chooseSuffixObj.attr('checked'));
    
    },
    // 判断是否还有全选
    isHasQxSuffixCheckbox : function(id) {
                                var suffixCheckboxObj = $("input[name=suffix][regSuffix=regSuffix]");
                                var isQxChecked = false;
                                
                                for(var i = 0; i < suffixCheckboxObj.length; i++) {
                                    if(suffixCheckboxObj[i].checked == true) {
                                        isQxChecked = true;
                                    }else {
                                        isQxChecked = false;
                                        break;
                                    }
                                }
                                var chooseSuffixObj = $("#" + id);
                                chooseSuffixObj.attr("checked", isQxChecked);
    },
    // 单个进行注册
    singlezc : function(ctx, suffix) {
        $('#singleSuffixID').val(suffix);
        document.singleBuyDomainForm.action = ctx + '/domain/buy.do?' + Math.random();
		document.singleBuyDomainForm.submit();
    },
    // 批量进行注册
    zcdgym : function(ctx) {
                 var suffixCheckboxObj = $("input[type=checkbox][name=suffix][regSuffix=regSuffix][checked=true]");
                 if(suffixCheckboxObj.length == 0) {
                     showDivErr('请选择域名！','result');
                     return;
                 }
			     document.buyDomainForm.action = ctx + '/domain/buy.do?' + Math.random();
			     document.buyDomainForm.submit();
    },
    
    // 首页面显示域名后缀
    indexCheckSuffix : function(
                      domainSuffixTypeValue,
                      domainSuffixTypeEn, domainSuffixTypeCn, domainSuffixTypeWx, domainSuffixTypeArea) {
                      var enObj = $("#domainSuffixTypeEnID");
					  var cnObj = $("#domainSuffixTypeCnID");
					  var wxObj = $("#domainSuffixTypeWxID");
					  var areaObj = $("#domainSuffixTypeAreaID");
					  
					  $(result).css("display","none");
					  
					  if(domainSuffixTypeValue == domainSuffixTypeEn) {
					      // 显示
				          enObj.css("display","");
				          cnObj.css("display","none");
				          wxObj.css("display","none");
				          areaObj.css("display","none");
				          // 多选框是否可选
				          $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeEn+"]").attr("disabled", "");
				          $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeCn+"]").attr({disabled:"true", checked: false});
				          $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeWx+"]").attr({disabled:"true", checked: false});
				          $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeArea+"]").attr({disabled:"true", checked: false});
				          
				          // 初始化值
				          $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeEn+"]").each(function() {
				              if(this.value == '.com') { this.checked = 'true'; }
				              if(this.value == '.cn') { this.checked = 'true'; }
				              if(this.value == '.cc') { this.checked = 'true'; }
				              if(this.value == '.me') { this.checked = 'true'; }
				          });
				          $('#indexDomainCheckFormID').removeAttr("action");
					      $('#ssffSpanID').css("display", "");
					      $('#searchButtonSpanID').css("display", "none");
				          return;
					   }
					    
					   if(domainSuffixTypeValue == domainSuffixTypeCn) {
					       // 显示
					       enObj.css("display","none");
				           cnObj.css("display","");
				           wxObj.css("display","none");
				           areaObj.css("display","none");
					       // 多选框是否可选
				           $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeEn+"]").attr({disabled:"true", checked: false});
				           $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeCn+"]").attr("disabled", "");
				           $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeWx+"]").attr({disabled:"true", checked: false});
				           $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeArea+"]").attr({disabled:"true", checked: false});
				          
				            // 初始化值
				           $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeCn+"]").each(function() {
				               if(this.value == '.中国') { this.checked = 'true'; }
				               if(this.value == '.cc') { this.checked = 'true'; }
				               if(this.value == '.com') { this.checked = 'true'; }
				           });
				           $('#indexDomainCheckFormID').removeAttr("action");
					       $('#ssffSpanID').css("display", "");
					       $('#searchButtonSpanID').css("display", "none");
					       return;
					    }
					    
					    if(domainSuffixTypeValue == domainSuffixTypeWx) {
					        // 显示
					        enObj.css("display","none");
				            cnObj.css("display","none");
				            wxObj.css("display","");
				            areaObj.css("display","none");
					        // 多选框是否可选
					        $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeEn+"]").attr({disabled:"true", checked: false});
				            $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeCn+"]").attr({disabled:"true", checked: false});
				            $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeWx+"]").attr("disabled", "");
				            $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeArea+"]").attr({disabled:"true", checked: false});

//					        $('#indexDomainCheckFormID').attr("action", jsCtx + "/domain/check.do?method=domfloSchres");
					        $('#ssffSpanID').css("display", "none");
					        $('#searchButtonSpanID').css("display", "");
					        return;
					    }
					    
					    if(domainSuffixTypeValue == domainSuffixTypeArea) {
					        // 显示
					        enObj.css("display","none");
				            cnObj.css("display","none");
				            wxObj.css("display","none");
				            areaObj.css("display","");
					        // 多选框是否可选
					        $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeEn+"]").attr({disabled:"true", checked: false});
				            $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeCn+"]").attr({disabled:"true", checked: false});
				            $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeWx+"]").attr({disabled:"true", checked: false});
				            $("input[type=checkbox][name=suffix][domainSTC="+domainSuffixTypeArea+"]").attr("disabled", "");
				            
				            $('#indexDomainCheckFormID').removeAttr("action");
					        $('#ssffSpanID').css("display", "");
					        $('#searchButtonSpanID').css("display", "none");
					        return;
					    }
    
    }
};

var ValidateCodeHelper = {
    changeValidateCode : function(imageId, ctx) {
        $('#' + imageId).attr("src", ctx + "/Modules/agent/serv/pages/validate_picture.jsp?" + Math.random());
    },
    changeValidateCode2 : function(imageId, ctx) {
        $('#' + imageId).attr("src", ctx + "/Modules/agent/serv/pages/validate_picture2.jsp?" + Math.random());
    },
    changeValidateCode3 : function(imageId, ctx) {
        $('#' + imageId).attr("src", ctx + "/Modules/agent/serv/pages/validate_picture3.jsp?" + Math.random());
    },
    changeValidateCode4 : function(imageId, ctx) {
        $('#' + imageId).attr("src", ctx + "/Modules/agent/serv/pages/validate_picture4.jsp?" + Math.random());
    }
}



function checkNull(prefixID){
	var domainvalue = document.getElementById(prefixID).value;
	if(''==domainvalue||domainvalue==null){
		showDivErr('请输入域名!','result');
		return false;
	}
	return true;
}    

function showDivErr(text,id)
{
    $('#' + id).html(text).css('color','#F4F222').css('display','inline');
}  
