//<!--  

function fnChkNumeric(EName)
	{
		var sForm, sVal;
		sForm = document.forms[0].elements;
		sVal = sForm[EName].value;
		sTmpValRep=(sVal.replace(/^\W+/,'')).replace(/\W+$/,'');
		var SpecChar="." //Identify the special characters allowed in this entry</FONT>
		var VerifyChar

		var sLength=sVal.length //Gets the number of characters in the text box</FONT>
		for(var i=0; i!=sLength; i++) //Creates the loop used to check each character</FONT>
			{
			aChar=sVal.substring(i,i+1) //Checking each character in action</FONT>
			if(aChar<"0" || aChar>"9") //If there is an incorrect entry, clear it and send the user a message
				return false;
			}
			return true;

	}
function fnChkSpecial(sInString)
	{
		var n, i, sDblQuote,SPer,SCap,SNot, sMsg;		
		//n = sInString.length;
		sDblQuote='\"';
		SPer='\%';
		SCap='\^';
		SNot='\~';
		if (sInString.indexOf(sDblQuote)!=-1) 
			{
				alert('Comment Cannot Contain \"Quotes');
				return false;
			}	
		if (sInString.indexOf(SPer)!=-1) 
			{
				alert('Comment Cannot Contain \%');
				return false;
			}	
		if (sInString.indexOf(SCap)!=-1) 
			{
				alert('Comment Cannot Contain \^');
				return false;
			}
		if (sInString.indexOf(SNot)!=-1) 
			{
				alert('Comment Cannot Contain \~');
				return false;
			}	
		return true;
	}

function fnChkEmail(strEmail)
	{
		strEmail = trim(strEmail).toLowerCase();
		var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
		var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; 
		if (!reg1.test(strEmail) && reg2.test(strEmail))
				return true;
		else
				return false;
	}		
function fnSetCheckBox(ChkName)
	{
		var sForm;
		sForm = document.forms[0].elements;
		for (var i=0;i<sForm.length;i++)
			{
				var e = sForm[i];
				if (e.type == 'checkbox' && e.name != ChkName)
					{
						e.checked = false;
					}
						  
			}
	}
function fnCheckNos(oEle, sElementName, bAllowEmpty, nIntPart, nPrecision, bCheckRange, nMin, nMax)
	{
		var  sTmp, sTmpArr, nIntPart;
		nIntPart = nIntPart - nPrecision;
		sTmp = trim(oEle.value);
		if (sTmp.length<=0)
			{
				if (bAllowEmpty==0)  //don't allow empty
					{
						alert(sElementName + ' cannot be empty');
						oEle.focus();
						return  false;
					}
				else
					return true;
			}
				
		if (sTmp/sTmp !=1 && sTmp !=0) 
			{
				alert('Enter a valid value for ' + sElementName);
				oEle.focus();
				return false;
			}
				
		if (bCheckRange)
			if (sTmp<nMin || sTmp>nMax)
				{
				   alert(sElementName + ' not in allowed range (' + nMin + ' to ' + nMax + ')' );
				   return false;
				}	
		sTmpArr = sTmp.split('.');
		if (sTmpArr[0] && nIntPart>0)
			{
				if (sTmpArr[0].length > nIntPart)
					{
						alert('Integer Part cannot be longer than ' + nIntPart);
						return false;
					}
			}
		if (nPrecision>0)
			{
				if (sTmpArr[1])
					if (sTmpArr[1].length>nPrecision)
					{
						alert( sElementName + ' can have only ' + nPrecision + ' decimals');
						oEle.focus();
						return false;
					}
			}
		else
			{
				for (i=sTmp.length-1; i>=0;i--)
					if (sTmp.substr(i,1)=='.')
						{
							alert( sElementName + ' must be a whole number');
							oEle.focus();
							return false;
						}
				return true;
			}
		return true;
	}

function fnCheckNosPartial(oEle, sElementName, bAllowEmpty, nIntPart, nPrecision, bCheckRange, nMin, nMax)
	{
		var  sTmp, sTmpArr, nIntPart;
		nIntPart = nIntPart - nPrecision;
		sTmp = trim(oEle.value);
		if (sTmp.length<=0)
			{
				if (bAllowEmpty==0)  //don't allow empty
					{
						//alert(sElementName + ' cannot be empty');
						//oEle.focus();
						return  false;
					}
				else
					return true;
			}
				
		if (sTmp/sTmp !=1 && sTmp !=0) 
			{
				//alert('Enter a valid value for ' + sElementName);
				//oEle.focus();
				return false;
			}
				
		if (bCheckRange)
			if (sTmp<nMin || sTmp>nMax)
				{
				   alert(sElementName + ' not in allowed range (' + nMin + ' to ' + nMax + ')' );
				   return false;
				}	
		sTmpArr = sTmp.split('.');
		if (sTmpArr[0] && nIntPart>0)
			{
				if (sTmpArr[0].length > nIntPart)
					{
						alert('Integer Part cannot be longer than ' + nIntPart);
						return false;
					}
			}
		if (nPrecision>0)
			{
				if (sTmpArr[1])
					if (sTmpArr[1].length>nPrecision)
					{
						alert( sElementName + ' can have only ' + nPrecision + ' decimals');
						oEle.focus();
						return false;
					}
			}
		else
			{
				for (i=sTmp.length-1; i>=0;i--)
					if (sTmp.substr(i,1)=='.')
						{
							alert( sElementName + ' must be a whole number');
							oEle.focus();
							return false;
						}
				return true;
			}
		return true;
	}
	
function trim(strText) 
	{ 
	    // this will get rid of leading spaces 
	    while (strText.substring(0,1) == ' ') 
	        strText = strText.substring(1, strText.length);

	    // this will get rid of trailing spaces 
	    while (strText.substring(strText.length-1,strText.length) == ' ')
	        strText = strText.substring(0, strText.length-1);

	   return strText;
	}
function fnGetLen(EName)
	{
		var sForm, sVal;
		sForm = document.forms[0].elements;
		sVal = sForm[EName].value;
		sTmpValRep=(sVal.replace(/^\W+/,'')).replace(/\W+$/,'');
		nLength = sTmpValRep.length;
		
		return nLength;
	}

function SetCombo(EName, EValue)
	{
		//alert(EName);
		//alert(EValue);
		if (EValue=='') return;
		for(i=0;i<document.forms[0].elements[EName].options.length;i++)
			if (document.forms[0].elements[EName].options[i].value==EValue)
			   document.forms[0].elements[EName].selectedIndex=i;
	}
function SetComboText (EName, EValue)
	{
		//alert(EValue);
		if (EValue=='') return;
		for(i=0;i<document.forms[0].elements[EName].options.length;i++)
			if (document.forms[0].elements[EName].options[i].text==EValue)
			   document.forms[0].elements[EName].selectedIndex=i;
	}
	
function fnChkSpecial1(sInString)
	{
		var n, i, spChar;		
		spChar='/';
		//alert(sInString.search(spChar));
		if (sInString.search(spChar)!=6) 
			{
				return false;
			}	
		return true;
	}
	
function reformatUSPhone (USPhone)
{   return (reformat (USPhone, "(", 3, ") ", 3, "-", 4))
}


function checkUSPhone (theField, emptyOK)
{   var phoneNumberDelimiters = "()- ";
	var iUSPhone = "Phone must be a 10 digit U.S. phone number (like 415 555 1212). Please reenter it now."
	if (checkUSPhone.arguments.length == 1) emptyOK = false;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
       if (!isUSPhoneNumber(normalizedPhone, false)) 
          return warnInvalid (theField, iUSPhone);
       else 
       {  // if you don't want to reformat as (123) 456-789, comment next line out
          theField.value = reformatUSPhone(normalizedPhone)
          return true;
       }
    }
}

function reformat (s)

{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

function isUSPhoneNumber (s)
{   if (isEmpty(s)) 
       if (isUSPhoneNumber.arguments.length == 1) return false;
       else return (isUSPhoneNumber.arguments[1] == true);
    return (isInteger(s) && s.length == 10)
}

function warnInvalid (theField, s)
{   theField.focus()
    theField.select()
    alert(s)
    return false
}

function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return false;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function stripCharsInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
//-->