
var whitespace = " \t\n\r";

 function isEmpty(s)
 {
   if((s == null) || (s.length == 0))
   return true;
 }


 function isWhitespace (s)
 {
      var i;

      if (isEmpty(s)) return true;

      for (i = 0; i < s.length; i++)
      {
           // Check that current character isn't whitespace.
           var c = s.charAt(i);

           if (whitespace.indexOf(c) == -1) return false;
      }
      // All characters are whitespace.
      return true;
 }


function forceEntry(inputFld, str) 
{
     var strInput = new String(inputFld.value);

     if (isWhitespace(strInput)) 
     {
         alert(str);
         inputFld.focus();
         return false;
     }
}


function forceLength(inputFld, minLength, str) 
{
     var strInput = new String(inputFld.value);

     if (strInput.length < minLength) 
     {
         alert(str);
         inputFld.focus();
         inputFld.select();
         return false;
     }
}


function forceSelect(inputFld,str)
{
	var strInput = new String(inputFld.value);

	if(strInput=="")
	{
		alert(str);
		inputFld.focus();
        return false;
     }
     else
     {
          return true;
     }
}

function forceRadioSelect(inputFld, ErrorMsg)
{
	var x=0;
		for(i=0;i<inputFld.length;i++)
		{
			if(inputFld[i].checked)
			{
				return true;
			}
		}
		alert(ErrorMsg);
		//inputFld.focus(); not supported.
		return false;
}

// onBlur="noDollerSigns(this)"
function noDollerSigns(callingElement)
{
	var r, re; 
    var s = callingElement.value;    
    re = /\$/g;           
    r = s.replace(re,"");
	callingElement.value=r;
}

function isNumeric(inputFld,str)
{
	x=inputFld.value;
    for(i=0;i<x.length;i++)
    {
        if(isNaN(x.charAt(i)))
        {
			alert(str);
            inputFld.focus();
            inputFld.select();
            return false;
		}
    }
}


function isEmail(inputFld)
{
	Email=inputFld.value;
	if (Email.indexOf("@")<3){
		alert("This email address seems wrong."
		+" Please check the email prefix and '@' sign.");
		inputFld.focus();
	    inputFld.select();
		return false;
	}
	if (Email.indexOf(".")<5){
		alert("This email address seems wrong. Please"
		+" check the suffix for accuracy.");
		inputFld.focus();
	    inputFld.select();
		return false;
	}
	var a=Email.indexOf("@");
	var p=Email.lastIndexOf(".");
	if (p==(a+1))
	{
		alert("This email address seems wrong. Please"
		+" check the suffix for accuracy.  (It should include"
		+" a domain between the \"@\" and the \".\")");
		inputFld.focus();
	    inputFld.select();
		return false;
	}
}


function isDateNumber(strNum,method)
{

	var str = new String(strNum);
	var i = 0;

	if (isNaN(parseInt(str)) || parseInt(str) < 0) return false;

	if (method == 2)
		if (parseInt(str) > 31)
			return false;
	if (method == 1)
		if (parseInt(str) > 12)
			return false;

	for (i = 0; i < str.length; i++)
		if (str.charAt(i) < '0' || str.charAt(i) > '9')
			return false;


	return true;
}

/****************************************************************/

// Displays an alert box with the passed in string...

function PromptErrorMsg(inputField,FieldName)
{
	alert("You have entered an invalid date for " + FieldName + ".  Please make sure your date format is in M/D/Y format.");
	inputField.focus();
}

/****************************************************************/

/* PURPOSE: Checks to see if the string is a valid date.  A valid
	date is defined as any of the following:

		MM/DD/YY, MM/DD/YYYY, M/D/YY, M/D/YYYY,
		MM-DD-YY, MM-DD-YYYY, M-D-YY, M-D-YYYY
*/

function ForceDate(inputFld,FieldName)
{
	var str = new String(inputFld.value);

	if (isWhitespace(str)) {
            alert("Please enter a "+FieldName+".");
            inputFld.focus();
            return false;
		// if the field is empty, just return true...
	}

	var i = 0, count = str.length, j = 0;
	while ((str.charAt(i) != "/" && str.charAt(i) != "-") && i < count)
		i++;

	if (i == count || i > 2) {
		PromptErrorMsg(inputFld,FieldName);
		return false;
	}

	var addOne = false;
	if (i == 2) addOne = true;

	if (!isDateNumber(str.substring(0,i),1)) {
		PromptErrorMsg(inputFld,FieldName);
		return false;
	}

	j = i+1;
	i = 0;

	while ((str.charAt(i+j) != "/" && str.charAt(j+i) != "-") && i+j < count)
		i++;

	if (i+j == count || i > 2) {
		PromptErrorMsg(inputFld,FieldName);
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),2)) {
		PromptErrorMsg(inputFld,FieldName);
		return false;
	}

	j = i+3;
	i = 0;

	if (addOne) j++;

	while (i+j < count)
		i++;


	if (i != 2 && i != 4) {
		PromptErrorMsg(inputFld,FieldName);
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),3)) {
		PromptErrorMsg(inputFld,FieldName);
		return false;
	}

	return true;
}

function ForceMoney(objField, FieldName)
{
	var strField = new String(objField.value);
	
	if (isWhitespace(strField)) return true;

	var i = 0;

	for (i = 0; i < strField.length; i++)
		if ((strField.charAt(i) < '0' || strField.charAt(i) > '9') && (strField.charAt(i) != '.')) {
			alert(FieldName + " must be a valid numeric value.  Please do not use commas or dollar signs or any non-numeric symbols.");
			objField.focus();
			return false;
		}

//	return true;
}


//Limits the filed length of a textarea 
function limitTextArea(callingElement, maxlimit)
	{
	if (callingElement.value.length > (maxlimit-1)) // if too long...trim it!
	callingElement.value = callingElement.value.substring(0, (maxlimit-1));
	}

//Creates a popup window of the size and position specified.
function doPop(url,ht,wdth)
	{
		window.open(url,"","top=0,left=0,width="+wdth+",height="+ht+",dependent=yes,titlebar=no,scrollbars=yes");
	}