Array.prototype.inArray = function(b) {
    for (var a = 0; a < this.length; a++) {
        if (this[a] === b) {
            return true;
        }
    }
    return false;
};
function setClassName(a, c) {
    if (typeof(a) != "object") {
        var a = $(a);
    }
    var b = a.className.split(" ");
    if (!b.inArray(c)) {
        a.className = a.className + " " + c;
    }
    return;
}
function deleteClassName(b, e) {
    if (typeof(b) != "object") {
        var b = $(b);
    }
    var d = b.className.split(" ");
    if (d.inArray(e)) {
        var a = "";
        for (var c = 0; c < d.length; c++) {
            if (d[c] != e) {
                a += " " + d[c];
            }
        }
        b.className = a;
    }
    return;
}
function changeClassName(a, b, c) {
    if (typeof(a) != "object") {
        var a = $(a);
    }
    deleteClassName(a, b);
    setClassName(a, c);
    return;
}
function getClassName(a, c) {
    if (typeof(a) != "object") {
        var a = $(a);
    }
    var b = a.className.split(" ");
    if (b.inArray(c)) {
        return true;
    } else {
        return false;
    }
}
FormValidator = function() {
    var d;
    var e;
    var b;
    var a;
    var c;
    this.formTypeArray = new Array();
    this.validate = true;
    this.addEvents = new Array();
    this.trIdKey = "b0b0P0st1d";
    this.formTypes = new Array("input", "textarea", "select");
    this.textareaItems;
};
FormValidator.prototype = {
    mouseoverEvent: function(a) {
        for (var b = 0; b < this.items.length; b++) {
            changeClassName(this.items[b].id + "tips", "showTips", "hiddenTips");
            if (getClassName(this.items[b], "showErrors")) {
                changeClassName(this.items[b].id + "hint", "hiddenError", "showError");
            }
        }
        changeClassName(a.id + "tips", "hiddenTips", "showTips");
        changeClassName(a.id + "hint", "showError", "hiddenError");
    },
     richTextEvent: function(b) {
        var a = b.getElementsByTagName("textarea")[0];
        changeClassName(b.id + "hint", "hiddenHidden", "showError");
        deleteClassName(b, "showErrors");
    },
    inputEventClick: function(c) {
        var d = c;
        var b = false;
        for (var a = 0; a < 10; a++) {
            d = d.parentNode;
            if (d != undefined && d.tagName == "DIV" && getClassName(d, "item")) {
                break;
                b = true;
            }
        }
        if (!getClassName(d, "item")) {
            return;
        }
        this.activationItem = d;
        deleteClassName(d, "showErrors");
        changeClassName(this.activationItem.id + "tips", "hiddenTips", "showTips");
        if ($("validateTag")) {
            $("validateTag").innerHTML = ("");
        }
    },
    inputEventBlur: function(b) {
        var a = this;
        changeClassName(this.activationItem.id + "tips", "showTips", "hiddenTips");
        
        setTimeout(function() {
            a.valids(b);
        },
        200);
    },
    setEvent: function() {
        var ax = this.method;
        var out = function() {
            eval(ax).richTextEvent(this);
            eval(ax).mouseoverEvent(this);
        };
        
        var over = function() {
            eval(ax).mouseoverEvent(this);
        };
        var form = $(this.formId);
        this.tables = form.getElementsByTagName("div");
        var itNum = 1;
        var its = new Array();
        var l = 0;
        var richtext = $("richText").value;
        for (var i = 0; i < this.tables.length; i++) {
            if (getClassName(this.tables[i], "item")) {
                this.tables[i].setAttribute("id", this.trIdKey + itNum);
                its[l] = this.tables[i];
                l++;
                var divs = this.tables[i].getElementsByTagName("div");
                for (var j = 0; j < divs.length; j++) {
                    if (getClassName(divs[j], "hiddenTips")) {
                        divs[j].setAttribute("id", this.trIdKey + itNum + "tips");
                    }
                    if (getClassName(divs[j], "hiddenError")) {
                        divs[j].setAttribute("id", this.trIdKey + itNum + "hint");
                    }
                }
                itNum++;
                this.tables[i].onmouseover = over;
                if (richtext == 1) {
                    var textareas = this.tables[i].getElementsByTagName("textarea");
                    for (var t = 0; t < textareas.length; t++) {
                        if (textareas[t].id == "description" || textareas[t].id == "dianpujianj") {
                            this.tables[i].onmouseover = out;
                        }
                    }
                }
            }
        }
        this.items = its;
        var val = function() {
            eval(ax).inputEventBlur(this);
        };
        var set = function() {
            eval(ax).inputEventClick(this);
        };
        for (var y = 0; y < this.formTypes.length; y++) {
            var types = $(this.formId).getElementsByTagName(this.formTypes[y]);
            this.formTypeArray[y] = types;
            for (var i = 0; i < types.length; i++) {
                types[i].onblur = val;
                types[i].onfocus = set;
            }
        }
        $(this.formId).onsubmit = function() {
            $("postSubmit").disabled = true;
            var f = eval(ax);
            f.validate = true;
            for (var n = 0; n < f.formTypeArray.length; n++) {
                for (var i = 0; i < f.formTypeArray[n].length; i++) {
                    f.valids(f.formTypeArray[n][i]);
                }
            }
            for (var m = 0; m < f.addEvents.length; m++) {
                try {
                    if (typeof(eval(f.addEvents[m])) == "function") {
                        var e = eval(f.addEvents[m])();
                        if (e != null) {
                            f.validate = false;
                        }
                    }
                } catch(x) {}
            }
            if (f.validate) {
                var antis = "areald";
                $("validateTag").innerHTML = ('<div class="tjtips_box tjtips_box_lodding"><input type="hidden" name="' + antis + '" />表单正在提交中，请稍候！：）</div>');
                return true;//是否允许提交，允许改为true
            } else {
                $("postSubmit").disabled = false;
                if ($("validateTag")) {
                    $("validateTag").innerHTML = ('<div class="tjtips_box"><strong>上边表单中某项填写存在错误，请重新填写后再提交！：）<br />出错的部分背景色是红的！</strong></div>');
                }
                return false;
            }
        };
    },
    valids: function(v) {
        var classNames = v.className.split(" ");
        if (classNames.inArray("nophone")) {
            var e = nophoneValid(v.value);
            if (e != null) {
                var b = this.returnError("nophone", e);
                this.hiddenError(v);
                
            }else {
                this.hiddenError(v);
            }
        }
        if (classNames.inArray("required") || classNames.inArray("tagsCheckBox")) {
            if (v.type == "checkbox" || v.type == "radio") {
                if (classNames.inArray("tagsCheckBox")) {
                    e = tagsCheckBoxValid(v);
                    var b = this.returnError("tagsCheckBox", e);
                } else {
                    if (classNames.inArray("required")) {
                        if (v.type == "checkbox") {
                            e = requiredCheckboxValid(this.formId, v);
                            var b = this.returnError(v.name, e);
                        } else {
                            e = requiredRadioValid(this.formId, v);
                            var b = this.returnError(v.name, e);
                        }
                    }
                }
            } else {
                if (classNames.inArray("required")) {
                    e = (requiredValid(v.value));
                    var b = this.returnError(v.name, e);
                }
            }
            if (e != null) {
                this.hiddenError(v);
                return this.showError(v, b);
            } else {
                this.hiddenError(v);
            }
        }
        if (classNames.inArray("numeric")) {
            v.value = DBC2SBC(v.value);
            var e = numericValid(v.value);
            var b = this.returnError("numeric", e);
            if (e != null) {
                this.hiddenError(v);
                return this.showError(v, b);
            } else {
                this.hiddenError(v);
            }
        }
        if (classNames.inArray("contacts")) {
            var e = contactsValid(v);
            var b = this.returnError("contacts", e);
            if (e != null) {
                this.hiddenError(v);
                return this.showError(v, b);
            } else {
                this.hiddenError(v);
            }
        }
        if (classNames.inArray("field")) {
            try {
                if (typeof(eval(v.name + "Valid")) == "function") {
                    var e = eval(v.name + "Valid")(v.value);
                    var b = this.returnError(v.name, e);
                    if (e != null) {
                        this.hiddenError(v);
                        return this.showError(v, b);
                    } else {
                        this.hiddenError(v);
                    }
                }
            } catch(x) {}
        }
    },
    hiddenError: function(b) {
        var c = b;
        for (var a = 0; a < 10; a++) {
            c = c.parentNode;
            if (c != undefined && c.tagName == "DIV" && getClassName(c, "item")) {
                break;
            }
        }
        deleteClassName(c, "showError");
        changeClassName(c.id + "hint", "showError", "hiddenError");
        $(c.id + "hint").innerHTML = "";
    },
    returnError: function(c, a) {
        var b = new Array();
        b.required = new Array("必填选项不能为空");
        b.tagsCheckBox = new Array("必填选项不能为空");
        b.numeric = new Array('请用数字填写,不能包含"-"等其他符号。', "不能填写“0”");
        b.title = new Array("标题不能为空", "标题字数要小于25个字");
        if ($("richText").value == 1) {
            b.description = new Array("内容不能为空", "字数要在10-10000字之间");
        } else {
            b.description = new Array("内容不能为空", "字数要在3000字以内");
        }
        b.dianpujianj = new Array("字数要在10-10000字之间");
        b.fuwujianjie = new Array("不能为空且字数要在100个字以内");
        b.contact = new Array("联系方式长度要在200字以内", "联系方式不能不填", "联系方式除联系人必须填写一个");
        b.nophone = new Array("为保护您的联系方式请勿留电话号码");
        b.areaSelector = new Array("建议选择详细地区，使信息更易查找");
        b.email = new Array("邮件地址不能为空！", "邮件地址输入有错误！");
        b.contacts = new Array("座话填写有错误，如有分机号请用“-”分开，如“021-63254521-8965”！", "电子邮件填写有错误，请重新填写！", "QQ/MSN填写有错误，请重新填写！", "两种联系方式必须填写一种！");
        if (b[c]) {
            return b[c][a];
        } else {
            return b.required[0];
        }
    },
    showError: function(b, c) {
        var d = b;
        for (var a = 0; a < 10; a++) {
            d = d.parentNode;
            if (d != undefined && d.tagName == "DIV" && getClassName(d, "item")) {
                break;
            }
        }
        setClassName(d, "showErrors");
        changeClassName(d.id + "hint", "hiddenError", "showError");
        changeClassName(d.id + "tips", "showTips", "hiddenTips");
        $(d.id + "hint").innerHTML = c;
        this.validate = false;
    },
    hiddenError: function(b) {
        var c = b;
        for (var a = 0; a < 10; a++) {
            c = c.parentNode;
            if (c != undefined && c.tagName == "DIV" && getClassName(c, "item")) {
                break;
            }
        }
        deleteClassName(c, "showError");
        changeClassName(c.id + "hint", "showError", "hiddenError");
        $(c.id + "hint").innerHTML = "";
    }
};
function requiredCheckboxValid(f, b) {
    var a = $(f).getElementsByTagName(b.tagName);
    var g = new Array();
    for (var d = 0; d < a.length; d++) {
        if (a[d].type == "checkbox" && a[d].name == b.name) {
            g[g.length] = a[d];
        }
    }
    var c = 0;
    for (d = 0; d < g.length; d++) {
        if (g[d].checked) {
            c++;
        }
    }
    var e = 1;
    if (e && c < e) {
        return 0;
    }
    return null;
}
function requiredRadioValid(f, b) {
    var a = $(f).getElementsByTagName(b.tagName);
    var g = new Array();
    for (var d = 0; d < a.length; d++) {
        if (a[d].type == "radio" && a[d].name == b.name) {
            g[g.length] = a[d];
        }
    }
    var c = 0;
    for (d = 0; d < g.length; d++) {
        if (g[d].checked) {
            c++;
        }
    }
    var e = 1;
    if (c == 0) {
        return 0;
    }
    return null;
}
function descriptionValid(a) {
    if (!$("richText")) {
        return null;
    }
    if ($("richText").value == 1) {
        var b = FCKeditorAPI.GetInstance("description").GetXHTML();
        if (b.length > 50000 || b.length < 16) {
            return 1;
        } else {
            return null;
        }
    } else {
        var b = $("description");
        if (stringTrim(b.value) == "") {
            return 0;
        }
        if (b.value.length > 3000) {
            return 1;
        } else {
            return null;
        }
    }
}
function numericValid(b) {
    var c = DBC2SBC(b);
    if (c == "") {
        return null;
    } else {
        if (c == 0) {
            return 1;
        } else {
            var a = /^[0-9\.]*$/;
            if (!a.test(c)) {
                return 0;
            }
        }
    }
    return null;
}
function emailValid(b) {
    var c = DBC2SBC(b);
    if (c == "") {
        return 0;
    }
    var a = /^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+$/;
    if (!a.test(c)) {
        return 1;
    } else {
        if (c.length > 60) {
            return 1;
        } else {
            return null;
        }
    }
}
function titleValid(a) {
    var b = stringTrim(a);
    if (b == "") {
        return 0;
    } else {
        if (b.length > 25) {
            return 1;
        } else {
            return null;
        }
    }
}
function DBC2SBC(b) {
    var c = stringTrim(b);
    var a = "";
    for (i = 0; i < c.length; i++) {
        code = c.charCodeAt(i);
        if (code >= 65281 && code <= 65373) {
            a += String.fromCharCode(c.charCodeAt(i) - 65248);
        } else {
            if (code == 12288) {
                a += String.fromCharCode(c.charCodeAt(i) - 12288 + 32);
            } else {
                a += c.charAt(i);
            }
        }
    }
    return a;
}
function contactValid(b) {
    var c = DBC2SBC(b);
    if (c == "") {
        return 1;
    }
    if (c.length > 200) {
        return 0;
    }
    var a = /([_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+)|(\d{3,20})/;
    if (!a.test(c)) {
        return 2;
    }
    return null;
}
function nophoneValid(b) {
    var c = b;
    var a = /^(13|15)\d{9}$|^(13|15)\d{9}[^\d]+|[^\d]+(13|15)\d{9}$|[^\d]+(13|15)\d{9}[^\d]+/;
    if (a.test(c)) {
        return 0;
    }
    var a = /^\d{7,8}$|^\d{7,8}[^\d]+|[^\d]+\d{7,8}$|[^\d]+\d{7,8}[^\d]+/;
    if (a.test(c)) {
        return 0;
    }
    return null;
}
function requiredValid(a) {
    var b = stringTrim(a);
    if (b == "") {
        return 0;
    } else {
        return null;
    }
}
function stringTrim(a) {
    return a.replace(/(^\s*)|(\s*$)/g, "");
}
function ChangeProvince(obj){
//    $("placetip").innerHTML = ("正在加载中...");
    document.all("capitalCN").length=1;
    document.all("cityCN").length=1;
    var url="/member/myajax.htm";
    var myAjax = new Ajax.Request(url+'?checktype=changepro&value='+obj.value, {method: 'get', onComplete:showCityByPro}); 
}
function showCityByPro(response){
    var result = response.responseText;
    
　　var piArray = result.split(",");
    for(var i=0;i<piArray.length;i++)
　　　　                {
　　　　　　                var ary1 = piArray[i].toString().split("|");
　　　　　　                document.all("capitalCN").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
　　　　                }
　  $("placetip").innerHtml="";
}

function ChangeCity(obj){
    document.all("cityCN").length=1;
    var url="/member/myajax.htm";
    var myAjax = new Ajax.Request(url+'?checktype=changecity&value='+obj.value, {method: 'get', onComplete:showAreaByCity}); 
}
function showAreaByCity(response){
    var result = response.responseText;
    
　　var piArray = result.split(",");
    for(var i=0;i<piArray.length;i++)
　　　　                {
　　　　　　                var ary1 = piArray[i].toString().split("|");
　　　　　　                document.all("cityCN").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
　　　　                }
}
function addIframe(b) {
    var a = ('<iframe name="' + b + '" id="' + b + '"></iframe>');
    var d = document.createElement("div");
    d.style.display = "none";
    d.innerHTML = a;
    $("iframes").appendChild(d);
    var c = $("imgHint");
    c.value = parseInt(c.value) + 1;
    return;
}
function setLiImg(b) {
    var a = document.createElement("li");
    a.setAttribute("id", "li_" + b);
    a.innerHTML = ('<img src="/images/img_loader.gif" width="64" height="64" /><span><a href="javascript:void(0)" onclick="RemovePreview(this)">取消</a></span>');
    $("imagesUl").appendChild(a);
    $("imagesUl").style.display="block";
    return;
}
function RemovePreview(a) {
    $("imagesUl").removeChild(a.parentNode.parentNode);
    return;
}
function insertImg(d, c, a) {//d:序号,c:图片路径,a:缩略图路径
    var b = a;
    $("iframes").removeChild($(d).parentNode);
    if (!$("li_" + d)) {
        return;
    }
    $("li_" + d).innerHTML = ('<input type="hidden" name="Imagethum[]" value="' + a + '" /><input type="hidden" name="image[]" value="' + c + '" /><img src="' + b + '" width="64" height="64" /><span><a href="javascript:void(0)" onclick="RemovePreview(this)">删除</a></span>');
    
    return;
}
function setLiImgError(c, b) {
    switch (b) {
    case 401:
        var a = "图片太大没有上传成功";
        break;
    case 402:
        var a = "服务器连接失败图片没有上传成功";
        break;
    default:
        var a = "图片有问题，没有上传成功";
        break;
    }
    $("li_" + c).innerHTML = ('<div class="imgUpError">' + a + '</div><a href="javascript:void(0)" onclick="RemovePreview(this)">取消</a>');
    
}
function myAddPanel(c, a, b) {
    if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) {
        window.sidebar.addPanel(c, a, b);
    } else {
        window.external.AddFavorite(a, c);
    }
}
function addfavorite(c, a, b){ 
    if (document.all){ 
        window.external.addFavorite(c,a); 
    } else if (window.sidebar) { 
        window.sidebar.addPanel(a, c, b); 
    } 
}