﻿// JavaScript Document
var IsCheck = false;
var NameCheck = false;
var strResult = '';

function RegCheck()
{
	if (document.UserReg.loginName.value=="" || document.UserReg.loginPass.value=="" || document.UserReg.email.value=="" || IsCheck==false)
	{
		//alert("请输入完整的信息！");
		document.getElementById('errDiv').style.display = "block";
		var errDiv=document.getElementById('errDiv');
		errDiv.style.border = '1px solid #FF7300';
		errDiv.style.backgroundColor = '#FFF5D8';
		errDiv.style.color = '#ff0000';
		errDiv.innerText="请输入完整的信息！";		
		return false
	}
	return true;
}

function LoginNameBlur()
{
	var loginNameDiv=document.getElementById('loginNameDiv');
	//alert(loginNameDiv.innerText);
	if (document.UserReg.loginName.value=="")
	{
		loginNameDiv.style.border = '1px solid #FF7300';
		loginNameDiv.style.backgroundColor = '#FFF5D8';
		loginNameDiv.style.color = '#ff0000';
		loginNameDiv.innerText="用户名不能为空！";
		//document.UserReg.loginName.focus();
		IsCheck = false;
		return false;
		
	}
	else
	{
		CheckUserExist(document.UserReg.loginName.value);
		//if (CheckUserExist(document.UserReg.loginName.value))
		//alert(strResult);
		if (strResult == '0')
		{
			loginNameDiv.style.border = '1px solid #FF7300';
			loginNameDiv.style.backgroundColor = '#FFF5D8';
			loginNameDiv.style.color = '#ff0000';
			loginNameDiv.innerText="改用户已被占用，请重新填写！";
			//document.UserReg.loginName.focus();
			NameCheck = false;
			IsCheck = false;
			return false;
		}
		else if (strResult == '1')
		{
			loginNameDiv.style.backgroundColor = "#FFFFFF";
			loginNameDiv.style.border = '';
			loginNameDiv.style.color = '#999999';
			loginNameDiv.innerText="祝贺您，此用户名可以使用！";
			IsCheck = true;
			return true;
		}
		
	}
	return true;
}

function LoginPassBlur()
{
	var loginPassDiv=document.getElementById('loginPassDiv');
	//alert(loginNameDiv.innerText);
	if (document.UserReg.loginPass.value=="")
	{
		loginPassDiv.style.border = '1px solid #FF7300';
		loginPassDiv.style.backgroundColor = '#FFF5D8';
		loginPassDiv.style.color = '#ff0000';
		loginPassDiv.innerText="密码不能为空！";
		//document.UserReg.loginPass.focus();
		IsCheck = false;
		return false;
	}
	else
	{
		loginPassDiv.style.backgroundColor = "#FFFFFF";
		loginPassDiv.style.border = '';
		loginPassDiv.style.color = '#999999';
		loginPassDiv.innerText="填写正确！";
		IsCheck = true;
		return true;
	}
	return true;
}

function LoginPassCheck()
{
	var loginPassDiv=document.getElementById('loginPass1Div');
	//alert(loginNameDiv.innerText);
	if (document.UserReg.loginPass1.value=="")
	{
		loginPassDiv.style.border = '1px solid #FF7300';
		loginPassDiv.style.backgroundColor = '#FFF5D8';
		loginPassDiv.style.color = '#ff0000';
		loginPassDiv.innerText="密码不能为空！";
		//document.UserReg.loginPass1.focus();
		IsCheck = false;
		return false;
	}
	else
	{
		if (document.UserReg.loginPass.value != document.UserReg.loginPass1.value)
		{
			loginPassDiv.style.border = '1px solid #FF7300';
			loginPassDiv.style.backgroundColor = '#FFF5D8';
			loginPassDiv.style.color = '#ff0000';
			loginPassDiv.innerText="两次密码输入不一致！";
			//document.UserReg.loginPass1.focus();
			IsCheck = false;
			return false;
		}
		else
		{
			loginPassDiv.style.backgroundColor = "#FFFFFF";
			loginPassDiv.style.border = '';
			loginPassDiv.style.color = '#999999';
			loginPassDiv.innerText="填写正确！";
			IsCheck = true;
			return true;
		}
		
	}
	return true;
}

function EmailBlur()
{
	var emailDiv=document.getElementById('emailDiv');
	//alert(loginNameDiv.innerText);
	if (document.UserReg.email.value=="")
	{
		emailDiv.style.border = '1px solid #FF7300';
		emailDiv.style.backgroundColor = '#FFF5D8';
		emailDiv.style.color = '#ff0000';
		emailDiv.innerText="E-mail不能为空！";
		//document.UserReg.loginName.focus();
		IsCheck = false;
		return false;
	}
	else
	{
		if (!EmailCheck(document.UserReg.email.value))
		{
			emailDiv.style.border = '1px solid #FF7300';
			emailDiv.style.backgroundColor = '#FFF5D8';
			emailDiv.style.color = '#ff0000';
			emailDiv.innerText="E-mail格式不正确！";
			//document.UserReg.loginName.focus();
			IsCheck = false;
			return false;
		}
		else
		{
			emailDiv.style.backgroundColor = "#FFFFFF";
			emailDiv.style.border = '';
			emailDiv.style.color = '#999999';
			emailDiv.innerText="填写正确！";
			IsCheck = true;
			return true;
		}
	}
	return true;
}

function ParentNameBlur()
{
	var parentNameDiv=document.getElementById('parentNameDiv');
	//alert(loginNameDiv.innerText);
	if (document.UserReg.parentName.value=="")
	{
		parentNameDiv.style.border = '1px solid #FF7300';
		parentNameDiv.style.backgroundColor = '#FFF5D8';
		parentNameDiv.style.color = '#ff0000';
		parentNameDiv.innerText="请输入家长名称，方便我们联系！";
		//document.UserReg.loginPass.focus();
		IsCheck = false;
		return false;
	}
	else
	{
		parentNameDiv.style.backgroundColor = "#FFFFFF";
		parentNameDiv.style.border = '';
		parentNameDiv.style.color = '#999999';
		parentNameDiv.innerText="填写正确！";
		IsCheck = true;
		return true;
	}
	return true;
}



function ParentAgeBlur()
{
	var parentAgeDiv=document.getElementById('parentAgeDiv');
	
	if (document.UserReg.parentAge.value != "")
	{
		if (isNaN(document.UserReg.parentAge.value))
		{
			parentAgeDiv.style.border = '1px solid #FF7300';
			parentAgeDiv.style.backgroundColor = '#FFF5D8';
			parentAgeDiv.style.color = '#ff0000';
			parentAgeDiv.innerText="年龄格式不正确！";
			//document.UserReg.loginName.focus();
			IsCheck = false;
			return false;
		}
		else
		{
			if (document.UserReg.parentAge.value<0 || document.UserReg.parentAge.value>100)
			{
				parentAgeDiv.style.border = '1px solid #FF7300';
				parentAgeDiv.style.backgroundColor = '#FFF5D8';
				parentAgeDiv.style.color = '#ff0000';
				parentAgeDiv.innerText="年龄格式不正确！";
				//document.UserReg.loginName.focus();
				IsCheck = false;
				return false;
			}
			else
			{
				parentAgeDiv.style.backgroundColor = "#FFFFFF";
				parentAgeDiv.style.border = '';
				parentAgeDiv.style.color = '#999999';
				parentAgeDiv.innerText="填写正确！";
				IsCheck = true;
				return true;
			}
		}
	}
	else
	{
		parentAgeDiv.style.backgroundColor = "#FFFFFF";
		parentAgeDiv.style.border = '';
		parentAgeDiv.style.color = '#999999';
		//parentAgeDiv.innerText="填写正确！";
		IsCheck = true;
		return true;
	}
}

function ChildAgeBlur()
{
	var childAgeDiv=document.getElementById('childAgeDiv');
	
	if (document.UserReg.childAge.value != "")
	{
		if (isNaN(document.UserReg.childAge.value))
		{
			childAgeDiv.style.border = '1px solid #FF7300';
			childAgeDiv.style.backgroundColor = '#FFF5D8';
			childAgeDiv.style.color = '#ff0000';
			childAgeDiv.innerText="年龄格式不正确！";
			//document.UserReg.loginName.focus();
			IsCheck = false;
			return false;
		}
		else
		{
			if (document.UserReg.childAge.value<0 || document.UserReg.childAge.value>100)
			{
				childAgeDiv.style.border = '1px solid #FF7300';
				childAgeDiv.style.backgroundColor = '#FFF5D8';
				childAgeDiv.style.color = '#ff0000';
				childAgeDiv.innerText="年龄格式不正确！";
				//document.UserReg.loginName.focus();
				IsCheck = false;
				return false;
			}
			else
			{
				childAgeDiv.style.backgroundColor = "#FFFFFF";
				childAgeDiv.style.border = '';
				childAgeDiv.style.color = '#999999';
				childAgeDiv.innerText="填写正确！";
				IsCheck = true;
				return true;
			}
		}
	}
	else
	{
		childAgeDiv.style.backgroundColor = "#FFFFFF";
		childAgeDiv.style.border = '';
		childAgeDiv.style.color = '#999999';
		//parentAgeDiv.innerText="填写正确！";
		IsCheck = true;
		return true;
	}
}

function ZipBlur()
{
	var zipDiv=document.getElementById('zipDiv');
	
	if (document.UserReg.zip.value != "")
	{
		if (isNaN(document.UserReg.zip.value))
		{
			zipDiv.style.border = '1px solid #FF7300';
			zipDiv.style.backgroundColor = '#FFF5D8';
			zipDiv.style.color = '#ff0000';
			zipDiv.innerText="邮政编码格式不正确！";
			//document.UserReg.loginName.focus();
			IsCheck = false;
			return false;
		}
		else
		{
			if (document.UserReg.zip.value.length != 6)
			{
				zipDiv.style.border = '1px solid #FF7300';
				zipDiv.style.backgroundColor = '#FFF5D8';
				zipDiv.style.color = '#ff0000';
				zipDiv.innerText="邮政编码格式不正确！";
				//document.UserReg.loginName.focus();
				IsCheck = false;
				return false;
			}
			else
			{
				zipDiv.style.backgroundColor = "#FFFFFF";
				zipDiv.style.border = '';
				zipDiv.style.color = '#999999';
				zipDiv.innerText="填写正确！";
				IsCheck = true;
				return true;
			}
		}
	}
	else
	{
		zipDiv.style.backgroundColor = "#FFFFFF";
		zipDiv.style.border = '';
		zipDiv.style.color = '#999999';
		//parentAgeDiv.innerText="填写正确！";
		IsCheck = true;
		return true;
	}
}

function TelBlur()
{
	var telDiv=document.getElementById('telDiv');
	//alert(loginNameDiv.innerText);
	if (document.UserReg.tel.value!="")
	{
		if (!PhoneCheck(document.UserReg.tel.value))
		{
			telDiv.style.border = '1px solid #FF7300';
			telDiv.style.backgroundColor = '#FFF5D8';
			telDiv.style.color = '#ff0000';
			telDiv.innerText="联系电话格式不正确！";
			//document.UserReg.loginName.focus();
			IsCheck = false;
			return false;
		}
		else
		{
			telDiv.style.backgroundColor = "#FFFFFF";
			telDiv.style.border = '';
			telDiv.style.color = '#999999';
			telDiv.innerText="填写正确！";
			IsCheck = true;
			return true;
		}
	}
	else
	{
		//telDiv.style.backgroundColor = "#FFFFFF";
		//telDiv.style.border = '';
		//telDiv.style.color = '#999999';
		//parentAgeDiv.innerText="填写正确！";
		//IsCheck = true;
		//return true;
		telDiv.style.border = '1px solid #FF7300';
		telDiv.style.backgroundColor = '#FFF5D8';
		telDiv.style.color = '#ff0000';
		telDiv.innerText="请输入联系电话，方便我们联系！";
		//document.UserReg.loginPass.focus();
		IsCheck = false;
		return false;
	}
	return true;
}

function AddressBlur()
{
	var addressDiv=document.getElementById('addressDiv');
	//alert(loginNameDiv.innerText);
	if (document.UserReg.address.value=="")
	{
		addressDiv.style.border = '1px solid #FF7300';
		addressDiv.style.backgroundColor = '#FFF5D8';
		addressDiv.style.color = '#ff0000';
		addressDiv.innerText="请输入联系地址，方便我们联系！";
		//document.UserReg.loginPass.focus();
		IsCheck = false;
		return false;
	}
	else
	{
		addressDiv.style.backgroundColor = "#FFFFFF";
		addressDiv.style.border = '';
		addressDiv.style.color = '#999999';
		addressDiv.innerText="填写正确！";
		IsCheck = true;
		return true;
	}
	return true;
}


//检查现在填写哪个
function WhoOnfocus(idName)
{
    document.getElementById('errDiv').style.display = "none";

	var myId = document.getElementById(idName);
	myId.style.backgroundColor = "#F7FFDD";
	myId.style.border = '1px solid #485E00';
	myId.style.color = "#999999";
}

function WhoOnblur(idName)
{
	var myId = document.getElementById(idName);
	myId.style.backgroundColor = "#FFFFFF";
	myId.style.border = '';
	myId.style.color = "#999999";
}

function EmailCheck(email)
{
	var Expression = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	var objExp = new RegExp(Expression);
	if (objExp.test(email) == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}


function PhoneCheck(tel)
{
	var i,j,strTemp;
	strTemp="0123456789-()#";
	for (i=0;i<tel.length;i++)
	{
		j=strTemp.indexOf(tel.charAt(i)); 
		if (j==-1)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	
}

//检查会员是否重复
function CheckUserExist(name)
{
	var geturl='CheckUserXml.aspx?userName='+name;
	CreateXmlHttpReq(geturl, function() {UserExistXml()});
	return true;
}

function UserExistXml()
{
	try
	{
		if(xmlhttp.readyState <= 3) return false;
		if (xmlhttp.status != 200) return false;
		strResult = xmlhttp.responseText;
	}
	catch(e){}
}

//AJAX接口部分
//`````````````````````````````````````````````````
var agt = navigator.userAgent.toLowerCase();
var is_opera = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_opera;
var is_ie5 = (agt.indexOf("msie 5") != -1) && document.all;
var xmlhttp;
//~2
function CreateXmlHttpReq(url, handler)
{
	try
	{
		if (is_ie) {    
			var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
			try {      
				xmlhttp = new ActiveXObject(control);
			} catch(e) {
				alert("You need to enable active scripting and activeX controls");
				DumpException(e);
			}
		} else {
			xmlhttp = new XMLHttpRequest();
		}
		xmlhttp.onreadystatechange = function() {handler();}
	 
		xmlhttp.open('POST', url, false);
		//alert(url);

		xmlhttp.send(null);	
	return true;
	}
	catch(e){alert('CreateXmlHttpReq ' + e.description);}
}
