﻿var Cook = {
    GetCookie: function(objname) {//取
        if (document.cookie.length > 0) {
            var c_start = document.cookie.indexOf(objname + "=");
            if (c_start != -1) {
                c_start = c_start + objname.length + 1;
                var c_end = document.cookie.indexOf("&", c_start);
                if (c_end == -1)
                    c_end = document.cookie.length;
                return unescape(document.cookie.substring(c_start, c_end));
            }
        }
        return null;
    },
    SetCookie: function(name, value) { //设
        var exp = new Date();
        exp.setDate(exp.getDate() + 1);
        if (document.cookie == '') {
            document.cookie = name + "=," + escape(value) + ",; expires=" + exp.toGMTString() + ";path=/";
        } else {
        document.cookie += escape(value) + ",; expires=" + exp.toGMTString() + ";path=/";
        }
    }
};
var Post = {
    EmailPostClick: function(objtype) {
        var stremail =document.getElementById("txt_mail").value;
        var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        if (!myreg.test(stremail)) {
            alert("电子邮件格式不对！");
            return;
        }
        $.ajax({
            type: "POST",
            url: "../aspx/ajax.aspx",
            data: "action=addemail&email=" + stremail + "&type=" + objtype,
            success: function(data) {
                if (data == "1") {
                    alert("提交成功！");
                    document.getElementById("txt_mail").value="";
                }
                else
                    alert("提交失败！");
            }
        });
    }
};
var Survey = {
    PostClick: function() {
        var subjectID = $("#hidsubject").val();
        if (Cook.GetCookie("UserSubject") != null && Cook.GetCookie("UserSubject").indexOf("," + subjectID + ",") != '-1') {
            alert("对不起,你不能重复投票!");
            return;
        }
        var surveycount = $("#hidsurveycount").val();

        for (var i = 1; i <= surveycount; i++) {
            var suveryid = $("#hidsurvey_" + i).val();
            var surveydetailcount = $("#hidsurveydetailcount_" + i).val();
            var detailvalue = "";
            var strtitle = $("#hidsurveytitle_" + i).val();
            if ($("#ckeck_detail_" + i + "_1").attr("type") == "checkbox") {
                for (var j = 1; j <= surveydetailcount; j++) {
                    if ($("#ckeck_detail_" + i + "_" + j).attr("checked"))
                        detailvalue += $("#ckeck_detail_" + i + "_" + j).val() + ",";
                }
            } else if ($("#ckeck_detail_" + i + "_1").attr("type") == "radio") {
                for (var j = 1; j <= surveydetailcount; j++) {
                    if ($("#ckeck_detail_" + i + "_" + j).attr("checked")) {
                        detailvalue += $("#ckeck_detail_" + i + "_" + j).val() + ",";
                        break;
                    }
                }
            }
            if (detailvalue == null || detailvalue == '') {
                alert("请选择" + strtitle + ",谢谢!");
                return;
            }
        }

        for (var i = 1; i <= surveycount; i++) {
            var suveryid = $("#hidsurvey_" + i).val();
            var surveydetailcount = $("#hidsurveydetailcount_" + i).val();
            var detailvalue = "";
            var strtitle = $("#hidsurveytitle_" + i).val();
            if ($("#ckeck_detail_" + i + "_1").attr("type") == "checkbox") {
                for (var j = 1; j <= surveydetailcount; j++) {
                    if ($("#ckeck_detail_" + i + "_" + j).attr("checked"))
                        detailvalue += $("#ckeck_detail_" + i + "_" + j).val() + ",";
                }
            } else if ($("#ckeck_detail_" + i + "_1").attr("type") == "radio") {
                for (var j = 1; j <= surveydetailcount; j++) {
                    if ($("#ckeck_detail_" + i + "_" + j).attr("checked")) {
                        detailvalue += $("#ckeck_detail_" + i + "_" + j).val() + ",";
                        break;
                    }
                }
            }
            $.ajax({
                type: "POST",
                url: "../aspx/ajax.aspx",
                data: "action=addsuvery&subjectID=" + subjectID + "&suveryid=" + suveryid + "&detailID=" + detailvalue,
                success: function(data) {
                }
            });
        }
        Cook.SetCookie("UserSubject", subjectID);
        alert("提交完成!");
        return;
    }, AllPostUserClick: function() {
        var surveycount = $("#hidsurveycount").val();
        var subjectID = $("#hidsubject").val();
        if (Cook.GetCookie("UserSubject") != null && Cook.GetCookie("UserSubject").indexOf("," + subjectID + ",") != '-1') {
            alert("对不起,你不能重复投票!");
            return;
        }
        for (var i = 1; i <= surveycount; i++) {

            var surveydetailcount = $("#hidsurveydetailcount_" + i).val();
            var detailvalue = "";
            var strtitle = $("#hidsurveytitle_" + i).val();
            if ($("#ckeck_detail_" + i + "_1").attr("type") == "checkbox") {
                for (var j = 1; j <= surveydetailcount; j++) {
                    if ($("#ckeck_detail_" + i + "_" + j).attr("checked"))
                        detailvalue += $("#ckeck_detail_" + i + "_" + j).val() + ",";
                }
            } else if ($("#ckeck_detail_" + i + "_1").attr("type") == "radio") {
                for (var j = 1; j <= surveydetailcount; j++) {
                    if ($("#ckeck_detail_" + i + "_" + j).attr("checked")) {
                        detailvalue += $("#ckeck_detail_" + i + "_" + j).val() + ",";
                        break;
                    }
                }
            }
            if (detailvalue == null || detailvalue == '') {
                alert("请选择" + strtitle + ",谢谢!");
                return;
            }
        }

        var strusername = $("#txt_name").val();
        var strcompanyname = $("#txt_comp").val();
        var strtel = $("#txt_tel").val();
        var strposition = $("#txt_position").val();
        var straddr = $("#txt_address").val();
        var strpostr = $("#txt_poster").val();

        if (strusername == null || strusername == '') {
            alert("姓名不能为空!");
            $("#txt_name").focus();
            return;
        }
        if (strtel == null || strtel == '') {
            alert("联系电话不能为空!");
            $("#txt_tel").focus();
            return;
        }
        if (straddr == null || straddr == '') {
            alert("公司地址不能为空!");
            $("#txt_address").focus();
            return;
        }
        $.ajax({
            type: "POST",
            url: "../aspx/ajax.aspx",
            data: "action=addsuveryuser&subjectID=" + subjectID + "&username=" + strusername + "&companyname=" + strcompanyname + "&tel=" + strtel + "&position=" + strposition + "&addr=" + straddr + "&postr=" + strpostr,
            success: function(data) {
                if (data == "0") {
                    alert("操作失败,请重新提交!");
                    return;
                }
                Survey.AllPostClick(data);
            }
        });
    },
    AllPostClick: function(objuserid) {
        var subjectID = $("#hidsubject").val();
        if (Cook.GetCookie("UserSubject") != null && Cook.GetCookie("UserSubject").indexOf("," + subjectID + ",") != '-1') {
            alert("对不起,你不能重复投票!");
            return;
        }
        var surveycount = $("#hidsurveycount").val();
        for (var i = 1; i <= surveycount; i++) {
            var suveryid = $("#hidsurvey_" + i).val();
            var surveydetailcount = $("#hidsurveydetailcount_" + i).val();
            var detailvalue = "";
            var strtitle = $("#hidsurveytitle_" + i).val();
            if ($("#ckeck_detail_" + i + "_1").attr("type") == "checkbox") {
                for (var j = 1; j <= surveydetailcount; j++) {
                    if ($("#ckeck_detail_" + i + "_" + j).attr("checked"))
                        detailvalue += $("#ckeck_detail_" + i + "_" + j).val() + ",";
                }
            } else if ($("#ckeck_detail_" + i + "_1").attr("type") == "radio") {
                for (var j = 1; j <= surveydetailcount; j++) {
                    if ($("#ckeck_detail_" + i + "_" + j).attr("checked")) {
                        detailvalue += $("#ckeck_detail_" + i + "_" + j).val() + ",";
                        break;
                    }
                }
            }
            $.ajax({
                type: "POST",
                url: "../aspx/ajax.aspx",
                data: "action=addsuvery&subjectID=" + subjectID + "&suveryid=" + suveryid + "&detailID=" + detailvalue + "&userID=" + objuserid,
                success: function(data) {
                }
            });
        }
        Cook.SetCookie("UserSubject", subjectID);
        alert("提交完成!");
        return;
    }
};
var Contact = {
    PostClick: function() {
        if ($("#txt_name").val() == null || $("#txt_name").val() == '') {
            alert("姓名不能为空!");
            $("#txt_name").focus();
            return false;
        }
        if ($("#txt_tel").val() == null || $("#txt_tel").val() == '') {
            alert("联系电话不能为空!");
            $("#txt_tel").focus();
            return false;
        }
        if ($("#txt_email").val() == null || $("#txt_email").val() == '') {
            alert("电子邮箱不能为空!");
            $("#txt_email").focus();
            return false;
        }
        var stremail = $("#txt_email").val();
        var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        if (!myreg.test(stremail)) {
            alert("电子邮件格式不对！");
            return false;
        }
        if ($("#txt_content").val() == null || $("#txt_content").val() == '') {
            alert("留言内容不能为空!");
            $("#txt_content").focus();
            return false;
        }
        return true;
    }
};
var Confer = {
    PostClick: function() {
        if ($("#txt_name").val() == null || $("#txt_name").val() == '') {
            alert("姓名不能为空!");
            $("#txt_name").focus();
            return false;
        }
        if ($("#txt_position").val() == null || $("#txt_position").val() == '') {
            alert("职位不能为空!");
            $("#txt_position").focus();
            return false;
        }
        if ($("#txt_comp").val() == null || $("#txt_comp").val() == '') {
            alert("公司名称不能为空!");
            $("#txt_comp").focus();
            return false;
        }
        if ($("#txt_tel").val() == null || $("#txt_tel").val() == '') {
            alert("电话不能为空!");
            $("#txt_tel").focus();
            return false;
        }
        if ($("#txt_email").val() == null || $("#txt_email").val() == '') {
            alert("邮箱不能为空!");
            $("#txt_email").focus();
            return false;
        }
        var stremail = $("#txt_email").val();
        var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        if (!myreg.test(stremail)) {
            alert("邮箱格式不对！");
            $("#txt_email").focus();
            return false;
        }

    }
};
var Register = {
    PostClick: function() {
        if ($("#txt_name").val() == null || $("#txt_name").val() == '') {
            alert("姓名不能为空!");
            $("#txt_name").focus();
            return false;
        }
        if ($("#txt_position").val() == null || $("#txt_position").val() == '') {
            alert("职位不能为空!");
            $("#txt_position").focus();
            return false;
        }
        if ($("#txt_comp").val() == null || $("#txt_comp").val() == '') {
            alert("公司名称不能为空!");
            $("#txt_comp").focus();
            return false;
        }
        if ($("#txt_tel").val() == null || $("#txt_tel").val() == '') {
            alert("电话不能为空!");
            $("#txt_tel").focus();
            return false;
        }
        if ($("#txt_email").val() == null || $("#txt_email").val() == '') {
            alert("邮箱不能为空!");
            $("#txt_email").focus();
            return false;
        }
        var stremail = $("#txt_email").val();
        var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        if (!myreg.test(stremail)) {
            alert("邮箱格式不对！");
            $("#txt_email").focus();
            return false;
        }
        if ($("#txt_number").val() == null || $("#txt_number").val() == '') {
            alert("参会人数不能为空!");
            $("#txt_number").focus();
            return false;
        }
        if ($("#drop_currency").val() == null || $("#drop_currency").val() == '') {
            alert("货币类型不能为空!");
            $("#drop_currency").focus();
            return false;
        }
        if ($("#txt_amount").val() == null || $("#txt_amount").val() == '') {
            alert("总金额不能为空!");
            $("#txt_amount").focus();
            return false;
        }
    }
};

var Live = {
    sitetype: '',
    detailID: 0,
    times: '',
    InIt: function(objsitetype, objdetailid, objstatus, objtimes) {
        if ($("#stopupdate").attr("checked"))
            return;
        if (objstatus != null && objstatus != '' && objstatus == '1')
            return;
        this.sitetype = objsitetype;
        this.detailID = objdetailid;
        this.times = objtimes;
        $('body').everyTime('1das', 'C', Live.GetLiveDetailList, 0, true);
    },
    GetLiveDetailList: function() {
        if ($("#stopupdate").attr("checked"))
            return;
        $.ajax({
            type: "POST",
            url: "../aspx/ajax.aspx",
            data: "action=getlive&type=" + Live.sitetype + "&detailID=" + Live.detailID + "&times=" + Live.times,
            success: function(data) {
                if (data == "0") {
                    return;
                }
                var strdata = data.toString().split("%");
                $("#divMessage").append(strdata[0]);
                Live.detailID = strdata[1];
            }
        });
    }
};
var News = {
    SearchPostClick: function() {
        if ($("#txt_key").val() == null || $("#txt_key").val() == '' || $("#txt_key").val() == '请输入关键字') {
            alert("请选择搜索条件!");
            return false;
        }
        return true;
    },
    PostEmailClick: function(objtype) {
        var stremail = $("#txt_mail2").val();
        var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        if (!myreg.test(stremail)) {
            alert("电子邮件格式不对！");
            return;
        }
        $.ajax({
            type: "POST",
            url: "../aspx/ajax.aspx",
            data: "action=addemail&email=" + stremail + "&type=" + objtype,
            success: function(data) {
                if (data == "1") {
                    alert("提交成功！");
                    $("#txt_mail2").val("");
                }
                else
                    alert("提交失败！");
            }
        });
    }
};
var SiteTools = {
    FavoritesClick: function(avgtitle, avgurl) {
        if (document.all)
            window.external.AddFavorite(avgurl, avgtitle);
        else if (window.sidebar)
            window.sidebar.addPanel(avgtitle, avgurl, "")
    },
    HomePage: function(avg, objval) {
        try {
            obj.style.behavior = 'url(#default#homepage)';
            obj.setHomePage(val);
        }
        catch (e) {
            if (window.netscape) {
                try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                }
                catch (e) {
                    alert("此操作被浏览器拒绝！");
                }
                var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                prefs.setCharPref('browser.startup.homepage', val);
            }
        }
    },
    FontZoom: function(objval) {
        $("#content").css("font-size", objval + "px");
    }
};
