///////////////////////////////////////////////////////////////
//  Common Functions
//


//--------------------------------------------------
//	Auto Tab
//--------------------------------------------------
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		for (var i=getIndex(input)+1; i<input.form.length; i++) {
			if (input.form[i].type != "hidden") {
				input.form[i % input.form.length].focus();
				break;
			}
		}
	}

	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
			if(arr[index] == ele)
				found = true;
			else
				index++;
		return found;
	}

	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input)index = i;
			else i++;
		return index;
	}
	
	return true;
}
//---------------------
// end of autotab
//---------------------



//--------------------------------------------------------------
// The user can go to the next form field just by pressing the 
// enter key instead of the tab key
//--------------------------------------------------------------

nextfield = "box1"; // name of first box on page
netscape = "";
ver = navigator.appVersion; len = ver.length;
for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
netscape = (ver.charAt(iln+1).toUpperCase() != "C");

function keyDown(DnEvents) { // handles keypress
	if (!eval('document.forms[0].' + nextfield)) return;
	// determines whether Netscape or Internet Explorer
	k = (netscape) ? DnEvents.which : window.event.keyCode;
	if (k == 9) { // k == 13 || enter/tab key pressed
		if (nextfield == 'done') return true; // submit, we finished all fields
		else { // we're not done yet, send focus to next box
			eval('document.forms[0].' + nextfield + '.focus()');
			return false;
		}
	}
}

document.onkeydown = keyDown; // work together to analyze keystrokes
if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);



//--------------------------------------------------------------------------
// Places the focus on the first editable field in a form on any web page
//--------------------------------------------------------------------------
function placeFocus() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) {
			if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}

function do_open(link, name)
{
	newwin = window.open(link, name, "resizable=yes, scrollbars=yes");
	if (!newwin.opener) newwin.opener = self;
}

function confirm_delete(link)
{
	var msg = "Are you sure?"
	
	confirm_w_msg(msg,link);
}

function confirm_w_msg(msg,link)
{
	if (confirm(msg)) do_open(link, "Acknowledgement");
}

function SetCurrAcct(CurrAcct)
{
	top.CurrAcct = CurrAcct;
}

//--------------------------------------------------------------------------
// Used By Claims
//--------------------------------------------------------------------------
function SetReasonText(RsnCode,RsnText)
{
	RsnText.value = RsnCode.options[RsnCode.selectedIndex].text;
}

//--------------------------------------------------------------------------
// Number Formatter
//--------------------------------------------------------------------------

  // Original JavaScript code by Duncan Crombie: dcrombie@chirp.com.au
  // Please acknowledge use of this code by including this header.

  // CONSTANTS
  var separator = ","; // use comma as 000's separator
  var decpoint = "."; // use period as decimal point
  var percent = "%";
  var currency = "$"; // use dollar sign for currency
// Begin Change -- Harry Spear 02/15/01
  var negCurFontClr = "red"; // Color used for negative currency
  var formatCurrency = "$,##0.00";
  var formatNoDollarSign = ",##0.00";
// End Change

  function formatNumber(number, format, print) { // use: formatNumber(number, "format")

    if (print) document.write("formatNumber(" + number + ", \"" + format + "\")<br>");

    if (number - 0 != number) return null; // if number is NaN return null
    var useSeparator = format.indexOf(separator) != -1; // use separators in number
    var usePercent = format.indexOf(percent) != -1; // convert output to percentage
    if (usePercent) number *= 100;
    var useCurrency = format.indexOf(currency) != -1; // use currency format
    format = strip(format, separator + percent + currency); // remove key characters
    number = "" + number; // convert number input to string

    // split number and format into LHS and RHS using decpoint as divider
    var dec = number.indexOf(decpoint) != -1;
    var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
    var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";
    dec = format.indexOf(decpoint) != -1;
    var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
    var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

    // adjust decimal places by cropping or adding zeros to LHS of number
    if (srightEnd.length < nrightEnd.length) {
      var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
      nrightEnd = nrightEnd.substring(0, srightEnd.length);
      if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1); // round up

// patch provided by Patti Marcoux 1999/08/06
      while (srightEnd.length > nrightEnd.length) {
        nrightEnd = "0" + nrightEnd;
      }

      if (srightEnd.length < nrightEnd.length) {
        nrightEnd = nrightEnd.substring(1);
        nleftEnd = (nleftEnd - 0) + 1;
      }
    } else {
      for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
        if (srightEnd.charAt(i) == "0") nrightEnd += "0"; // append zero to RHS of number
        else break;
      }
    }

    // adjust leading zeros
    sleftEnd = strip(sleftEnd, "#"); // remove hashes from LHS of format
    while (sleftEnd.length > nleftEnd.length)
      nleftEnd = "0" + nleftEnd; // prepend zero to LHS of number

// patch provided by Drew Degentesh 2001/02/07
    var isNegative = (nleftEnd.length > 0 && nleftEnd.charAt(0) == "-");
    if (isNegative) nleftEnd = nleftEnd.substring (1);

    if (useSeparator) nleftEnd = separate(nleftEnd, separator); // add separator
    var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : ""); // combine parts
    output = ((useCurrency) ? currency : "") + output + ((usePercent) ? percent : "");
// Begin Change -- Harry Spear 02/15/01
    var outputStr = new String ((isNegative ? ((useCurrency) ? "(" : "-") : "") + output + ((isNegative && useCurrency) ? ")" : ""));
    return (isNegative && useCurrency ? outputStr.fontcolor(negCurFontClr) : outputStr);
// End Change
  }

  function strip(input, chars) { // strip all characters in 'chars' from input
    var output = ""; // initialise output string
    for (var i=0; i < input.length; i++)
      if (chars.indexOf(input.charAt(i)) == -1)
        output += input.charAt(i);
    return output;
  }

  function separate(input, separator) { // format input using 'separator' to mark 000's
    var output = ""; // initialise output string
    for (var i=0; i < input.length; i++) {
      if (i != 0 && (input.length - i) % 3 == 0) output += separator;
      output += input.charAt(i);
    }
    return output;
  }

function fnOpen(sURL, iHeight, iWidth, bScrollbars)
{
	var tmpWin, features, qt;

	vURL = sURL;

//	alert("fnOpen=" + homePageGuestName + "; " + vURL);

	features =	"status=no,toolbar=no,menubar=yes,location=yes,resizable=yes";
	if (!isNaN(iHeight))
	{
		features += ",height=" + iHeight;
	}
	if (!isNaN(iWidth))
	{
		features += ",width=" + iWidth;
	}
	if (bScrollbars)
	{
		features += ",scrollbars=yes";
	}

	tmpWin = window.open(vURL,"",features);
}

//---------------------------------
//GoTo SCRIPT BY ALEX KEENE 1997
//INFO@FIRSTSOUND.COM
//---------------------------------
function GoToURL(j, URLis) 
{
	window.status=('Connecting....')

//	alert("URL is " + URLis);
  
// 	var URLis;
// 	URLis = document.URLframe.Dest.value
  
   	if (URLis == "" || URLis.length <= 8)
        { 
     		j.value = "Try Again"
      		alert('\nOops!\n\nYou must enter a valid URL');
         	window.status=('Missing data or Invalid. Try again?.')
        } 
    	else
        {
 		j.value = "Connecting to: http://" + URLis 

//		alert("Connecting to: http://" + URLis + "  Please wait........");  

 		var location=(URLis);
         	this.location.href = location;
		window.status=('Connecting to ' + URLis + '  Please wait........');
        }
}
