﻿//Feedback的验证开始
var checkForm = function() {
    var bValid = true;
    var title = document.getElementById("txtTitle"),
       content = document.getElementById("txtContent"),
       companyName = document.getElementById("txtCompanyName"),
       tname = document.getElementById("txtName"),
       email = document.getElementById("txtEmail"),
       phone = document.getElementById("txtPhone"),
       fax = document.getElementById("txtFax"),
       url = document.getElementById("txtWebUrl");
       
       bValid = bValid && checkLength(title, 2, 50);
       bValid = bValid && checkLength(content, 2, 2000);
       bValid = bValid && checkLength(companyName, 2, 50);

       bValid = bValid && RegData(tname, "name");
       bValid = bValid && RegData(email, "email");
       bValid = bValid && RegData(phone, "phone");
       bValid = bValid && RegData(url, "url");
       bValid = bValid && RegData(fax, "fax");

    return bValid;
}

var RegData = function(obj, tag) {
    var reg;
    switch (tag) {
        case "email":
            reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
            break;
        case "url":
            reg = /^(http:\/\/www)?.+(com|cn|net)$/;
            break;
        case "fax":
            reg = /^\d{3}-?\d{8}|\d{4}-?\d{8}$/;
            break;
        case "phone":
            reg = /^\d{3,4}-?\d{7,8}$|^1[3|4|5|8][0-9]\d{8}$/;
            break;
        case "name":
            reg = /^[\u4e00-\u9fa5]{2,4}$|^[a-zA-Z]{3,12}$/;
            break;
        default: break;
    }
    if (tag != "name" && tag != "phone") {
        //验证网址，传真，电子邮箱，当为空是返回true,否则进行验证
        if (obj.value.length > 0) {
            if (!reg.exec(obj.value)) {
                obj.className = "error";
                obj.focus();
                return false;
            }
            else {
                obj.className = "";
                return true;
            }
        }
        else {
            return true;
        }
    }
    else {
        //验证姓名，联系电话
        if (!reg.exec(obj.value)) {
            obj.className = "error";
            obj.focus();
            return false;
        }
        else {
            obj.className = "";
            return true;
        }
    }
}
var checkLength = function(obj, min, max) {
    if (obj.value.length > max || obj.value.length < min) {
        obj.className = "error";
        obj.focus();
        return false;
    } else {
        obj.className = "";
        return true;
    }
}
//feedback的验证结束

//产品详细页面验证开始
var checkMobile = function() {
    var obj = document.getElementById("phone");
    var reg = /^1[3|4|5|8][0-9]\d{8}$/;
    if (!reg.exec(obj.value)) {
        obj.className = "error";
        obj.focus();
        return false;
    }
    else {
        obj.className = "";
        return true;
    }
}

function openwin() {
    window.open("/xunpan.html", "newwindow", "height=500, width=530, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
}

var openwinAd = function() {
    $.blockUI({
        message: $('#divXunpan'),
        css: {
            padding: 0,
            margin: 0,
            width: '600px',
            top: ($(window).height() - 600) / 2 + 'px',
            left: ($(window).width() - 542) / 2 + 'px',
            textAlign: 'center',
            color: '#000',
            border: '1px solid #aaa',
            cursor: 'pointer'
        }
    });
}

//产品详细页面验证结束
