//common.js
var blinkCount = 5;
var timerBl;
var mpane;
var delayBl = 300;
var delayMsgWait = 4500;
var scWidth = screen.width;
var leftPos = ((scWidth - 760) / 2) - 11;
function messagepanel(message,status){

	mpane = document.getElementById('message_pane');
	mpane.style.left = leftPos;
	mpane.innerHTML = message;
	
	switch(status){
		case 0:
			mpane.style.display = "none";
			break;
		case 1:
			mpane.style.display = "block";
			mpane.style.background= "#D41E13";
			mpane.style.color= "#ffffff";
			blinkCount = 5;
			showMpane();
			break;
		case 3:
			mpane.style.display = "block";
			mpane.style.background = "#8AA3A0";
			mpane.style.color = "#FFFFFF";
			break;			
		case 4:
			mpane.style.background = "#FF9933";
			mpane.style.color = "#FFFFFF";
			blinkCount = 4;
			delayMsgWait = 2500;
			showMpane();
			break;
	}
}

function showMpane(){
		//mpane.style.background = "#FFFFFF";
		mpane.style.display = "block";
		timerBl = setTimeout('hideMpane()',delayBl);
		if(blinkCount == 0){
			clearTimeout(timerBl);
			setTimeout('messagepanel("",0)',delayMsgWait);
		}
}

function hideMpane(){
		//mpane.style.background = "#000000";
		mpane.style.display = "none";
		timerBl = setTimeout('showMpane()',delayBl);
		blinkCount--;
}

/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}

function disableElement(elementId){
	document.getElementById(elementId).disabled = true;
	}
function enableElement(elementId){
	document.getElementById(elementId).disabled = false;
	}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function validate(){
	//simple form validaton for text fields
	for(i=0;i<arguments.length;i++)
		if(Trim(document.getElementById(arguments[i]).value) == ""){
			messagepanel("Simple blanks are not allowed",4);
			return false;
		}
return true;
}


function compare(oldObj,newObj,confirmObj){
	if(document.getElementById(newObj).value != document.getElementById(confirmObj).value){
		messagepanel('Password confirmation does not match!',1);
		return false;
		}
	if(Trim(document.getElementById(oldObj).value) == ''){
		messagepanel('Check old password..!',1);
		return false;
		}
	if(Trim(document.getElementById(newObj).value) == ''){
		messagepanel('Check new password.. Blanks are not accepted!',1);
		return false;
		}
	}
	


/**
 * Sets/unsets the pointer in browse mode
 *
 * @param   object   the table row
 * @param   object   the color to use for this row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, thePointerColor)
{
    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        var theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        var theCells = theRow.cells;
    }
    else {
        return false;
    }

    var rowCellsCnt  = theCells.length;
    for (var c = 0; c < rowCellsCnt; c++) {
        theCells[c].style.backgroundColor = thePointerColor;
    }

    return true;
} // end of the 'setPointer()' function

