

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;


//------------ universal vars if needed ----- 
//----[these are used for the bookmarking tools]
var thisURL = document.location.href.split("#"); //removes any anchor in the link 
var getTitle = document.title
var newTitleArray = new Array();
newTitleArray = getTitle.split("|") 
var escapeTitle = escape (newTitleArray[0]);


//-----------------------------------------------------------------------------
//code for search box in masthead
function checkform (form) {
  if (form.ss.value == "") {
    alert( "Please enter a term in the search box." );
    form.ss.focus();
    return false ;
  }
	return true ;
}

//-----------------------------------------------------------------------------
//code to pop-up a window
function openWin(theURL, winName, features) {
  window.open(theURL, winName, features);
}


//---------BEGIN: DREAMWEAVER's standard swap image code------------//

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];}
}
//--------- END: DREAMWEAVER's standard swap image code------------//

//----------BEGIN: GET COOKIE-------------//

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// ------------------------------------//



//--------------------------------------------------------------------------------------------------------------------
//Pop-up window code, please use this not above, see prod docs

var popWin = null    // use this when referring to pop-up window
var winCount = 0
var winName = "popWin"
function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop){
  var d_winLeft = 20  // default, pixels from screen left to window left
  var d_winTop = 20   // default, pixels from screen top to window top
  winName = "popWin" + winCount++ //unique name for each pop-up window
  closePopWin()           // close any previously opened pop-up window
  if (openPopWin.arguments.length >= 4)  // any additional features? 
    winFeatures = "," + winFeatures
  else 
    winFeatures = "" 
  if (openPopWin.arguments.length == 6)  // location specified
    winFeatures += getLocation(winWidth, winHeight, winLeft, winTop)
  else
    winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
  popWin = window.open(winURL, winName, "width=" + winWidth 
           + ",height=" + winHeight + winFeatures)
  }
  
// close pop-up window if it is open 
function closePopWin(){    
  if (navigator.appName != "Microsoft Internet Explorer" 
      || parseInt(navigator.appVersion) >=4) //do not close if early IE
    if(popWin != null) if(!popWin.closed) popWin.close() 
  }

//optional code below is for old browsers

function getLocation(winWidth, winHeight, winLeft, winTop){
  return ""
  }
  
  function getLocation(winWidth, winHeight, winLeft, winTop){
  var winLocation = ""
  if (winLeft < 0)
    winLeft = screen.width - winWidth + winLeft
  if (winTop < 0)
    winTop = screen.height - winHeight + winTop
  if (winTop == "cen")
    winTop = (screen.height - winHeight)/2 - 20
  if (winLeft == "cen")
    winLeft = (screen.width - winWidth)/2
  if (winLeft>0 & winTop>0)
    winLocation =  ",screenX=" + winLeft + ",left=" + winLeft	
                + ",screenY=" + winTop + ",top=" + winTop
  else
    winLocation = ""
  return winLocation
  }


//code to display referer on page, just call with no params
function refer() {
  if (!document.referrer) {
    document.write("&nbsp;")
  }
  else {
    document.write(document.referrer);
  }
}

//----- BEGIN: For NAV bar - Rollover functionality for subnav 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: For NAV bar - Rollover functionality for subnav menus to work in IE ----- //

//-------- BEGIN: Close and open divs------------------// 
function closediv (divtoclose){
	//close (hide) a div - send the name of the div you want to close
	var divname = document.getElementById(divtoclose);
	divname.style.display = 'none';
}

function opendiv (divtoopen){
	// open (show) a div - send the name of the div you want to close
	var divname = document.getElementById(divtoopen);
	divname.style.display = 'block';
}
//-------- END: Close and open divs----------------// 


//----  BEGIN: FUNCTION for the TABBED buckets (RANDOM TAB) (up to 4 tabs) ----- //
//--- NOTE - there is a script that must go with the tabbed bucket - see the homepage ---//

function TabObject(tabName, tabCSS)
{
	this.TabName = tabName;
	this.TabCSS  = tabCSS;
}

function setDisplay(selectedTab, tabsListObject)
{
	for(var i=0; i<tabsListObject.length; i++)
	{
		var fontTab = document.getElementById(tabsListObject[i].TabName);
		var tempObject = document.getElementById(tabsListObject[i].TabCSS);
		fontTab.className = (i==selectedTab) ? "TabFront" : "TabBack";
		tempObject.style.display = (i==selectedTab) ? "block" : "none";
	}
}


function addLoadEvent(func) {
	var oldonload = window.onload;
	
	if (typeof window.onload != 'function') {
		window.onload = func;
	} 
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
// ----  END: FUNCTION for the TABBED buckets ----- ///


//------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 first and second directory names -------------//


//------- START: RESIZES WINDOW FOR SLIDESHOWS (does not work for IE) ------//
function changeWindowSize(windowWidth,windowHeight) {
	top.window.resizeTo(windowWidth,windowHeight);
}
//------- END: RESIZES WINDOW FOR SLIDESHOWS (does not work for IE) ------//


// ------- START: open and close boxes

function open_box(whichbox) 
	{
		    document.getElementById(whichbox).style.display="block";
			
	}
function close_box(whichbox) 
	{
		    document.getElementById(whichbox).style.display="none";
			
	}
	
//---------	END: open and close boxes



//------- START: Change article body text from default to larger ------//
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 = '';
		}
		
	}
//------- END: Change article body text from default to larger ------//

//--------BEGIN: get url & get title for a document -------------//

	function getArticleTitle(){ //grabs the title from the <title> tag before the first pipe | symbol
              var input = document.title;
              var output = "";
			   for(var ii=0; ii < input.length; ii++) {
				  var char = input.charAt(ii);
				  if((char >= 'A' && char <= 'Z') || (char >= 'a' && char <= 'z') || (char >= '0' && char <= '9')) {
					  output += char;
				  }
			   }
			   return output;
			}
	function cleanUpURL(){ // gets url & remove the # if there is one
           var thisURL = window.location.href.split("#");
           return thisURL[0];
      	}
//--------END: get url & get title for a document -------------//
//------- OPEN in window behind if existing - otherwise will  open a new window - Added 3/4/09 by Ilan  ------
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();
}

//--------------------------------------------------------------------------------------
//--------For email popup - aty the bottom of page 'website support' link---------------
	var daurl = ("http://costest.construction.com/cest/emailus/form2.asp?rd="+document.location.href);
	var canurl = ("http://costest.construction.com/cest/emailus/supplyform.asp?subject=canhelp");
	var needurl = ("http://costest.construction.com/cest/emailus/supplyform.asp?subject=needhelp");
	var friendurl = ("http://costest.construction.com/cest/efriend/friend.asp?rd="+document.location.href);
	
	function maillink(p){
		window.open(p,'mail','width=617,height=561,scrollbars=yes,toolbar');
	}
//--------end email code----------------------------------------------------------------




