// E-mail Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
function emailvalidation(entered, alertbox)
{
with (entered)
	{
	apos=value.indexOf("@"); 
	dotpos=value.lastIndexOf(".");
	lastpos=value.length-1;
	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>4 || lastpos-dotpos<2) 
	{if (alertbox) {alert(alertbox);} return false;}
	else {return true;}
	}
} 

function emptyvalidation(entered, alertbox)
{
with (entered)
	{
	var _alpha = value.search(/[a-z]|[A-Z]/);
	var _num = value.search(/[0-9]/);
	if (value==null || value=="" || _alpha==-1 && _num==-1)
	{if (alertbox!="") {alert(alertbox);} return false;}
	else {return true;}
	}
}

function emptySelect(entered, alertbox)
{
// Emptyfield Validation for Select boxes by Puc Covelli / Mick Casey
// Please do not remove this line and the two lines above.
/* Checking if the Selectbox's field is empty.
Optional parameters are:
text --text that will show in an alertbox if content is illegal.*/
with (entered)
	{
	if (options[selectedIndex].value==null || options[selectedIndex].value=="")
	{if (alertbox!="") {alert(alertbox);} return false;}
	else {return true;}
	}
}


// Word Filter 2.0
// (c) 2002 Premshree Pillai
// Created : 29 September 2002
// http://www.qiksearch.com
// http://javascript.qik.cjb.net
// E-mail : qiksearch@rediffmail.com

var swear_words_arr=new Array("fuck","wank","cunt");
var swear_alert_arr=new Array();
var swear_alert_count=0;

function reset_alert_count()
{
 swear_alert_count=0;
}

function wordFilter(form,fields)
{
	reset_alert_count();
	var compare_text;
	var fieldErrArr=new Array();
	var fieldErrIndex=0;
	for(var i=0; i<fields.length; i++)
	{
		eval('compare_text=document.' + form + '.' + fields[i] + '.value;');
		for(var j=0; j<swear_words_arr.length; j++)
		{
			for(var k=0; k<(compare_text.length); k++)
			{
				if(swear_words_arr[j]==compare_text.substring(k,(k+swear_words_arr[j].length)).toLowerCase())
				{
					swear_alert_arr[swear_alert_count]=compare_text.substring(k,(k+swear_words_arr[j].length));
					swear_alert_count++;
					fieldErrArr[fieldErrIndex]=i;
					fieldErrIndex++;
				}
			}
		}
	}
	var alert_text="";
	for(var k=1; k<=swear_alert_count; k++)
	{
		alert_text+="\n" + "(" + k + ")  " + swear_alert_arr[k-1];
		eval('compare_text=document.' + form + '.' + fields[fieldErrArr[0]] + '.focus();');
		eval('compare_text=document.' + form + '.' + fields[fieldErrArr[0]] + '.select();');
	}
	if(swear_alert_count>0)
	{
		alert("Message cannot be submitted.\nThe following illegal words were found:\n_______________________________\n" + alert_text + "\n_______________________________");
		return false;
	}
	else
	{
		// if we've got this far, check to see if any of the fields are blank
		for(var i=0; i<fields.length; i++) {
				if (eval('document.' + form + '.' + fields[i] + '.value')=="") {
				alert("Please complete the " + fields[i] + " field");
				eval('document.' + form + '.' + fields[i] + '.focus()');
				return false;
				}
			}
	}	
}


// from register.cfm
function formvalidation(thisform)
{
with (thisform)
	{
	if (emptyvalidation(firstname,"Please enter your First Name")==false) {firstname.focus(); return false;};	
	if (emptyvalidation(lastname,"Please enter your Last Name")==false) {lastname.focus(); return false;};	
	if (emailvalidation(email,"Please enter a valid Email address")==false) {email.focus(); return false;};
	if (emptyvalidation(username,"Please enter a Username")==false) {username.focus(); return false;};
	}
} 

// from login.cfm
function loginvalidation(thisform)
{
with (thisform)
	{
	if (emptyvalidation(email,"Please enter your email")==false) {email.focus(); return false;};	
	if (emptyvalidation(password,"Please enter your Password")==false) {password.focus(); return false;};
	}
} 

// from login.cfm forgotten
function forgottenvalidation(thisform)
{
with (thisform)
	{
	if (emailvalidation(email,"Please enter a valid Email address")==false) {email.focus(); return false;};
	}
} 

// from actions/unsubscribe.cfm
function formvalidation11(thisform)
{
with (thisform)
	{
	if (emailvalidation(email,"Please enter a valid Email address")==false) {email.focus(); return false;};
	}
} 

// from messageboards/thread.cfm
function formvalidation12(thisform)
{
with (thisform)
	{
	if (emptyvalidation(title,"Please enter a title for your topic")==false) {title.focus(); return false;};	
	if (emptyvalidation(body,"You must start off the topic with a message!")==false) {body.focus(); return false;};
	}
} 

// from messageboards/thread.cfm
function formvalidation13(thisform)
{
with (thisform)
	{
	if (emptyvalidation(subject,"Please enter a title for your message")==false) {subject.focus(); return false;};	
	if (emptyvalidation(body,"You must enter a message!")==false) {body.focus(); return false;};
	}	
}



// from changepassword.cfm
function passwordvalidation(thisform)
{
with (thisform)
	{
	if (emptyvalidation(password,"Please enter a Password")==false) {password.focus(); return false;};
	if (emptyvalidation(passwordcheck,"Please enter your Password again")==false) {passwordcheck.focus(); return false;};	
	
	// make sure the two passwords match
	if (password.value != passwordcheck.value)
		{
		alert("Your two Passwords don't match each other. Please type them in again.");
		return false;
		}
	}	
}
