var digits = "0123456789";
// reformat (TARGETSTRING, STRING, INTEGER, STRING, INTEGER ... )       
//
// Inserts formatting characters or delimiters within TARGETSTRING.
//
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;
}
// Returns true if all characters in string s are numbers.
//
function isInteger (s)
{   var i;
    // 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 >= "0") && (c <= "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
// Removes all characters which do NOT appear in string bag 
// from string s.
function stripCharsNotInBag (s, bag)
{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is 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;
}

// This function will replace all occurences of string X with string Y in the argument
function ReplaceString(argvalue, x, y) {
	var leading, trailing, i;

	if (argvalue == "") return argvalue;
	i = argvalue.indexOf(x);
	while (i != -1) {
//	while ((i = argvalue.indexOf(x)) != -1) {
		leading = argvalue.substring(0, i);
		trailing = argvalue.substring(i + x.length, argvalue.length);
		argvalue = leading + y + trailing;
		i = argvalue.indexOf(x, i + y.length);
	}
	return argvalue;
}
// Added by kent 7/25/2001
function Rtrim(thestr){
	var cont = true;
	while (cont){
		trailing = thestr.substring(thestr.length-1,thestr.length);
		// if last char is a space, strip it off and continue testing the last space 
		if(trailing==" "){
			thestr = thestr.substring(0,thestr.length-1);
		}
		else{
			cont = false;
		}
	}
	return thestr;
}

// Added by kent 2/22/2002
function writeoutput(div,msg){
	// for ie
	if (document.all) {
		var thediv = eval(div);
		thediv.innerHTML=msg;
	}
	// for netscape
	if (document.layers) {
		var thediv = eval("document."+div);
		thediv.document.write(msg);
		thediv.document.close();
	}
}
// Added by kent 3/11/2002
//CASE SENSITIVE Returns the first index of an occurrence of a substring in a string
function Find(substr, str) {
	i = str.indexOf(substr);
	return i;
}
// Added by kent 3/11/2002
//CASE IN-SENSITIVE Returns the first index of an occurrence of a substring in a string
function FindNoCase(substr, str) {
	str = str.toLowerCase();
	i = str.indexOf(substr);
	return i;
}

// Added by kent 3/11/2002
// This will tell us how many occurences of substr within a string
function OccursNoCase(substr, str){
	var i = 0;
	var x = 0;	// counter 
	if ((str == "")||(substr == "")) return x;
	tempstr = str.toLowerCase();
	i = tempstr.indexOf(substr);
	while (i != -1) {
		x = x + 1;
		leading_str = tempstr.substring(0, i);
		trailing_str = tempstr.substring(i + substr.length, tempstr.length);
		tempstr = leading_str + trailing_str;
		i = tempstr.indexOf(substr, i);
		//alert("tempstr: "+tempstr+"\ni: "+i);
	}
	return x;
}
// Added by kent 3/11/2002
//returns length of list 
function ListLen(inList,delim){
	var len = 0;
	if (inList.length){
		var myarray = inList.split(delim);
		len = myarray.length;
	}
	return len;
}
