///////////////////////////////////////////////////////
// common.js
// 
// This file contains the common javascript functions.
//
// Mei W. Yang
// 01/03/02
///////////////////////////////////////////////////////

//
// Check if a string consists of all blanks
//
function isBlank(s) {
  out=trim(s);
  return((out.length==0));
}


//
// Check if a string is a number
//
function isNumber(s) {
  var mynumber=parseFloat(s);
  if (isNaN(mynumber)) return (false);
  var foundE=false;
  var foundDot=false;
  for (var i=0; i< s.length; i++) {
    if (s.charAt(i) < '0' || s.charAt(i) > '9') {
      if (s.charAt(i) == '+' || s.charAt(i) == '-') {
        if (i != 0 && !foundE) {
          return(false);
        }
      } else if (s.charAt(i) == 'e' || s.charAt(i) == 'E') {
        if (foundE) {
          return(false);
        }
        foundE=true;
      } else if (s.charAt(i) == '.') {
        if (foundDot) {
          return(false);
        }
        foundDot=true;
      } else {return(false);}
    }
  }
  return(true);
}

//
// Trim spaces in both ensd of a string
//
function trim(s) {
    out=new String(s);
    re=/^\s*/;
    out=out.replace(re,"");
    re=/\s*$/;
    out=out.replace(re,"");
    return(out);

}

//
// Hide print button when print
//
//    Usage example:
//    <div id="noprint">
//        <BUTTON onClick="printPage(window,document.all.noprint);">Print</BUTTON>
//    </div>

function printPage(win, obj)
{
obj.style.visibility='hidden';
win.print();
obj.style.visibility='visible';
}

//
// Hide multiple div tags when print using getElementByID instead of document.all
//
// Usage example where "null, null" could be replaced with other div tag IDs to hide in print:
// <div id="noprint1">
//     <BUTTON onClick="printPageSelection(window,'noprint1',null,null);">Print</BUTTON>
// </div>
function printPageSelection(win, obj1, obj2, obj3){
	if(obj1 != null) document.getElementById(obj1).style.visibility="hidden";
	if(obj2 != null) document.getElementById(obj2).style.visibility="hidden";
	if(obj3 != null) document.getElementById(obj3).style.visibility="hidden";
	win.print();
	if(obj1 != null) document.getElementById(obj1).style.visibility="visible";
	if(obj2 != null) document.getElementById(obj2).style.visibility="visible";
	if(obj3 != null) document.getElementById(obj3).style.visibility="visible";
}

//
// Disable right-click
//  (copied from http://web-wise-wizard.com/javascript-tutorials/disable-right-click.html)
//  to disable right-click, add the following to your page:
//     <script>
//         window.onload=trap_page_mouse_key_events;
//     </script>
//
//
function disable_right_click(e)
{
    var browser = navigator.appName.substring ( 0, 9 );
    var event_number = 0;
    if (browser=="Microsoft")
        event_number = event.button;
    else if (browser=="Netscape")
        event_number = e.which;

    if ( event_number==2 || event_number==3 )
        {
        alert ("Right Mouse Button Is Disabled");
        return (false);
        }

    return (true);
}

function check_mousekey ()
{
    var mouse_key = 93;
    var keycode = event.keyCode;

    if ( keycode == mouse_key )
        alert ( "Mouse Key Is Disabled" );
}

function trap_page_mouse_key_events ()
{
    var browser = navigator.appName.substring ( 0, 9 );

    document.onmousedown = disable_right_click;

    if ( browser == "Microsoft" )
        document.onkeydown = check_mousekey;
    else if ( browser == "Netscape" )
        document.captureEvents( Event.MOUSEDOWN );
}

function numeralsOnly(evt) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charChode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		alert("Enter numerals only in this field.");
		return false;
	}
	return true;
}

function breakout_of_frame(){
  if (top.location != self.location) {
        top.location = self.location.href;
  }
}

function handleMaskFF(eId,rootEl){
        if(rootEl.type == 'password'){
                rootEl.type="text";
                document.getElementById(eId).innerHTML='&nbsp; hide &nbsp;';
        }else{
                rootEl.type="password";
                document.getElementById(eId).innerHTML='show';
        }
        return false;
}
        //IE compatible
function handleMask(eId,rootEl){
         var newObj = document.createElement('input');
         newObj.setAttribute('name', 'loginid');
         newObj.setAttribute('id', 'loginid');
         newObj.setAttribute('value', rootEl.value);
         newObj.setAttribute('size','25');
         newObj.setAttribute('maxlength', '20');
         newObj.setAttribute('autocomplete','off');
         newObj.setAttribute('className', 'input');
         if(rootEl.type == 'password'){
               document.getElementById(eId).innerHTML='hide';
               newObj.setAttribute('type', 'text');
               rootEl.parentNode.replaceChild(newObj,rootEl);
               newObj.focus();
         }else{
               document.getElementById(eId).innerHTML='show';
               newObj.type = 'password';
               rootEl.parentNode.replaceChild(newObj,rootEl);
               newObj.focus();
         }
         return false;
}

