﻿// JavaScript Document
//通用选项卡

function change(name,cursel,n,def,selc){
 for(i=1;i<=n;i++){
  var menu=document.getElementById(name+i);
  var con=document.getElementById("con_"+name+"_"+i);
  if(i==cursel)
  {
	  menu.className=def;
	  con.style.display="block";
  }
	else
	{
		menu.className=selc;
		con.style.display="none";
	}
 // menu.className=(i==cursel?"sec1":"sec2");
 // con.style.display=(i==cursel?"block":"none");
 }
}
function celCom(id) {
    document.getElementById("com" + id).className = "aboutselect";
}
function celUser(id) {
    document.getElementById("use" + id).className = "aboutselect";
}
function celTop(id) {
    if (id < 4) {
        document.getElementById("top" + id).className = "changetop";
    } else {
    document.getElementById("top" + id).className = "changetop1";
    }
}
function checkTeam() {
    if (isEmpty("StartTime")) {
        alert("出发日期不能为空!");
        return false;
    }
    if (isEmpty("Destination")) {
        alert("意向目的地不能为空!");
        return false;
    }
 
    if (isEmpty("realname")) { 
      alert("联系人不能为空!");
        return false;
    }
    if (isNaN(document.getElementById("fromtime3").value)) {
        alert("计划人数请输入数字！");
        return false;
    }
    if (isNaN(document.getElementById("realname3").value)) {
        alert("电话填写错误!");
        return false;
    }
    if (document.getElementById("realname4").value != "") {
        if (document.getElementById("realname4").value.indexOf("@") == -1 || document.getElementById("realname4").value.indexOf(".") == -1) {
            alert("电子邮件格式不正确!");
            return false;
        }
    }
}
function isEmpty(id) {

    if (!document.getElementById("" + id).value.replace(/(^\s*)|(\s*$)/g, "")) {
        return true ;
    }
    return false ;
}
/*检查字符串中是否含有危险字符串*/
function isDangerousString(str) {
    var pattern = /^[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']/;
    var isTrue = pattern.test(str);
    return isTrue;
}
//验证注册
function checkReg() {
    if (isEmpty("Name")) {
        alert("会员名不能为空!");
        return false;
    }
    if (isDangerousString($("#Name").val())) {
        alert("真实姓名中含敏感字符!");
        return false;
    }
    if (isEmpty("Password")) {
        alert("密码不能为空!");
        return false;
    } 
      if ($("#Password").val() == "" || $("#Password").val().length < 6) {
        alert("密码长度必须大于6!");
        return false;
    }
    if (isEmpty("Rpwd")) {
        alert("确认密码不能为空!");
        return false;
    }
 
    if (document.getElementById("Password").value != document.getElementById("Rpwd").value) {
        alert("密码和确认密码不一致!");
        return false;
    }
    if (isEmpty("vcode")) {
        alert("验证码不能为空!");
        return false;
    }
    if (isEmpty("Mobile")) {
        alert("手机号不能为空!");
        return false;
    }
    
    if (isEmpty("Email")) {
        alert("电子邮箱不能为空!");
        return false;
    }
    else {
        if (document.getElementById("Email").value.indexOf("@") == -1 || document.getElementById("Email").value.indexOf(".") == -1) {
            alert("电子邮件格式不正确!");
            return false;
        }
    }
if (!document.getElementById("IsRead").checked) {
        alert("未阅读服务条款");
        return false;
    }
    
}
function validName() {
    var url = "/HTML/CheckName?name=" + document.getElementById("Name").value;
    $.get(url, function(data) { 
     if(data=="false")
    {
     alert("此用户名已被注册!"); $("#Name").focus();} 
    });

}
function getTotal() {
    var nums = document.getElementsByName("pn");
    var pn = 0;
    var tot = 0;
    for (j = 0; j < nums.length; j++) {
        if (isNaN(nums[j].value)) {
            nums[j].value = 1;
        }

        pn = pn + parseInt(nums[j].value);
        if (navigator.appName.indexOf("Explorer") > -1) {

            tot += parseInt(nums[j].value * (document.getElementById("p" + j).innerText));
        } else {
            tot += parseInt(nums[j].value * (document.getElementById("p" + j).textContent));
        }
    }

    if (navigator.appName.indexOf("Explorer") > -1) {
        document.getElementById("stotal").innerText = tot;
        document.getElementById("pnum").innerText = pn;
    } else {
        document.getElementById("stotal").textContent = tot;
        document.getElementById("pnum").textContent = pn;
    }
   //document.getElementById("htotal").value = tot;
}
function addord() {
    var pattern = /^\\S+$/;

    if (!$("#Name").val().replace(/(^\s*)|(\s*$)/g, "")) {
        alert("真实姓名不能为空!");
        return false;
    }
    if (!$("#Mobile").replace(/(^\s*)|(\s*$)/g, "")) {
        alert("手机号不能为空!");
        return false;
    }

    if (isDangerousString($("#Name").val())) {
        alert("真实姓名中含敏感字符!");
        return false;
    }
    if (isMobilePhoneNumber($("#Mobile").val())) {
        alert("手机号输入不正确!");
        return false;
    }
    if (isTelphoneNumber($("#Tel").val())) {
        alert("电话号码输入不正确!");
        return false;
    }
}
