// JavaScript Document

//弹出一个小窗口
function popUpWindow(link){
	var goPage = window.open(link, "newwindow", "height=300,width=400,top=0,left=0,toolbar=no,alwaysRaised=yes,menubar=no,scrollbars=yes, resizable=no,location=no, status=no, left=" + (screen.width - 400) / 2 + ",top=" + (screen.height - 300) / 2);
	goPage.focus();
}

//
var info = null;

function update(id, url) {
		new Ajax.Updater(id, url, {method: "get", evalScripts: true});
}

function post(id, url, form) {
		new Ajax.Updater(id, url, {method: "post", parameters:Form.serialize(form), evalScripts: true});
}

function toggle(id) {
	if ($(id).style.display == 'none') {
		$(id).style.display = 'block';
	} else {
		$(id).style.display = 'none';
	}
}

var sUserAgent = navigator.userAgent;
var isOpera = sUserAgent.indexOf("Opera") > -1;
var isIE = sUserAgent.indexOf("compatible") > -1 && sUserAgent.indexOf("MSIE") > -1 && !isOpera;

var loadingFrame = '<link href="/css/dilu.css" rel="stylesheet" type="text/css" />';
loadingFrame += '<div class="mol_show" style="width:412px;overflow:hidden">';
loadingFrame += '<div class="sh_box" style="height:291px;">';
loadingFrame += '<img src="/images/indicator_small.gif" /> Loading...';
loadingFrame += '</div>';
loadingFrame += '</div>';

var outObject;

///////////////////////////////////////////////////
// job selector function

function findSelectedJob() {
	var chk=document.getElementsByName('sjs');
	var arrays = new Array();
	for(var i=0;i < chk.length;i++) {
		if(chk[i].checked){
			arrays.push(chk[i].value);
		}
	}
	
	return arrays;
}

function showSelector() {
	var top = document.documentElement.scrollTop;
	var left = document.documentElement.scrollLeft;

	var selectedLeft = document.documentElement.clientWidth * 0.13 + left;
	var selectedTop = document.documentElement.clientHeight * 0.15 + top;

	if (isIE) {
		$("disableDiv").style.left = left;
		$("disableDiv").style.top = top;

		$("selected_layer").style.left = selectedLeft;
		$("selected_layer").style.top = selectedTop;
	} else {
		$("selected_layer").style.left = selectedLeft + "px";
		$("selected_layer").style.top = selectedTop + "px";
	}

	$("disableDiv").style.display="block";

	document.body.scroll = "no";
	document.body.style.overflow = "hidden";

	$("selected_layer").style.display="block";
}

function hideSelectLayer(){
	document.body.scroll = "auto";
	document.body.style.overflow = "auto";
	
    $("disableDiv").style.display="none";
	$("selected_layer").style.display="none";	
}   

///////////////////////////////////////////////////
// location selector function

function replaceFrame(response) {
	$('jaceLocationLayer').contentWindow.document.writeln(response.responseText);
	$('jaceLocationLayer').contentWindow.document.close();
}

function setSchool(textbox, valueObject, languageVersion) {
	$('jaceLocationLayer').contentWindow.document.writeln(loadingFrame);
	$('jaceLocationLayer').contentWindow.document.close();
	var params = 'labelId=' + textbox.getAttribute("id");
	
	if (valueObject !== null) {
		params += '&valueId=' + valueObject.getAttribute("id");
	}

	if (valueObject.value === null) {
		new Ajax.Request('/common/showSchools.htm', {method: 'post', parameters: params + '&languageVersion=' + languageVersion, evalScripts: true, onComplete: replaceFrame});
	} else {
		new Ajax.Request('/common/showSchools.htm', {method: 'post', parameters: params + '&languageVersion=' + languageVersion + '&schoolId=' + valueObject.value, evalScripts: true, onComplete: replaceFrame});
	}

	var dads  = $('jaceLocationLayer').style;
	var th = textbox;
	var ttop  = textbox.offsetTop;     //textbox控件的定位点高
	var thei  = textbox.clientHeight;  //textbox控件本身的高
	var tleft = textbox.offsetLeft;    //textbox控件的定位点宽
	var ttyp  = textbox.type;          //textbox控件的类型
	while ((textbox = textbox.offsetParent) !== null){ttop+=textbox.offsetTop; tleft+=textbox.offsetLeft;}
	if(ttop>328) {
		if (isIE) {
			dads.top  = ((ttyp=="image")? ttop-dads.pixelHeight : ttop-6-dads.pixelHeight);
		} else {
			dads.top  = ((ttyp=="image")? ttop-dads.pixelHeight : ttop-6-dads.pixelHeight) + "px";
		}
	} else {
		if (isIE) {
			dads.top  = (ttyp=="image")? ttop+thei : ttop+thei+6;
		} else {
			dads.top  = ((ttyp=="image")? ttop+thei : ttop+thei+6) + "px";
		}
	}
	outObject = th;
	if (isIE) {
		dads.left = tleft;
	} else {
		dads.left = tleft + "px";
	}

	dads.display='block';
}

function closeSchool() {
	$('jaceLocationLayer').style.display='none';
}

//任意点击时关闭该控件        //ie6的情况可以由下面的切换焦点处理代替
document.onclick=function(e) {
	e = window.event || e;
	var srcElement = e.srcElement || e.target;
	if (srcElement != outObject && $('jaceLocationLayer'))
		closeSchool();
}

//按Esc键关闭，切换焦点关闭
document.onkeyup=function(e) {
	e = window.event || e;
	var activeElement = document.activeElement || e.explicitOriginalTarget;
	if (e.keyCode==27 && $('jaceLocationLayer')) {
		if(outObject)
			outObject.blur();
		closeSchool();
	} else if(activeElement && $('jaceLocationLayer'))
		if(activeElement != outObject) {
			closeSchool();
	}
}


function isDate(str){ 
var reg = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/
if (reg.test(str)) return true;
return false;
} 

function checkEmail() {
	var email = $("email");
	info = $("emailInfo").innerHTML;
	if (email.value == null || email.value.length < 1) {
		$("emailInfo").innerHTML = '<font color=\"red\">请填写Email</font>';
		return;
	}
	
	if (!check(email.value)) {
		$("emailInfo").innerHTML = '<font color=\"red\">Email格式不正确。</font>';
		return;
	}
	
	email.disabled = true;
	$("emailInfo").innerHTML = '正在验证Email...';
	new Ajax.Request('/system/user.dl', {method:"post", parameters:"email="+email.value+"&method=check", onSuccess:checkResponse});
}

function check(email) {
	if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
}

function checkResponse(response) {
	$("email").disabled = false;
	var result = response.responseXML.getElementsByTagName("result");
	if (result[0].getAttribute("code") != 200) {
		$("emailInfo").innerHTML = "<font color=\"red\">Email已经被占用，请使用别的Email进行注册。</font>";
		$("button").disabled = true;
	} else {
		$("emailInfo").innerHTML = '<font color=\"green\">Email可以使用。</font>';
		$("button").disabled = false;
	}
}

function checkIdcard() {
	var idcardReg = /(^[a-zA-Z0-9]+)/;
	if ($("idcardno").value == null || $("idcardno").value.length < 1) {
		$("idcardNoInfo").innerHTML = '<font color=\"red\">请填写身份证号</font>';
	} else{
		$("idcardNoInfo").innerHTML = '<font color=\"green\">身份证号正确</font>';
	}
}

function checkPassword() {
	if ($("password").value == null || $("password").value.length < 6) {
		$("passwordInfo").innerHTML = '<font color=\"red\">密码长度不够</font>';
	} else {
		$("passwordInfo").innerHTML = '<font color=\"green\">密码正确</font>';
	}
}

function checkConfirmPassword() {
	if ($("confirmPassword").value == null || $("confirmPassword").value.length < 1) {
		$("confirmPasswordInfo").innerHTML = '<font color=\"red\">请填写确认密码</font>';
	}
	
	if ($("password").value != $("confirmPassword").value) {
		$("confirmPasswordInfo").innerHTML = '<font color=\"red\">密码和确认密码不一致</font>';
	} else {
		$("confirmPasswordInfo").innerHTML = '<font color=\"green\">确认密码正确</font>';
	}
}

function register() {
	if ($("email").value == null || $("email").value.length < 1) {
		$("emailInfo").innerHTML = '<font color=\"red\">请填写Email</font>';
		return;
	}
	
	if (!check($("email").value)) {
		$("emailInfo").innerHTML = '<font color=\"red\">Email格式不正确。</font>';
		return;
	}

	if ($("idcardno").value == null || $("idcardno").value.length < 1) {
		$("idcardNoInfo").innerHTML = '<font color=\"red\">请填写身份证号</font>';
		return;
	}

	if ($("password").value == null || $("password").value.length < 1) {
		$("passwordInfo").innerHTML = '<font color=\"red\">请填写密码</font>';
		return;
	}

	if ($("confirmPassword").value == null || $("confirmPassword").value.length < 1) {
		$("confirmPasswordInfo").innerHTML = '<font color=\"red\">请填写确认密码</font>';
		return;
	}

	if ($("password").value != $("confirmPassword").value) {
		$("confirmPasswordInfo").innerHTML = '<font color=\"red\">密码和确认密码不一致</font>';
		return;
	}

	//var idcardReg = /(^[a-zA-Z]+)/;
	//if(!idcardReg.test($("idcardno").value)){
	//	$("idcardNoInfo").innerHTML = '<font color=\"red\">请输入正确证件号</font>';
	//}

	if($("checkbox").getAttribute("checked")== false){
		$("agreementInfo").innerHTML = '<font color=\"red\">同意用户协议才能注册</font>';
		return;
	}

	$("registerForm").submit();
}

function forgetPassword() {
	if ($("email").value == null || $("email").value.length < 1) {
		$("emailInfo").innerHTML = '<font color=\"red\">请填写Email</font>';
		return;
	}
	if (!check($("email").value)) {
		$("emailInfo").innerHTML = '<font color=\"red\">Email格式不正确。</font>';
		return;
	}
		
	$("forgetPasswordForm").submit();
}

function login(posted) {
	if ($('email').value == null || $('email').value == '') {
		alert('Email不能为空。');
		return;
	}

	if (!check($("email").value)) {
		alert('Email格式不正确。');
		return;
	}

	if ($('password').value == null || $('password').value == '') {
		alert('密码不能为空。');
		return;
	}

	if ($('password').value.length < 6) {
		alert('密码太短。');
		return;
	}

	if ($('checkCode').value == null || $('checkCode').value == '') {
		alert('验证码不能为空。');
		return;
	}

	if (posted) {
		post('login', '/system/user.dl', 'loginForm');
	} else {
		loginForm.submit();
	}
}

//personal页面的检查项
function checkBirthdate() {

		if(!($("birthDate").value == null || $("birthDate").value.length < 1)&&!isDate($("birthDate").value)){
	    alert("请输入正确的日期.例如：2000-01-02");
	    $("birthDate").focus();
	    return;
	}
}

//CV中的base_info页面的检查必填项
function checkCvBaseInfo() {
	if ($("surname").value == null || $("surname").value.length < 1) {
		alert("请填写您的姓！");
		return;
	}
	
	if ($("firstname").value == null || $("firstname").value.length < 1) {
		alert("请填写您的名！");
		return;
	}
	
	if ($("birthDate").value == null || $("birthDate").value.length < 1) {
		alert("请填写您的生日！");
		return;
	}else if(!isDate($("birthDate").value)){
	    alert("请输入正确的生日日期.例如：2000-01-02");
	    return;
	}
	
	if ($("idcardTypeId").value == null || $("idcardTypeId").value.length < 1) {
		alert("请填写您的证件类型！");
		return;
	}
	
	if ($("idcardNo").value == null || $("idcardNo").value.length < 1) {
		alert("请填写您的身份证号！");
		return;
	}
	
	//var idcardReg = /(^[0-9a-zAZ-Z]+)/;
	//if(!idcardReg.test($("idcardno").value)){
	//	alert("请您输入正确的证件号");
	//	return;
	//}
	
	if ($("address").value == null || $("address").value.length < 1) {
		alert("请填写您的联系地址！");
		return;
	}
	
	if ($("email").value == null || $("email").value.length < 1 ) {
		alert("请填写您的邮箱！");
		return;
	}
	
	var email = $("email");
	if(!check(email.value)){
		alert("请您输入正确的电子邮箱地址！");
		return;
	}

	if ($("availableDate").value == null || $("availableDate").value.length < 1) {
		alert("请填写您能上班的日期！");
		return;
	}else if(!isDate($("availableDate").value)){
	    alert("请输入正确的上班日期.例如：2000-01-02");
	    return;
	}
	
	if ($("countryId").options[$("countryId").selectedIndex].value == "NULL") {
		alert("请填写您所在的国家！");
		return false;
	}
	
//	if ($("hukouProvinceId").options[$("hukouProvinceId").selectedIndex].value == "NULL" && ($("hukouCountryOther").value == null || $("hukouCountryOther").value.length < 1)) {
//		alert("请填写您的户口所在地！");
//		return false;
//	}
	
	if ($("mobile").value == null || $("mobile").value.length < 1) {
		alert("请填写您的手机号码！");
		return;
	}
	
	/*yangcb 10.15
	var mobile = $("mobile");
	if(!isValidPhone(mobile.value)){
		alert("请您输入正确的手机号码！");
		return;
	}
	*/
	
	if ($("availableDate").value < $("birthDate").value) {
		alert("请正确填写您的生日或最早可上班时间！");
		return;
	}
			
	$("cv").submit();
}

//CV中的education页面的检查必填项
function checkEducationForm() {
	if ($("school").value == null || $("school").value.length < 1) {
		alert("请填写您的学校！");
		return false;
	}
	
	if ($("major").options[$("major").selectedIndex].value == "NULL") {
		alert("请填写您的专业！");
		return false;
	}
	
	if ($("degree").options[$("degree").selectedIndex].value == "NULL") {
		alert("请填写您的学位！");
		return false;
	}
	
	if ($("gpa").options[$("gpa").selectedIndex].value == "NULL") {
		alert("请填写您的GPA！");
		return false;
	}
	
	if($("fromYear").value>$("toYear").value || ($("fromYear").value==$("toYear").value && $("fromMonth").value>$("toMonth").value) ){
		alert("请正确填写您的受教育时间！");
		return false;
	}	
	return true;
}

//CV中的证书必填项校验
function checkQualificationForm() {
	if ($("courseName").value == null || $("courseName").value.length < 1) {
		alert("请填写您的证书的名称！");
		return false;
	}
	
	if ($("courseProvider").value == null || $("courseProvider").value.length < 1) {
		alert("请填写您的证书的颁发者！");
		return false;
	}
	
	return true;
}

//CV中的奖学金必填项校验
function checkAwardForm() {
	if ($("awardName").value == null || $("awardName").value.length < 1) {
		alert("请填写您的奖学金名称！");
		return false;
	}
	
	if ($("grantBy").value == null || $("grantBy").value.length < 1) {
		alert("请填写您的奖学金颁发机构！");
		return false;
	}
	
	return true;
}

//CV中的课外活动必填项校验
function checkCurriculumForm() {
	if ($("curriculumName").value == null || $("curriculumName").value.length < 1) {
		alert("请填写您的课外活动名称！");
		return false;
	}
	
	if ($("remark").value == null || $("remark").value.length < 1) {
		alert("请填写您的课外活动内容！");
		return false;
	}
	
	if($("fromYear").value>$("toYear").value || ($("fromYear").value==$("toYear").value && $("fromMonth").value>$("toMonth").value) ){
		alert("请正确填写您的课外活动时间！");
		return false;
	}
	
	return true;
}

//CV中的课外活动必填项校验
function checkLanguageTestForm() {
	if ($("testId").options[$("testId").selectedIndex].value == "NULL") {
		alert("请填写您的语言考试名称！");
		return false;
	}
	
	if ($("result").value == null || $("result").value.length < 1) {
		alert("请填写您的语言考试的成绩或者等级！");
		return false;
	}
	
	return true;
}

//CV中的工作经历必填项校验
function checkWorkHistoryForm() {	
	if ($("jobTitle").value == null || $("jobTitle").value.length < 1) {
		alert("请填写您的职位名称！");
		return false;
	}
	
	if ($("workCountry").options[$("workCountry").selectedIndex].value == "NULL") {
		alert("请填写您的工作所在国家！");
		return false;
	}
	
	if ($("workCity").options[$("workCity").selectedIndex].value == "NULL") {
		alert("请填写您的工作所在城市！");
		return false;
	}
	
	if ($("jobType").options[$("jobType").selectedIndex].value == "NULL") {
		alert("请填写您的工作类型！");
		return false;
	}
	
	if ($("employer").value == null || $("employer").value.length < 1) {
		alert("请填写您的雇主！");
		return false;
	}
	
	if ($("achievement").value == null || $("achievement").value.length < 1) {
		alert("请填写您的主要成果！");
		return false;
	}

//	if($("fromYear").value>$("toYear").value || ($("fromYear").value==$("toYear").value && $("fromMonth").value>$("toMonth").value) ){
	if($("fromYear").value>$("toYear").value){
		alert("请正确填写您的工作经历时间！");
		return false;
	}
	
	return true;
}

//CV中的推荐人必填项校验
function checkReferenceForm() {	
	if ($("refName").value == null || $("refName").value.length < 1) {
		alert("请填写您的推荐人的姓名！");
		return false;
	}
	
	if ($("refCompanyId").value == null || $("refCompanyId").value.length < 1) {
		alert("请填写您的推荐人所在的公司！");
		return false;
	}
	
	if ($("refTel").value == null || $("refTel").value.length < 1 ) {
		alert("请填写您的推荐人的电话！");
		return false;
	}
	
	if ($("refTel").value == null || $("refTel").value.length < 1 ) {
		alert("请填写您的推荐人的电话！");
		return false;
	}
	/*
	var refTel = $("refTel");
	if(!isValidPhone(refTel.value)){
		alert("请您输入有效的电话号码！");
		return;
	}
	*/
	
	if ($("refRelationship").value == null || $("refRelationship").value.length < 1) {
		alert("请填写您和推荐人的关系！");
		return false;
	}
	
	return true;
}


//光标在验证码栏按回车登陆
function enterToSubmit(){
	 if (event.keyCode == 13) {
        event.returnValue=false;
        event.cancel = true;
        $("submitButton").click();
    }
}

function outTime() {
	var now = new Date();
	var day = now.getDay();
	var week = null;
	var hour = now.getHours();
	var welcome = null;
	if(hour >= 0 && hour < 5) 
		welcome = "凌晨好"
	if(hour >= 5 && hour < 8) 
		welcome = "早上好"
	if(hour >= 8 && hour < 11) 
		welcome = "上午好"
	if(hour >= 11 && hour < 13) 
		welcome = "中午好"
	if(hour >= 13 && hour < 17) 
		welcome = "下午好"
	if(hour >= 17 && hour < 24) 
		welcome = "晚上好"

 	switch (day) {   
	case 0:   
		week = "星期日";   
		break;
	case 1:   
		week = "星期一";   
		break;
	case 2:   
		week = "星期二";   
		break;
	case 3:   
		week = "星期三";   
		break;
	case 4:   
		week = "星期四";   
		break;
	case 5:   
		week = "星期五";   
		break;
	case 6:   
		week = "星期六";   
		break; 
	}
	
	document.write(welcome + "，今天是：" + now.getYear() + "年" + (now.getMonth() + 1) + "月" + now.getDate() + "日 " + week);
}

//控制TextArea的输入字符串长度 使用实例：<textarea maxlength="10" onkeyup="return isMaxLen(this);" onblur="return isMaxLen(this);"></textarea>
function isMaxLen(o){ 
	var nMaxLen=o.getAttribute? parseInt(o.getAttribute("maxlength")):""; 
	if(o.getAttribute && o.value.length>nMaxLen){ 
	o.value=o.value.substring(0,nMaxLen) 
	} 
} 

var Spry;
if (!Spry) Spry = {};
if (!Spry.Widget) Spry.Widget = {};

Spry.Widget.TabbedPanels = function(element, opts)
{
	this.element = this.getElement(element);
	this.defaultTab = 0;
	this.tabSelectedClass = "TabbedPanelsTabSelected";
	this.tabHoverClass = "TabbedPanelsTabHover";
	this.tabFocusedClass = "TabbedPanelsTabFocused";
	this.panelVisibleClass = "TabbedPanelsContentVisible";
	this.focusElement = null;
	this.hasFocus = false;
	this.currentTabIndex = 0;
	this.enableKeyboardNavigation = true;

	Spry.Widget.TabbedPanels.setOptions(this, opts);

	if (typeof (this.defaultTab) == "number")
	{
		if (this.defaultTab < 0)
			this.defaultTab = 0;
		else
		{
			var count = this.getTabbedPanelCount();
			if (this.defaultTab >= count)
				this.defaultTab = (count > 1) ? (count - 1) : 0;
		}

		this.defaultTab = this.getTabs()[this.defaultTab];
	}

	if (this.defaultTab)
		this.defaultTab = this.getElement(this.defaultTab);

	this.attachBehaviors();
};

Spry.Widget.TabbedPanels.prototype.getElement = function(ele)
{
	if (ele && typeof ele == "string")
		return document.getElementById(ele);
	return ele;
};

Spry.Widget.TabbedPanels.prototype.getElementChildren = function(element)
{
	var children = [];
	var child = element.firstChild;
	while (child) {
		if (child.nodeType == 1 /* Node.ELEMENT_NODE */)
			children.push(child);
		child = child.nextSibling;
	}
	return children;
};

Spry.Widget.TabbedPanels.prototype.addClassName = function(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) != -1))
		return;
	ele.className += (ele.className ? " " : "") + className;
};

Spry.Widget.TabbedPanels.prototype.removeClassName = function(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) == -1))
		return;
	ele.className = ele.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), "");
};

Spry.Widget.TabbedPanels.setOptions = function(obj, optionsObj, ignoreUndefinedProps)
{
	if (!optionsObj)
		return;
	for (var optionName in optionsObj) {
		if (ignoreUndefinedProps && optionsObj[optionName] == undefined)
			continue;
		obj[optionName] = optionsObj[optionName];
	}
};

Spry.Widget.TabbedPanels.prototype.getTabGroup = function()
{
	if (this.element) {
		var children = this.getElementChildren(this.element);
		if (children.length)
			return children[0];
	}
	return null;
};

Spry.Widget.TabbedPanels.prototype.getTabs = function()
{
	var tabs = [];
	var tg = this.getTabGroup();
	if (tg)
		tabs = this.getElementChildren(tg);
	return tabs;
};

Spry.Widget.TabbedPanels.prototype.getContentPanelGroup = function()
{
	if (this.element) {
		var children = this.getElementChildren(this.element);
		if (children.length > 1)
			return children[1];
	}
	return null;
};

Spry.Widget.TabbedPanels.prototype.getContentPanels = function()
{
	var panels = [];
	var pg = this.getContentPanelGroup();
	if (pg)
		panels = this.getElementChildren(pg);
	return panels;
};

Spry.Widget.TabbedPanels.prototype.getIndex = function(ele, arr)
{
	ele = this.getElement(ele);
	if (ele && arr && arr.length) {
		for (var i = 0; i < arr.length; i++) {
			if (ele == arr[i])
				return i;
		}
	}
	return -1;
};

Spry.Widget.TabbedPanels.prototype.getTabIndex = function(ele)
{
	var i = this.getIndex(ele, this.getTabs());
	if (i < 0)
		i = this.getIndex(ele, this.getContentPanels());
	return i;
};

Spry.Widget.TabbedPanels.prototype.getCurrentTabIndex = function()
{
	return this.currentTabIndex;
};

Spry.Widget.TabbedPanels.prototype.getTabbedPanelCount = function(ele)
{
	return Math.min(this.getTabs().length, this.getContentPanels().length);
};

Spry.Widget.TabbedPanels.addEventListener = function(element, eventType, handler, capture)
{
	try {
		if (element.addEventListener)
			element.addEventListener(eventType, handler, capture);
		else if (element.attachEvent)
			element.attachEvent("on" + eventType, handler);
	} catch (e) {}
};

Spry.Widget.TabbedPanels.prototype.onTabClick = function(e, tab)
{
	this.showPanel(tab);

	if (e.preventDefault) e.preventDefault();
	else e.returnValue = false;
	if (e.stopPropagation) e.stopPropagation();
	else e.cancelBubble = true;

	return false;
};

Spry.Widget.TabbedPanels.prototype.onTabMouseOver = function(e, tab)
{
	this.addClassName(tab, this.tabHoverClass);
	return false;
};

Spry.Widget.TabbedPanels.prototype.onTabMouseOut = function(e, tab)
{
	this.removeClassName(tab, this.tabHoverClass);
	return false;
};

Spry.Widget.TabbedPanels.prototype.onTabFocus = function(e, tab)
{
	this.hasFocus = true;
	this.addClassName(tab, this.tabFocusedClass);
	return false;
};

Spry.Widget.TabbedPanels.prototype.onTabBlur = function(e, tab)
{
	this.hasFocus = false;
	this.removeClassName(tab, this.tabFocusedClass);
	return false;
};

Spry.Widget.TabbedPanels.ENTER_KEY = 13;
Spry.Widget.TabbedPanels.SPACE_KEY = 32;

Spry.Widget.TabbedPanels.prototype.onTabKeyDown = function(e, tab)
{
	var key = e.keyCode;
	if (!this.hasFocus || (key != Spry.Widget.TabbedPanels.ENTER_KEY && key != Spry.Widget.TabbedPanels.SPACE_KEY))
		return true;

	this.showPanel(tab);

	if (e.preventDefault) e.preventDefault();
	else e.returnValue = false;
	if (e.stopPropagation) e.stopPropagation();
	else e.cancelBubble = true;

	return false;
};

Spry.Widget.TabbedPanels.prototype.preorderTraversal = function(root, func)
{
	var stopTraversal = false;
	if (root)
	{
		stopTraversal = func(root);
		if (root.hasChildNodes()) {
			var child = root.firstChild;
			while (!stopTraversal && child) {
				stopTraversal = this.preorderTraversal(child, func);
				try { child = child.nextSibling; } catch (e) { child = null; }
			}
		}
	}
	return stopTraversal;
};

Spry.Widget.TabbedPanels.prototype.addPanelEventListeners = function(tab, panel)
{
	var self = this;
	Spry.Widget.TabbedPanels.addEventListener(tab, "click", function(e) { return self.onTabClick(e, tab); }, false);
	Spry.Widget.TabbedPanels.addEventListener(tab, "mouseover", function(e) { return self.onTabMouseOver(e, tab); }, false);
	Spry.Widget.TabbedPanels.addEventListener(tab, "mouseout", function(e) { return self.onTabMouseOut(e, tab); }, false);

	if (this.enableKeyboardNavigation) {
		var tabIndexEle = null;
		var tabAnchorEle = null;

		this.preorderTraversal(tab, function(node) {
			if (node.nodeType == 1) {
				var tabIndexAttr = tab.attributes.getNamedItem("tabindex");
				if (tabIndexAttr) {
					tabIndexEle = node;
					return true;
				}
				if (!tabAnchorEle && node.nodeName.toLowerCase() == "a")
					tabAnchorEle = node;
			}
			return false;
		});

		if (tabIndexEle)
			this.focusElement = tabIndexEle;
		else if (tabAnchorEle)
			this.focusElement = tabAnchorEle;

		if (this.focusElement) {
			Spry.Widget.TabbedPanels.addEventListener(this.focusElement, "focus", function(e) { return self.onTabFocus(e, tab); }, false);
			Spry.Widget.TabbedPanels.addEventListener(this.focusElement, "blur", function(e) { return self.onTabBlur(e, tab); }, false);
			Spry.Widget.TabbedPanels.addEventListener(this.focusElement, "keydown", function(e) { return self.onTabKeyDown(e, tab); }, false);
		}
	}
};

Spry.Widget.TabbedPanels.prototype.showPanel = function(elementOrIndex)
{
	var tpIndex = -1;
	
	if (typeof elementOrIndex == "number")
		tpIndex = elementOrIndex;
	else // Must be the element for the tab or content panel.
		tpIndex = this.getTabIndex(elementOrIndex);
	
	if (!tpIndex < 0 || tpIndex >= this.getTabbedPanelCount())
		return;

	var tabs = this.getTabs();
	var panels = this.getContentPanels();

	var numTabbedPanels = Math.max(tabs.length, panels.length);

	for (var i = 0; i < numTabbedPanels; i++) {
		if (i != tpIndex) {
			if (tabs[i])
				this.removeClassName(tabs[i], this.tabSelectedClass);
			if (panels[i]) {
				this.removeClassName(panels[i], this.panelVisibleClass);
				panels[i].style.display = "none";
			}
		}
	}

	this.addClassName(tabs[tpIndex], this.tabSelectedClass);
	this.addClassName(panels[tpIndex], this.panelVisibleClass);
	panels[tpIndex].style.display = "block";

	this.currentTabIndex = tpIndex;
};

Spry.Widget.TabbedPanels.prototype.attachBehaviors = function(element)
{
	var tabs = this.getTabs();
	var panels = this.getContentPanels();
	var panelCount = this.getTabbedPanelCount();

	for (var i = 0; i < panelCount; i++)
		this.addPanelEventListeners(tabs[i], panels[i]);

	this.showPanel(this.defaultTab);
};


var trObject = null;

function clickTr(tr) {
	if (trObject != null) {
		trObject.className = "unselected";
		tr.className = "selected";
	} else {
		tr.className = "selected";
	}
	
	trObject = tr;
}


//-------------------------------------------------------------------------------------------------------------//
function xing(){
	if(personal.surname.value==''){
		alert('不能为空'); 
		personal.surname.focus();
	}else{
		return;
	}
}

function ming(){
	if(personal.firstname.value==''){
		alert('不能为空'); 
		personal.firstname.focus();
	}else{
		return;
	}
}


var id;
var type;
var Phone;
var Post;
 /*-------------------------------------------------------------------------------------------------------
 //校验是否为合法的身份证号码
// 只能是数字，15或18位，18位的最后一位可以是x*/
function checkID(id) 
{ 
	if(id.value==''){
		alert('证件编号不能为空'); 
		personal.idcardNo.focus();
		return;
	}
	//var id = /(^[a-zA-Z0-9]+)/;
	//if(!id.test($("idcardno").value)){
	//	alert("请输入正确的身份证号");
	//	personal.idcardNo.focus();
	//	return;
	//}
} 

/*-------------------------------------------------------------------------------------------------------*/
/* 函数功能：固话，手机号码检查函数，合法返回null,反之,返回错误信息
函数参数：value,待检查的号码
检查规则：
　　(1)区号用"("、")"或"-"和其他部分隔开成
　　(2)电话号码为7到8位
　　(3)如果电话号码中包含有区号，那么区号为三位或四位
　　(4)移动电话号码为11或12位，如果为12位,那么第一位为0

function checkPhone(Phone)
{
	if(Phone.value=="" || Phone.value==null){
		return ;
	}
	//var Phone=/(^[0]\d{2}\-\d{8}$)|(^[0]\d{3}\-\d{7,8}$)|(^[0]?[1][3][0-9]\d{8}$)/;
	//var Phone=/(^[0]\d{2}\-\d{8}$)|(^[0]\d{3}\-\d{7,8}$)|(^[0]?[1][3][0-9]\d{8}$)|(^0\d{10}$)|(^\d{1,4}-0\d{2}-\d{8}$)|(^\d{1,4}-0\d{3}-\d{7}$)|(^[1][3]\d{9}$)|(^[1][5]\d{9}$)|(^\d{1,4}-[1][3]\d{9}$)|(^\d{1,4}[1][3]\d{9}$)|(^\d{1,4}[1][5]\d{9}$)|(^\d{1,4}-[1][5]\d{9}$)/;
	  var Phone=/(^[0]\d{2}\-\d{8}$)|(^[0]\d{3}\-\d{7,8}$)|(^[0]?[1][3][0-9]\d{8}$)|(^0\d{10}$)|(^\d{1,4}-0\d{2}-\d{8}$)|(^\d{1,4}-\d{2}-\d{8}$)|(^\d{1,4}\d{2}\d{8}$)|(^\d{1,4}-0\d{3}-\d{7}$)|(^[1][3]\d{9}$)|(^[1][5]\d{9}$)|(^\d{1,4}-[1][3]\d{9}$)|(^\d{1,4}[1][3]\d{9}$)|(^\d{1,4}[1][5]\d{9}$)|(^\d{1,4}-[1][5]\d{9}$)/;
	if(!Phone.test($("tel").value)){
		alert("您输入的电话号码不存在!");
		personal.tel.focus();
		return;
	}
   
}
*/

function isValidPhone(phone)
{
	if (phone.search(/(^[0]\d{2}\-\d{8}$)|(^[0]\d{3}\-\d{7,8}$)|(^[0]?[1][3][0-9]\d{8}$)|(^0\d{10}$)|(^\d{1,4}-0\d{2}-\d{8}$)|(^\d{1,4}-\d{2}-\d{8}$)|(^\d{1,4}\d{2}\d{8}$)|(^\d{1,4}-0\d{3}-\d{7}$)|(^[1][3]\d{9}$)|(^[1][5]\d{9}$)|(^\d{1,4}-[1][3]\d{9}$)|(^\d{1,4}[1][3]\d{9}$)|(^\d{1,4}[1][5]\d{9}$)|(^\d{1,4}-[1][5]\d{9}$)/) != -1)
		return true;
	else
		return false;	   
}
 /*-------------------------------------------------------------------------------------------------------*/

 //邮编校验
function checkYouBian(Post) 
{ 
	if($("postCode").value== null || $("postCode").value.length < 1)
		return;
		
 	var Post = /(^\d{6}$)/;
 	if(!Post.test($("postCode").value)){
 		alert("您输入的邮编不合法!");
		return;
 	} 
} 
/*-------------------------------------------------------------------------------------------------------*/
/*
函数名称：Trim
函数功能：去除字符串两边的空格
函数参数：str,需要处理的字符串
********************/
function Trim(str)
{
    return str.replace(/(^\s*)|(\s*$)/g, "");
}

/*-------------------------------------------------------------------------------------------------------*/
//去除两边空格后在判断是否为空
function IsNull(str)
{
	var returnValue="您输入的不可为空!";
	//alert (str);
    return (Trim(str) == "") ? returnValue : str;
}

/*-------------------------------------------------------------------------------------------------------*/
























