<!--
//Globals
var newPopUpWindow;

// Check browser version
var isNav4 = false, isNav5 = false, isIE4 = false;
if(navigator.appName == "Netscape") 
  {
  if (navigator.appVersion < "5") 
    {
    isNav4 = true;
    isNav5 = false;
    }
  else
    if (navigator.appVersion > "4") 
	  {
      isNav4 = false;
      isNav5 = true;
      }
  }
else 
  {
  isIE4 = true;
  }

function formCheck(formobj, fieldRequired, fieldDescription){
	// Dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	// Determine what each named object is, and then ensure that none are empty
	for (var i = 0; i < fieldRequired.length; i++)
	    {
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj[obj.selectedIndex].value == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;

			case "select-multiple":
				if (obj.selectedIndex == -1 || obj[obj.selectedIndex].value == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "password":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "file":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}
	
	// If something has been added to alert message, display alert window to user
	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

// Check if str contains only numbers
function isOnlyNumber(str)
 {
 if (str.search(/[^0-9]/g) == -1)
   {
   return true;
   } 
 else 
   {
   return false;
   }
 }

 // Check if str contains only numbers
function isInteger(str)
 {
 if (isOnlyNumber(str))
   {
   return true;
   } 
 else 
   {
   alert(str + " is an invalid non-decimal numeric format");
   return false;
   }
 }
 
// Checks for valid email address
// V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com)
function isComplexEmail (emailStr) 
  {
  
  /* The following variable tells the rest of the function whether or not to verify that the address ends in a two-letter country or well-known
   Top level domains (TLD).  1 means check it, 0 means don't. */

  var checkTLD=1;

  /* The following is the list of known TLDs that an e-mail address must end with. */

  var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

  /* The following pattern is used to check if the entered e-mail address fits the user@domain format.  It also is used to separate the username
   from the domain. */

  var emailPat=/^(.+)@(.+)$/;

  /* The following string represents the pattern for matching all special characters.  We don't want to allow special characters in the address. 
  These characters include ( ) < > @ , ; : \ " . [ ] */

  var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

  /* The following string represents the range of characters allowed in a username or domainname.  It really states which chars aren't allowed.*/

  var validChars="\[^\\s" + specialChars + "\]";

  /* The following pattern applies if the "user" is a quoted string (in which case, there are no rules about which characters are allowed
  and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com is a legal e-mail address. */

  var quotedUser="(\"[^\"]*\")";

  /* The following pattern applies for domains that are IP addresses, rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
  e-mail address. NOTE: The square brackets are required. */

  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

  /* The following string represents an atom (basically a series of non-special characters.) */

  var atom=validChars + '+';

  /* The following string represents one word in the typical username. For example, in john.doe@somewhere.com, john and doe are words.
  Basically, a word is either an atom or quoted string. */

  var word="(" + atom + "|" + quotedUser + ")";

  // The following pattern describes the structure of the user

  var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

  /* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */

  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

  /* Finally, let's start trying to figure out if the supplied address is valid. */

  /* Begin with the coarse pattern to simply break up user@domain into different pieces that are easy to analyze. */

  var matchArray=emailStr.match(emailPat);

  if (matchArray==null) 
    {

    /* Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address. */

    alert("Email address seems incorrect (check @ and .'s)");
    return false;
    }
  
  var user=matchArray[1];
  var domain=matchArray[2];

  // Start by checking that only basic ASCII characters are in the strings (0-127).

  for (i=0; i<user.length; i++) 
    {
     if (user.charCodeAt(i)>127) 
	   {
	   alert("Email address Error - Username contains invalid characters.");
       return false;
       }
    }
  for (i=0; i<domain.length; i++) 
    {
    if (domain.charCodeAt(i)>127) 
	  {
      alert("Email address Error - Domain name contains invalid characters.");
      return false;
      }
    }

   // See if "user" is valid 
   if (user.match(userPat)==null) 
     {
     // user is not valid
     alert("Email address Error - Invalid username.");
     return false;
     }

  /* if the e-mail address is at an IP address (as opposed to a symbolic
    host name) make sure the IP address is valid. */

  var IPArray=domain.match(ipDomainPat); 
  if (IPArray!=null) 
    {
    // this is an IP address
    for (var i=1;i<=4;i++) 
	  {
      if (IPArray[i]>255) 
	    {
        alert("Email address Error - Invalid Destination IP address!");
        return false;
        }
       }
     return true;
    }

  // Domain is symbolic name.  Check if it's valid.
 
  var atomPat=new RegExp("^" + atom + "$");
  var domArr=domain.split(".");
  var len=domArr.length;
  for (i=0;i<len;i++) 
    {
    if (domArr[i].search(atomPat)==-1) 
	  {
      alert("Email address Error - Invalid domain name.");
      return false;
      }
     }

  /* domain name seems valid, but now make sure that it ends in a known top-level domain (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding the domain or country. */

  if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) 
    {
    alert("Email address Error - Must end in a well-known domain or two letter " + "country.");
    return false;
    }

  // Make sure there's a host name preceding the domain.

  if (len<2) 
    {
    alert("Email address Error - Missing hostname!");
    return false;
    }

   // If we've gotten this far, everything's valid!
   return true;
  }
  
  
// Function used to test for valid NUMBER ONLY entries in textfields
function checkField(inputObject, type)
{ 
 if(inputObject.value == "")
    return true;
 
 var validated;
 var outputString = "";
 var textColor = inputObject.style.color;
 var textBgColor = inputObject.style.backgroundColor;
 if (textBgColor == "")
   {
   textBgColor='white';
   }
 // Do not remove
 // Weird HACK needed to ensure that focus returns to violated textfield
 // Otherwise, focus is lost
 function fieldFocus() 
   {
   inputObject.focus();
   }
 function clearField() 
   {
   inputObject.value="";
   inputObject.style.color=textColor;
   }
 if(checkForProfanity(inputObject.value))
   {
 switch(type)
   {
   case "SSN":
      validated = isSSN(inputObject.value);
   break
   case "integer":
      validated =  isInteger(inputObject.value);
   break
   case "email":
      validated =  isComplexEmail(inputObject.value);
   break
   default:
     validated = true;
   break
   }
   }
 else
   {
   validated = false;
   }
 if (!validated)
   {
   var randomnumber=Math.floor(Math.random()*101);
   //inputObject.style.color='white';
   inputObject.style.color=textBgColor;
   inputObject.value=randomnumber;
   setTimeout(fieldFocus, 100);
   setTimeout(clearField, 50);
   }
}

//#################################################
//## Function: clearAllFields
//## Added by Kevin Vaughan
//## Description:  This function compares traverses
//## through entire form elements array and sets values
//## to null or 0
//## @param formObj - Form object to be cleared
//## @return - None
//#################################################
function clearAllFeilds(formobj)
{
for(var i = 0; i < formobj.elements.length; i++){
		var obj = formobj.elements[i];
		if (obj){
			switch(obj.type){
			case "select-one":
				obj.selectedIndex = -1;
				break;

			case "select-multiple":
				obj.selectedIndex = -1;
				break;
			case "text":
			case "password":
			case "textarea":
				obj.value = "";
				obj.value = null;
				break;
			default:
			}
			if (obj.type == undefined){
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
                                            obj[j].checked = false
					}
				}
			}
		}
	}

}  // end clearAllFields func.

function handleEnter(obj,action)
{
if (document.layers)
  obj.captureEvents(Event.KEYDOWN);
  obj.onkeydown =
	function test(evt) { 
      var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
      if (keyCode == 13)   //13 = the code for pressing ENTER 
      {
	  if (action=="")
	    {
         document.forms[0].submit();
        }
	 else
	   {
	   eval(action);
	   }
	  }
  }
}

function checkForProfanity(inString) 
  {
  
  var wordCount = 70;
  var outputString = "Please refrain from using the word(s): "
  var regRemoval = /[\s\W\d]/g;
  var profanity = false;
  var isProfane = new makeArray(wordCount);
  var word = new makeArray(wordCount);
  //var temp = formObj.value;
  
  inString += leetSpeak(inString);
  inString = inString.replace(regRemoval,'');
  inString = inString.toLowerCase();

  
  word[0] = "asshole";
  word[1] = "bastard";
  word[2] = "beastial";
  word[3] = "bestial";
  word[4] = "bitch";
  word[5] = "blowjob";
  word[6] = "clit";
  word[7] = "cock";
  word[8] = "cum";
  word[9] = "cunilingus";
  word[10] = "cunillingus";
  word[11] = "cunnilingus";
  word[12] = "cunt";
  word[13] = "cyberfuc";
  word[14] = "damn";
  word[15] = "dildo";
  word[16] = "dink";
  word[17] = "ejaculat";
  word[18] = "fag";
  word[19] = "fart";
  word[20] = "felatio";
  word[21] = "fellatio";
  word[22] = "freak";
  word[23] = "fuck";
  word[24] = "fuk";
  word[25] = "gangbang";
  word[26] = "gaysex";
  word[27] = "gimp";
  word[28] = "gism";
  word[29] = "giz";
  word[30] = "hoe";
  word[31] = "horniest";
  word[32] = "horny";
  word[33] = "idiot";
  word[34] = "jack-off";
  word[35] = "jerk-off";
  word[36] = "jism";
  word[37] = "jiz";
  word[38] = "kock";
  word[39] = "kondum";
  word[40] = "kum";
  word[41] = "kunilingus";
  word[42] = "mothafuck";
  word[43] = "motherfuck";
  word[44] = "nerd";
  word[45] = "nigger";
  word[46] = "nuts";
  word[47] = "orgasim";
  word[48] = "orgasm";
  word[49] = "penis";
  word[50] = "phuk";
  word[51] = "phuq";
  word[52] = "prick";
  word[53] = "pussies";
  word[54] = "pussy";
  word[55] = "shit";
  word[56] = "slut";
  word[57] = "smut";
  word[58] = "suck";
  word[59] = "spunk";
  word[60] = "stupid";
  word[61] = "tits";
  word[62] = "turd";
  word[63] = "twat";
  word[64] = "vagina";
  word[65] = "whore";
  word[66] = "whoe";
  word[67] = "teets";
  word[68] = "knockers";
  word[69] = "niger";
	
  for (var j = 0; j < wordCount; j++) 
    {
    isProfane[j] = inString.indexOf(word[j]);
	    if (isProfane[j] != -1)
		  {
		  outputString += " " + word[j];
		  profanity = true;
		  }
    }

  if (profanity) 
	  {
      alert(outputString);
      //formObj.value = "";
      //formObj.focus();
	  outputString = "Please refrain from using the word(s): ";
	  //profanity=false;
	  return false;
      }
    else 
	  {
	  return true;
	  }
  }
  
function makeArray(n) 
  {
  this.length = n
  for (var i = 1; i<=n; i++) 
    {
    this[i] = new String();
    }
  return this
  }
  
// Check for leetspeak
function leetSpeak(tempString) 
  {
  var LeetValueArray = new Array("4","3","8","ph","1","\\|\\\\\/\\|","\\|\\\\\\|","0","5","7","\\+","\\(","6","9","\\|\\-\\|","\\|\\<","\\/\\<","\\|2","\\|\\_\\|","\\\\\/\\\\\/","\\\\\/","\\/\\/","\\>","\\>\\\<","\\>","\\'\\/","\\|","\\/");
  var LeetReplaceArray = new Array("a","e","b","f","i","m","n","o","s","t","t","d","g","g","h","k","k","p","u","w","v","w","x","x","y","y","i","v");
  var reg;
  for(i=0;i<LeetValueArray.length;i++)
    {
	//alert(LeetValueArray[i]);
	reg = new RegExp(LeetValueArray[i],"g");
	tempString = tempString.replace(reg,LeetReplaceArray[i]);
    //alert(tempString);
	}
  return(tempString);
  }

-->


