//-----------------------------------------------------------------------------
// Layer Style.
//-----------------------------------------------------------------------------

function hideLayer(layer) {

	if (layer==null)
		return;
		
	switch (browser){
		case "NAV6":
		case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    layer.style.visibility = "hidden";
		    break;
	}
}

function showLayer(layer) {

	switch (browser){
		case "NAV6":
		case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    layer.style.visibility = "visible";
		    break;
	}
}

function isVisible(layer) {

	switch (browser){
		case "NAV6":
		case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
			if (layer.style.visibility == "visible" || layer.style.visibility=="")
				return(true);
	}

	return(false);
}

function getzIndex(layer) {

	switch (browser){
		case "NAV6":
		case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		     return(layer.style.zIndex);
	}

	return(-1);
}

function setzIndex(layer, z) {

	switch (browser){
		case "NAV6":
		case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    layer.style.zIndex = z;
		    break;
	}

}

function moveLayer(layer, x, y) {

	switch (browser){
		case "NAV6":
		case "NAV7":
		    layer.style.left = x + 'px';
		    layer.style.top  = y + 'px';
		    //layer.left = x + 'px';
		    //layer.top  = y + 'px';
		    break;
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    layer.style.pixelLeft = x;
		    layer.style.pixelTop  = y;
		    break;
	}
}

//-----------------------------------------------------------------------------
// Layer Attributes.
//-----------------------------------------------------------------------------

function getLayerLeft(layer){

	switch (browser){
		case "NAV6":
		case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		     return(layer.style.left);
	}

	return(-1);	

}

function setLayerLeft(layer, leftValue){

	switch (browser){
		case "NAV6":
		case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		     layer.style.left=leftValue;
	}

}

function getLayerTop(layer){

	switch (browser){
		case "NAV6":
		case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		     return(layer.style.top);
	}

	return(-1);	

}

function setLayerTop(layer, topValue){

	switch (browser){
		case "NAV6":
		case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		     layer.style.top=topValue;
	}

}

function getLayerWidth(layer){

	switch (browser){
		case "NAV6":
		case "NAV7":
		    return(parseInt(layer.style.width));
		    break;
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    return(layer.clientWidth);
	}

	return(-1);	

}

function getLayerHeight(layer){

	switch (browser){
		case "NAV6":
		case "NAV7":
		    return(parseInt(layer.style.height));
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    return(layer.clientHeight);
	}

}

//-----------------------------------------------------------------------------
// Layer clipping.
//-----------------------------------------------------------------------------

function clipLayer(layer, cliptop, clipright, clipbottom, clipleft) {

	if (isNaN(cliptop)==true) return;
	switch (browser){
		case "NAV6":
		case "NAV7":
			var newClip="rect(" + cliptop + " " +  clipright + " " + clipbottom + " " + clipleft + ")";
		    layer.style.clip = newClip;
		    break;
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    layer.style.clip = 'rect(' + cliptop + 'px ' +  clipright + 'px ' + clipbottom + 'px ' + clipleft +'px)';
		    break;
	}
}

function getClipLeft(layer) {

	switch (browser){
    	case "NAV6":
    	case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
			var str =  layer.style.clip;
			if (!str)
			  return(0);
			var clip = getClipValues(layer.style.clip);
			return(clip[3]);
	}

	return(-1);
}

function getClipTop(layer) {

	switch (browser){
		case "NAV6":
		case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
			var str =  layer.style.clip;
			if (!str)
			  return(0);
			var clip = getClipValues(layer.style.clip);
			return(clip[0]);
	}
	return(-1);
}

function getClipRight(layer) {

	switch (browser){
		case "NAV6":
		case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
			var str =  layer.style.clip;
			if (!str)
			  return(layer.style.pixelWidth);
			var clip = getClipValues(layer.style.clip);
			return(clip[1]);
	}
	return(-1);
}

function getClipBottom(layer) {

	switch (browser){
    	case "NAV6":
    	case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
			var str =  layer.style.clip;
			if (!str)
			  return(layer.style.pixelHeight);
			var clip = getClipValues(layer.style.clip);
			return(clip[2]);
	}
	return(-1);
}

function getClipWidth(layer) {

	switch (browser){
    	case "NAV6":
    	case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
			var str = layer.style.clip;
			if (!str)
			  return(layer.style.pixelWidth);
			var clip = getClipValues(layer.style.clip);
			return(clip[1] - clip[3]);
	}
	return(-1);
}

function getClipHeight(layer) {

	switch (browser){
    	case "NAV6":
    	case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
			var str =  layer.style.clip;
			if (!str)
			  return(layer.style.pixelHeight);
			var clip = getClipValues(layer.style.clip);
			return(clip[2] - clip[0]);
	}
	return(-1);
}

function getClipValues(str) {

  var clip = new Array();
  var i;

  // Parse out the clipping values for IE/NAV6 layers.

  i = str.indexOf("(");
  clip[0] = parseInt(str.substring(i + 1, str.length), 10);
  i = str.indexOf(" ", i + 1);
  clip[1] = parseInt(str.substring(i + 1, str.length), 10);
  i = str.indexOf(" ", i + 1);
  clip[2] = parseInt(str.substring(i + 1, str.length), 10);
  i = str.indexOf(" ", i + 1);
  clip[3] = parseInt(str.substring(i + 1, str.length), 10);
  return(clip);
}


//-----------------------------------------------------------------------------
// Layer utilities.
//-----------------------------------------------------------------------------

function findLayer(layerID, doc) {

  var i, layer;

	switch (browser){
		case "NAV6":
		case "NAV7":
			return document.getElementById(layerID);
		case "IE4":
		    return eval("document.all." + layerID);
		case "IE5":
		case "IE6":
		case "IE7":
		    return document.getElementById(layerID);
			
	}

  return null;

}


function setLayerBackgroundImage(layer, backgroundURL){

	switch (browser){
		case "NAV6":
		case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		     layer.style.backgroundImage="url(" + backgroundURL + ")";
		     break;
	}

}

function setLayerBackgroundColor(layer, backgroundColor){

	switch (browser){
		case "NAV6":
		case "NAV7":
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		     layer.style.backgroundColor=backgroundColor;
		     break;
	}

}



//-----------------------------------------------------------------------------
// Window and page properties.
//-----------------------------------------------------------------------------

function getWindowWidth() {

	switch (browser){
		case "NAV6":
		case "NAV7":
		    return(window.innerWidth);
		    break;
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    return(document.body.clientWidth);
	}
	return(-1);
}

function getWindowHeight() {

	switch (browser){
		case "NAV6":
		case "NAV7":
		    return(window.innerHeight);
		    break;
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    return(document.body.clientHeight);
	}
	return(-1);
}

function getPageWidth() {

	switch (browser){
		case "NAV6":
		case "NAV7":
		    return(document.body.scrollWidth);
		    break;
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    return(document.body.scrollWidth);
	}
	return(-1);
}

function getPageHeight() {

	switch (browser){
		case "NAV6":
		case "NAV7":
		    return(document.body.scrollHeight);
		    break;
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    return(document.body.scrollHeight);
	}
	return(-1);
}

function getPageScrollX() {

	switch (browser){
		case "NAV6":
		case "NAV7":
		    return(window.pageXOffset);
		    break;
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    return(document.body.scrollLeft);
	}
	return(-1);
}

function getPageScrollY() {

	switch (browser){
		case "NAV6":
		case "NAV7":
		    return(window.pageYOffset);
		    break;
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    return(document.body.scrollTop);
	}
	return(-1);
}

function getBodyLeftMargin() {

	switch (browser){
		case "NAV6":
		case "NAV7":
		    return document.body.marginwidth;
		    break;
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    return(document.body.leftMargin);
	}
	return(-1);
}

function getBodyTopMargin() {

	switch (browser){
		case "NAV6":
		case "NAV7":
		    return document.body.marginheight;
		    break;
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    return(document.body.topMargin);
	}
	return(-1);
}

function getBodyRightMargin() {

	switch (browser){
		case "NAV6":
		case "NAV7":
		    return document.body.marginwidth;
		    break;
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		    return(document.body.rightMargin);
	}
	return(-1);
}

function getElementOffsetTop(el) {

	switch (browser){
		case "NAV6":
		case "NAV7":
			return el.offsetTop;
			break;
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
			var TopOffset = el.offsetTop;
			var elParent = el.offsetParent;
			while (elParent != null) {
			    TopOffset += elParent.offsetTop;
			    elParent = elParent.offsetParent;
			}
			return TopOffset;
	}

}

function getElementOffsetLeft(el) {

	switch (browser){
		case "NAV6":
		case "NAV7":
			return el.offsetLeft;
			break;
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
			var LeftOffset = el.offsetLeft;
			var elParent = el.offsetParent;
			while (elParent != null) {
			    TopOffset += elParent.offsetLeft;
			    elParent = elParent.offsetParent;
			}
			return LeftOffset;
	}

}

function convertRGBToHex (RedValue, GreenValue, BlueValue) {

	if ((RedValue >255) || (RedValue < 0) || (GreenValue<0) || (GreenValue>255) || (BlueValue<0) || (BlueValue>255)){
		alert ("Please enter digits between 0 and 255");
		return false;
	}

	var HexRed = Dec2Hex(RedValue);
	var HexGreen = Dec2Hex(GreenValue);
	var HexBlue = Dec2Hex(BlueValue);
	
	return "#" +  HexRed + HexGreen + HexBlue;

}

function Dec2Hex (Dec) {

	var HexChars="012345689ABCDEF";
	
	var a = Dec % 16;
	var b = (Dec - a)/16;
	
	var hex = "" + HexChars.charAt(b) + HexChars.charAt(a);
	
	return hex;
}

function filenameFromURL(URLString) {

	var LastSlash=URLString.lastIndexOf ('/', URLString.length-1);
	var FileName=URLString.substring  (LastSlash+1, URLString.length);
	return FileName;
	
}	
// Attach an eventHandler to an element
function addEvent(oElement, eventHandler, eventName) {

	if (eventName.substring(0,2) == 'on'){
		eventName = eventName.substring(2, eventName.length);
	}
	
	switch (browser.browserGroup){
		case "NAV":
			oElement.addEventListener(eventName, eventHandler, false);
			break;
		case "IE":
			oElement.attachEvent('on' + eventName, eventHandler);
	}
	
}

// Remove an eventHandler from an element
function removeEvent(oElement, eventHandler, eventName) {

	if (eventName.substring(0,2) == 'on'){
		eventName = eventName.substring(2, eventName.length);
	}

	switch (browser.browserGroup){
		case "NAV":
			oElement.removeEventListener(eventName, eventHandler, true);
			break;
		case "IE":
			oElement.detachEvent(eventName, eventHandler);
	}
}