function isEmptyString(str){

	var reg = /^[\s]*$/;
	if(str.match(reg)){
		return true;
	}
	else{
		return false;
	}
}

function isValidateUserName(str){

	var reg = /^[^ '<>\f\n\r\t\n]{1,}$/;
	if(str.match(reg)){
		return true;
	}
	else{
		return false;
	}
}

function isValidateEmail(str){

	var reg = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	if(str.match(reg)){
		return true;
	}
	else{
		return false;
	}
}

function isValidateString(str){

	var reg = /^[^<>]{0,}$/;
	if(str.match(reg)){
		return true;
	}
	else{
		return false;
	}
}

function isValidateYear(str){

	var reg = /^[\d]{2}$/;
	if(str.match(reg)){
		return true;
	}
	else{
		return false;
	}
}

function isValidateTel(str){
	var reg = /^([0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9|\s]{3,15}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9})$/;
	if(str.match(reg)){
		return true;
	}
	else{
		return false;
	}
}

function validateForgetPwd(){
	if(isEmptyString(document.all.uidoremail.value)){
		alert("Enter an email address or a username.");
		return false;
	}
	else{
		return true;
	}
}

function validateChangeEmail(){
	if(!isValidateEmail(document.all.oldemail.value)){
		alert("Enter your old email address.");
		return false;
	}
	if(!isValidateEmail(document.all.newemail.value)){
		alert("Enter your new email address.");
		return false;
	}
	
	return true;
}

function validateRegister(){
	if(!isValidateUserName(document.all.uid.value)){
		alert("Enter a username.");
		return false;
	}
	if(!isValidateEmail(document.all.email.value)){
		alert("Enter an email address.");
		return false;
	}
	if(!isValidateString(document.all.firstname.value)){
		alert("Check your first name. It shouldn't contain characters which can't be processed such as \"<\" and \">\".");
		return false;
	}
	if(!isValidateString(document.all.lastname.value)){
		alert("Check your last name. It shouldn't contain characters which can't be processed such as \"<\" and \">\".");
		return false;
	}
	if(!isValidateYear(document.all.year.value)&&document.all.year.value!=""){
		alert("Check the date of birth. You can only enter 2 numbers in this box. For example for 1970 enter 70.");
		return false;
	}
	if(!isValidateTel(document.all.phone.value)&&document.all.phone.value!=""){
		alert("Check your telephone number. You can only enter numbers or dashes(-) in this box.");
		return false;
	}
	if(!isValidateString(document.all.address.value)){
		alert("Check your address. It  shouldn't contain characters which can't be processed such as \"<\" and \">\".");
		return false;
	}
	if(!isValidateString(document.all.salary.value)){
		alert("Check your salary. It  shouldn't contain characters which can't be processed such as \"<\" and \">\".");
		return false;
	}

	return true;
}

function validatePersonal(){

	if(!isValidateString(document.all.firstname.value)){
		alert("Check your first name. It  shouldn't contain characters which can't be processed such as \"<\" and \">\".");
		return false;
	}
	if(!isValidateString(document.all.lastname.value)){
		alert("Check your last name. It  shouldn't contain characters which can't be processed such as \"<\" and \">\".");
		return false;
	}
	if(!isValidateYear(document.all.year.value)&&document.all.year.value!=""){
		alert("Check the date of birth. You can only enter 2 numbers in this box. For example for 1970 enter 70.");
		return false;
	}
	if(!isValidateTel(document.all.phone.value)&&document.all.phone.value!=""){
		alert("Check your telephone number. You can only enter numbers or dashes(-) in this box.");
		return false;
	}
	if(!isValidateString(document.all.address.value)){
		alert("Check your address. It  shouldn't contain characters which can't be processed such as \"<\" and \">\".");
		return false;
	}

	return true;
}

function isValidateSame(str1,str2){
	if(str1!=str2){
		return false;
	}
	return true;
}

function validateRegistration(){

	if(!isValidateSame(document.all.pwd1.value,document.all.pwd2.value)){
		alert("Your passwords don't match. Enter them again.");
		return false;
	}

	if(!isValidateEmail(document.all.email.value)){
		alert("Enter an email address.");
		return false;
	}
	return true;
}

function validateLogin(){
	if(!isValidateUserName(document.all.uid.value)){
		alert("Enter a username. It shouldn't contain characters which can't be processed such as \"<\" and \">\".");
		return false;
	}
	/*if(isEmptyString(document.all.pwd.value)){
		alert("Enter a password.");
		return false;
	}*/
}

function openSCORoot(item_id) 
{
	var handle = window.open("scoroot.asp?item_id=" + item_id,"SCORoot","height=510,width=775,left=" + (screen.width-775)/2 + ",top="+(screen.height-510)/2+",toolbar=no");
	handle.focus();
}