// JavaScript Document
var FIRSTNAME_FIRST = 0;
var LASTNAME_FIRST = 1;

var USERNAME_DIR = FIRSTNAME_FIRST;

// Please call it when change the First name of Last name
function setUsername(usernameId, firstnameId, lastNameId){
	var firstname = document.getElementById(firstnameId).value;
	var lastname = document.getElementById(lastNameId).value;
	
	if (USERNAME_DIR == FIRSTNAME_FIRST){
		document.getElementById(usernameId).value = firstname + ", " +lastname;
	}else{
		document.getElementById(usernameId).value = lastname + " " + firstname;
	}
}

// Check the password is equal to the confirm password
function checkPassword(password1Id, password2Id){
	var pwd1 = document.getElementById(password1Id).value;
	var pwd2 = document.getElementById(password2Id).value;
	
	if (pwd1 ==='' || pwd2 === ''){
		alert("Please enter the passwords.");
		return false;
	}
	
	if (pwd1 !== pwd2){
		alert("The passwords you entered did not match.");
		return false;
	}
	return true;
}

function checkEmail(email){
	if (email === ''){
		alert("Please enter email.");
		return false;
	}else if (!email.match("[a-zA-Z0-9]+@[a-zA-Z0-9]+[\.]+[a-zA-Z0-9]+")){
		alert("\""+email+"\" is not valid email.");
		return false;
	}
	return true;
}

//Check is a phone number
function isPhoneNo(strNo){
	if (strNo.indexOf('/') != -1)
		return false;
	if (strNo.indexOf('\\') != -1)
		return false;
	return ( strNo.search("[a-zA-Z\s\,\'\"\^\&\$\@\!]+") == -1);
}

function isInteger(val){
	return (val.search("[^0-9\.\-]+") == -1);	
}