
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 ;
}

//-----------------------------------------------------------------------------
//code for email pop-up window
var myrl = location.href;
var daurl = ("http://costest.construction.com/cest/emailus/form2.asp?rd="+myrl);
function maillink(p) {
	window.open(p,'mail','width=617,height=561,scrollbars=yes,toolbar');
}

//-----------------------------------------------------------------------------
//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');
			}
		}
		

//------START: get first and second directory names -------------//
function getFirstDirName() { //returns the name of the first directory a page is in - return empty if undefined
		var subsection = document.location.href
		var subsectionArray = new Array();
		subsectionArray = subsection.split("\/");
		var firstDirName = subsectionArray[3];
		if (firstDirName == undefined){
		return '';
			} else { 
			return firstDirName;
			}
		
}
function getSecondDirName() {//returns the name of the second directory a page is in - return empty if undefined
		var subsection = document.location.href
		var subsectionArray = new Array();
		subsectionArray = subsection.split("\/"); 
		var seconDirName = subsectionArray[4];
		
		if (seconDirName == undefined){
		return '';
			} else { 
			return seconDirName;
			}
		
		
}

//------END: get first and second 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();
}
