var timeout=30;

function browsercheck()
{
	this.ver=navigator.appVersion;
	this.agent=navigator.userAgent;
	this.dom=document.getElementById?1:0;
	this.opera5=this.agent.indexOf("Opera 5")>-1;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6;
	this.mac=this.agent.indexOf("Mac")>-1;
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5);
	return this;
}
var bw=new browsercheck();
var px = bw.ns4||window.opera?"":"px";

function makeObj(obj,nest)
{
	// base
    nest=(!nest) ? "":'document.'+nest+'.';
	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
  	this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
	this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight;
	this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight;
	
	// functions
	this.show=show;
	this.hide=hide;
	this.isvisible=isvisible;
	this.showhide=showhide;
	this.moveto=moveto;
	this.moveby=moveby;
	this.menuitem_onmouseover=menuitem_onmouseover;
	this.menuitem_onmouseout=menuitem_onmouseout;
	
	// used vars
	this.isscrolling=false;
	
	// position
	o=this.el;curleft=0;curtop=0;
	while (o.offsetParent)
	{
		curleft += o.offsetLeft;
		curtop += o.offsetTop;
		o = o.offsetParent;
	}
	
	this.x=curleft + this.css.left;
	this.y=curtop + this.css.top;
	
	// name
	this.obj = "o" + obj;
    eval(this.obj + "=this");
    return this;
}

function show()
{
	this.css.visibility="visible";
}

function hide()
{
	this.css.visibility="hidden";
}

function isvisible()
{
	return (this.css.visibility=="visible");
}

function showhide()
{
	if (this.css.visibility=="visible")
		this.css.visibility="hidden";
	else
		this.css.visibility="visible";
}

function moveto(x,y)
{	
	this.x = x;
	this.y = y;
	this.css.left = x + px;
	this.css.top = y + px;
}

function moveby(x,y)
{
	this.x = this.x+x;
	this.y = this.y+y;
	this.css.left = this.x+px;
	this.css.top = this.y+px;
}

var AUTOHIDE_DELAY = 1000
var visiblelayer = null;
var hidelayertimer = 0;

function menuitem_onmouseover(layer)
{
	clearTimeout(hidelayertimer);
	if (layer)
	{
		if (visiblelayer)
			visiblelayer.hide();
		visiblelayer=layer;
		visiblelayer.show();
	}
}

function menuitem_onmouseout()
{
	if (visiblelayer)
		hidelayertimer=setTimeout("visiblelayer.hide();",AUTOHIDE_DELAY);
}

function setSelectOptions(the_form, the_select, do_check)
{
    var selectObject = document.forms[the_form].elements[the_select];
    var selectCount  = selectObject.length;

    for (var i = 0; i < selectCount; i++) 
    {
        selectObject.options[i].selected = do_check;
    }

    return true;
}

function submitForm(the_form)
{
	var selectForm = document.forms[the_form];
	
    selectForm.submit();
}

function loadXMLDoc(url) 
{ 
if (window.XMLHttpRequest) { /* Firefox */ req = new XMLHttpRequest();req.onreadystatechange = processReqChange;req.open("GET", url, true);req.send(null);} 
else if (window.ActiveXObject) { /* Internet explorer */ req = new ActiveXObject("Microsoft.XMLHTTP");if (req) { req.onreadystatechange = processReqChange;req.open("GET", url, true);req.send();}}
}

function URLEncode( plaintext )
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

function URLDecode( encoded )
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
}

function initArray()
{
    this.length = initArray.arguments.length;
    for (var i = 0; i < this.length; i++)
        this[i] = initArray.arguments[i];
}

function from10toradix(value,radix)
{
    var retval = '';
    var ConvArray = new initArray(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F');
    var intnum;
    var tmpnum;
    var i = 0;

    intnum = parseInt(value,10);
    if (isNaN(intnum)){
        retval = 'NaN';
    }else{
        while (intnum > 0.9){
            i++;
            tmpnum = intnum;
            // cancatinate return string with new digit:
            retval = ConvArray[tmpnum % radix] + retval;  
            intnum = Math.floor(tmpnum / radix);
            if (i > 100){
                // break infinite loops
                retval = 'NaN';
                break;
            }
        }
    }
    return retval;
}

function leadingzero(num,ln)
{
	while (num.length<ln)
		num="0"+num;
	return num;
}
