/*
Programmer: adrian@inet.co.cr
Date: 11/08/2002
Description: This function validates the fields for registration command
*/

function RegisterValidator(form)
{
	leaving = false; //this is used to disable exit traffic
	var slash_num;
	var slash_ok = true;
	var stralias=new String(form.alias.value);
        
	if( form.alias.value === "")
	{
			alert("Please type your nickname!");
			form.alias.focus();
			return (false);
	}
	
	//var stralias = form.alias.value;
	var alpha = new Number(checkAlphaNumeric(stralias));
	if(alpha != -1) {
		if((stralias.charAt(alpha) != "-") && (stralias.charAt(alpha) != "_")) {
			alert("Please don't use '" + stralias.charAt(alpha) + "' characters in your nickname");
			form.alias.focus();
			return false;
		}
	}
	
	
	//Check if alias has at least 6 chars
	
	if ((stralias.length < 6) || (stralias.length > 12))
	{
		alert("Your Nickname must be at least 6 characters long and no more than 12.");
		form.alias.focus();
		return false;
	}
	//Check if alias has at least 6 chars
	
	if (!(CharFind(stralias)))
	{
		alert("Your Nickname must starts with an alphabetical character!");
		form.alias.focus();
		return(false);
	}
		
	//check if alias starts with "cl-" or "web-"
	if (!CheckNick(stralias))
	{
		alert("Your nickname cannot start with cl-, we- or tech-");
		form.alias.focus();
		return(false);
	}
	//check if alias starts with "cl-" or "web-"*/
	
	if(form.email.value === "")
	{
			alert("Please type your email!");
			form.email.focus();
			return (false);
	}
	
	//Check if this field has /
	if(!CheckSlashes(form.email.value))
	{
			alert("Please use no / characters in your email");
			form.email.focus();
			return (false);
	}
	//Check if this field has /
	
	//Check if email contains a @
	stremail = new String(form.email.value);
	if (stremail.indexOf("@") == -1)
	{
		alert("Your email address you provided is not valid. Please make sure you typed it correctly");
		form.email.select();
		return false;
	}
	//Check if email contains a @
	
	//Check if email contains a .
	if (stremail.indexOf(".") == -1)
	{
		alert("Your email address you provided is not valid. Please make sure you typed it correctly.");
		form.email.select();
		return false;
	}
	//Check if email contains a .
	
	if (!(CheckSpaces(form.email.value)))
	{
		alert("Your email must not contain spaces!");
		form.email.focus();
		return(false);
	}
	if(form.password.value === "")
	{
			alert("Please type your password!");
			form.password.focus();
			return (false);
	}
	if(form.password.value.indexOf("&")!=-1)
	{
			alert("Please don't use '&' characters in your password");
			form.password.focus();
			return (false);
	} 
	if(form.password.value.indexOf("#")!=-1)
	{
			alert("Please don't use '#' characters in your password");
			form.password.focus();
			return (false);
	} 
	
	if(form.confirm.value==="")
	{
			alert("Please confirm your password!");
			form.confirm.focus();
			return (false);
	}

	//Check if password and confirmed password match
	if (form.password.value!=form.confirm.value)
	{
		alert("Your password does not match!");
		form.confirm.focus();
		return (false);
	}
	//Check if password and confirmed password match
	
	//Check if password starts with an alphabetical char
	strpassword=new String(form.password.value);
	if (!(CharFind(strpassword)))
	{
		alert("Your Password must starts with an alphabetical character!");
		form.password.focus();
		return(false);
	}
	//Check if password starts with an alphabetical char
	
	if (!(CheckSpaces(form.alias.value)))
	{
		alert("Your nickname must not contain spaces!");
		form.alias.focus();
		return(false);
	}
	
	if (!(CheckSpaces(form.password.value)))
	{
		alert("Your password must not contain spaces!");
		form.password.focus();
		return(false);
	}
	
	//Check if this field has /
	if(!CheckSlashes(form.password.value))
	{
			alert("Please use no / characters in your password");
			form.password.focus();
			return (false);
	}
	//variable for exit traffic:
	exiting = 0;
	return(true);
}

function CharFind(strField)
{
	//Check if alias starts with an alphabetical char
	if (!((strField.charCodeAt(0) > 64) && (strField.charCodeAt(0) < 91)) && !((strField.charCodeAt(0) > 96) && (strField.charCodeAt(0) < 123)))
	{
		return false;
	}
	//Check if alias starts with an alphabetical char
	return (true);
}

function CheckNick(strNickname)
{
	var strupalias;
	//check if alias starts with "cl-", "web-", "tech-"
	strtech=new String ("tech-");
	strtech=strtech.toUpperCase();
	strchat=new String ("cl-");
	strchat=strchat.toUpperCase();
	strweb=new String ("web-");
	strweb=strweb.toUpperCase();
	strupalias=strNickname.toUpperCase();
	if (strupalias.charAt(0)=="W") {
			strupalias=strupalias.substr(0,4);
	} else if (strupalias.charAt(0)=="C") {
			strupalias=strupalias.substr(0,3);
	} else {
			strupalias=strupalias.substr(0,5);
	}
	if ((strupalias==strchat) || (strupalias==strweb) || ((strupalias==strtech)))
	{
		return false;	
	}
	return(true);
	//check if alias starts with "cl-", "web-", "tech-"
}

function CheckStrangeChars(strField)
{
	for(i=0;i>strField.length;i++)
	{
		if (!((strField.charAt(0) > 64) && (strField.charAt(0) < 91)))
		{
			return(false);
		}
		if (!((strField.charAt(0) > 64) && (strField.charAt(0) < 91)))
		{
			return(false);
		}
	}
	return (true);
}

function CheckSpaces(strField)
{
	//Check if alias has spaces
	strInput=new String(strField);
	if (strInput.indexOf(" ") != -1)
	{
		return false;
	}
	return(true);
	//Check if alias has spaces
}

function CheckSlashes(strField)
{
	//Check if alias has spaces
	strInput=new String(strField);
	if (strInput.indexOf("/") != -1)
	{
		return false;
	}
	return(true);
	//Check if alias has spaces
}

function checkAlphaNumeric(value) {
	for(i = 0; i< value.length; i++) {
		if( ((value.charCodeAt(i) < 65) || (value.charCodeAt(i) > 90)) &&
			((value.charCodeAt(i) < 97) || (value.charCodeAt(i) > 122)) &&
			((value.charCodeAt(i) < 48) || (value.charCodeAt(i) > 57))) {
			return i;	
		}
	}
	return -1;
}


function RegisterValidatorNonAlert(form)
{
	var slash_num;
	var slash_ok = true;
	var stralias=new String(form.alias.value);
        
	if(form.alias.value==="")
	{
			form.alias.focus();
			return (false);
	}
	
	//var stralias = form.alias.value;
	var alpha = new Number(checkAlphaNumeric(stralias));
	if(alpha != -1) {
		if((stralias.charAt(alpha) != "-") && (stralias.charAt(alpha) != "_")) {
			form.alias.focus();
			return false;
		}
	}
	
	
	//Check if alias has at least 6 chars
	
	if ((stralias.length < 6) || (stralias.length > 12))
	{
		form.alias.focus();
		return false;
	}
	//Check if alias has at least 6 chars
	
	if (!(CharFind(stralias)))
	{
		form.alias.focus();
		return(false);
	}
		
	//check if alias starts with "cl-" or "web-"
	if (!CheckNick(stralias))
	{
		form.alias.focus();
		return(false);
	}
	//check if alias starts with "cl-" or "web-"*/
	
	if(form.email.value==="")
	{
			form.email.focus();
			return (false);
	}
	
	//Check if this field has /
	if(!CheckSlashes(form.email.value))
	{
			form.email.focus();
			return (false);
	}
	//Check if this field has /
	
	//Check if email contains a @
	stremail = new String(form.email.value);
	if (stremail.indexOf("@") == -1)
	{
		form.email.select();
		return false;
	}
	//Check if email contains a @
	
	//Check if email contains a .
	if (stremail.indexOf(".") == -1)
	{
		form.email.select();
		return false;
	}
	//Check if email contains a .
	
	if (!(CheckSpaces(form.email.value)))
	{
		form.email.focus();
		return(false);
	}
	if(form.password.value==="")
	{
			form.password.focus();
			return (false);
	}
	if(form.password.value.indexOf("&")!=-1)
	{
			form.password.focus();
			return (false);
	} 
	if(form.password.value.indexOf("#")!=-1)
	{
			form.password.focus();
			return (false);
	} 
	
	if(form.confirm.value==="")
	{
			form.confirm.focus();
			return (false);
	}

	//Check if password and confirmed password match
	if (form.password.value!=form.confirm.value)
	{
		form.confirm.focus();
		return (false);
	}
	//Check if password and confirmed password match
	
	//Check if password starts with an alphabetical char
	strpassword=new String(form.password.value);
	if (!(CharFind(strpassword)))
	{
		form.password.focus();
		return(false);
	}
	//Check if password starts with an alphabetical char
	
	if (!(CheckSpaces(form.alias.value)))
	{
		form.alias.focus();
		return(false);
	}
	
	if (!(CheckSpaces(form.password.value)))
	{
		
		form.password.focus();
		return(false);
	}
	
	//Check if this field has /
	if(!CheckSlashes(form.password.value))
	{
		
			form.password.focus();
			return (false);
	}
	//variable for exit traffic:
	exiting = 0;
	return(true);
}
