// JavaScript Document

/**
*Checks for alphabetic characters
*/
function isLetter(c)
{
	//if the character passes the evaluation, it isn't a letter
	if(((c < "a") || (c > "z")) && ((c < "A") || (c > "Z")))
	{
		return false;
	}//end if
	return true;
}//end isAlpha()

/**
*Checks for alphabetic characters, hyphens and spaces
*/
function isAlpha(c)
{
	//if the character passes the evaluation, it is not a letter, hyphen or space
	if(((c < "a") || (c > "z")) && ((c < "A") || (c > "Z")) && ((c != "-") && (c != " ")))
	{
		return false;
	}//end if
	return true;
}//end isAlpha()

/**
*Checks for numeric characters
*/
function isNumber(c)
{
	//if the character passes the evaluation it isn't a number
	if((c < "0") || (c > "9"))
	{
		return false;
	}//end if
	return true;
}//end isNumber

/**
*Checks for alphanumeric characters, spaces, hyphens, periods and pound
*/
function isAlphaNum(c)
{
	//if the character passes the evaluation, then it isn't an alphanumeric character, space, period or number sign
	if(((c < "0") || (c > "9")) && (((c < "a") || (c > "z")) && ((c < "A") || (c > "Z")) && (c != " ") && (c != "-") && (c != ".") && (c != "#")))
	{
		return false;
	}//end if
	return true;
}//end isAlphaNum()


function checkUsername()
{
	var username = document.form.username.value;
	
	if((username == null || username == "")|| username.length < 4 || username.length >20)
	{
		//document.form.username.style.color = "FFFFFF";
		//document.form.username.style.backgroundColor = "FFCC66";
		return false;
	}//end if
	
	return true;	
}//end function checkUsername()



function checkEmail() 
{
	//obtain the value of the email field and use a regular expression to make sure the address is valid
	var email = document.form.email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.ca)|(\..{2,2}))$)\b/gi);
	
	//if the address is valid, return true
	if (!email)
	{
		//set the text color to white and the background color to turquoise and return false
	  // document.form.email.style.color = "FFFFFF";
	   //document.form.email.style.backgroundColor = "FFCC66";
	   return false;
	}//end else
	return true;
}//end checkEmail()


function validate()
{
	var username = checkUsername();
	var email = checkEmail();
	
	
	if(!username)
	{
		alert('Error! Please verified the username!');
		document.form.username.style.backgroundColor = "FFCC66";
		return false;
	}//end if
	
	
	if(!email)
	{
		alert('Error! Please verified your email address!');
		document.form.email.style.backgroundColor = "FFCC66";
		return false;
	}//end if
	
	
	return true;
}//** END of Function **

function changeColor(c)
{
	//c.style.color = "000000";
	c.style.backgroundColor = "FFFFFF";
}//end changeColor()

//***************************************************************************
//				LOGIN BOX VALIDATION          						        *
//***************************************************************************
function checkUsernameBox()
{
	var user_box = document.form2.user_box.value;
	
	if((user_box == null || user_box == "")|| user_box.length < 4 || user_box.length >20)
	{
		//document.form1.username.style.color = "FFFFFF";
		//document.form1.username.style.backgroundColor = "FFCC66";
		return false;
	}//end if
	
	return true;	
}//end function checkUsername()

function checkPasswordBox()
{
	var pass_box= document.form2.pass_box.value;
	
	if((pass_box == null || pass_box == "")|| pass_box.length < 4 || pass_box.length >20)
	{
		//document.form1.password.style.color = "FFFFFF";
		//document.form1.password.style.backgroundColor = "FFCC66";
		return false;
	}//end if
	
	return true;
}


function validate_login_box()
{
	var user = checkUsernameBox();
	var pass = checkPasswordBox();
		
	if(!user)
	{
		alert("Please verified your username!");
		
		document.form2.user_box.style.backgroundColor = "FFCC66";
		return false;
	}//end if
	if(!pass)
	{
		alert("Please verified your password!");
		
		document.form2.pass_box.style.backgroundColor = "FFCC66";
		return false;
	}//end if
	
	return true;
}//** END of Function **

function changeColor_login_box(c)
{
	c.style.backgroundColor = "FFFFFF";
}//end changeColor()