function round(number,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function checkNum(sChar) {

	if((sChar != '0') &&
		(sChar != '1') &&
		(sChar != '2') &&
		(sChar != '3') &&
		(sChar != '4') &&
		(sChar != '5') &&
		(sChar != '6') &&
		(sChar != '7') &&
		(sChar != '8') &&
		(sChar != '9')) {
		
		return false;
		
	} else {
	
		return true;
		
	}
}//end function checkNum()
		
function isNumeric(sString) {

	var isNum = true;
	var stringLen = sString.length;
	
	if(stringLen == 0) {
	
		isNum = false;
		
	} else {
	
		for(count = 0; count < stringLen; count++) {
	
			if(!(checkNum(sString.charAt(count)))) {
		
				isNum = false;
				break;
		
			}	
		}
	}
	
	return isNum;
	
}// end function checkValue()

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 isFloat(s)

{   var i;
    var seenDecimalPoint = false;
	var decimalPointDelimiter = "."
    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return false;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    // 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 ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}
// Check whether string s is empty. 
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function getIndex(myValue, optionName){
	//this function will return the selected index based on the list box or combo box value
	//or return 0 if not found
	var myIndex = 0;
	for (var i = 0; i < optionName.options.length; i++) {
		if (myValue == optionName.options[i].value) {
			myIndex = i;
			break;
		}
	}
	return myIndex;

}

function setListBox(myValue, myLstBox){
	// sets when values are intgegers
	// example: setListBox(6, document.thisForm.lstStartLane)
	// my value cannot be null - i use the NZ vb_function to replace Null values with 0
	// example with NZ: setListBox(<%=NZ(myRS("WeekDay"), 0)%>, document.thisForm.lstDayOfWeek)
	if (!isEmpty(myValue) && isInteger(myValue)){
		myLstBox.options[(getIndex((myValue), myLstBox))].selected = true;
	}

}

function setListBox2(myValue, myLstBox){
	// SETS when values are strings
	// example: setListBox(6, document.thisForm.lstStartLane)
	// my value cannot be null - i use the NZ vb_function to replace Null values with 0
	// example with NZ: setListBox(<%=NZ(myRS("WeekDay"), 0)%>, document.thisForm.lstDayOfWeek)
	if (!isEmpty(myValue)){
		myLstBox.options[(getIndex((myValue), myLstBox))].selected = true;
	}

}

function setOptionGroup(myValue, myOptGroup){

	myOptGroup[getIndexOptGroup(myValue, myOptGroup)].checked = true;

}
function getIndexOptGroup(myValue, optionName){
	//this function will return the index based on the option / radio button value
	//or return 0 if not found
	var myIndex = 0;
	for (var i = 0; i < optionName.length; i++) {
		//alert(optionName[i].value);
		if (myValue == optionName[i].value) {
			myIndex = i;
			break;
		}
	}
	return myIndex;

}


function isEmail (s)
{   
	if (isEmpty(s)) {
       return false;
	}    
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

//verifies that selected index is not first item value 
function isListBoxSelected(myListBox, myNotValue){
	//myListBox -- ex: document.thisForm.lstWeekDay
	//myNotValue -- the default value from the list box you do not want selected
	if (myListBox.options[myListBox.selectedIndex].value == myNotValue){
		return false;
	}
	else {
		return true;
	}	


}




// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;
	var whitespace = " \t\n\r";

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, 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 stripWhitespace (s){
	var whitespace = " \t\n\r";
	return stripCharsInBag (s, whitespace);
}

// Removes all characters which appear in string bag from string s.
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;
}