
var AgntUsr = navigator.userAgent.toLowerCase();
var DomYes = (document.getElementById)?1:0;
var NavYes = (AgntUsr.indexOf('mozilla') != -1 && AgntUsr.indexOf('compatible') == -1)?1:0;
var ExpYes = (AgntUsr.indexOf('msie') != -1)?1:0;
var Opr5 = (AgntUsr.indexOf('opera 5')!= -1 || AgntUsr.indexOf('opera/5') != -1)?1:0;
var DomNav = (DomYes && NavYes)?1:0;
var DomExp = (DomYes && ExpYes)?1:0;
var Nav4 = (NavYes && !DomYes && document.layers)?1:0;
var Exp4 = (ExpYes && !DomYes && document.all)?1:0;

var randomnumber = Math.round(Math.random() * 100000);
var contentblock = 0;

//-----------------------------------------------------------------------------
//code for search function in masthead
function checkform ( form )
{
    if (form("sp-q").value == "") {
        alert( "Please enter a term in the search box." );
        form("sp-q").focus();
        return false ;
    }
	return true ;
}


//-----------------------------------------------------------------------------
//jump menus

function jumpMenu (target,selObj,restore) {
  if (selObj.selectedIndex > 0 && selObj.options[selObj.selectedIndex].value != '') {
    window.open(selObj.options[selObj.selectedIndex].value,target);
  }
  else if (selObj.options[selObj.selectedIndex].value == '') {
    selObj.selectedIndex = 0;
  }
  if (restore)
    selObj.selectedIndex = 0;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//-----------------------------------------------------------------------------
function skipTo (obj) {
  location.href = "#" + obj[obj.selectedIndex].value;
  return false;
}

//-------------------------------------------------------
function ad(p, r) {
  var num = Math.round(Math.random() * 10000000);
  var ord = "<a href='http://" + p + "jump" +  r + "ord=" + num + "?'><img src='http://" + p + "ad" + r + "ord=" + num + "?' border='0'></a>";
  return ord;
} 

//-------------------------------------------------------
function openprintable(page) {
 OpenWin = window.open(page, "CtrlWindow", "resizable=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,status=no ,height=500,width=657");
}


//-------------------------------------------------------
//code to pop-up a window and other Dreamweaver built beahavior code 

function openWin(theURL, winName, features) {
  window.open(theURL, winName, features);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
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_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_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];}
}


//-------------------------------------------------------
//  code for NEW sweets search box

function MHCSearch()
		{
			var search_keyword=document.getElementById('ad_keyword').value;
			if (search_keyword != '')
			{
			window.open('http://products.construction.com/portal/server.pt?open=512&objID=204&PageID=252&cached=true&mode=2&querySearch='+search_keyword+'&mustInclude=&searchSource=ES');
			}
		}
		
//----- BEGIN: rollover functionality for AR menus to work in IE ------

startList = function() {	
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("navigation");
		if(navRoot != null && "undefined" != typeof(navRoot)) {
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") { 
					node.onmouseover=function()  {
						this.className+=" over";
					}
					node.onmouseout = function() {
						this.className=this.className.replace(" over", "");
					}
				}
			}
		}
	}
}

window.onload=startList;

//-------END rollover functionality for menus in IE ----


//this function prevents the return/enter key from working becuase the sweets search box throws a severe error 
function stopRKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
}

document.onkeypress = stopRKey;



//------Function for tabs for recently most commented & recomended widget

	function setDisplay( objectID, state, objectIDOff, stateOff, tabA, tabB){
		var object = document.getElementById(objectID);
		object.style.display = state;
		var objectOff =  document.getElementById(objectIDOff);
		objectOff.style.display = stateOff;
		var FontTab = document.getElementById(tabA);
		FontTab.className = "currentTabFront";
		var BackTab = document.getElementById(tabB);
		BackTab.className = "currentTabBack";
	}



//-------  OAS QUERY function for BTS section - the following function will grab the sub section of a BTS article and put it in the OAS query location
// --- required on to call this function: OAS_query = getBTSquery(); 

function getBTSquery() {
		var subsection = document.location.href
		var subsectionArray = new Array();
		subsectionArray = subsection.split("\/"); 
		return subsectionArray[6];
}
//------- END OAS QUERY function for BTS section	
		
		

//------START: get  directory names -------------//

function getDirectoryName(whichDir) { //returns the name of directory you need: call  - getDirectoryName(1) or getDirectoryName(2) etc
		var subsection = document.location.href;
		var subsectionArray = new Array();
		subsectionArray = subsection.split("\/");
		var directory = whichDir + 2;
		var DirName = subsectionArray[directory];
		if (DirName == undefined){
		return '';
			} else { 
			return DirName.toLowerCase();
			}
		
}	

//------END: get  directory names -------------//


//------- RESIZES WINDOW FOR SLIDESHOWS  ------
function changeWindowSize(windowWidth,windowHeight) {
	top.window.resizeTo(windowWidth,windowHeight);
}

//------- OPEN in window behind if existing - otherwise will  open a new window  ------
function openclose(theURL){

		if(top.window.opener &&!top.window.opener.closed) {
			top.window.opener.location=theURL;
		}
		else {
			window.open(theURL,'','toolbar=yes,location=yes,status=yes,scrollbars=yes');
		}
		top.window.close();
}

//------- CHANGE TEXT SIZE IN ARTICLES  ------
function changetext(size){
		var textSmallerLink = document.getElementById('textSmaller');
		var textLargerLink = document.getElementById('textLarger');
		var articleText = document.getElementById('articleBodyText');
		var currentChoice =  document.getElementById(size);
		currentChoice.className = 'current';
		if(currentChoice == textLargerLink){
		textSmallerLink.className = '';
		articleText.className = 'largerText';
		}else {textLargerLink.className = '';
		articleText.className = '';
		}
	}

// ------ load a function when windoe is done loading ----------//

function addLoadEvent(func) {
	var oldonload = window.onload;
	
	if (typeof window.onload != 'function') {
		window.onload = func;
	} 
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// ------ hide comments on individual article ----------//

function hidecomments(){
	var getComments = document.getElementById('comments');
	var getCommentLink =  document.getElementById('commentTool');
		getComments.style.display="none";
		getCommentLink.style.display="none";
	}
	// drop thge following code somewhere on the article who's comment you want to hide:	
	//	inside a JS tag - addLoadEvent(hidecomments);
	
	
	

// **************************************************************************************
// ************************* new for 2010 project page redesign *************************
// **************************************************************************************
	
	
//-- BEGIN: code for in-window pop-up VIDEO window ------------------


	function findWindowWidth(){
		
			if( typeof( window.innerWidth ) == 'number' ) {
				//Non-IE
				return window.innerWidth;
			} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
				//IE 6+ in 'standards compliant mode'
				return document.documentElement.clientWidth;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				return document.body.clientWidth;
		  }
			return (null);
	
		}
		function findWindowHeight(){
	
			 if( typeof( window.innerWidth ) == 'number' ) {
				//Non-IE
				return window.innerHeight;
			  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
				//IE 6+ in 'standards compliant mode'
				return document.documentElement.clientHeight;
			  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				return document.body.clientHeight;
			  }
			return (null);
	
		}
		
		function openVideoPopUp(){
		
			var videoPopOutBoxObj = document.getElementById('videoPopOutBox');
			var videoPopOutThumbnailOjb = document.getElementById('videoPopOutThumbnail');
			var grayScreen = document.getElementById('grayScreen');
				 videoPopOutBoxObj.style.display="block";
			var getBoxWidth = videoPopOutBoxObj.offsetWidth;
			var getBoxHeight = videoPopOutBoxObj.offsetHeight;			
			var leftPosition = Math.round((findWindowWidth()-getBoxWidth)/2);
			var topPosition = Math.round((findWindowHeight()-getBoxHeight)/2);

			grayScreen.style.display="block";
			videoPopOutThumbnailOjb.style.display="none";
			//videoPopOutBoxObj.style.left=leftPosition+"px";
			//videoPopOutBoxObj.style.top=topPosition+"px";
			videoPopOutBoxObj.style.visibility="visible";
				
		}
//-- END: code for in-window pop-up video window ------------------

//---- BEGIN: show spec sheets if var is in URL
function showSpecSheet(){
		close_box('articleBodyText');
		open_box('projectSpecSheet');
	}
//---- END: show spec sheets if var is in URL

//------ BEGIN: expands and contracts project description on landing pages

function expandDescription(){
					var getDescriptionBox = document.getElementById("decsriptionText");
					getDescriptionBox.style.overflow="visible";
					getDescriptionBox.style.height="auto";
					close_box('viewMore');
					open_box('viewLess');
				} 
				function collapseDescription(){
					var getDescriptionBox = document.getElementById("decsriptionText");
					getDescriptionBox.style.overflow="hidden";
					getDescriptionBox.style.height="30px";
					close_box('viewLess');
					open_box('viewMore')
				}
			// goes with the following:
			// <div id="decsriptionText">test here</div>
			// <div id="viewMore"><a href="javascript:;" onclick="expandDescription();">More</a></div>
			// <div id="viewLess"><a href="javascript:;" onclick="collapseDescription()">Less</a></div>
//------END-----------




//---------BEGIN: check is a position is in the listPosition for OAS -----

function checkOASLisPos(whichPos){
 	var positionArray = new Array();
	positionArray = OAS_listpos.split(",");
	for (i =0; i < positionArray .length; i++){
		if (positionArray[i] == whichPos){
			return true
		}
	}
}

// to call on page: 
// if (checkOASLisPos('Right') == true){ //change 'Rigth' to the position you want to check
//	document.write('<div class="rectangleAd"> ----- Advertising -----<br />');
//	OAS_AD('Right');
//	document.write('</div>');
//	}

//---------END: check is a position is in the listPosition for OAS -----

