//Checking the browser type
var isIE = false;
var isNav = (navigator.appName.indexOf("Netscape")>=0);
var isNav4 = false;
var isIE4 = false;
var is5up = false;
if (isNav) {
	if (parseFloat(navigator.appVersion)<5) {
		isNav4=true;
	} else {
		is5up = true;
	}
} else {
	isIE4=true;
	isIE=true;
	if (navigator.appVersion.indexOf("MSIE 5")>0) {
		isIE4 = false;
		is5up = true;
	}
}

// Create a DHTML layer
function setCursor(mode)
{
	var mapStyle;

	if (document.all) {
		mapStyle = document.all.theMapImage.style;
	}
	else
		return false;

	if (mode == "zoin" || mode == "zout" || mode == "info")
		mapStyle.cursor = "crosshair";
	else if (mode == "move")
		mapStyle.cursor = "move";
	else
		mapStyle.cursor = "default";
}

function createLayer(name, left, top, width, height, visible, content, bgcolor)
{
	var layer;
	//alert(name);
	//alert("top " + top);
	//alert("left " + left);
	//alert(width);
	//alert(height);
	//alert(content);
	//alert(bgcolor);
	if (isNav4) {
		document.writeln('<layer name="' + name + '" left=' + left + ' top=' + top + ' width=' + width + ' height=' + height +  ' visibility=' + (visible ? '"show"' : '"hide"') + ' bgcolor=' + bgcolor + '>');
		document.writeln(content);
		document.writeln('</layer>');
		layer = getLayer(name);
		layer.width = width;
		layer.height = height;
	}

	else {
		if (navigator.appVersion.indexOf("MSIE 6")>0)
		{
		//alert("ok " + visible);
			document.writeln('<div id="' + name + '" style="background-color: '+ bgcolor +'; position:absolute; overflow:none; left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px;' + ' visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');
			document.writeln(content);
			document.writeln('</div>');
		}
		else
		{
		//alert("ok2 " + navigator.appVersion);
			document.writeln('<div id="' + name + '" style="background-color: '+ bgcolor +'; position:absolute; overflow:none; left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px;' + ' visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');
			document.writeln(content);
			document.writeln('</div>');
		}
	}
	clipLayer(name, 0, 0, width, height);
}
// get the layer object called "name"
/*
function getLayer(name)
{
	if (document.layers)
		return(document.layers[name]);
	else if (document.all) {
		var layer = eval('document.all.' + name);

	  	if (layer != null) {
			return layer.style;
		}
		else
			return(null);
	}
	else
		return(null);
}
*/
function getLayer(name) {
	  if (isNav4) {
	    return(document.layers[name]);
	  }
	  else if (isIE4) {
	  	if ( eval('document.all.' + name) != null) {
		    layer = eval('document.all.' + name + '.style');
		    return(layer);
		} else
			return(null);
	  } else if (is5up) {
		var theObj = document.getElementById(name);
		return theObj.style
	  } else
	    return(null);
}

// move layer to x,y
function moveLayer(name, x, y)
{
  	var layer = getLayer(name);
	if (layer != null) {
	  	//if (document.layers)
	  	if (isNav4) {
	 		layer.moveTo(x, y);
        }
        else {
	  	//if (document.all) {
	 		layer.left = x + "px";
			layer.top  = y + "px";
	  	}
	}
}
/*

// toggle layer to invisible
function hideLayer(name)
{
	var layer = getLayer(name);

	if (layer != null) {
		//if (document.layers)
		if (isNav4)
	 		layer.visibility = "hide";
	  	//if (document.all)
	  	else
			layer.visibility = "hidden";
	}
}

// toggle layer to visible
function showLayer(name)
{
  var layer = getLayer(name);
  
	if (layer != null) {
	  	//if (document.layers)
	  	if (isNav4)
	 		layer.visibility = "show";
	  	//if (document.all)
	  	else
			layer.visibility = "visible";
	}
	
}*/

// toggle layer to invisible
function hideLayer(name)
{
	//alert("hide layer " + name);
	var layer = getLayer(name);
	if (name == "theLoadFlag"){
  		var layer2 = getLayer("theFilterImage");
	}
	else {
		var layer2 = null;
	}
	if (layer != null) {
		if (isNav4){
	 		layer.visibility = "hide";
	 	}
	  	else {
			layer.visibility = "hidden";
			if (layer2 != null){
				layer2.visibility = "hidden";
			}
		}
	}
}

// toggle layer to visible
function showLayer(name)
{
  //alert("show layer " + name);
  var layer = getLayer(name);
  if (name == "theLoadFlag"){
	 //alert("inside showlayer");
  	 var layer2 = getLayer("theFilterImage");
  }
  else {
	var layer2 = null;
  }
	if (layer != null) {
	  	if (isNav4){
	 		layer.visibility = "show";
	 	}
	  	else {
			layer.visibility = "visible";
			if (layer2 != null){
				layer2.visibility = "visible";
			}
			
		}
	}
	
}

// clip layer display to clipleft, cliptip, clipright, clipbottom
/*
function clipLayer(name, clipleft, cliptop, clipright, clipbottom)
{
	var layer = getLayer(name);
	if (layer != null) {
		if (document.layers) {
			layer.clip.top	= cliptop;
			layer.clip.left = clipleft;
			layer.clip.right = clipright;
			layer.clip.bottom = clipbottom;
		}
		if (document.all)
			layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
	}
}
*/

function clipLayer(name, clipleft, cliptop, clipright, clipbottom) {
	var layer = getLayer(name);
	if (layer != null) {
  		if (isNav4) {
			layer.clip.left   = clipleft;
			layer.clip.top    = cliptop;
		    layer.clip.right  = clipright;
			layer.clip.bottom = clipbottom;
		} else if (isIE) {
		//alert("cliptop " + cliptop + " clipright " + clipright + " clipbottom " + clipbottom + " clipleft " + clipleft);
			layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
	    } else {
     		layer.height = clipbottom - cliptop;
			layer.width	= clipright - clipleft;
			layer.top	= (cliptop+vspc) + "px";
			layer.left	= (clipleft+hspc) + "px";
			//alert(name + " clipped");
		}
	}
}
