var searchInfoCount = function() {
    //调用时请最少对 InfoType,infoNumber赋值，否则将出现错误
    this.infoType = 0; //1=供应，2=求购，3=企业，4=资讯,5=展会
    this.infoNumber = 0; //信息数量
    this.ShowDivId = "notInfoDiv";
    this.keywords = ""; //信息搜索关键词
    this.classid = ""; //分类ID
    this.classNav = ""; //分类导航
    this.country = ""; //所属国家
    this.province = ""; //所遇省份
    this.city = ""; //所属省份
    this.url = document.location.href; //当前页面的URL地址，此地址会包含很多条件的可能
    this.companyMode = ""; //企业模式
    var sendUrl = "";
    var jsonObj = null;

    var sinputId = "sinputEmail";
    var scheckId = "scheckisother";
    var sbtnId = "sbtnsend";
    var sotherId = "stextareaother";
    var slogidId = "shiddenlogid";
    var sotherDivId = "otherdiv";
    var showobjid = "";
    //根据条件判判断操作，
    this.Action = function() {
        if (this.infoNumber == 0) {
            showobjid = this.ShowDivId;
            jsonObj = { infoType: this.infoType,
                infoNumber: this.infoNumber,
                keywords: escape(this.keywords),
                classid: this.classid,
                classNav: escape(this.classNav),
                country: escape(this.country),
                province: escape(this.province),
                city: escape(this.city),
                url: escape(this.url),
                companyMode: escape(this.companyMode),
                action: "",
                email: "",
                otherInfo: "",
                logId: 0
            }
            //alert(this.companyMode);
            //显示提示输入EMAIL的框框
            this.ShowNoInfo();
            this.AddLog();
        }
    }



    //添加记录
    this.AddLog = function() {
        jsonObj.action = "addlog";
        $.post("/ajaxPage/searchInfoCount.asp", jsonObj,
		function(data, textStatus) {
		    changeShow(data);

		}, "text");
    }

    var changeShow = function(data) {
        document.getElementById(slogidId).value = data;
        //if	(parseInt(data)<0 )
        ///{
        //alert("sdf");
        //document.getElementById(showobjid).innerHTML='<div class="showmsg">您已经向我们提交过次</div>';

        //}
    }

    //显示提示信息
    this.ShowNoInfo = function() {
        //this.SavePostInfo();
        //建立对象，承载用户输入
        var divObj = document.getElementById(this.ShowDivId);
        var divForm = document.createElement("DIV");
        divForm.id = "emaildivform";

        if (divObj != null) {
            var formStr = '<div class="rows msg">您可以留下您的Email，当有相关信息时我们会第一时间发送给您。</div>';
            formStr += '<div class="rows"><div class="name">*E-Mail:</div><div class="input"><input type="text" maxlength="50" id="' + sinputId + '" /></div></div>';
            formStr += '<div class="rows"><div class="checkbox"><input type="checkbox" id="' + scheckId + '" onclick="sic.changeother(this)" />我要填写详细描述</div></div>';
            formStr += '<div class="checkbox" id="' + sotherDivId + '" style="display:none"><textarea id="' + sotherId + '" /></textarea></div>';
            formStr += '<div class="btn"><input type="button" id="' + sbtnId + '" onclick="sic.SendInfo(this)"  value="确定提交"/><input type="hidden" value="0" id="' + slogidId + '" ></div>';
            divForm.innerHTML = formStr;
            //document.body.appendChild(divForm);
            divObj.appendChild(divForm);


            //var divInput=createElement("DIV");
            //var objInput = createElement("input");
            //objInput.id="inputEmail";
            //objInput.maxlength=50;

            //var objCheckBox=createElement("input");
        }
        return 0;
    }

    //提交用户记录
    this.SendInfo = function(btnObj) {
        var email = document.getElementById(sinputId).value;
        var otherInfo = document.getElementById(sotherId).value;
        var logId = document.getElementById(slogidId).value;

        if (!this.IsEmail(email)) {
            return false
        }
        jsonObj.action = "postinfo";
        jsonObj.otherInfo = otherInfo;
        jsonObj.email = email;
        jsonObj.logId = logId;
        btnObj.value = "正在提交，请稍后..."
        btnObj.onclick = function() { };
        btnObj.disabled = "disabled";
        $.ajax({
            type: "post",
            url: "/ajaxPage/searchInfoCount.asp",
            success: function(data, textStatus) {
                if (parseInt(data) != 3) {
                    document.getElementById(showobjid).innerHTML = '<div id="emaildivform" class="msg">您的Email信息已经提交成功，我们会第一时间将您需要的信息发送给您。</div>';
                }
                else {
                    alert("信息提交失败，请联系管理员或重试");
                }
            },
            error: function(textStatus) {
                alert("信息提交失败，请联系管理员或重试");
            },
            data: jsonObj
        });
        return 0;
    }

    this.IsEmail = function(email) {
        if (email == "") {
            alert("Email地址不能为空");
            return false;
        }

        if (email.length > 100) {
            alert("Email地址长度不能大于100");
            return false;
        }
        if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
            return true;
        }
        else {
            alert("请正确填写Email地址")
        }
    }

    this.changeother = function(obj) {
        document.getElementById(sotherDivId).style.display = obj.checked ? "" : "none";
    }
    //this.AjaxShow=function()
    //{
    //}
}
var sic = new searchInfoCount()
