var digits = "0123456789";

var strLowercaseLetters = "abcdefghikjlmnopqrstuvwxyz"

var strUppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

var strWhitespace = " \t\n\r";

//This Function takes a string and checks whether or not is in valid email format.

function isEmail(str) {

  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}


function isPhoneFax(str) {
 
 // are regular expressions supported?
  var supported = 0;

  if (window.RegExp) {

    var tempStr = "a";
 
    var tempReg = new RegExp(tempStr);

    if (tempReg.test(tempStr)) supported = 1;
 
  }
 if (!supported) {
	alert("Please update your browser and/or turn on javascript");
	return false;
    return (str.indexOf("(") > 2) && (str.indexOf(")") > 0);

	}


	var r1 = /\(?\d{3}\)?([-\/\.\s])\d{3}([-\/\.\s])\d{4}/

	var OK = r1.exec(str)
	if (!OK)
		return false;
	else
		return true;
}

function ShowError(s)
{
	var fnt = document.getElementById("val_" + s);

	if (fnt)
	{
		fnt.style.display="";
	}
}

function HideError(s)
{
	var fnt = document.getElementById("val_" + s);

	if (fnt)
	{
		fnt.style.display="none";
	}
}


//STRING FUNCTIONS

function IsEmpty(s)
{
	
	if (IsWhiteSpace(s)) { return true; }
	return ((s == null) || (s.length == 0))
}

function IsWhiteSpace(s)
{
	var i;
	
	//if (IsEmpty(s)) return true;
	//Check each character of string. If non-whitespace character is found,
	//return false, else return true.
	
	for (i = 0; i < s.length; i++)
	{
		//check current char
		var c = s.charAt(i);
		//if current char is not equal to any char in whitespace string, return false.
		if (strWhitespace.indexOf(c) == -1) return false;
	}
	//all chars are whitespace 
	return  true;
}



function removeConsecutiveSpaces(inString)
{
	//this function takes as input a string, replaces consecutive spaces in it with
	//a single space, trims the spaces at the end of the string, if any and returns 
	//the string trimmed.
	var inStringLength = inString.length
	var outString = ""
	var currentChar 
	var previousChar
	//loop through all characters in the string
    for (i = 0; i < inStringLength; i++)
    {   
        //get the current character
        currentChar = inString.charAt(i);
        //if the current char and the previous char are not BOTH spaces then
        //	add the current char to the output string
        //else (if they are both spaces)
        //	ignore and do not add to output string
        //end if
        if ( ! ((currentChar == " ") && (previousChar == " ")) )
        {
			outString = outString + currentChar
	}
		//make the current char the previous char before getting a new one
		previousChar = currentChar
    }
    //now we need to trim the string 
    //if the first character is a space, remove it
    if (outString.charAt(0) == " ")
	{
		//substr returns the characters in a string beginning at the specified location
		//through the specified number of characters.  The location is the index of the
		//character while the length is the actual number of characters to be extracted.
		//get all characters except the first one, which is a space
		outString = outString.substr(1)
	}
	//determine the length of the outString now
    var outStringLength = outString.length
    //if the last character (length is always 1 greater than the index of the last char)
    //is a space
	if (outString.charAt(outStringLength - 1) == " ")
	{
		//extract all but the last character of the string
		outString = outString.substr(0, outStringLength - 1)
	}
	//return the trimmed string
    return outString
	}


