function P7_limit(a,b){ //v1.1.3 by PVII-www.projectseven.com
 document.p7limit=a;document.p7min=b;
 if(document.getElementById&&navigator.appVersion.indexOf("MSIE")>-1&&!window.opera){
 if(window.attachEvent){window.attachEvent("onresize",P7_setMinWidth);
 window.attachEvent("onload",P7_setMinWidth);}else{onload=P7_setMinWidth;
 onresize=P7_setMinWidth;}}}P7_limit('topwrapper',760);
function P7_setMinWidth(){ //v1.1.3 by PVII-www.projectseven.com
 var cw,w,pl,pr,ml,mr,br,bl,ad,theDiv=document.p7limit;
 var g=document.getElementById(theDiv);w=parseInt(document.p7min);
 if(g&&document.body&&document.body.clientWidth){gs=g.currentStyle;
 cw=parseInt(document.body.clientWidth);pl=parseInt(gs.paddingLeft);
 pr=parseInt(gs.paddingRight);ml=parseInt(gs.marginLeft);mr=parseInt(gs.marginRight);
 bl=parseInt(gs.borderLeftWidth);br=parseInt(gs.borderRightWidth);ml=ml?ml:0;
 mr=mr?mr:0;pl=pl?pl:0;pr=pr?pr:0;bl=bl?bl:0;br=br?br:0;ad=pl+pr+ml+mr+bl+br;
// if(cw<=w){w-=ad;g.style.width=w+"px";}else{g.style.width="auto";}}
   if(cw<=w){w-=ad;g.style.width=w+"px";}else{g.style.width="auto";}}
}


var myWidth=0;
var myLength=0;

// JavaScript Document
function initSearchBox(formfield) {
	document.getElementById(formfield).value = 'keywords, part #';
}
function PrePopSearchBox(formfield) {
	if (document.getElementById(formfield).value == '') 
		{	document.getElementById(formfield).value = 'keywords, part #';
		}
}

function emptySearchBox(formfield) {
	if (document.getElementById(formfield).value == 'keywords, part #') 
	{	document.getElementById(formfield).value = '';
	}
}

function overlay() {
	el = document.getElementById("overlay");
	el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}
	
function reportSize() {
	myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else {
		if( document.documentElement &&
				( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else {
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}
		}
	}
}

function setInnerWidth(w,h){
	window.resizeTo(800,800);
	reportSize();
	var oX = 800-myWidth;
	var oY = 800-myHeight;
	window.resizeTo( (w+oX) , (h+oY) );
}

function setStyle(objId, style, value){
		document.getElementById(objId).style[style]= value;
}
	/* USAGE:
	 * objId    = element id.
	 * style    = the style to be changed.
	 * value    = the value assigned to the style.
	*/

function doTest(){
	reportSize();
	var myNewHeight = myHeight-250;
	var footMargin = myHeight-40;
	//setStyle("sidebar","Height","480px");
	var sizeElement = document.getElementById("sidebar");
	var sizePage = document.getElementById("page");
	var sizeFooter = document.getElementById("footer");
	sizeElement.style.height = myNewHeight + 'px';
	//sizePage.style.height = myHeight-40 + 'px';
	//sizeFooter.style.marginBottom = '40px';
	//document.getElementById("currentvalues").innerHTML = "Current inner: "+myWidth+"*"+myHeight;
}

function init(){
	window.onresize = doTest;
	doTest();
}

function toggleLayer(whichLayer) {	
	if (document.getElementById)	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	}
	else 	{
		if (document.all)		{
			// this is the way old msie versions work
			var style2 = document.all[whichLayer].style;
			style2.display = style2.display? "":"block";
		}
		else 		{
			if (document.layers)			{
				// this is the way nn4 works
				var style2 = document.layers[whichLayer].style;
				style2.display = style2.display? "":"block";
			}
		}
	}
}	

function getposOffset(overlay, offsettype) {
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null)
	{
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function overlaymenu(curobj, subobjstr, opt_position){
	if (document.getElementById){
		var subobj=document.getElementById(subobjstr)
		subobj.style.display=(subobj.style.display!="block")? "block" : "none"
		var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0)
		var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
		xpos = xpos+curobj.offsetWidth
		ypos = ypos-(subobj.offsetHeight / 2)
		subobj.style.left=xpos+"px"
		//subobj.style.left="250px"
		subobj.style.top=ypos+"px"
		return false
	}
	else return true
}

function overlayclose(subobj){
	document.getElementById(subobj).style.display="none"
}

function setInnerHTML(layer,description){
	document.getElementById(layer).innerHTML=description;
}

// the following is used for toggling layer visibility on the exploding diagram pages
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  //return [ scrOfX, scrOfY ];
}

function getObject( obj ) {

  // look for object using standards friendly reference
  if ( document.getElementById ) {
    obj = document.getElementById( obj );

  // be friendly to IE 4 and others
  }
  else if ( document.all ) {
    obj = document.all.item( obj );
  // return a null reference in case we want to build null checks into any consuming methods
  }
	else {
		obj = null;
	}

  // return the reference
  return obj;
}
  
function moveObject( obj, e, position_x, offset_y ) {

  // declare the variables
  // offset is optional, set to 0 for layer to appear precisely where the mouse is
  var tempX = 0;
  var tempY = 0;
  var xoffset = -302; // 1/2 of the layer's width
  var yoffset = 55;
  var objHolder = obj;

  // get the client browser width and height
  reportSize();
  getScrollXY();
  // retrieve object reference
  obj = getObject( obj );
  if (obj==null) return;

  // retrieve mouse coordinates
  if (document.all) {
		if (event == null)
		{}else
		{
	    tempX = event.clientX + document.body.scrollLeft;
			tempY = event.clientY + document.body.scrollTop;
    }
  } else {
		if (e == null)
		{}
		else
		{
	    tempX = e.pageX;
			tempY = e.pageY;
    }
  }
  if (/MSIE 7/.test(navigator.userAgent)) {
	tempY = document.documentElement.scrollTop;
	tempX = document.documentElement.scrollLeft;
	}
	tempY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    tempY = window.pageYOffset;
    tempX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    tempY = document.body.scrollTop;
    tempX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    tempY = document.documentElement.scrollTop;
    tempX = document.documentElement.scrollLeft;
  }	


  // for now let's force the x-coord to be 1/2 of the screen width
  tempX = (myWidth/2);
  
  // simple error prevention (so layer won't appear off the screen)
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}


	var objwidth = obj.clientWidth;
	if (typeof(position_x) == 'undefined')
	{
		position_x = 'centered';
	}

	switch (position_x)
	{
		case 'centered':
			if (objwidth > 0)
			{
				xoffset = (objwidth / -2);
			}
			break;
		case 'centerright':
			xoffset = 0;
			break;
	}

	if (typeof(offset_y) == 'undefined')
	{
		offset_y = 0;
	}

	yoffset += offset_y;
		
	//  var objwidth = obj.style.width.substring(0,obj.style.width.indexOf("px"));
	//  if (objwidth > 0)
	//  {
	//    xoffset = Math.round(objwidth / 2);
	//  }
  
  // add retrieved values to the default offset and set as the pixel location of the layer
  obj.style.top  = (tempY + yoffset) + 'px';
  obj.style.left = (tempX + xoffset) + 'px';

  // change menu to visible, in it's new location
  displayObject( objHolder, true );
}
  
function displayObject( obj, show ) {

  // retrieve reference object
  obj = getObject( obj );
  if (obj==null) return;

  // set modifiers to display or hide the layer depending on the boolean
//  obj.style.display = show ? 'block' : 'none';
//  obj.style.visibility = show ? 'visible' : 'hidden';
}

// function to auto open tree nav upon page load
function preOpen(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var i,s,c,k,j,tN,hh,og;
		var b = document.getElementById(whichLayer);
		if(b.parentNode && b.parentNode.childNodes) 
		{ tN=b.parentNode.childNodes;
		} else { return;}
 
		for(i=0;i<tN.length;i++) { 
 			if(tN[i].tagName=="DIV"){ 
 				s=tN[i].style.display;
		 	  hh=(s=="block")?"none":"block";
	  		if(og==1){ 
	  			hh="block";
			  }
				tN[i].style.display=hh;
	 		}
	  }
	}
}

// function to print page
function printWindow(){
   bV = parseInt(navigator.appVersion)
   if (bV >= 4) window.print()
}


function applyStyle(pRule, pTarget, pStyleSheet)
{
	if (pRule == null) { return; }
	if (pTarget == null) { return; }
	if (!pTarget.style) { return; }
	if (pStyleSheet == null) { pStyleSheet = "webpropack"; }
	
	var regex = new RegExp("-([a-z|[A-Z])", "g");
	
	var ss = document.styleSheets;
	for (var i=0; i < ss.length; i++)
	{
		if (ss[i].href == null)
		{
			continue;
		}
		if (ss[i].href.toLowerCase().indexOf(pStyleSheet.toLowerCase()) > 0)
		{
			var rules = ss[i].rules || ss[i].cssRules;
			for (var j=0; j < rules.length; j++)
			{
				if (rules[j].selectorText.toLowerCase() == pRule.toLowerCase())
				{
					var cssText = rules[j].style.cssText.replace(pRule, "").replace("{", "");
					while (cssText.indexOf("; ") >= 0)
					{
						cssText = cssText.replace("; ", ";");
					}
					
					var arrCssText = cssText.split(";");
					for (var k=0; k < arrCssText.length; k++)
					{
						var arrRule = arrCssText[k].split(":");
						var property = arrRule[0].toLowerCase();
						while (regex.test(property) > 0)
						{
							var replacement = property.substr(regex.lastIndex - 1, 1).toUpperCase();
							property = property.replace(regex, replacement);
							//property = property.substring(0, regex.lastIndex - 2) + RegExp.lastMatch.toUpperCase() + property.substring(regex.lastIndex);
						}
						
						while (property.indexOf("-") >= 0)
						{
							property = property.replace("-", "");
						}

						if (arrRule[1] == null)
						{
							continue;
						}

						if (arrRule[1].indexOf(" ") == 0)
						{
							arrRule[1] = arrRule[1].substring(1);
						}

						if (property.length > 0)
						{
							pTarget.style[property]=arrRule[1];
						}

//						var cmd = "pTarget.style[\"";
//						cmd += property;
//						cmd += "\"]= '";
//						cmd += arrRule[1];
//						cmd += "';";



//						eval(cmd);
					}
				}
			}
		}
	}
}