﻿// JavaScript Document
var script_ext = ".php";
var ajax_as = "#Pisces19860306/19760817Leo#";
var ajaxserver_path = "/global/ajax_server/";
var i = 0;
function onClickEvent(isForm, isObject) {
	switch (isForm.id) {
		case "eregistration_form":
			switch (isObject.id) {
				case "eregistration_button":
					if (isForm.chinese_name.value.length == 0) {
						alert("提示信息：请您输入负责人的姓名！");
						isForm.chinese_name.focus();
					} else
					if (isForm.mobile.value.length == 0) {
						alert("提示信息：请您输入电话号码！");
						isForm.mobile.focus();
					} else
					if (isForm.email.value.length == 0) {
						alert("提示信息：请您输入电子信箱地址！");
						isForm.email.focus();
					} else
					if (isForm.pattern.value == 0) {
						alert("提示信息：请您选择培训模式！");
						isForm.pattern.focus();
					} else
					if (isForm.cnumber.value.length == 0) {
						alert("提示信息：请您输入参加培训的人数！");
						isForm.cnumber.focus();
					} else
					if (isForm.budget.value.length == 0) {
						alert("提示信息：请您输入培训预算，单位：元/人！");
						isForm.budget.focus();
					} else
					if (isForm.company_name.value.length == 0) {
						alert("提示信息：请您输入企业名称！");
						isForm.company_name.focus();
					} else
					if (isForm.company_address.value.length == 0) {
						alert("提示信息：请您输入企业地址！");
						isForm.company_address.focus();
					} else {
						EvalObject("eregistration_send");
						var chinese_name = isForm.chinese_name.value
						var mobile = isForm.mobile.value
						var email = isForm.email.value
						var pattern = isForm.pattern.value
						var cnumber = isForm.cnumber.value
						var budget = isForm.budget.value
						var company_name = isForm.company_name.value
						var company_address = isForm.company_address.value
						var company_website = isForm.company_website.value
						sendClientData(isObjectEval, "chinese_name=" + chinese_name + "&mobile=" + mobile + "&email=" + email + "&pattern=" + pattern + "&cnumber=" + cnumber + "&budget=" + budget + "&company_name=" + company_name + "&company_address=" + company_address + "&company_website=" + company_website, "eregistration_send");
					}
					break;
			}
			break;
		case "pregistration_form":
			switch (isObject.id) {
				case "ok_button":
					var gender_object = document.getElementsByName("gender");
					var lo_object = document.getElementsByName("learning_objectives");
					var payment_object = document.getElementsByName("payment");
					i = 0;
					var gender = "";
					while (i < gender_object.length) {
						if (gender_object[i].checked) {
							gender = gender_object[i].value;
						}
						i ++;
					}
					i = 0;
					var lo = "";
					var lo_value = "";
					while (i < lo_object.length) {
						if (lo_object[i].checked) {
							lo_value += lo_object[i].value;
							lo += lo_object[i].value + "#LO#";
						} else {
							lo += "#LO#";
						}
						i ++;
					}
					i = 0;
					var payment = "";
					while (i < payment_object.length) {
						if (payment_object[i].checked) {
							payment = payment_object[i].value;
						}
						i ++;
					}
					if (isForm.chinese_name.value.length == 0) {
						alert("提示信息：请您输入中文姓名！");
						isForm.chinese_name.focus();
					} else
					if (gender.length == 0) {
						alert("提示信息：请您选择性别！");
					} else
					if (isForm.age.value.length == 0) {
						alert("提示信息：请您输入年龄！");
						isForm.age.focus();
					} else
					if (isForm.education.value.length == 0) {
						alert("提示信息：请您输入学历！");
						isForm.education.focus();
					} else
					if (isForm.mobile.value.length == 0) {
						alert("提示信息：请您输入手机号码");
						isForm.mobile.focus();
					} else
					if (isForm.email.value.length == 0) {
						alert("提示信息：请您输入电子信箱！");
						isForm.email.focus();
					} else
					if (isForm.city.value.length == 0) {
						alert("提示信息：请您输入城市名称！");
						isForm.city.focus();
					} else
					if (isForm.professional.value.length == 0) {
						alert("提示信息：请您输入职业！");
						isForm.professional.focus();
					} else
					if (lo_value.length == 0) {
						alert("提示信息：请您选择学习目的！");
					} else
					if (payment.length == 0) {
						alert("提示信息：请您选择支付方式！");
					} else {
						EvalObject("pregistration_send");
						var class_name = isForm.class_name.value;
						var chinese_name = isForm.chinese_name.value;
						var age = isForm.age.value;
						var education = isForm.education.value;
						var mobile = isForm.mobile.value;
						var email = isForm.email.value;
						var province = isForm.province.value;
						var city = isForm.city.value;
						var professional = isForm.professional.value;
						sendClientData(isObjectEval, "class_name=" + class_name + "&chinese_name=" + chinese_name + "&gender=" + gender + "&age=" + age + "&education=" + education + "&mobile=" + mobile + "&email=" + email + "&province=" + province + "&city=" + city + "&professional=" + professional + "&lo=" + lo + "&payment=" + payment, "pregistration_send");
					}
					break;
			}
			break;
		case "subscribe_form":
			switch (isObject.id) {
				case "subscribe_button":
					if (isForm.subscribe_email.value.length == 0) {
						alert("提示信息：请您输入电子邮件地址！");
						isForm.subscribe_email.focus();
					} else
					if (isForm.subscribe_type.value == 0) {
						alert("提示信息：请您从订阅列表中选择一个订阅类型！");
						isForm.subscribe_type.focus();
					} else {
						EvalObject("subscription_send");
						sendClientData(isObjectEval, "chinese_name=邮件订阅&email=" + isForm.subscribe_email.value + "&subscription_type=" + isForm.subscribe_type.value, "subscription_send");
					}
					break;
			}
			break;
		case "reservation_form":
			switch (isObject.id) {
				case "reservation_button":
					if (isForm.chinese_name.value.length == 0) {
						alert("提示信息：请您输入姓名！");
						isForm.chinese_name.focus();
					} else
					if (isForm.mobile.value.length == 0) {
						alert("提示信息：请您输入手机号码！");
						isForm.mobile.focus();
					} else
					if (isForm.email.value.length == 0) {
						alert("提示信息：请您输入电子信箱地址！");
						isForm.email.focus();
					} else
					if (isForm.course.value == 0) {
						alert("提示信息：请您选择课程！");
						isForm.course.focus();
					} else
					if (isForm.address.value.length == 0) {
						alert("提示信息：请您输入您的联系地址！");
						isForm.address.focus();
					} else {
						EvalObject("reservation_send");
						var chinese_name = isForm.chinese_name.value;
						var mobile = isForm.mobile.value;
						var email = isForm.email.value;
						var course = isForm.course.value;
						var address = isForm.address.value;
						sendClientData(isObjectEval, "chinese_name=" + chinese_name + "&mobile=" + mobile + "&email=" + email + "&course=" + course + "&address=" + address, "reservation_send");
					}
					break;
			}
			break;
		case "registration_form":
			switch (isObject.id) {
				case "send_button": register_option(isForm, isObject, "application_send"); break;
				case "reset_button": reset_option(isForm); break;
			}
			break;
		case "ceshi_form":
			switch (isObject.id) {
				case "send_button": register_option(isForm, isObject, "ceshi_send"); break;
				case "reset_button": reset_option(isForm); break;
			}
			break;
		case "studyguide_form":
			switch (isObject.id) {
				case "studyguide_button":
					if (isForm.chinese_name.value.length == 0) {
						alert("提示信息：请您输入姓名！");
						isForm.chinese_name.focus();
					} else
					if (isForm.mobile.value.length == 0) {
						alert("提示信息：请您输入电话号码！");
						isForm.mobile.focus();
					} else
					if (isForm.email.value.length == 0) {
						alert("提示信息：请您输入电子信箱地址！");
						isForm.email.focus();
					} else
					if (isForm.address.value.length == 0) {
						alert("提示信息：请您输入地址！");
						isForm.address.focus();
					} else {
						var chinese_name = isForm.chinese_name.value;
						var mobile = isForm.mobile.value;
						var email = isForm.email.value;
						var address = isForm.address.value;
						EvalObject("studyguide_send");
						sendClientData(isObjectEval, "chinese_name=" + chinese_name + "&mobile=" + mobile + "&email=" + email + "&address=" + address, "studyguide_send");
					}
					break;
			}
			break;
	}
}
function clearNoNumber(isObject) {
	isObject.value = isObject.value.replace(/[^\d.]/g,"");
	isObject.value = isObject.value.replace(/^\./g,"");
	isObject.value = isObject.value.replace(/\.{2,}/g,".");
	isObject.value = isObject.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}
function EvalObject(isObjectId) {
	var isObject_array = "{id:'" + isObjectId + "'}";
	isObjectEval = eval('(' + isObject_array + ')');
}
/* AJAX核心控制代码开始 */
function createAJAX() { AJAX = (window.ActiveXObject)?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest(); }
function sendClientData(isObject, isPostData, isUrl) {
	createAJAX();
	if (AJAX != null) {
		var post_data = isPostData;
		AJAX.open("post", ajaxserver_path + isUrl + script_ext +"?TimeStamp=" + new Date().getTime(), true);
		AJAX.onreadystatechange = function() { getServerData(isObject) };
		AJAX.setRequestHeader("Cache-Control","no-cache");
		AJAX.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		AJAX.send(post_data);
	}
}
/* AJAX核心控制代码结束 */

/* AJAX数据处理代码开始 */
function getServerData(isObject) {
	if (AJAX.readyState == 4) {
		if (AJAX.status == 200) {
			var getResults;
			var getResults = AJAX.responseText;
			var getResultsArray = getResults.split(ajax_as);
			switch (isObject.id) {
				case "eregistration_send":
					if (getResultsArray[0] == "OK") {
						alert("提示信息：您的信息已经提交至客户服务中心，我们会根据您提供的联系信息第一时间与您取得联系！");
						window.location.href = window.location.href;
					} else {
						alert("提示信息：与服务器通讯中断，请检查您的网络状态！");
					}
					break;
				case "pregistration_send":
					if (getResultsArray[0] == "OK") {
						alert("提示信息：您的信息已经提交至客户服务中心，我们会根据您提供的联系信息第一时间与您取得联系！");
						window.location.href = window.location.href;
					} else {
						alert("提示信息：与服务器通讯中断，请检查您的网络状态！");
					}
					break;
				case "subscription_send":
					if (getResultsArray[0] == "OK") {
						alert("提示信息：您的信息已经提交至客户服务中心，我们会根据您提供的联系信息第一时间与您取得联系！");
						window.location.href = window.location.href;
					} else {
						alert("提示信息：与服务器通讯中断，请检查您的网络状态！");
					}
					break;
				case "reservation_send":
					if (getResultsArray[0] == "OK") {
						alert("提示信息：预约成功，我们会根据您提供的联系信息第一时间与您取得联系！");
						window.location.href = window.location.href;
					} else {
						alert("提示信息：与服务器通讯中断，请检查您的网络状态！");
					}
					break;
				case "getCourse":
					var cl_array = getResultsArray[0].split("#CLASS_LIST#");
					var class_list = document.getElementById("course");
					var course_list = document.getElementById("course");
					var course_item = "";
					i = 0;
					while (i < cl_array.length-1) {
						class_items = new Option (cl_array[i], cl_array[i]);
						class_list.options.add(class_items);
						i ++;
					}
					i = 1;
					while (i < course_list.length) {
						course_item += '<option value="' + course_list[i].value + '">' + course_list[i].value; + '</option>'
						i ++;
					}
					document.getElementById("course_item").value = course_item;
					break;
				case "application_send": Results(getResultsArray[0], "ad2.php"); break; // 广告页跳转
				case "ceshi_send": Results(getResultsArray[0], "http://www.cambridgeesol.org/testyourenglish/"); break; // 广告页跳转
				case "studyguide_send":
					if (getResultsArray[0] == "OK") {
						alert("提示信息：您的信息已经提交至客户服务中心，我们会根据您提供的联系信息第一时间与您取得联系！");
						window.location.href = window.location.href;
					} else {
						alert("提示信息：与服务器通讯中断，请检查您的网络状态！");
					}
					break;
			}
		}
	}
}
function LoadCourse() {
	EvalObject("getCourse");
	sendClientData(isObjectEval, null, "getCourse");
}
function swpcontrol(isObject) {
	var swpcontrol_object = document.getElementById("swpcontrol_area").getElementsByTagName("div");
	var item_number = 0;
	while (item_number < swpcontrol_object.length) {
		if (swpcontrol_object[item_number].id == isObject.id) {
			document.getElementById(isObject.id + "_area").style.display = "block";
		} else {
			document.getElementById(swpcontrol_object[item_number].id + "_area").style.display = "none";
		}
		item_number ++;
	}
}
function Results(isResultsArray, isGo) {
	if (isResultsArray == "OK") {
	  alert("提示信息：您的信息已经提交至客户服务中心，我们会根据您提供的联系信息第一时间与您取得联系！");
	  window.location.href = isGo;
	} else {
	  alert("提示信息：与服务器通讯中断，请检查您的网络状态！");
	}
}
function register_option(isForm, isObject, isSendId) {
  var gender_object = document.getElementsByName("gender");
  var lo_object = document.getElementsByName("learning_objectives");
  i = 0;
  gender = "";
  while (i < gender_object.length) {
	  if (gender_object[i].checked) {
		  gender = gender_object[i].value;
	  }
	  i ++;
  }
  i = 0;
  lo = "";
  while (i < lo_object.length) {
	  if (lo_object[i].checked) {
		  lo += lo_object[i].value + "#LO#";
	  } else {
		  lo += "#LO#";
	  }
	  i ++;
  }
  if (isForm.chinese_name.value.length == 0) {
	  alert("提示信息：请您输入姓名！");
	  isForm.chinese_name.focus();
  } else
  if (gender.length == 0) {
	  alert("提示信息：请您选择性别！")
  } else
  if (isForm.mobile.value.length == 0) {
	  alert("提示信息：请您输入手机号码！");
	  isForm.mobile.focus();
  } else
  if (isForm.email.value.length == 0) {
	  alert("提示信息：请您输入电子信箱地址！");
	  isForm.email.focus();
  } else
  if (isForm.age.value.length == 0) {
	  alert("提示信息：请您输入年龄！");
	  isForm.age.focus();
  } else
  if (isForm.address.value.length == 0) {
	  alert("提示信息：请您输入您的联系地址！");
	  isForm.address.focus();
  } else
  if (lo.length == 0) {
	  alert("提示信息：请您选择学习目的！");
  } else {
	  EvalObject(isSendId);
	  var chinese_name = isForm.chinese_name.value;
	  var mobile = isForm.mobile.value;
	  var email = isForm.email.value;
	  var age = isForm.age.value;
	  var address = isForm.address.value;
	  var note = isForm.note.value;
	  var channel = isForm.channel.value;
	  sendClientData(isObjectEval, "chinese_name=" + chinese_name + "&gender=" + gender + "&mobile=" + mobile + "&email=" + email + "&age=" + age + "&address=" + address + "&lo=" + lo + "&note=" + note + "&channel=" + channel, "application_send");
  }
}
function reset_option(isForm) {
  var option = confirm("警告：这个操作将清空您现在正在填写的报名信息，您确认这样做吗");
  if (option) {
	  isForm.reset();
  }
}
function application() {
	var s = '<div class="l_bottom_left_021" title="在线预约">';
	s += '<h1></h1>';
	s += '<img src="/templets/cambridge/images/l_bottom_left_02_img_36.jpg" width="228" height="118" style="margin:0 0 0 2px;" />';
	s += '<form action="/" id="reservation_form" name="reservation_form" method="post">';
	s += '<ul>';
  s += '<li>姓名：<input type="text" class="l_bottom_inputs" id="chinese_name" name="chinese_name" maxlength="20"/></li>';
	s += '<li>电话：<input type="text"  class="l_bottom_inputs" id="mobile" name="mobile" maxlength="11" onkeyup="clearNoNumber(this);"/></li>';
  s += '<li>Mail：<input type="text" class="l_bottom_inputs" id="email" name="email" maxlength="50" /></li>';
	s += '<li>课程：<select class="l_bottom_inputs" id="course" name="course"><option value="0">--请选择课程--</option>' + document.getElementById("course_item").value + '</select></li>';
	s += '<li>城市：<input type="text" class="l_bottom_inputs" id="address" name="address" maxlength="50" /></li>';
	s += '<p class="l_sy_yuyue"><button id="reservation_button" onclick="onClickEvent(this.form, this);" id="reservation_button" type="button" style="background: url(/templets/cambridge/images/l_ky_26.jpg) no-repeat; height: 29px; width: 74px; cursor: pointer;"></button></p>';
  s += '</ul>';
  s += '</form>';
  s += '</div>';
	msgbox.Show('',s,'',230,380);///参数:标题,内容(提示为连接页面时可为空),连接页面地址(使用文字是可为空),宽度,高度 
}