﻿var ver_sign = {
    sTitle: { cn: "桐庐·黄页", en: "China Pages" },
    addfav: { cn: "加入收藏失败，请使用Ctrl+D进行添加", en: "put into collection was defeated,please use ctrl+D to add file" },
    loadFav1: { cn: "加入收藏", en: "add to favorite" },
    loadFav2: { cn: "加入收藏夹", en: "put into collection" },
    welcome: { cn: "欢迎您，", en: "welcomes you," },
    seachtext: { cn: "请输入你要搜索的内容", en: "please input content that you wanna search" },
    preview: { cn: "上一页", en: "previous page" },
    next: { cn: "下一页", en: "next page" },
    logout:{cn:"退出",en:" logout "},
    poptitle: { cn: "中国黄页提示您", en: "chinapage prompt you" },
    close: { cn: "关闭", en: "close" },
    confirm: { cn: "确定", en: "confirm" },
    cancel: { cn: "取消", en: "cancel" },
    alert1: { cn: "您已经收藏过该公司", en: "you have collection this company" },
    alert2: { cn: "添加失败", en: "accession was defeated" },
    case1: { cn: "将此公司添加到您的收藏夹", en: "make this company put into your collection" },
    item: { cn: "公&nbsp;&nbsp;&nbsp;司：", en: "company" },
    memo: { cn: "标&nbsp;&nbsp;&nbsp;注：", en: "mark" },
    case2: { cn: "请登陆后再添加收藏夹", en: "after login and then put into collection" },
    email: { cn: "用户名：", en: "user name" },
    password: { cn: "密&nbsp;&nbsp;&nbsp;码：", en: "password:" },
    radom: { cn: "验证码：", en: "identifying code" },
    case3: { cn: "已成功添加到您的收藏夹", en: "put into collection was successed" },
    success: { cn: "您已成功将该公司添至您的收藏夹，可在【管理中心>>收藏夹】中查看！", en: "you have successed make this company put into your collection  ,can lookat in favorite of administrative center " },
    closetip: { cn: "本窗口3秒后自动关闭！", en: "This window automatically closes after 3 seconds" },
    filename: { cn: "文件名：", en: "file name:" },
    files1: { cn: "请输入文档访问密码", en: "please input password" },
    files3: { cn: "密码不对", en: "password incorrect" },
    files2: { cn: "文档访问密码正确", en: "password correct" },
    files4: { cn: "正在下载中...", en: "download in progress" },
    files5: { cn: "如果没有自动下载，", en: " if no automatic download," },
    files6: { cn: "请点击这里", en: "please click here" }
}
function AddFavorite() {
    var sTitle, sURL;
    try {
        sTitle = ($("#companyname")[0] ? $("#companyname").html() : eval("ver_sign.sTitle." + curr));
        sURL = ($("#companyname")[0] ? window.location : "http://ww2.tlnews.com.cn/09hy");
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e) {
            alert(eval("ver_sign.addfav." + curr));
        }
    }
}
function SetHome(obj) {
    vrl = ($("#companyname")[0] ? window.location : "http://ww2.tlnews.com.cn/09hy");
    try {
        obj.style.behavior = 'url(#default#homepage)';
        obj.setHomePage(vrl);
    }
    catch (e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                prefs.setCharPref('browser.startup.homepage', vrl);
            }
            catch (e) {
                //alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。"); 
            }
        }
        else { throw e }
    }
}
//查询
function getCookie(key) {
    var _c = document.cookie;
    if (!_c.match(/uinfo=/))
        return null;
    var r = new RegExp(key + "=([^&]+)([&]|$)");
    var arr = r.exec(_c);
    return decodeURIComponent(RegExp.$1);
}

function loadtip() {
    if ($("#toptip")) {
        if (getCookie("uid") != null && getCookie("uid") != "") {
            $("#toptip").html("<span>" + eval("ver_sign.welcome." + curr) + getCookie("nick") + "！[<a href='/member/logout.html'>" + eval("ver_sign.logout." + curr) + "</a>]</span>");
            $("div.logpic").remove();
        }
    }
}
function loadFav(itemid, prof) {

    fav1 = '<a href="javascript:void(0)" onclick="javascript:AddFavorite();" title=' + eval("ver_sign.loadFav1." + curr) + '><span>' + eval("ver_sign.loadFav1." + curr) + '</span></a>';
    fav2 = '<a href="javascript:void(0)" onclick="javascript:popLayer.tip(\'' + itemid + '\',\'' + prof + '\')" title=' + eval("ver_sign.loadFav2." + curr) + '><span id="addajax">' + eval("ver_sign.loadFav2." + curr) + '</span></a>';
    $("#top2").after(($("#companyname")[0] && curr == "cn" ? fav2 : fav1));
}
$(document).ready(function() {
    //收藏
    if (!$("#companyname")[0]) {
        loadFav('', '');
    }
    //欢迎词
    loadtip();
    //主营行业筛选
    $("#buttseekbiz").click(function() {
        var s = location.href;
        if (getkeyv("key") == "")
            s = clearparam("key");
        var biz = [];
        $.each($(":checkbox[name=seekbizmodel]"), function(i, o) {
            if (o.checked)
                biz.push(o.value);
        });
        if (biz.length == 0) {
            if (!getkeyv("bmod"))
                return;
            else
                location.href = clearparam("bmod", s);
        }
        else {
            location.href = reparam("bmod", biz.join(","), s);
        }
    });
    $(":checkbox[name=seekbizmodel]").click(function() {
        if (this.checked && this == $(":input[name=seekbizmodel]:last")[0])
            $(":checkbox[name=seekbizmodel]:not(:last)").removeAttr("checked");
        else
            $(":checkbox[name=seekbizmodel]:last").removeAttr("checked");
    });
    //关键词搜索
    $("#seachform").submit(function() {
        if ($(":text[name=seachtext]").val() == eval("ver_sign.seachtext." + curr))
            $(":text[name=seachtext]").val("");
        if(curr == "cn")
            curr = "ww2";
        location.href = "http://" + curr + "ww2.tlnews.com.cn/09hy/company/list.html?key=" + encodeURIComponent($(":text[name=seachtext]").val());
        return false;
    });
    //tradeid筛选
    $("a[name=seektrade]").click(function() {
        var s = initsurl();
        var _i = s.indexOf("?");
        location.href = "/company/" + $(this).attr("vt") + "/" + $(this).attr("vt2") + ".html" + (_i > -1 ? s.substring(s.indexOf("?")) : "");
    });
    //tradeid2筛选
    $("a[name=seektrade1]").click(function() {
        var s = initsurl();
        var _i = s.indexOf("?");
        location.href = "/company/" + $(this).attr("vt") + ".html" + (_i > -1 ? s.substring(s.indexOf("?")) : "");
    });
    //地区筛选
    $(":input[name=seekarea]").change(function() {
        var s = initsurl();
        if (this.value != "") {
            location.href = reparam("are", this.value, s);
        }
        else if (getkeyv("are")) {
            location.href = clearparam("are", s);
        }
    });
    //注册资金筛选
    $(":input[name=seekass]").change(function() {
        var s = initsurl();
        if (this.value != "") {
            location.href = reparam("ass", this.value, s);
        }
        else if (getkeyv("ass")) {
            location.href = clearparam("ass", s);
        }
    });
    //是否审核筛选
    $(":input[name=seekcby]").change(function() {
        var s = initsurl();
        if (getkeyv("cby") == "")
            s = clearparam("cby");
        if (this.value != "") {
            location.href = reparam("cby", this.value, s);
        }
        else if (getkeyv("cby")) {
            location.href = clearparam("cby", s);
        }
    });
    //企业人数筛选
    $(":input[name=seekpnum]").change(function() {
        var s = initsurl();
        if (this.value != "") {
            location.href = reparam("pnum", this.value, s);
        }
        else if (getkeyv("pnum")) {
            location.href = clearparam("pnum", s);
        }
    });
    if ($("#site-nav")[0]) {
        var href = location.href;
        var r = /\/(\w+)\.html/;
        if (href.match(r)) {
            var tar = RegExp.$1;
            $("#site-nav .sel").removeAttr("class");
            $("#site-nav a[href^=" + tar + "] span").addClass("sel");
            $("#nav-curr").html($("#site-nav a[href^=" + tar + "] span").html());
        }
    }
    if ($("input[name=seachtext]")[0]) {
        var msg = ((getkeyv("key") && getkeyv("key") != "") ? decodeURIComponent(getkeyv("key")) : eval("ver_sign.seachtext." + curr));
        $("input[name=seachtext]").val(msg);
        $("input[name=seachtext]").click(function() {
            if (this.value == eval("ver_sign.seachtext." + curr))
                this.value = "";
        });
    }
}); //2540.83 779.28
function clearsearch(o) {
    if (o.value == eval("ver_sign.seachtext." + curr))
        o.value = "";
}

function reparam(n, v, s) {
    if (!s)
        var s = location.href;
    var r = new RegExp("(" + n + "=[^&]+)(&|$)");
    if (s.match(r)) {
        return s.replace(RegExp.$1, n + "=" + encodeURIComponent(v));
    }
    else {
        if (s.indexOf("?") == -1) {
            return s + "?" + n + "=" + encodeURIComponent(v);
        }
        else {
            return s + "&" + n + "=" + encodeURIComponent(v);
        }
    }

}
function clearparam(key, s) {
    if (!s)
        var s = location.href;
    var r = new RegExp("((\\?|&)" + key + "=[^&]*)(&|$)");
    if (s.match(r)) {
        s = s.replace(RegExp.$1, "");
        if (s.indexOf("?") == -1 && s.indexOf("&") > -1)
            s = s.replace("&", "?");
    }
    return s;

}
function initsurl() {
    var s = location.href;
    if (getkeyv("key") == "")
        s = clearparam("key");
    s = s.replace(/\/(p-[\d]+)/, "");
    return s;

}

function getkeyv(key) {
    var s = location.href;
    var r = new RegExp(key + "=([^&]*)(&|$)");
    if (s.match(r)) {
        return RegExp.$1;
    }
    return null;
}

function loadPage(total, pageno, pagesize) {
    if (total == 0) return false;
    mylist = new TurnPage("mylist");
    mylist.pageSize = pagesize;
    mylist.currPage = pageno;
    mylist.total = total;
    mylist.callback = function() {
        var h = location.href;
        location.href = reparam("psiz", mylist.pageSize, reparam("pno", mylist.currPage));
    };
    $("#pager").html(mylist.getOutput());
}

function TurnPage(callerName) {
    this.total = 0; //总记录数 

    this.pageSize = 10; //每页显示记录数
    this.currPage = 1; //当前页
    this.callback = function() { };

    this.showCurrPageCount = true; //是否显示页码
    this.currPageCount = 20; //每次显示10个页码


    this.pre = '<a title="' + eval("ver_sign.preview." + curr) + '" id="scroll_prev" class="preview">' + eval("ver_sign.preview." + curr) + '</a>';
    this.preHref = '<a title="' + eval("ver_sign.preview." + curr) + '" id="scroll_prev" onclick="' + callerName + '.turn({#},true)" class="preview">' + eval("ver_sign.preview." + curr) + '</a>';
    this.next = '<a id="scroll_next" class="scroll_button">' + eval("ver_sign.next." + curr) + '</a>';
    this.nextHref = '<a title="' + eval("ver_sign.next." + curr) + '" id="scroll_next" onclick="' + callerName + '.turn({#},false)" class="next">' + eval("ver_sign.next." + curr) + '</a>';

    this.currPageStart = 1; //第一个页码

    this._isPre = false; //是否向前翻页
    this.show = function() {//是否显示翻页，总记录数为0时，不显示。

        if (this.total > 0) {
            return true;
        }
        else {
            return false;
        }
    };
    this.getPageCount = function() {
        if (this.total % this.pageSize > 0) {
            return parseInt(this.total / this.pageSize) + 1;
        }
        else {
            return parseInt(this.total / this.pageSize);
        }
    };
    this.getOutput = function() {
        eval(callerName);
        var inner = [];
        //前页
        if (this.currPage > 1) {
            inner.push(this.preHref.replace("{#}", this.currPage - 1));
        }
        //中段
        if (this.showCurrPageCount) {
            if (this.currPage > 88)
                this.currPageCount = 13;
            if (this.currPage > 990)
                this.currPageCount = 11;
            this.currPageStart = this.currPage - parseInt(this.currPageCount / 2);
            var end = this.currPage + parseInt(this.currPageCount / 2);
            if (this.currPageStart < 1)
                this.currPageStart = 1;
            if (end < this.currPageCount)
                end = this.currPageCount;
            var _end = parseInt(this.total / this.pageSize) + (this.total % this.pageSize > 0 ? 1 : 0)
            if (end > _end)
                end = _end;
            for (i = this.currPageStart; i <= end; i++) {
                if (end == 1) { }
                else if (this.currPage == i)
                    inner.push('<strong>' + i + '</strong>');
                else {
                    inner.push('<a onclick="' + callerName + '.turn(' + i + ',false)" class="pages-active font-s">');
                    inner.push(i);
                    inner.push('</a>');
                }
            };
        }
        //后页
        if (this.currPage < end && _end > 1) {
            inner.push(this.nextHref.replace("{#}", this.currPage + 1));
        }
        return inner.join('');
    };
    this.turn = function(index, ispre) {
        this.currPage = index;
        this._isPre = ispre;
        this.callback.call();
    };
}

var popLayer = {};
popLayer.show = function(poptitle, popcont, popbutt, autodisappear, callback) {
    $("body").append(popLayer.create());
    if (popcont)
        $("#popcont").html(popcont);
    if (popbutt)
        $("#popsub").html(popbutt);
    if (poptitle)
        $("#popt").html(poptitle);
    var _l = ($(window).width() - $("#poplayer").width()) / 2 + 'px';
    var _t = $(document).scrollTop() + 150 + "px";
    $("#bgpopLayer").css("height", $(document).height());
    $("#bgpopLayer").css("width", $(document).width());
    $("#poplayer").css("left", _l);
    $("#poplayer").css("top", _t);
    //$("#poplayer-i").css("left",_l);
    //$("#poplayer-i").css("top",_t);
    if (autodisappear || autodisappear == null)
        window.setTimeout(popLayer.close, 3000);
    if (typeof (callback) == "function") {
        callback.call();
    }
}
popLayer.close = function() {
    $("#bgpopLayer").remove();
    $("#poplayer").remove();
    //$("#poplayer-i").remove();
}
popLayer.create = function() {
    popLayer.close();
    return _layer = '\
		<form id="popform">\
		<div id="bgpopLayer"></div>\
		<div id="poplayer">\
			<div class="pop-title">\
				' + eval("ver_sign.poptitle." + curr) + '\
				<p><a href="javascript:void(0)" onclick="popLayer.close()">' + eval("ver_sign.close." + curr) + '</a></p>\
			</div>\
			<div class="pop-t" id="popt">\
			</div>\
			<div class="pop-cont" id="popcont">\
			</div>\
			<div id="popsub">\
				<input type=button onclick="popLayer.close()" class="submit" value="' + eval("ver_sign.confirm." + curr) + '"/>\
			</div>\
		</div>\
		</form>\
	';
}
//login layer by wwj 2009-8-7
popLayer.tip = function(itemid, memo, callback) {
    if (getCookie("uid") != null && getCookie("uid") != "") {

        $.post("/common/checkMyFavorites.html", { item: 1, itemid: itemid }, function(data) {
            if (data == "1") {
                alert(eval("ver_sign.alert1." + curr));
                return true;
            }
            else {
                popLayer.showtip(1);
                $("#memo").html(memo + "...");
                $("#item").html($("#companyname").html());
                $("#memo").change(function() {
                    if ($(this).val().length > 50) { $(this).val($(this).val().substring(0, 55)) }
                });
                $("#loginForm").submit(function() {
                    $.post("/common/addToMyFavorites.html", { item: 1, itemid: itemid, memo: encodeURIComponent($("#memo").val()) }, function(data) {
                        if (data == "1") {
                            popLayer.showtip(3);
                        }
                        else { alert(eval("ver_sign.alert2." + curr)) };
                    })
                    return false;
                });
            }
        })
    }

    else {
        popLayer.showtip(2);
        $("#loginForm").submit(function() {
            $.post("/member/loginresult.html/ajax", { email: $("#Temail").val(), pwd: $("#Tpwd").val(), radom: $("#Tradom").val() }, function(data) {
                if (typeof (data) == "string" && data.match(/error=/)) {
                    alert(data.replace("error=", "").replace('"', '').replace('"', ''));
                    $("#vcodeimg").attr("src", "/images/vcode.jpg?" + (new Date()).getTime());
                    return;
                }
                else {
                    popLayer.closetip();
                }
                if (typeof (data) == "string" && data.match(/"ok"/)) {
                    loadtip();
                    $("#addajax").click();
                }
                if (typeof (callback) == "function") {
                    callback.call();
                }
            })
            return false;
        });
    }



}

popLayer.showtip = function(type, callback) {
    $("body").append(popLayer.createtip(type));
    var _l = ($(window).width() - $("#poplayer").width()) / 2 + 'px';
    var _t = $(document).scrollTop() + 150 + "px";
    $("#bgpopLayer").css("height", $(document).height());
    $("#bgpopLayer").css("width", $(document).width());
    $("#closepic").click(function() { popLayer.closetip() });
    $("#piccancel").click(function() { popLayer.closetip() });

    if (type == 3) {
        window.setTimeout(popLayer.closetip, 3000);
    }
    else {
        window.setTimeout(popLayer.closetip, 300000);
    }
    if (typeof (callback) == "function") {
        callback.call();
    }
}
popLayer.createtip = function(type) {
    popLayer.closetip();
    switch (type) {
        case 1:
            return _layer = '\
	    <div id="bgpopLayer"></div>\
	    <div class="rigmainbox" id="rigmainbox">\
	    <form id="loginForm" method="post">\
	        <div class="rightlogin">\
		        <div class="logpeps">\
			        <div class="logtxts">' + eval("ver_sign.case1." + curr) + '</div>\
			        <div class="closepic"><img id="closepic" src="/css/toptip/images/close.gif" /></div>\
		        </div>\
		        <div class="orgpic"></div>\
		        <div class="tabdl">\
			        <table cellpadding="0"  border="0" class="boxtabl">\
				        <tr>\
					        <td class="lefttxts">' + eval("ver_sign.item." + curr) + '</td><td class="inputkk" id="item"></td>\
				        </tr>\
				        <tr>\
					        <td class="lefttxts">' + eval("ver_sign.memo." + curr) + '</td><td class="inputkk"><textarea id="memo" rows="3" / ></textarea></td>\
				        </tr>\
			        </table>\
		        </div>\
		        <div class="buts">\
			        <input name="" type="image" src="/css/toptip/images/shc.gif" />\
			        <span class="rbut"><input name="" onclick="this.form.reset();return false;" type="image" src="/css/toptip/images/chx.gif"/></span>\
		        </div>\
	        </div>\
	    </form>\
        </div>';
            break;
        case 2:
            return _layer = '\
	    <div id="bgpopLayer"></div>\
	    <div class="rigmainbox" id="rigmainbox">\
	    <form id="loginForm" method="post">\
	        <div class="rightlogin">\
		        <div class="logpeps">\
			        <div class="logtxts">' + eval("ver_sign.case2." + curr) + '</div>\
			        <div class="closepic"><img id="closepic" src="/css/toptip/images/close.gif" /></div>\
		        </div>\
		        <div class="orgpic"></div>\
		        <div class="tabdl">\
			        <table cellpadding="0"  border="0" class="boxtabl">\
				        <tr>\
					        <td class="lefttxts">' + eval("ver_sign.email." + curr) + '</td><td class="inputkk"><input type="text" id="Temail" width="140" height="20"/ ></td>\
				        </tr>\
				        <tr>\
					        <td class="lefttxts">' + eval("ver_sign.password." + curr) + '</td><td class="inputkk"><input type="password" id="Tpwd" width="140" height="20"/ ></td>\
				        </tr>\
				        <tr>\
					        <td class="lefttxts">' + eval("ver_sign.radom." + curr) + '</td><td class="inputkk2"><input type="text" id="Tradom" width="80" height="20"/ ><img id="vcodeimg" src="/images/vcode.jpg"/></td>\
				        </tr>\
			        </table>\
		        </div>\
		        <div class="buts">\
			        <input name="" type="image" src="/css/toptip/images/dl.gif" />\
			        <span class="rbut"><input id="piccancel" type="image" src="/css/toptip/images/qx.gif" /></span>\
		        </div>\
	        </div>\
	    </form>\
        </div>';
        case 3:
            return _layer = '\
	    <div id="bgpopLayer"></div>\
	    <div class="rigmainbox" id="rigmainbox">\
	        <div class="rightlogin">\
		        <div class="logpeps">\
			        <div class="logtxts">' + eval("ver_sign.case3." + curr) + '</div>\
			        <div class="closepic"><img id="closepic" src="/css/toptip/images/close.gif" /></div>\
		        </div>\
		        <div class="orgpic"></div>\
		        <div class="tabdl">\
			       <table cellpadding="0"  border="0" class="boxtab1" >\
		                <tr>\
		                <td style="text-align:center; font-size:14px; line-height:25px;">' + eval("ver_sign.success." + curr) + '</td>\
		                </tr>\
		                <tr>\
		                <td style="text-align:center; font-size:9px; line-height:20px;">' + eval("ver_sign.closetip." + curr) + '</td>\
		                </tr>\
		            </table>\
		        </div>\
		        <div style="text-align:center; margin-top:0px;">\
		            <input id="piccancel" type="image" src="/css/toptip/images/colbut.gif" />\
		        </div>\
	        </div>\
        </div>';
    }
}
popLayer.closetip = function() {
    $("#bgpopLayer").remove();
    $("#rigmainbox").remove();
}
function checkForm(jo) {
    var valid = true;
    $.each(jo, function(i, n) {
        if (!checkField($(n)))
            valid = false;
    });
    return valid;
}
function checkField(jo) {
    var email = /^\w+([-+.]\w+)*@\w+([-+.]\w+)*\.\w+([-.]\w+)*$/;
    var pwd = /^.{6,20}$/;
    var pwd1 = new RegExp("^" + $(":input[id=pwd]").val() + "$");
    var nick = /[a-zA-Z0-9\u4e00-\u9fa5]+/;
    var radom = /^.{4,6}$/;
    var radom2 = /^.{4,6}$/;
    var pwdanswer = /^.{1,50}$/;
    var isvalid = true;
    if (!jo.attr('id') || eval("typeof(" + jo.attr('id') + ")") == "undefined")
        return true;
    if (!jo.val().match(eval(jo.attr('id')))) {
        isvalid = false;
    }
    if (!isvalid) {
        if (jo.siblings("[name=e]")[0]) {
            jo.siblings("[name=e]").css("display", "");
            jo.siblings("[name=t]").hide();
        }
        else {
            jo.parent().siblings("[name=e]").css("display", "");
            jo.parent().siblings("[name=t]").hide();
        }
        return false;
    }
    else {
        if (jo.siblings("[name=e]")[0]) {
            jo.siblings("[name=e]").hide();
            jo.siblings("[name=t]").css("display", "");
        }
        else {
            jo.parent().siblings("[name=e]").hide();
            jo.parent().siblings("[name=t]").css("display", "");
        }
        return true;
    }
}

function onsure(srcc, tar) {
    srcc.click(function() {
        if (srcc.attr('checked') == true) {
            tar.removeAttr("disabled");
        }
        else {
            tar.attr("disabled", "true");
        }
    });
}
function toggleHid(jo) {
    if (jo.css("display") == "none")
        jo.css("display", "");
    else
        jo.css("display", "none");
}
function getRndNum(lbound, ubound) {
    return (Math.floor(Math.random() * (ubound - lbound) + lbound));
}

//头部按钮
$(document).ready(function() {
    var href = location.href;
    var r = /infonews/;
    var rs = r.exec(href);
    if (rs == "infonews") {
        $("#infonews").removeClass("menu-b").addClass("menu-bb");
//        $("#DIVversion").hide();
    }
    else {
        $("#company").removeClass("menu-a").addClass("menu-aa");
    }
});

