var reg = {
    contextPath: null,
    
    init: function(context){
        var self = this;
        self.contextPath = context;
    },
    
    checkEmail: function(obj){
        var self = this;
        
        $.ajax({
            type: "POST",
            data: "email=" + $('#' + obj).val(),
            url: self.contextPath + "/user!checkEmail.do",
            success: function(resMsg){
                if (resMsg == "success") {
                    $("#emailerr").hide();
                    //					$("#email").focus();
                    //					$("#successInfo").show();
                    //					$('#'+self.button).attr("disabled",false);
                }
                else {
                    //					$("#successInfo").hide();
                    $("#emailerr").show();
                    $("#email").focus();
                    //					$("#emailformaterror").hide();													
                    //					$('#'+self.button).attr("disabled",true);
                }
            }
        });
    },
    
    checkDomainName: function(obj){
        var self = this;
        
        $.ajax({
            type: "POST",
            data: "domainname=" + $('#' + obj).val(),
            url: self.contextPath + "/user!checkDomainName.do",
            success: function(resMsg){
                if (resMsg == "success") {
                    $("#domainerr").hide();
                    //document.getElementById("sub").disabled=false;
                    //					$("#emailformaterror").hide();
                    //					$("#successInfo").show();
                    //					$('#'+self.button).attr("disabled",false);
                }
                else {
                    $("#domainname").focus();
                    $("#domainerr").show();
                    //document.getElementById("sub").disabled=true;
                    //					$("#emailformaterror").hide();													
                    //					$('#'+self.button).attr("disabled",true);
                }
            }
        });
    },
    
    checkCode: function(obj){
        var self = this;
        
        $.ajax({
            type: "POST",
            data: "checkcode=" + $('#' + obj).val(),
            url: self.contextPath + "/user!checkCode.do",
            success: function(resMsg){
                if (resMsg == "success") {
                    $("#checkcodeerr").hide();
                    //					$("#emailformaterror").hide();
                    //					$("#successInfo").show();
                    //					$('#'+self.button).attr("disabled",false);
                }
                else {
                    $("#checkcode").focus();
                    $("#checkcodeerr").show();
                    //					$("#emailformaterror").hide();													
                    //					$('#'+self.button).attr("disabled",true);
                }
            }
        });
    },
    
    getCountry: function(obj){
        var self = this;
        
        $.ajax({
            type: "POST",
            data: "code=" + $('#' + obj).val(),
            
            url: self.contextPath + "/haizhiwei!getCountry.do",
            success: function(resMsg){
                if (resMsg != "error") {
                    var sel = document.getElementById(obj);
                    
                    if (sel.options.length != 0) {
                        clearOptions('country');
                    }
                    var arr = resMsg.split(",");
                    var arrValue = new Array(), arrText = new Array(), arrTemp = new Array();
                    for (i = 0, arrLen = arr.length; i < arrLen; i++) {
                        arrTemp = arr[i].split(":");
                        arrValue[i] = arrTemp[0];
                        arrText[i] = arrTemp[1];
                        
                    }
                    addOptions('country', arrValue, arrText);
                    clearOptions('city');
                }
                else {
                    clearOptions('country');
                }
            }
        });
    },
    
    getCity: function(obj){
        var self = this;
        $.ajax({
            type: "POST",
            data: "code=" + $('#' + obj).val(),
            url: self.contextPath + "/haizhiwei!getCity.do",
            success: function(resMsg){
                if (resMsg != "error") {
                    var sel = document.getElementById(obj);
                    
                    if (sel.options.length != 0) {
                        clearOptions('city');
                    }
                    var arr = resMsg.split(",");
                    var arrValue = new Array(), arrText = new Array(), arrTemp = new Array();
                    for (i = 0, arrLen = arr.length; i < arrLen; i++) {
                        arrTemp = arr[i].split(":");
                        arrValue[i] = arrTemp[0];
                        arrText[i] = arrTemp[1];
                        
                    }
                    addOptions('city', arrValue, arrText);
                }
                else {
                    clearOptions('city');
                }
            }
        });
    }
}
function addOptions(selectId, arrValue, arrText){
    var sel = document.getElementById(selectId);
    if (sel != undefined) {
    
        for (i = 0, arrLen = arrValue.length; i < arrLen; i++) {
            sel.options.add(new Option(arrText[i], arrValue[i]));
        }
    }
    else {
        return false;
    }
}

function clearOptions(selectId){
    var sel = document.getElementById(selectId);
    if (sel != undefined) {
        sel.options.length = 0;
        sel.options.add(new Option("鐠囩兘锟藉瀚�", "-1"));
    }
    else {
        return false;
    }
    sel.options[0].selected = true;
}

function getNewCity(obj){
    //alert("coming ...");
    
    var self = this;
    $.ajax({
        type: "POST",
        data: "code=" + obj,
        url: self.contextPath + "/haizhiwei!getCity.do",
        success: function(resMsg){
            //alert(resMsg);
            if (resMsg != "error") {
            
                var arr = resMsg.split(",");
                var arrValue = new Array(), arrText = new Array(), arrTemp = new Array();
                for (i = 0, arrLen = arr.length; i < arrLen; i++) {
                    arrTemp = arr[i].split(":");
                    arrValue[i] = arrTemp[0];
                    arrText[i] = arrTemp[1];
                    
                }
                //alert(arrValue);
				clearOptions('city');
                addOptions('city', arrValue, arrText);
                //clearOptions('city');
            }
            else {
                clearOptions('city');
            }
        }
    });
}
