//Copyright Brett Martin Ltd

// this is the function for changing the background cell or row colour 

    function CNavRollOver(oTd) {if (!oTd.contains(event.fromElement)) {oTd.bgColor="#009933";}}
  function CNavRollOut(oTd) {if (!oTd.contains(event.toElement)) {oTd.bgColor="#006633";}}
    function NavRollOver(oTd) {if (!oTd.contains(event.fromElement)) {oTd.bgColor="#999999";}}
  function NavRollOut(oTd) {if (!oTd.contains(event.toElement)) {oTd.bgColor="#cccccc";}}

  
//end of function
/*********************************************************************************************/
  
// this is the jumpmenu 
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//***********************************************************************************************
//--Pop Up Window

function popwin(x,y,z)

{window.open(x,y,'status=no,scrollbars=no,resizable=yes,width='+ y +',height='+ z);}


//-->

//--Pop Up Window with scrollbar

function scrollpopwin(x,y,z)

{window.open(x,y,'status=no,scrollbars=yes,resizable=yes,width='+ y +',height='+ z);}


//-->




//*********************************************************************************
//
//				Tracker Nav
//
//**********************************************************************************



//==========================================================================
//The Following functions are used to create a page tracking nav
//==========================================================================


//============================================================================
// Is called when page is unloaded adds page title and Url to a cookie
function addPageRefTocookie() 
{
       	   var myArray = new Array( );
		   if(cookieExists("bmPageCrumb")) //adds the first page 
		   {
				   var cookieString = (getMyCookie("bmPageCrumb"));
				   var myArray = cookieString.split(",");
				   		   
					var refUrl = myArray[(myArray.length -1)];
		  			var urlArray = refUrl.split("|");   

				   if(getPageTitle() != urlArray[0])
				   {

				   myArray[myArray.length] = getPageTitle() + "|" + document.URL;
				   				   
				   }
					
					var arrayAsString = myArray.join(",");
					setMyCookie('bmPageCrumb',arrayAsString);
		   }
		   else
		   {
		   setMyCookie('bmPageCrumb',getPageTitle());
		   }
}

//=======================================================================
//returns the last 8 chars from the last word in the page title
function getPageTitle()
{
	var myTitle = document.title;
	var titleArray = myTitle.split(" - ");
	myTitle = titleArray[(titleArray.length -1)];
	myTitle = trim(myTitle);
	var shortTitle;
			if (myTitle.length > 16)
			{
			shortTitle = myTitle.substring(0, 13);
			 
			shortTitle += "...";
			}
			else
			{
			var charToAdd = 16 - myTitle.length ;
			for (var i = 0; i < charToAdd; i++)
			{
				myTitle = myTitle + " ";
			} 
			shortTitle = myTitle;
			}
return shortTitle;

}




function displayPageRef() 
{
     if(isCookieEnabled()&&cookieExists( "bmPageCrumb"))
   {
  
		   var myArray = new Array( );
		   
		   var cookieString = (getMyCookie("bmPageCrumb"));
		   var myArray = cookieString.split(",");
				  //for (var i = 0; i < myArray.length; i++) 
				 for (var i = myArray.length-1; i >= 0; i--) 
				   {
				  var refUrl = myArray[i];
				  var urlArray = refUrl.split("|");
						
							   var pageDes ="<a href=" ;
							   pageDes += urlArray[1] + ">";
							   pageDes +=	urlArray[0];
							   pageDes +=	"</a>";
							   pageDes += "<br>";
							   
			var myNewOption = new Option(urlArray[0], urlArray[1], false, false);
			//var j = 0;//builds listfrom top down
			var bmTrackItem =document.trackNav.selectNav.options.length;
			document.trackNav.selectNav.options[bmTrackItem] = myNewOption;		   

					}


	 }
   else
   {
   			var myNewOption = new Option("View recent pages","#", false, false);
			//var j = 0;//builds listfrom top down
			var j =document.trackNav.selectNav.options.length;
			document.trackNav.selectNav.options[j] = myNewOption;
   }

}

//***********************************************************************************************

//					End Tracker Nav
//***************************************************************************************************



//=============================================================================================

// used for a jump box
function navigate(choice) {
    var url = choice.options[choice.selectedIndex].value;
    if (url) {
        location.href = url;
    		}
}




//=================================================================================================

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} 



//===============================================================================================
function cookieExists( cookieName)
{
   
    var cookieString = (getMyCookie(cookieName));
   
    if (cookieString == "") 
	{
      return false;
    } 
	else 
	{
        return true;
    }

}

function isCookieEnabled()
{

if (typeof document.cookie == "string") {
    if (document.cookie.length == 0) {
        document.cookie = "test";
        return (document.cookie == "test");
        document.cookie = "";
	
		
    } else {
        return true;
    }
}
	
}



//===========================================================================
// utility function to retrieve an expiration date in proper
// format; pass three integer parameters for the number of days, hours,
// and minutes from now you want the cookie to expire (or negative
// values for a past date); all three parameters are required,
// so use zeros where appropriate
function getExpDate(days, hours, minutes) {
    var expDate = new Date( );
    if (typeof days == "number" && typeof hours == "number" && 
        typeof hours == "number") {
        expDate.setDate(expDate.getDate( ) + parseInt(days));
        expDate.setHours(expDate.getHours( ) + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes( ) + parseInt(minutes));
        return expDate.toGMTString( );
    }
}



// utility function called by getMyCookie( )
function getMyCookieVal(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}


// primary function to retrieve cookie by name
function getMyCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return getMyCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return "";
}

  

   
// store cookie value with optional details as needed
function setMyCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "; path=/;") +	//this was modified to include the root path
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
   
// remove the cookie by setting ancient expiration date
function deleteCookie(name,path,domain) {
    if (getMyCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

//=================================================================================================
//Code to place a random quote from a library of quotes to appear at top of polycarbonate pages. 
//Array of quotes
 
 var quotes = new Array( );
quotes[quotes.length] = {quote:"Enjoy Natural Light" , 
                          sector:"Roofing"};
quotes[quotes.length] = {quote:"Daylight In Everyday Life" , 
                          sector:"Roofing"};
quotes[quotes.length] = {quote:"Light, An Essential Element" , 
                          sector:"Roofing"};
quotes[quotes.length] = {quote:"Shedding Light On Business" , 
                          sector:"Roofing"};
quotes[quotes.length] = {quote:"Superior Glazing Solutions" , 
                          sector:"Roofing"};
quotes[quotes.length] = {quote:"Ultimate Choice In Roofing" , 
                          sector:"Roofing"};
quotes[quotes.length] = {quote:"Providing Good Natural Lighting" , 
                          sector:"Roofing"};
quotes[quotes.length] = {quote:"Safe, Attractive and Practical" , 
                          sector:"Roofing"};
quotes[quotes.length] = {quote:"Natural Daylight" , 
                          sector:"Roofing"};
quotes[quotes.length] = {quote:"Outstanding Performance" , 
                          sector:"Semifinished"};
quotes[quotes.length] = {quote:"Strong, Vibrant Colours" , 
                          sector:"Semifinished"};
quotes[quotes.length] = {quote:"Reputation For Quality" , 
                          sector:"Semifinished"};
quotes[quotes.length] = {quote:"Versatile, Strong, Flawless" , 
                          sector:"Semifinished"};
quotes[quotes.length] = {quote:"Superb Performance" , 
                          sector:"Semifinished"};
quotes[quotes.length] = {quote:"Ideal for a variety of applications" , 
                          sector:"Semifinished"};
quotes[quotes.length] = {quote:"Optimum Surface Finish" , 
                          sector:"Semifinished"};
quotes[quotes.length] = {quote:"Comprehensive Systems" , 
                          sector:"Building"};
quotes[quotes.length] = {quote:"High Quality Systems" , 
                          sector:"Building"};
quotes[quotes.length] = {quote:"Fast Efficient Installation" , 
                          sector:"Building"};
quotes[quotes.length] = {quote:"High Level Of Performance" , 
                          sector:"Building"};
quotes[quotes.length] = {quote:"Maximum Choice And Flexibility" , 
                          sector:"Building"};
quotes[quotes.length] = {quote:"First Class Products" , 
                          sector:"Building"};
quotes[quotes.length] = {quote:"Original Designs" , 
                          sector:"Building"};
						


//Function that produces a random number calculation to obtain an index for the array to select a quote.

function getSaying(section) {
var sectionquotes = new Array();
	
	for (var i=0; i < quotes.length; i++) 
	{
		if(quotes[i].sector == section) 
		{
			sectionquotes.push(quotes[i].quote);
		}
	}
	
	var currIndex = Math.floor(Math.random( ) * (sectionquotes.length));
	var output = "";
    output += sectionquotes[currIndex];
	return output;
}

//sets timing of BM survey

function surveyTime(){
	setTimeout('timedSurvery()', 7000);
	
	}

