//Javascript name: Common Tools
//FileName: common.js


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function highlight(row, item_series) {
	if (typeof(row.style) == 'undefined' || typeof(row.cells) == 'undefined') {
	    return false;
	}
	var num_rows = row.cells.length;
	for (var c = 0; c < num_rows; c++) {
	    row.cells[c].bgColor = item_series;
	}
	return true;
}

function GoToPage(location) {
	window.location.href = location;
}

/******************************************************************************/
// Embedded Popups

function showpopbox(sName,offsetX,offsetY,sLink) {
	// fix burn through
	fixBurnThru(true);

	// get the position of the associated link
	if ((sLink == null) || (sLink == "")) { 
		sLink = sName+'_link';
	}

	if (document.getElementById(sLink) != null) {
		var xPos = findPos(document.getElementById(sLink),'x');
		var yPos = findPos(document.getElementById(sLink),'y');
		// pad the position so the link will not be covered
		xPos = xPos + 5;
		yPos = yPos + 13;
	} else {
		// if there's no link to attach to, put the popup under the nav
		var xPos = 100;
		var yPos = 150;
	}
	// move elements if needed
	if (!isNaN(offsetX)) { xPos = xPos + offsetX; }
	if (!isNaN(offsetY)) { yPos = yPos + offsetY; }
	// open the embedded popup
	document.getElementById(sName).style.display = 'block';
	document.getElementById(sName).style.left = xPos + "px";
	document.getElementById(sName).style.top = yPos + "px";
	return;
}
function hidepopbox(sName) {
	// Closes the popups
	document.getElementById(sName).style.display = 'none';
	// fix burn through
    fixBurnThru(false);
	return;
}
// finds the position of the click to place the popup
function findPos(obj,axis) {
	var cur = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			if (axis == 'x') { cur += obj.offsetLeft }
			else { cur += obj.offsetTop }
			obj = obj.offsetParent;
		}
	} else {
		if ((axis == 'x') && (obj.x)) { cur += obj.x; }
		if ((axis == 'y') && (obj.y)) { cur += obj.y; }
	}
	return cur;
}
// fix the burnthrough on select elements in IE, ns6 and 7 do not have burn-through
// this script is duplicated in menu_settings.js as "fixBurn" for external sites (RNT, Unopi, etc)
function fixBurnThru(isHidden) {
	// only run for IE 6 or lower
	if (document.all && (navigator.userAgent.indexOf("MSIE 7") == -1)) {
		var rows = document.getElementsByTagName('select');
		for( var i = 0, row; row = rows[i]; i++ ) {
			if (isHidden) {
				row.style.visibility = "hidden";
			} else {
				row.style.visibility = "visible";
			}
		}
	}
	return;
}

function OpenNewWindow(theURL,myWidth,myHeight) {
  var myLeft = (screen.width-myWidth)/2; 
  var myTop = (screen.height-myHeight)/2;
  var winName = "viewer";
  var scroll_option = "no";
  var resize_option = "no";
  var features = 'toolbar=no,location=no,directories=no,status=no,menubar=no,width='+myWidth+',height='+myHeight+',top='+myTop+',left='+myLeft+',scrollbars='+scroll_option+',resizable='+resize_option;
  view_image=window.open(theURL,winName,features);
  //view_image.resizeTo(myWidth,myHeight);
  //view_image.window.focus();
}