ns = (navigator.appName == 'Netscape' && document.layers != null) ? true:false;
ns6 = (navigator.appName == 'Netscape' && document.getElementById) ? true:false;

function swapImage(LayerName, ImageName, ImageSrc) {
	if ((LayerName != "") && (ns)) {
		getLayer('',LayerName).document[ImageName].src=ImageSrc;
	} else {
		document[ImageName].src=ImageSrc;
	}
}

function ChangeLayerContent(LayerName, NewContent)
{
	thisLayer = getLayer(document,LayerName);
	if (document.layers) {	// NS
		thisLayer.document.open();
		thisLayer.document.write(NewContent);
		thisLayer.document.close();
	} else {	// IE & NS6
		thisLayer.innerHTML = NewContent;
	}
}

function getLayer (level, LayerName) {
	if (document.all) {
		// IE
		return eval(LayerName);
	} else if (document.getElementById) {
		// NS6
		return document.getElementById(LayerName);
	} else if (document.layers) {
		// NS
		if (level == "") { level = document; }
		if (level.layers) {
			for (var i = 0; i < level.layers.length; i++) {
				if (level.layers[i].name == LayerName) return level.layers[i];
				else if (level.layers[i].layers.length > 0) {
					var obj = getLayer(level.layers[i], LayerName)
					if (obj && obj != null) return obj;
				}
			}
		}
		return false;
	}
}

function swapLayers() { 
	// This function is dependant of the "getLayer" script
	var i, visStr, args, theObj;
	args = swapLayers.arguments;
	for (i=0; i<(args.length-1); i+=2) { //with arg pairs (objName,visStr)
		visStr = args[i+1];
		theObj = getLayer ('', args[i]);
		if (ns) { //NS
			if (theObj) theObj.visibility = visStr;
		} else { // IE / NS6
			if (visStr == 'show') visStr = 'visible'; //convert vals
			if (visStr == 'hide') visStr = 'hidden';			
			if (theObj) theObj.style.visibility = visStr;
		}
	}
}

function MoveLayerTo(LayerName, NewX, NewY) { 
	theObj = getLayer ('',LayerName);
	if (ns && theObj) { //NS
		theObj.y = NewY;
		theObj.x = NewX;
	} else if (theObj) { // IE / NS6
		theObj.style.top = NewY;
		theObj.style.left = NewX;		
	}
}

function getImagePosition(imagename) {
// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	ns6 = (navigator.appName == 'Netscape' && document.getElementById) ? true:false;
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=ImagePosition_getPageOffsetLeft(document.all[imagename]);
		y=ImagePosition_getPageOffsetTop(document.all[imagename]);
	} else if (use_gebi && !ns6) {
		var o=document.getElementById(imagename);
		x=o.offsetLeft; y=o.offsetTop;
	} else if (use_css) {
		x=ImagePosition_getPageOffsetLeft(document.all[imagename]);
		y=ImagePosition_getPageOffsetTop(document.all[imagename]);
	} else if (use_layers || ns6) {
		var found=0;
		for (var i=0; i<document.images.length; i++) {
			if (document.images[i].name==imagename) { found=1; break; }
		}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
		}
		if (ns6) {
			x=document.images[i].offsetLeft;
			y=document.images[i].offsetTop;
		} else {
			x=document.images[i].x;
			y=document.images[i].y;
		}			
	} else {
		coordinates.x=0; coordinates.y=0; return coordinates;
	}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
}

// Functions for IE to get position of an object
function ImagePosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
}
	
function ImagePosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
}

function openPopup() {

	url = arguments[0];

	var iWidth = 700;
	var iHeight = 540;
	var sScrollbars = "yes";
	
	if (arguments[1] != undefined) {
		iWidth = arguments[1];
	}
	if (arguments[2] != undefined) {
		iHeight = arguments[2];
	}
	if (arguments[3] != undefined) {
		sScrollbars = arguments[3];
	}		
	
	var winLeft = ((screen.width - iWidth) / 2)
	var winTop = ((screen.height - iHeight) / 2)
	windowFeatures = "width="+iWidth+",height="+iHeight+",scrollbars="+sScrollbars+",resize=no,";
	windowFeatures = windowFeatures + "top=" + winTop + ",";
	windowFeatures = windowFeatures + "left=" + winLeft;	
	window.open(url, "",windowFeatures);
}

function openCompPopup() {

	url = arguments[0];

	var iWidth = 760;
	var iHeight = 650;
	var sScrollbars = "yes";
	
	if (arguments[1] != undefined) {
		iWidth = arguments[1];
	}
	if (arguments[2] != undefined) {
		iHeight = arguments[2];
	}
	if (arguments[3] != undefined) {
		sScrollbars = arguments[3];
	}		
	
	var winLeft = ((screen.width - iWidth) / 2)
	var winTop = ((screen.height - iHeight) / 2)
	windowFeatures = "width="+iWidth+",height="+iHeight+",scrollbars="+sScrollbars+",resize=no,";
	windowFeatures = windowFeatures + "top=" + winTop + ",";
	windowFeatures = windowFeatures + "left=" + winLeft;	
	window.open(url, "",windowFeatures);
}



function openPrintPopup(url) 

{	var winTop = (screen.height / 2) - 300;
	var winLeft = (screen.height / 2) - 250;
	windowFeatures = "width=600,height=500,scrollbars=yes,";
	windowFeatures = windowFeatures + "top=" + winTop + ",";
	windowFeatures = windowFeatures + "left=" + winLeft;	
	window.open(url, "",windowFeatures);
	
}




