function error(form_obj, errmsg) {
    if (errfound)
        return;
    window.alert(errmsg);
    form_obj.select();
    form_obj.focus();
    errfound = true;
}

function emailCheck() {
    var emailStr = document.form2.email.value;
    if (emailStr != "") {
        var emailPat = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
        var matchArray = emailStr.match(emailPat);
        if (matchArray == null) {
            return false;
        }
        return true;
    }
    else {
        return true;
    }
}

//单独处理选择表出错信息
function errselect(form_obj, errmsg) {
    if (errfound) return;
    window.alert(errmsg);
    form_obj.focus();
    errfound = true;
}

//主检验程序
function Validate() {
    errfound = false;
    var PvcID = "0";
    if (document.getElementById("selPvc") != null) {
        try {
            var selectOb = document.getElementById("selPvc");
            var index = selectOb.selectedIndex;
            if (selectOb.options[index].value != "0")
                PvcID = selectOb.options[index].value;
            if (PvcID != "" && PvcID != "0") {
                document.getElementById("PvcHid").value = PvcID;
            }
        }
        catch (error) { }
    }
    if (document.form2.Product.value == "")
        error(document.form2.Product, "感兴趣的产品忘了填写!");
//    else if (document.form2.department.value == "")
//        error(document.form2.department, "您的单位名称忘了填写!");
    else if (document.form2.yourname.value == "")
        error(document.form2.yourname, "您的姓名忘了填写!");
    else if (document.form2.phone.value == "")
        error(document.form2.phone, "联系电话忘了填写!");
    //else if(document.form2.addr.value=="")
    //error(document.form2.addr,"您的联系地址忘了填写!"); 
    //else if(document.form2.email.value=="")
    //error(document.form2.email,"您的常用邮箱忘了填写!");
    else if (!emailCheck()) {
        alert("Email地址有误");
        return false;
    }
//    else if (document.form2.message.value == "")
//        error(document.form2.message, "对产品的要求忘了填写!");
//    else if (PvcID == "" || PvcID == "0") {
//                alert("请选择您所在省份!");
//                return; 
//    }
    else {
        var inputs = document.getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == "submit" || inputs[i].type == "reset")
                inputs[i].disabled = "disabled";
        }
   
        fSaveP2VDo();
        //SendMSG.SendMessage(0);
        var a = _gelstn('body')[0];

        jQuery.ajax({
            url: "/SendMessage.aspx", //方法路径URL
            data: {
                Product: document.form2.Product.value,                   //产品
                department: document.form2.department.value,        //单位
                yourname: document.form2.yourname.value,          //姓名
                phone: document.form2.phone.value,                    //联系电话
                addr: document.form2.addr.value,        //详细地址
                email: document.form2.email.value,                  //邮箱
                message: document.form2.message.value,                 //意见建议
                Vnum: document.form2.Vnum.value,    //验证码
                selPvc:document.form2.PvcHid.value   //省份
            }, //参数
            dataType: 'json',
            type: 'POST',
            contentType: 'application/x-www-form-urlencoded; charset=utf-8',
            async: true, //默认异步调用11
            success: function (data) {
                var ret;
                try {
                    ret = eval(data);
                }
                catch (ex) {
                    ret = eval("data=" + data);
                }
                switch (ret.Success) {
                    case "1":
                        a.removeChild(document.getElementById("SaveWin"));
                        alert(ret.Detail);
                        window.parent.location.reload();
                        return true;
                    case "-1":
                    case "-2":
                    case "-3":
                    case "-5":
                    case "-2016001":
                    case "-2016002":
                        a.removeChild(document.getElementById("SaveWin"));
                        alert(ret.Detail);
                        return false;
                    default:
                        a.removeChild(document.getElementById("SaveWin"));
                        return false;
                }
            },
            error: function () {
                a.removeChild(document.getElementById("SaveWin"));
                alert('提交数据失败!');
                return false;
            }
        });
    }

}
function $$() { var elements = new Array(); for (var i = 0; i < arguments.length; i++) { var element = arguments[i]; if (typeof element == 'string') element = document.getElementById(element); if (arguments.length == 1) return element; elements.push(element); } return elements; }
function _gelstn(a) { return document.getElementsByTagName ? document.getElementsByTagName(a) : new Array(); }
function fPopSaveWin(pos) {
    var a = _gelstn('body')[0];
    var x = document.createElement("div");
    x.id = 'SaveWin';
    x.style.zIndex = 90;
    x.style.position = "absolute";
    x.style.left = 0;
    x.style.top = 0;
    x.style.right = 0;
    x.style.margin = 0;
    x.style.width = "100%";
    if (document.documentElement.scrollHeight > document.documentElement.clientHeight) {
        //有滚动条
        //x.style.height = buttom.offsetTop + buttom.offsetHeight;
        x.style.height = document.getElementsByName("ok")[0].offsetTop + document.getElementsByName("ok")[0].offsetHeight;
    }
    else {
        x.style.height = document.documentElement.clientHeight;
    }
    a.appendChild(x);
    var c = document.createElement('div');
    c.style.position = "absolute";
    c.style.filter = "alpha(opacity=50)";
    c.style.opacity = "0.5";
    c.style.backgroundColor = "#000";
    c.style.width = "100%";
    //alert(document.documentElement.clientHeight);
    c.style.height = x.style.height;
    //
    var b = document.createElement('div');
    b.style.textAlign = "center";
    b.style.position = "absolute";
    b.style.width = "95%";
    if (pos == "d") {
        b.style.top = order.offsetTop + order.offsetHeight;
    }
    else {
        b.style.top = (document.documentElement.clientHeight - 200) / 2;
    }
    var html = '' +
		'<div style="width:320px; height:120px; background-color:#FFFFFF; padding:2px;left:50%;top:50%;margin-left:-150px!important;margin-top:-60px!important;margin-top:0px;position:fixed!important;position:absolute;">' +
			'<div id="SaveFirstStep" style=" height:100%; width:100%; background-color:#f9fcff;border:1px solid #bccce1;font-size:12px">' +
				'<div style=" width:100%; height:29px; background-color:#ebf3fd">' +
					'<div style="padding:8px 0 0 8px;float:left;font:bold 14px "宋体"">正在处理' +
					'</div>' +
    //	'<div style="cursor:pointer;float:right; margin:7px 4px 0 0;" onclick="fCloseSaveInfo();"><img src="style/1/images/close.gif">' +
    //	'</div>' +
				'</div>' +
				'<div style=" height:25px; padding:20px 0 0 30px; text-align:left" id="SaveTitleInfo"><img src="/images/loading.gif">&nbsp;&nbsp;正在发送邮件,请稍候...' +
				'</div>' +
				'<div style="width:86%; font-size:0;border-top:1px dotted #CCCCCC;>' +
				'</div>' +
				'<div style=" width:100%;">' +

			'</div>' +
		'</div>';

    x.appendChild(c);
    x.appendChild(b);
    b.innerHTML = html;
}

function fCloseSaveInfo() {
    _gelstn('body')[0].removeChild($$("SaveWin"));
}


function fSaveP2VDo(p) {
    fPopSaveWin("d");
};