var bhssel = '';

var theBrowser = '';
var theBrowserType = '';
var theBrowserName = '';
var theBrowserString = '';
var theBrowserOS = '';
var theBrowserOSString = '';

/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function rowColor(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '') || typeof(theRow.style) == 'undefined') 
      return false;

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') 
      theCells = theRow.getElementsByTagName('td');
    else if (typeof(theRow.cells) != 'undefined')
      theCells = theRow.cells;
    else
      return false;

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined' && typeof(theCells[0].getAttribute) != 'undefined')
      { currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
      }
    // 3.2 ... with other browsers
    else 
    	{ currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
      } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
      { var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1, currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
          { var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
          }
      }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase())
      { if (theAction == 'over' && thePointerColor != '')
          newColor = thePointerColor;
        else if (theAction == 'click' && theMarkColor != '')
          { newColor = theMarkColor;
            marked_row[theRowNum] = true;
          }
      }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) 
      { if (theAction == 'out')
          newColor = theDefaultColor;
      }
    else if (theAction == 'click' && theMarkColor != '')
      { newColor = theMarkColor;
        marked_row[theRowNum] = true;
      }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase())
      { if (theAction == 'click') 
      	  { newColor = (thePointerColor != '') ? thePointerColor : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum]) ? true : null;
          }
      } // end 4

    // 5. Sets the new color...
    if (newColor) 
      { var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) 
          { for (c = 0; c < rowCellsCnt; c++)
              theCells[c].setAttribute('bgcolor', newColor, 0);
          }
        // 5.2 ... with other browsers
        else 
        	{ for (c = 0; c < rowCellsCnt; c++)
              theCells[c].style.backgroundColor = newColor;
          }
      } // end 5

    return true;
  } // end of the 'setPointer()' function

function doLogSubmit(myFRM, pgmpath, fr)
  { var myURL = "";
  
    myURL = pgmpath + 'bhssystem/pickitup/showlog_lines.php';
    myURL = myURL + '?sid=' + escape(myFRM.sid.value);
    myURL = myURL + '&name=' + escape(myFRM.name.value);
    myURL = myURL + '&what=' + escape(myFRM.what.value);
    myURL = myURL + '&type=' + escape(myFRM.type.value);
    myURL = myURL + '&cols=' + escape(myFRM.cols.value);
    myURL = myURL + '&stdate=' + escape(myFRM.stdate.value);
    myURL = myURL + '&l01=' + escape(myFRM.l01.checked);
    myURL = myURL + '&l02=' + escape(myFRM.l02.checked);
    myURL = myURL + '&l03=' + escape(myFRM.l03.checked);
    myURL = myURL + '&l04=' + escape(myFRM.l04.checked);
    
    if (fr == 'content')
  	  top.content.LOGLINES.document.location.href = myURL;
  	else
  	  top.LOGLINES.document.location.href = myURL;
  	
  	return(true);
  }

function menu_click(row, ncol, ccol)
  { alert (row+" "+tlin[row].style);
  }

function _checkBrowser()
  { var x = "ukn";
  	var bn = "Unknown";
  	var bt = "";
  	
  	if (document.ids)
      { x = 'nc4';
      	bn = "Netscape 4";
      	bt = "ns";
      }
    else if( document.all && !document.getElementById )
    	{ x = 'ie4';
    	  bn = "Internet Explorer 4";
    	  bt = "ie";
    	}
    else if( window.opera && !document.createElement )
    	{ x = 'op5';
    		bn = "Opera 5";
    		bt = "opera";
      }
    else if( window.opera && window.getComputedStyle )  
    	{ bn = "Opera ";
    		bt = "opera";
    		if(document.createRange)
    		  { x = 'op8';
    		  	bn += "8";
    		  }
        else if(window.navigate)
        	{ x = 'op7.5';
        		bn += "7.5";
        	}
        else 
        	{ x = 'op7.2';
        		bn += "7.2";
        	}
      }
    else if( window.opera && document.compatMode )
    	{ x = 'op7';
    		bn = "Opera 7";
    		bt = "opera";
    	}
    else if( window.opera && document.releaseEvents )
    	{ x = 'op6';
    		bn = "Opera 6";
    		bt = "opera";
    	}
    else if( document.contains && !window.opera )
    	{ x = 'kq3';
    		bn = "Konqueror 3";
    		bt = "konq";
      }
    else if(window.pkcs11&&window.XML)
    	{ x = 'f15'; 
    		bn = "Firefox 1.5";
    		bt = "mozilla";
      }
    else if( window.getSelection && window.atob )
    	{ x = 'nn7';
    		bn = "Netscape 7";
    		bt = "netscape";
      }
    else if( window.getSelection && !document.compatMode )
    	{ x = 'nn6';
    		bn = "Netscape 6";
    		bt = "netscape";
      }
    else if( window.clipboardData && document.compatMode )
      { if (window.XMLHttpRequest)
      	  { x = 'IE7';
      	  	bn = "Internet Explorer 7";
      	  	bt = "ie";
      	  }
      	else
      	  { x = 'IE6';
      	  	bn = "Internet Explorer 6";
      	  	bt = "ie";
      	  }
      }
    else if( window.clipboardData )
    	{ bn = "Internet Explorer 5";
    		bt = "ie";
    		x = 'ie5';
        if( !document.createDocumentFragment ) 
          { x += '.5';
          	bn += '.5';
          }
        if ( document.doctype && !window.print ) 
          { x += 'm';
          	bt = "ie";
          	theBrowserOS = "mac";
          }
      }
    else if( document.getElementById && !document.all ) 
    	{ x = 'op4';
    		bn = "Opera 4";
    		bt = "opera";
    	}
    else if( document.images && !document.all ) 
      { x = 'nn3';
      	bn = "Netscape 3";
      	bt = "ns";
      }
    else if(document.clientWidth&&!window.RegExp)
    	{ x = 'kq2';
    		bn = "Konqueror 2";
    		bt = "konq";
      }
    else if(window.updateCommands && !xxx)
    	{ x = 'kmel';
    		bn = "K-Meleon";
    		bt = "mozilla";
      }
    else 
    	{ x = 'ukn';
    		bn = "Unknown Browser";
    		bt = "unknown";
      }
    
    theBrowser = x;
    theBrowserName = bn;
    theBrowserType = bt;
    
    theBrowserOSString = (theBrowserOS == "mac") ? "Macintosh" : 'Win/other';
    theBrowserString = bn + ((theBrowserOSString != "") ? " (" + theBrowserOSString + ")" : '');
    
    return(true);
  }
 
function _browserInit()
  { _checkBrowser();
  	
  	return(true);
  }

function _trim(str)
  { while (str.substring(0,1)==' ')
  	  str = str.substring(1,str.length);
    while (str.substring(str.length-1,str.length)==' ')
      str = str.substring(0,str.length-1);
    return str;
  }
  
function getMozSelection(txtarea) 
  { var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		if (selEnd==1 || selEnd==2) selEnd=selLength;
		return((txtarea.value).substring(selStart, selEnd));
	}

function getsel(obj)
  { if (theBrowserType == 'mozilla') 
  	  bhssel = getMozSelection(obj);
    else if (theBrowserType == 'netscape')
    	bhssel = document.getSelection();
    else if (theBrowserType == 'ie') 
    	bhssel = document.selection.createRange().text;
    else 
    	return(false);
    bhssel = bhssel.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");

    return(true);
  }
  
 /* ********************************************************************************
 * Function printf(format_string,arguments...)
 * Javascript emulation of the C printf function (modifiers and argument types 
 *    "p" and "n" are not supported due to language restrictions)
 *
 * Copyright 2003 K&L Productions. All rights reserved
 * http://www.klproductions.com 
 *
 * Terms of use: This function can be used free of charge IF this header is not
 *               modified and remains with the function code.
 * 
 * Legal: Use this code at your own risk. K&L Productions assumes NO resposibility
 *        for anything.
 ******************************************************************************** */
function sprintf(fstring)
  { var pad = function(str,ch,len)
      { var ps='';
        for(var i=0; i<Math.abs(len); i++) ps+=ch;
        return len>0?str+ps:ps+str;
      }
    var processFlags = function(flags,width,rs,arg)
      { var pn = function(flags,arg,rs)
          { if(arg>=0)
              { if(flags.indexOf(' ')>=0) rs = ' ' + rs;
                else if(flags.indexOf('+')>=0) rs = '+' + rs;
              }
            else
                rs = '-' + rs;
            return rs;
          }
        var iWidth = parseInt(width,10);
        if(width.charAt(0) == '0')
          { var ec=0;
            if(flags.indexOf(' ')>=0 || flags.indexOf('+')>=0) ec++;
            if(rs.length<(iWidth-ec)) rs = pad(rs,'0',rs.length-(iWidth-ec));
            return pn(flags,arg,rs);
          }
        rs = pn(flags,arg,rs);
        if(rs.length<iWidth)
          { if(flags.indexOf('-')<0) rs = pad(rs,' ',rs.length-iWidth);
            else rs = pad(rs,' ',iWidth - rs.length);
          }    
        return rs;
      }
    var converters = new Array();
    converters['c'] = function(flags,width,precision,arg)
      { if(typeof(arg) == 'number') return String.fromCharCode(arg);
        if(typeof(arg) == 'string') return arg.charAt(0);
        return '';
      }
    converters['d'] = function(flags,width,precision,arg)
      { return converters['i'](flags,width,precision,arg); 
      }
    converters['u'] = function(flags,width,precision,arg)
      { return converters['i'](flags,width,precision,Math.abs(arg)); 
      }
    converters['i'] =  function(flags,width,precision,arg)
      { var iPrecision=parseInt(precision);
        var rs = ((Math.abs(arg)).toString().split('.'))[0];
        if(rs.length<iPrecision) rs=pad(rs,' ',iPrecision - rs.length);
        return processFlags(flags,width,rs,arg); 
      }
    converters['E'] = function(flags,width,precision,arg) 
      { return (converters['e'](flags,width,precision,arg)).toUpperCase();
      }
    converters['e'] =  function(flags,width,precision,arg)
      { iPrecision = parseInt(precision);
        if(isNaN(iPrecision)) iPrecision = 6;
        rs = (Math.abs(arg)).toExponential(iPrecision);
        if(rs.indexOf('.')<0 && flags.indexOf('#')>=0) rs = rs.replace(/^(.*)(e.*)$/,'$1.$2');
        return processFlags(flags,width,rs,arg);        
      }
    converters['f'] = function(flags,width,precision,arg)
      { iPrecision = parseInt(precision);
        if(isNaN(iPrecision)) iPrecision = 6;
        rs = (Math.abs(arg)).toFixed(iPrecision);
        if(rs.indexOf('.')<0 && flags.indexOf('#')>=0) rs = rs + '.';
        return processFlags(flags,width,rs,arg);
      }
    converters['G'] = function(flags,width,precision,arg)
      { return (converters['g'](flags,width,precision,arg)).toUpperCase();
      }
    converters['g'] = function(flags,width,precision,arg)
      { iPrecision = parseInt(precision);
        absArg = Math.abs(arg);
        rse = absArg.toExponential();
        rsf = absArg.toFixed(6);
        if(!isNaN(iPrecision))
          { rsep = absArg.toExponential(iPrecision);
            rse = rsep.length < rse.length ? rsep : rse;
            rsfp = absArg.toFixed(iPrecision);
            rsf = rsfp.length < rsf.length ? rsfp : rsf;
          }
        if(rse.indexOf('.')<0 && flags.indexOf('#')>=0) rse = rse.replace(/^(.*)(e.*)$/,'$1.$2');
        if(rsf.indexOf('.')<0 && flags.indexOf('#')>=0) rsf = rsf + '.';
        rs = rse.length<rsf.length ? rse : rsf;
        return processFlags(flags,width,rs,arg);        
      }  
    converters['o'] = function(flags,width,precision,arg)
      { var iPrecision=parseInt(precision);
        var rs = Math.round(Math.abs(arg)).toString(8);
        if(rs.length<iPrecision) rs=pad(rs,' ',iPrecision - rs.length);
        if(flags.indexOf('#')>=0) rs='0'+rs;
        return processFlags(flags,width,rs,arg); 
      }
    converters['X'] = function(flags,width,precision,arg)
      { return (converters['x'](flags,width,precision,arg)).toUpperCase();
      }
    converters['x'] = function(flags,width,precision,arg)
      { var iPrecision=parseInt(precision);
        arg = Math.abs(arg);
        var rs = Math.round(arg).toString(16);
        if(rs.length<iPrecision) rs=pad(rs,' ',iPrecision - rs.length);
        if(flags.indexOf('#')>=0) rs='0x'+rs;
        return processFlags(flags,width,rs,arg); 
      }
    converters['s'] = function(flags,width,precision,arg)
      { var iPrecision=parseInt(precision);
        var rs = arg;
        if(rs.length > iPrecision) rs = rs.substring(0,iPrecision);
        return processFlags(flags,width,rs,0);
      }
    farr = fstring.split('%');
    retstr = farr[0];
    fpRE = /^([-+ #]*)(\d*)\.?(\d*)([cdieEfFgGosuxX])(.*)$/;
    for(var i=1; i<farr.length; i++)
      { fps=fpRE.exec(farr[i]);
        if(!fps) continue;
        if(arguments[i]!=null) retstr+=converters[fps[4]](fps[1],fps[2],fps[3],arguments[i]);
        retstr += fps[5];
      }
    return retstr;
  }
/* Function sprintf() END */

function bhs_getBrowserLanguage()
  { if (navigator.appName == 'Netscape')
      var language = navigator.language;
    Else
      var language = navigator.browserLanguage;

    return(language);
  }

