var randomnumber = Math.round(Math.random() * 100000);

//-------------- return full year for footers (JS alternative to ASP script) -----
function currentYear() {
	var JSdate = new Date();
	var JSyear = JSdate.getYear();
	var count = JSyear.toString();
	var fullYear ='';
	if (count.length == 3){
		fullYear = JSyear + 1900;
	} else {
		fullYear = JSyear;
	}
	return fullYear;
}
//------------- END: return full year for footers -------------


//--------------------------------------------------------------------------------------
//-------- Code to create, read & delete cookies (must go with apporpiate calls) ---------------
// ----- example:  createCookie('HomePageSurvey','yes',7) ------------

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
//--------end----------------------------------------------------------------


//--------------------------------------------------------------------------------------
//--------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----------------------------------------------------------------
	
	
	
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;
}

ns4 = (document.layers)? true:false;
ie4 = (document.all)? true:false;

function loadIFrame(urlToLoad) {
  document.write("<iframe src="+urlToLoad+" width='150' height='106' scrolling='no' frameborder='0' marginwidth='0' marginheight='0'></iframe>");
}
function loadILayer(urlToLoad) {
  document.write("<ilayer src="+urlToLoad+" width='150' height='106' scrolling='no'></ilayer>");
}


function checkform ( form )
{
    if (form.ss.value == "") {
        alert( "Please enter a term in the search box." );
        form.ss.focus();
        return false ;
    }
    // ** END **
	return true ;
}


function checkOrps(someForm){

if((someForm.authcode.options[someForm.authcode.selectedIndex].value=="con100")||(someForm.authcode.options[someForm.authcode.selectedIndex].value=="con101")){
    someForm.orps.value=1;
}
else{
    someForm.orps.value=0;
}
}

function navimage (environment) {
	var site = "";
	if (environment > ""){
	  site=environment;
	}
	if (sponsor1.indexOf("home") > -1){
	  document.imghome.src = site+"/images/topnav_home_on.gif";
	}
	if (sponsor1.indexOf("center2") > -1){
	  document.imgresource.src = site+"/images/topnav_resource_on.gif";
	}
	if (sponsor1.indexOf("tert2") > -1){
	  document.imgresource.src = site+"/images/topnav_resource_on.gif";
	}
	if (sponsor1.indexOf("center3") > -1){
	  document.imgprojects.src = site+"/images/topnav_project_on.gif";
	}
	if (sponsor1.indexOf("tert3") > -1){
	  document.imgprojects.src = site+"/images/topnav_project_on.gif";
	}
	if (sponsor1.indexOf("center4") > -1){
	  document.imgproducts.src = site+"/images/topnav_products_on.gif";
	}
	if (sponsor1.indexOf("tert4") > -1){
	  document.imgproducts.src = site+"/images/topnav_products_on.gif";
	}
	if (sponsor1.indexOf("center5") > -1){
	  document.imgequipment.src = site+"/images/topnav_equip_on.gif";
	}
	if (sponsor1.indexOf("tert5") > -1){
	  document.imgequipment.src = site+"/images/topnav_equip_on.gif";
	}
	if (sponsor1.indexOf("center6") > -1){
	  document.imgcareer.src = site+"/images/topnav_career_on.gif";
	}
	if (sponsor1.indexOf("tert6") > -1){
	  document.imgcareer.src = site+"/images/topnav_career_on.gif";
	}
	if (sponsor1.indexOf("center7") > -1){
	  document.imgnews.src = site+"/images/topnav_news_on.gif";
	}	
	if (sponsor1.indexOf("tert7") > -1){
	  document.imgnews.src = site+"/images/topnav_news_on.gif";
	}
	if (sponsor1.indexOf("center8") > -1){
	  document.imgintl.src = site+"/images/topnav_intl_on.gif";
	}	
	if (sponsor1.indexOf("tert8") > -1){
	  document.imgintl.src = site+"/images/topnav_intl_on.gif";
	}
}

//-------------------------------------------------------


//  code for 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');
			}
		}

//-------------------------------------------------------
//  open new window (dreamweaver)

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


//-------------------------------------------------------
//  swap image code (dreamweaver)

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];}
}


//-----------------------------------
//------------- tooltip -------------		
var offsetxpoint = 0; // x offset of tooltip
var offsetypoint = 20 // y offset of tooltip

var ie = document.all;
var ns6 = (!ie && document.getElementById);
var enabletip = false;

if (ie || ns6)
{
	var tipobj = (document.all) ? document.all["dhtmltooltip"] : (document.getElementById) ? document.getElementById("dhtmltooltip") : "";
}

function ietruebody()
{
	return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}

function ddrivetip(thetext, thecolor, thewidth)
{
	if (ns6 || ie)
	{
		if (typeof thewidth != "undefined")
			tipobj.style.width = thewidth+"px";

		if (typeof thecolor != "undefined" && thecolor!= "")
			tipobj.style.backgroundColor = thecolor;
 		
		tipobj.innerHTML = thetext;
		enabletip = true;
		return false;
	}
}

function positiontip(e)
{
	if (enabletip) 
	{
		var curX = (ns6) ? e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY =(ns6) ? e.pageY : event.clientY+ietruebody().scrollTop;
		
		//Find out how close the mouse is to the corner of the window
		var rightedge = (ie && !window.opera) ? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20;
		var bottomedge = (ie &&!window.opera) ? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20;
		
		var leftedge = (offsetxpoint <0) ? offsetxpoint*(-1) : -1000;
		
		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge < tipobj.offsetWidth) //move the horizontal position of the menu to the left by it's width
			tipobj.style.left = (ie) ? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px";
		else if (curX < leftedge)
			tipobj.style.left = "5px";
		else //position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left = curX+offsetxpoint+"px";
			
		if (bottomedge < tipobj.offsetHeight)
			tipobj.style.top = (ie) ? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px";
		else
			tipobj.style.top = curY+offsetypoint+"px";
			
		tipobj.style.visibility = "visible";
	}
}

function hideddrivetip(){
	if (ns6 || ie)
	{
		enabletip = false;
		tipobj.style.visibility = "hidden";
		tipobj.style.left = "-1000px";
		tipobj.style.backgroundColor = '';
		tipobj.style.width = '';
	}
}

document.onmousemove = positiontip;

//------------- END tooltip -------------		
//---------------------------------------


//-----------------------------------
//------------- GRAB 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();
			}
		
}

//-----------------------------------
//------------- GRABS VARIABLES FROM URL -------------

function getURLVar(whichVar) { //returns the name of directory you need: call  - getDirectoryName(1) or getDirectoryName(2) etc
		var fullurl = document.location.href;
		var UrlArray = new Array();
		UrlArray = fullurl.split("?");
		var variableReturn = UrlArray[whichVar];
		if (variableReturn == undefined){
		return '';
			} else { 
			return variableReturn.toLowerCase();
			}
		
}


// ------- 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";
			
	}


//------- 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();
}

//------- 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 ------//


