
//Function to check that the form is filled in correctly

function CheckFormPass()
{

	//Check pass

	if (document.form2.passvalid.value == "")
	{
		alert("Actual password not valid");
		return false;
	}

	if (document.form2.password1.value == "")
	{
		alert("Please enter a password");
		document.form2.password1.focus();
		return false;
	}


	if (document.form2.passwordConf.value != document.form2.password1.value)
	{
		alert("Password don't match");
		document.form2.passwordConf.focus();
		return false;
	}



}

function testAddNews(){
    var title = document.news.title.value;
    var news = document.news.news.value;
    if (title == ""){
        alert("Please insert a title!");
        document.news.title.focus;
        return false;
    }
    if (news == ""){
        alert("News cannot be empty!");
        document.news.news.focus;
        return false;
    }
}

function testAddMovieComm(){
    var comment = document.mComm.comment.value;
    if (comment == ""){
        alert("Please insert a comment!");
        document.mComm.comment.focus;
        return false;
    }
}

function testAddComment(){
    var name = document.tstm.name.value;
    var comment = document.tstm.comment.value;
    if (name == ""){
        alert("Please insert a name!");
        document.tstm.name.focus;
        return false;
    }
    if (comment == ""){
        alert("Comment cannot be empty!");
        document.tstm.comment.focus;
        return false;
    }
}

function testForm(){

    var user = document.form1.username.value;
    if (user == "")
	{
		alert("Please enter a user id");
		document.form1.username.focus();
		return false;
	}
     if(!isNaN(user.charAt(0)))
	{
		alert("Usernames cannot begin with a number");
		document.form1.username.focus();
		return false;
	}
     if (document.form1.description.value == "")
	{
		alert("Please enter a description");
		document.form1.description.focus();
		return false;
	}
     if (document.form1.email.value == "")
	{
		alert("Please enter your email address");
		document.form1.email.focus();
		return false;
	}

	 if (! isValidEmail(document.form1.email.value)) {
	        alert("Please enter a valid email address");
	        return false;
	    }

	function indexOfNoCase(str1,str2)
	{
	  return str1.toUpperCase().indexOf(str2.toUpperCase());
	}

	if (indexOfNoCase(document.form1.email.value, "@aol.com") != -1)
	{
		alert("Due to technical problems with AOL email it cannot be used");
		document.form1.email.focus();
		return false;
	}
}

function CheckForm()
{

	var username = document.getElementById('username').toLowerCase();
        var description = document.getElementById('description');

	//Check User id
	if (document.form1.username.value == "")
	{
		alert("Please enter a user id");
		document.form1.username.focus();
		return false;
	}

	if (document.form1.description.value == "")
	{
		alert("Please enter a description");
		document.form1.description.focus();
		return false;
	}

	if(username.indexOf("shit") != -1 || username.indexOf("cunt") != -1 || username.indexOf("admin") != -1 || username.indexOf("asshole") != -1 || username.indexOf("pussy") != -1 || username.indexOf("whore") != -1 || username.indexOf("slut") != -1 || username.indexOf("cock") != -1 || username.indexOf("fuck") != -1 || username.indexOf("lolita") != -1 || username.indexOf("canine") != -1 || username.indexOf("faggot") != -1 || username.indexOf("toilet") != -1 || username.indexOf("licker") != -1 || username.indexOf("eater") != -1 || username.indexOf("nigga") != -1 || username.indexOf("nigger") != -1 || username.indexOf("k9") != -1 || username.indexOf("drinker") != -1 || username.indexOf("wallet") != -1 || username.indexOf("money") != -1 || username.indexOf("financial") != -1 || username.indexOf("cash") != -1 || username.indexOf("warning") != -1 || username.indexOf("ireneboss") != -1 || username.indexOf("ireneb0ss") != -1 || username.indexOf("JewBitch") != -1 || username.indexOf("blackmail") != -1 || username.indexOf("swallow") != -1 || username.indexOf("breed") != -1 || username.indexOf("420") != -1 || username.indexOf("hung") != -1 || username.indexOf("knine") != -1 || username.indexOf("kay9") != -1 || username.indexOf("kaynine") != -1 || username.indexOf("rapist") != -1 || username.indexOf("scat") != -1 || username.indexOf("pig") != -1 || username.indexOf("kennel") != -1 || username.indexOf("pedo") != -1 || username.indexOf("vomit") != -1 || username.indexOf("rape") != -1)
	{
		alert("Username is unavailable");
		document.form1.username.focus();
		return false;
	}

	if(!isNaN(username.charAt(0)))
	{
		alert("Usernames cannot begin with a number");
		document.form1.username.focus();
		return false;
	}



	//Check email
	if (document.form1.email.value == "")
	{
		alert("Please enter your email address");
		document.form1.email.focus();
		return false;
	}

	 if (! isValidEmail(document.form1.email.value)) {
	        alert("Please enter a valid email address");
	        return false;
	    }

	function indexOfNoCase(str1,str2)
	{
	  return str1.toUpperCase().indexOf(str2.toUpperCase());
	}

	if (indexOfNoCase(document.form1.email.value, "@aol.com") != -1)
	{
		alert("Due to technical problems with AOL email it cannot be used");
		document.form1.email.focus();
		return false;
	}

{


/*
	//Check zip
	if (document.form1.textfield3.value == "")
	{
		alert("Please enter your zip code");
		document.form1.textfield3.focus();
		return false;
	}

	if (document.form1.textfield3.value.length != 5)
	{
		alert("Please enter all five digits for your zip code");
		document.form1.textfield3.focus();
		return false;
	}
*/
function spcReplace(sStr)
{
    var s = '';
    for (var i = 0; i < sStr.length; i++) {
        if (sStr.charAt(i) != ' ') s += sStr.charAt(i);
    } return s;
}

	var testresults;
	var str=document.form1.email.value;
	var filter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

  if (filter.test(str))
	{
    testresults=true;
	}
	else
	{
    alert("Please enter a valid email address")
    document.form1.email.focus();
    return false;
	}

	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
	var checkStr = document.form1.username.value;
	var allValid = true;

	for (i = 0; i < checkStr.length; i++)
	{
    ch = checkStr.charAt(i);

    for (j = 0; j < checkOK.length; j++)
		{
      if (ch == checkOK.charAt(j))
			{
        break;
			}
		}

    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }

	}

	if (!allValid)
	{
    alert("Please enter only numbers & letters for the user id field");
    document.form1.username.focus();
    return false;
	}

	var checkkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
	var checkkStr = document.form1.password.value;
	var alllValid = true;
	for (i = 0; i < checkkStr.length; i++)
	{
    ch = checkkStr.charAt(i);

    for (j = 0; j < checkkOK.length; j++)
		{
      if (ch == checkkOK.charAt(j))
			{
        break;
			}
		}

		if (j == checkkOK.length)
		{
			alllValid = false;
			break;
		}
	}

	if (!alllValid)
	{
    alert("Please enter only numbers & letters for the password field");
    document.form1.password.focus();
    return false;
	}

	var checkkkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
	var checkkkStr = document.form1.passwordConf.value;
	var allllValid = true;

	for (i = 0; i < checkkkStr.length; i++)
	{
    ch = checkkkStr.charAt(i);

    for (j = 0; j < checkkkOK.length; j++)
		{
      if (ch == checkkkOK.charAt(j))
			{
        break;
			}
		}

    if (j == checkkkOK.length)
    {
      allllValid = false;
      break;
    }
	}
	if (!allllValid)
	{
    alert("Please enter only numbers & letters for the re-type password field");
    document.form1.passwordConf.focus();
    return false;
	}

	//Check for HTML tags before submitting the form
	for (var count = 0; count <= 3; ++count)
	{
		if ((document.form1.elements[count].value.indexOf("<", 0) >= 0) && (document.form1.elements[count].value.indexOf(">", 0) >= 0))
		{
			alert("Sorry, HTML tags are not permitted");
			document.form1.elements[count].focus();
			return false;
		}
	}

	return confirm("By clicking on the 'OK' button below, I agree to the terms of service of this website listed below.");
}
}

function checkMsg()
{
	var oEditor = FCKeditorAPI.GetInstance('message') ;
	var description = oEditor.GetXHTML(true);

	if (description == "")
	{
		alert("Message is empty");
		document.contact.message.focus();
		return false;
	}



}

function checkNewForum()
{
	var oEditor = FCKeditorAPI.GetInstance('message') ;
	var description = oEditor.GetXHTML(true);
	if (document.newForum.name.value == "")
	{
		alert("Please enter a name for forum");
		document.newForum.name.focus();
		return false;
	}
	if (document.newForum.description.value == "")
	{
		alert("Please enter a description");
		document.newForum.description.focus();
		return false;
	}
	if (description == "")
	{
		alert("First post cannot be empty");
		document.newForum.message.focus();
		return false;
	}
}

function checkNewForumMessage()
{
	var oEditor = FCKeditorAPI.GetInstance('message') ;
	var description = oEditor.GetXHTML(true);

	if (description == "")
	{
		alert("Message cannot be empty");
		document.newForum.message.focus();
		return false;
	}
}

function check_form2()
{
	var oEditor = FCKeditorAPI.GetInstance('description') ;
	var description = oEditor.GetXHTML(true);

	if (document.form1.sex.value == "")
	{
		alert("Please select gender value");
		document.form1.sex.focus();
		return false;
	}

	if (document.form1.orientation.value == "")
	{
		alert("Please select orientation value");
		document.form1.orientation.focus();
		return false;
	}

	if (document.form1.sexuality.value == "")
	{
		alert("Please select sexuality value");
		document.form1.sexuality.focus();
		return false;
	}

	if (description == "")
	{
		alert("Please enter a description");
		document.form1.description.focus();
		return false;
	}

	if (document.form1.city.value == "")
	{
		alert("Please select city value");
		document.form1.city.focus();
		return false;
	}
}

function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}