
/*********************************************
Checks that the email address has a '@' and '.'
parameter Text
returns 1 if the email address contains '.' and '@'
else  returns 0
**********************************************/

function isEmail(field){
    var theStr = field.value;
    var loc = theStr.indexOf("@");
    if(loc >= 0){
        loc = theStr.indexOf(".");
        if(loc >=0)  return(1)
        else{
             return(0);
        }
    }
    else{
        return(0);
    }
}
function doContainsWWW (field){
    var theStr = field.value;
    theStr = theStr.toUpperCase();
    //alert(theStr)
    var loc = theStr.indexOf("WWW.");
    //alert(loc)
        if(loc == 0){
		
		return(1)
        }
        else{
        	 return(0);
        }
}

function doContainsSpace (field){
    var theStr = field.value;
    var loc = theStr.indexOf(" ");
    if(loc >= 0){
         return(1)
        
    }
    else{
        return(0);
    }
}
/*
tests if a string contains a curse word
returns the location of the curse word in the string
0 if not found
*/
function isCurseWord(strVal){
    var strX = strVal.toUpperCase();
    //Check longer words containing shorter words
    var wordArray = new Array ("ASSHOLE", "ASS", "BITCH", "BASTARD", "FUCK", "SHIT", "NIGGER", "BITCH", "PUSSY");
    //Returns position of the index including 0.
    //If not found returns -1
    var i = 0;
    var isIllegal = 0;
    while(i < wordArray.length){
        var loc = strX.indexOf(wordArray[i]);
        if(loc >= 0){
            isIllegal = isSoloWord(loc, wordArray[i], strX);
            if(isIllegal == 1) 
                return (loc + 1); //in case the loc is @ 0
        }
        i++;
    }//end while
    return (0);//the word or sentence is o.k
}


/************************************
Function takes the 'word' passed in and determines
if there is a alpha character before the the 'word'
or after the 'word' int the string that was passed in.


Parameters - int the location (by using the indexOf()
             function) within the string of the first 
             letter of the word that we are checking.
             String - the word itself
             String - the string in which to search in.
returns
    - A 1 if the word was found with no Alpha 
    Character before or after the word passed in.
    - A 0 The word did have a letter before or 
      after the initial search string
*************************************/


function isSoloWord(loc, theWord, strX){
    theStr            = strX.toUpperCase();
    index             = loc;
    var Wordlength    = theWord.length;
    var Strlength     = theStr.length;
    var nextLetterPos = index + Wordlength;
    var ALPHA         ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    //Check for a letter before index
   
    if(index > 0){ //can go backwards at least one char
        var priorLetter = theStr.charAt(loc - 1);
        //Found a letter in front of the word
        if(ALPHA.indexOf(priorLetter) >= 0){
            return (0);
        }
    }
    //Check for a letter after
    if(Strlength > nextLetterPos){
        var nextLetter = theStr.charAt(nextLetterPos);
        //At least one letter after word
        if(ALPHA.indexOf(nextLetter) >= 0){
            return (0);
        }
    }

   //else must be a a word so return true
   return(1); //must be an illegal word 
}



/*********************************
Checks for the possibility of a link
in a string.
Parameters String
Returns the position of the possible link 
using the period as the point.
-1 if no link was found
**********************************/
function isStrLink(strVal){
    var theStr = strVal.toUpperCase();
    var length = theStr.length;
    var ALPHANUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    
    //Check for WWW.
    var loc = theStr.indexOf("WWW.");
    if(loc >= 0)  return (loc + 1); //in case the loc is @ 0
    
    //.COM
    loc = theStr.indexOf(".COM");
    //At least one letter after word
    if(loc >= 0){ //found it
        if(length >(loc + 4)){ //at least one more letter
            var nextLetter = theStr.charAt(loc + 4); //takes us to the end
            //-1 so not a letter or number after 'com'
            if(ALPHANUM.indexOf(nextLetter) < 0)  return (loc + 1); //in case the loc is @ 0
        }
        else return (loc + 1); //in case the loc is @ 0 ... no more letters so might be a link
    }
    //.NET
    loc = theStr.indexOf(".NET");
    //at least position to check
    if(loc >= 0){ //found it
        if(length >(loc + 4)){ //at least one more letter
            var nextLetter = theStr.charAt(loc + 4); //takes us to the end
            //-1 so not a letter or number after 'net'
            if(ALPHANUM.indexOf(nextLetter) < 0)  return (loc + 1); //in case the loc is @ 0
        }
        else  return (loc + 1); //in case the loc is @ 0 .. no more letters so might be a link
    }
    
    //. COM
    loc = theStr.indexOf(". COM");
    //at least position to check
    if(loc >= 0){ //found it
        if(length >(loc + 5)){ //at least one more letter
            var nextLetter = theStr.charAt(loc + 5); //takes us to the end
            //-1 so not a letter or number after 'net'
            if(ALPHANUM.indexOf(nextLetter) < 0)  return (loc + 1); //in case the loc is @ 0
        }
        else  return (loc + 1); //in case the loc is @ 0 ..no more letters so might be a link
    }
    //. NET
    loc = theStr.indexOf(". NET");
    //at least position to check
    if(loc >= 0){ //found it
        if(length >(loc + 5)){ //at least one more letter
            var nextLetter = theStr.charAt(loc + 5); //takes us to the end
            //-1 so not a letter or number after 'net'
            if(ALPHANUM.indexOf(nextLetter) < 0)  return (loc + 1); //in case the loc is @ 0
        }
        else  return (loc + 1); //in case the loc is @ 0 .. no more letters so might be a link
    }
   return(0); //must be o.k. 
}
    
/************************************************
Returns 1 if string contains only alhanumeric characters
Returns 0 if other characters are found

USEFUL for checking passwords and usernames
************************************************/
function isAlhaNumericString(theStr){
    var theStr          = theStr.toUpperCase();
    var Strlength     = theStr.length;
    var ALPHA       ="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
    var i = 0;
    
    while(i < Strlength){
        var theChar = theStr.charAt(i);
        //Found a letter in front of the word
        if(ALPHA.indexOf(theChar) < 0){
            return (0); //found a non-alphanumeric character
        }
        i = i + 1;
    }
    
   return(1); //must be o.k.
}
/****************************************************************/
/*** Check to see if the passed text field is blank.
**** e.g. Nothing was added to field (length is zero),
**** only spaces were added to the field, the value of 0.
          
**** If result is blank, user prompt with alert message of the field name,
**** the focus is set to the field, and 1 is returned. 

        Parameters: Controller
        Return:
            1 - if the field is empty
            0 - if the field is not empty
***********************************************************/

function isEmptyText(field){//isEmpty
    var length = field.length;
    //Nothing added to field || only spaces added to field
    if(length == 0 || field.value == 0){
		
       return(1);//return true
    }
		
    else{
		
		return(0);
	}
}
