function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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_changeProp(objName,x,theProp,theValue) { //v6.0
 var obj = MM_findObj(objName);
 if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
 if (theValue == true || theValue == false)
 eval("obj."+theProp+"="+theValue);
 else eval("obj."+theProp+"='"+theValue+"'");
 }
}

function showHide(objName,x,theProp,theValue) { 
/* hide divs with id="showHide0" to "showHide99" and show div with matching id 
onclick="showHide('showHide0','','style.display','block','DIV')"
IE bug alert: showHide = showhide as IE ignores case
*/
 var i,noneValue='none';
  for (i=0;i<=99;i++) 
	{
		var obj = MM_findObj(objName.substring(0,8)+i);
		if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
			if (noneValue == true || noneValue == false)
		      eval("obj."+theProp+"="+noneValue);
			else eval("obj."+theProp+"='"+noneValue+"'");
		}
		var obj = MM_findObj(objName);
		if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
			if (theValue == true || theValue == false)
		      eval("obj."+theProp+"="+theValue);
			else eval("obj."+theProp+"='"+theValue+"'");
		}
	}
}


function toggle(objName,x,theProp,theValue) { 
/* toggle divs with id of parameter
find the object
if none set to theValue
if theValue set to none
*/
	var targetBlock="showBlock"+objName;
	var targetShowImg="showImg"+objName;
	var objBlock = MM_findObj(targetBlock);
	var objShowImg = MM_findObj(targetShowImg);
	if(objBlock.style.display == "none"){
		objShowImg.src='../images/hide.gif';
		objBlock.style.display=theValue;
	}else{
		objShowImg.src='../images/show.gif';
		objBlock.style.display="none";
	}
}
function toggleTop(objName,x,theProp,theValue) { 
/* toggle divs with id of parameter
find the object
if none set to theValue
if theValue set to none
*/
/*	var targetBlock="content_top";*/
	var targetBlock="content_top";
	var objBlock = MM_findObj(targetBlock);
/*		*/
		objBlock.style.display=theValue;
		objBlock.style.display="none";
		/*document.body.scrollBy(0,300);*/
		/*objBlock.x="200";*/

}


/* externalLinks
turns tags like this
<a rel="external" href
into target="_blank"
but still validates as strict XHTML
*/
function externalLinks_old() 
{ 
    if (!document.getElementsByTagName) return; 
    var anchors = document.getElementsByTagName("a"); 
    var map = {external:"_blank", content:"content",parent:"_parent"}; 
    var anchor, i, target; 
	for (i=0; anchor=anchors[i++];)
	if( anchor.getAttribute("href") && (target=map[anchor.getAttribute("rel")]))
		anchor.setAttribute("target", target);
}

function externalLinks(){ 
/* rewrite links to enable javascript popups in valid xhtml pages 
valid values of rel are external or popup+parameters space delimited
examples of use
if rel='external' set target='_blank'
if rel='popup career 300 400' set onclick to popup in a window named career 300 wide and 400 high
*/
    if (!document.getElementsByTagName) {
		return; 
	}
	var defW = 640;
	var defH = 480;
	/* todo - check for missing or invalid width and height settings and set a default value for the popup*/
	var popupTitle = 'popup';
	var scrW = screen.availWidth;
    var scrH = screen.availHeight;
    var anchors = document.getElementsByTagName("a"); 
    var anchor, i, target, relIndex, relSplit, linkDest; 
    for (i=0;i<anchors.length;i++){
		anchor=anchors[i];
		/* does this anchor have a rel attribute set? */
		if( anchor.getAttribute("href") && anchor.getAttribute("rel") != null){
			linkDest = anchor.getAttribute("href"); 
			relIndex = anchor.getAttribute("rel"); 
			relSplit = relIndex.split(" ");
			switch(relSplit[0]) {
				case 'external' :
					anchor.setAttribute("target", "_blank");
					anchor.title+=' (external link that opens in new window)';
				break;
				case 'popup' :
/*					anchor.className+=anchor.className?' popup':'popup';*/
/* if popup parameters missing fill in with defaults */
					if(relSplit[1]==null){relSplit[1]='popup';}
					if(relSplit[2]==null){relSplit[2]=defW;}
					if(relSplit[3]==null){relSplit[3]=defH;}
					anchor.setAttribute("rel" , relSplit[0] + ' ' + relSplit[1] + ' ' + relSplit[2] + ' ' + relSplit[3]);
					/*anchor.title+=relSplit[1];*/
					/*anchor.title+=' (popup that opens in new window)';*/
					popupW=relSplit[2];
					popupH=relSplit[3];
					/*anchor.title+=' ' + popupW + 'x' + popupH;*/
					anchor.onclick=function(){newWin=window.open(this.href,this.rel.split(" ")[1],'location=no,menubar=no,status=no,resizable=yes,toolbar=no,scrollbars=yes,width=' + this.rel.split(" ")[2] + ',height=' + this.rel.split(" ")[3]);if(window.focus){newWin.focus()} return false;}
				break;
			}
		}
	}
}

function IE_showContent(){
/*document.documentElement.style.visibility = 'hidden';*/
document.documentElement.style.visibility = 'visible';
}

// Applies mimetype styles to hrefs in content div
function addDocLinks() {
	if(document.getElementById('content') != null){
		var content = document.getElementById('content');
		var contA = content.getElementsByTagName('a');
		var aCount = contA.length;
		for(i=0; i<aCount; i++) {
			var aExt = contA[i].href.slice(-3);
			switch(aExt) {
				case 'rtf' :
					contA[i].className = 'rtf';
					break;
				case 'pdf' :
					contA[i].className = 'pdf';
					break;
				case 'txt' :
					contA[i].className = 'txt';
					break;
			}
		}
	}
}

window.onload = function() {
	if(document.getElementById('new_58580000') != null){
		document.getElementById('new_58580000').focus();
	}
	if(document.getElementById('entered_code') != null){
		document.getElementById('entered_code').focus();
	}
	if(document.getElementById('barcode_entry') != null){
		document.getElementById('barcode_entry').focus();
	}
	externalLinks();
	/*IE_showContent(); IE css workaround, first hide, run IE7 css fixer then show after everything is in place commented out 28-9-2006*/
	/*showHide('showHide0','','style.display','block','DIV'); commented out 28-9-2006*/
/*	addDocLinks();*/
}
