/*
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Ispat Inland Benefits
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Title: 			common_javascript.js
Author:			Raymond S. Pietrzak
Date Written:	02/28/2002
--------------------------------------------------------------------------------
 Common javascript functions for the Benefits Web Site
--------------------------------------------------------------------------------
Maintenance Log
-------------------------------------------------------------------------------
02/28/2002 - Raymond S. Pietrzak: Original Creation
-------------------------------------------------------------------------------
*/

//Prints the document in the Contents_Frame
function Print_Document() {
   top.Contents_Frame.focus();
	Window.print();
}

function Process_Link(Menu_Key, Show_Details, Target) {

   if (Target == null)
      Target = "_blank";

   URL = "contents.asp?Menu_Key=" + Menu_Key;

   Open_Window(URL, Show_Details, Target);
}

//Open_Window function opens a new window
//URL: Address of the New Window
//Show_Details: true - show Menu Bar and Location, false (default) - Hide
//					 Menu Bar and Location
//Location: Location or Frame Name of the new window (default - "_blank")
function Open_Window(URL, Show_Details, Location) {
	var w = screen.availWidth * 0.96;

	if (!Location)
		Location = "_blank";

	if (Show_Details) {
		var h = screen.availHeight * 0.70;
		var Show = "yes";
	}
	else {
		var h = screen.availHeight * 0.80;
		var Show = "no";
	}

	w = w.toString();
	h = h.toString();

	if (Location != "_blank")
		window.open(URL, Location);
	else
		window.open(URL,
						Location,
						"left=0" +
						",top=0" +
						",width=" + w +
						",height=" + h +
						",resizable=yes" +
						",scrollbars=yes" +
						",toolbar=yes" +
						",location=" + Show +
						",menubar=yes");
}

//Trims a text area down to the maxlength property. To use this, set the
//maxlength = maximum number of characters for the text area
//set the onkeyup event = Trim_Text()
function Trim_Text() {
   var s = event.srcElement.value;
   var l = s.length;
   var m = event.srcElement.maxlength;
   if (l > m) {
   	alert("You have exceeded the maximum number of characters for this " +
   			"field: " + m +
   	      ". The value will be trimmed to " + m + " characters.");
      event.srcElement.value = s.substr(0, event.srcElement.maxlength);
   }
}

//Returns Text with leading and trailing spaces removed
function Trim(Text) {
   var s = r = Text;
   var l = s.length;
   var i;

   for (i = 0; i < l; ++i) {
      if (s.substr(i, 1) == " ")
         r = s.substring(i + 1, l);
      else
         break;
   }
   s = r;
   l = s.length;

   for (i = l - 1; l >= 0; --i) {
      if (s.substr(i, 1) == " ")
         r = r.substring(0, i)
      else
         break;
   }
   return(r);
}

// Auto-Tab to the next form field when the field length = maxLength characters
// Call in the onkeyup event: onkeyup="Auto_Tab()"
function Auto_Tab() {
	var key = event.keyCode;
	var form = document.forms[0];
	var Object = event.srcElement;
	var i;

	if (key < 48 && key != 32)
		return;

	if (Object.value.length == Object.maxLength) {
		for (i = 0; i < form.length; ++i) {
			if (form.elements[i] == Object)
				form.elements[i + 1].focus();
		}
	}
}