//############################################################
//#   Rod Dines - for chembuild.co.uk web site - 16 Feb 2006
//############################################################
function MainFormDoOnLoad(formObject, textPriceAnnotate, textPopupHelpTitle)
		{
			//Modify HTML content to suit purpose
			RenderPrices(formObject, textPriceAnnotate, textPopupHelpTitle);
			RenderSpecials(formObject, 'SPECIAL OFFER', 'Special Offer');
			//PrepareForm calls function in previously loaded JS file lib/chembuild_useableforms.js
			//to manage DHTML for dynamically controlling related fields and options based on user choices
			prepareForm();
			//var timerOffer=setTimeout("showSpecialOffer();",2000);  //Delay message 1000=1 seconds
		}


// bof- CATEGORIES MENU HANDLING
function menuDrawBackground(idMenuItem)
		{	
			var targetTd = document.getElementById(idMenuItem);
			var highlightBorder = "solid #111111 1px";
			if(targetTd != null){
				targetTd.style.background = "#ccc";
				targetTd.style.borderTop = highlightBorder;
				targetTd.style.borderRight = highlightBorder;
				targetTd.style.borderBottom = highlightBorder;
				targetTd.style.borderLeft = highlightBorder;
			}
		}
		
function menuClearBackground(idMenuItem)
		{
			var targetTd = document.getElementById(idMenuItem);
			var resetBorder = "solid #FFFFFF 1px";
			if(targetTd != null){
				targetTd.style.background = "#fff";
				targetTd.style.borderTop = resetBorder;
				targetTd.style.borderRight = resetBorder;
				targetTd.style.borderBottom = resetBorder;
				targetTd.style.borderLeft = resetBorder;
			}
		}
	
function ShowFullTitle(current, fullTitle)
		{
			if (current != null) current.title = fullTitle;
		}

function menuSendToTarget(url, isPopUp, winName, width, height, resize, scroll)
		{
			if(url != null) {
				if(isPopUp == 'yes') {
					//window.open();
					openWin(url,winName,width,height,resize,scroll);
				} else {
					document.location = url;
				}
			}
			event.cancelBubble=true;
		}
// eof- CATEGORIES MENU HANDLING

// bof- DHTML PAGE MODIFICATIONS OF Comersus Store pages for chembuild.co.uk
var sSiteRoot = '\/chemicalbuildingproducts\/';

function myModalDialogBox(q,caption,modal)
{
 q=(q||''); caption=(caption||'');
 modal=(modal||false);
 
 /*
 //not currently used but in consideration of using to manage the maximum height of the dialog
 var winW = 630, winH = 460;
 if (parseInt(navigator.appVersion)>3) {
  if (navigator.appName=="Netscape") {
   winW = window.innerWidth;
   winH = window.innerHeight;
  }
  if (navigator.appName.indexOf("Microsoft")!=-1) {
   winW = document.body.offsetWidth;
   winH = document.body.offsetHeight;
  }
 }
 */

 var myModalMessage=(OLns4?'<form name="modalmessage" action="javascript:void(0);">':'')
 + '<div style="font-size:14px;line-height:24px; background-color: white;"> '
 + '<table cellpadding=0 cellspacing=0><tr> '
 + '<td valign="top" style="padding:5px;"><img src="'+sSiteRoot+'images/satisfaction.gif" border="0" style="vertical-align: top;"><\/td> '
 + '<td style="padding:10px;">'+q+'<\/td> '
 + '<\/tr><tr><td colspan="2" style="text-align:center; font-size=10px; padding:5px;"><input type="checkbox" '
 + 'name="disablelongterm" value="disablelongterm" id="disablelongterm">&nbsp;Please dont show me this message again.&nbsp;&nbsp;'
 + '<span style="text-align:center; font-size=14px; font-weight:bold; padding:5px;"><input type="submit" '
 + 'onclick="myModalMessageClose((document.getElementById(\'disablelongterm\').checked==true));cClick();return false;" '
 + 'value="Close"><\/span><\/td>'
 + '<\/tr><\/table>'
 + '<\/div>'
 + (OLns4?'<\/form>':'');

 var myMessageTable = '<table cellpadding="0" cellspacing="0" border="0" width="620px" height="100%" class="rightbox" id="logo-table" style="width:100%; border:0px none; border-collapse:collapse; border-spacing:0px; margin:0px; padding:0px; text-align:left;"> '
 + '<tr><td rowspan="1" valign="top" align="center" style="background-color:#ffffff; border:0px"> '
 +  '<table cellpadding="0" cellspacing="0" border="0" width="449px" style="padding:5px;"><tr><td>' + myModalMessage + '<\/td><\/tr><\/table> '
 + '<\/td><td> '
 +  '<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%"><tr>'
 +   '<td valign="top" align="right" style="background-color:#ffffff; width:37px; height:40px; border:0px" id="logo-left-top"><img src="'+sSiteRoot+'images/logo-left-top74x80.jpg" style="width:37px; height:40px; border:0px" ><\/td> '
 +   '<td valign="top" align="center" style="background-color:#ffffff; width:74px; height:40px; border:0px" id="logo-center-top" class="logo-center-top"><img src="'+sSiteRoot+'images/logo-center-top74x40.jpg" style="width:74px; height:40px; border:0px" alt="Telephone Nationwide on 01202 601 701"><\/td> '
 +   '<td valign="top" align="left" style="background-color:#1C2B8D; width:60px; height:40px; border:0px" id="logo-right-top"><img src="'+sSiteRoot+'images/dummy.gif" style="width:37px; height:40px; border:0px"><\/td> '
 +  '<\/tr><tr> '
 +   '<td valign="top" align="right" style="background-color:#ffffff; width:37px; height:54px; border:0px" id="logo-left-center"><img src="'+sSiteRoot+'images/logo-left-center74x107.jpg" style="width:37px; height:54px; border:0px"><\/td> '
 +   '<td valign="top" align="center" style="background-color:#ffffff; width:74px; height:54px; border:0px" id="logo-center-center"><img src="'+sSiteRoot+'images/logo-center-center147x107.jpg" style="width:74px; height:54px; border:0px"><\/td> '
 +   '<td valign="top" align="left" style="background-color:#1C2B8D; width:60px; height:54px; border:0px" id="logo-right-center"><img src="'+sSiteRoot+'images/logo-right-center30x98.jpg" style="width:15px; height:49px; border:0px"><\/td> '
 +  '<\/tr><tr> '
 +   '<td valign="top" align="right" style="background-color:#ffffff; width:37px; height:14px; border:0px" id="logo-left-btm"><img src="'+sSiteRoot+'images/logo-left-btm74x27.jpg" style="width:37px; height:14px; border:0px"><\/td> '
 +   '<td valign="top" align="center" style="background-color:#ffffff; width:74px; height:14px; border:0px" id="logo-center-btm"><img src="'+sSiteRoot+'images/logo-center-btm147x27.jpg" style="width:74px; height:14px; border:0px"><\/td> '
 +   '<td valign="top" align="left" style="background-color:#1C2B8D; width:60px; height:14px; border:0px" id="logo-right-btm"><img src="'+sSiteRoot+'images/dummy.gif" style="width:15px; height:14px; border:0px"><\/td> '
 +  '<\/tr><tr> '
 +   '<td colspan="2" valign="bottom" align="right" style="background-color:#ffffff; width:111px; height:100%; border:0px" ><img src="'+sSiteRoot+'images/snowman.jpg" style="border:0px; vertical-align: bottom;"><\/td> '
 +   '<td valign="bottom" align="left" style="background-color:#1C2B8D; width:60px; height:100%; border:0px" ><img src="'+sSiteRoot+'images/dummy.gif" style="width:15px; height:100%; border:0px"><\/td> '
 +  '<\/tr><\/table> '
 + '<\/tr><tr style="height:100%;">'
 +  '<td colspan=2 valign="top" align="center" style="padding:0px; background-image:'+sSiteRoot+'images/FreeDeliveryAd.gif; width:620px; height:60px; border:0px">'
 +  '<img src="'+sSiteRoot+'images/FreeDeliveryAd.gif" border="0" width="620" height="60">'
 +  '<\/td>'
 + '<\/tr><\/table> ';

/*
 * Modify the styling appropriately for your site 
CGCLASS,'olcgD',CAPTIONFONTCLASS,'olcapD',, CLOSEFONTCLASS,'olcloD' FGCLASS,'olfgD', TEXTFONTCLASS,'oltxtD'
 , , SHADOW, SHADOWCOLOR,'#113377',
BGCOLOR, '#1C2B8D', CGCOLOR, '#1C2B8D'
*/

var closeIcon='<A HREF="JavaScript:void(0);" onclick="myModalMessageClose((document.getElementById(\'disablelongterm\').checked==true));cClick();return false;" ><IMG src="'+sSiteRoot+'images/closeicon.gif" border="0"><\/A>'; 

overlib(myMessageTable, EXCLUSIVEOVERRIDE, CLOSETEXT,closeIcon, caption?CAPTION:DONOTHING,caption?caption:DONOTHING, CAPTIONFONT,'ARIAL', CAPTIONSIZE,18, CLOSEFONT,'ARIAL', CLOSESIZE,14, CAPTIONPADDING,4, TEXTPADDING,0, BORDER,4, BGCOLOR,'#1C2B8D', CGCOLOR,'#1C2B8D', FGCOLOR,'#FFFFFF', modal?MODAL:DONOTHING, WRAP, STICKY, EXCLUSIVE, SCROLL, MIDX,0, MIDY,0);
}

function myModalMessageClose(longterm)
{
 /*
  * Set 1 day or 30 day cookie to prevent showing offers all the time
  */
 if (longterm==true)
  {
    createCookie('showNov2007Offer1','disabled',30);  //30 Day message
  }
 else 
  {
    //eraseCookie('showNov2007Offer1');
    createCookie('showNov2007Offer1','disabled',0);  //Session Cookie only when days = 0
  }
}

function showSpecialOffer()
{
 var myCap='PRICE BEATER Sale - till the end of 2007';

 var MySummaryBox ='<center><div style="border: medium double red; text-align:left; font:normal caps bold 14px arial; color:red; width:320px; padding:20px 0px 10px 20px">'
 +'<ul type="square">'
 +'<li>Free Delivery<\/li>'
 +'<li>Free Technical Support<\/li>'
 +'<li>And the Best Price Possible<\/li>'
 +'<\/ul>'
 +'<p style="font-size:18px;text-align:center; padding:0px">Tel: 01202 601701 Now!<br>You can\'t lose!<\/p>'
 +'<\/div></center>'

 var MyMessage ='<div>'
 +'<p style="font-weight:bold; font-size:16px; color:red; text-align:center">End of Year Trade & D.I.Y.<br>PRICE BEATER<br>Sale<\/p>'
 +'<p>Dear Customer, we interrupt your browsing to let you know we will save you money on any equivalent competitive product ordered before the end of the year*<\/p>'
 +'<p>Call for our special SALE prices and <span style="color:RED; font-weight:BOLD; border-bottom:2px RED;">quote "PRICE BEATER".<\/span><br>Our lines are open from 7:30am-7:30pm every day.<\/p>'
 +'<p>As always, we offer free technical advice and support.<br>Please note that during December we are also offering free delivery.<\/p>'
 + MySummaryBox
 +'<span style="font-size:9px"><p>*Please note: Orders placed before 31 December 2007 for delivery in January 2008 will also benefit from this offer.<\/p><\/span>'
 +'<\/div>';

 var MessageDisabled = readCookie('showNov2007Offer1');

 if (MessageDisabled)
 {
   // alert("message found existing cookie");
   if (!(MessageDisabled == 'disabled'))
   {
     // alert("message needs to erase cookie");
   }
   else
   {
     // alert("message disabled by cookie");
     // eraseCookie('showNov2007Offer1');
   }
 }
 else
 {
   myModalDialogBox(MyMessage, myCap, true); 
 }

}


function RenderPrices(formObject, textAnnotate, textPopupHelpTitle)
{
	// get all the paragraphs in the document
	var listofparagraphs = document.getElementsByTagName("p");
	var textHtml;
	var i;
	// find the one with our special text
	for(i = 0; i < listofparagraphs.length; i++)
	{
		textHtml = "";
		if(listofparagraphs[i].id == "productListing-price")
		{
			// found a price "productListing-price" <p>
			textHtml = textHtml + '<table class="productListing-price"><tr><td class="productListing-price">' + listofparagraphs[i].innerHTML + '</td></tr>';
			textHtml = textHtml + '<tr><td class="productListing-price-ruby"><p title="' + textPopupHelpTitle + '">' + textAnnotate + '</p></td></tr></table>';
			listofparagraphs[i].innerHTML = textHtml;
	  	}
	}
}


function RenderSpecials(formObject, textAnnotate, textPopupHelpTitle)
{
	// get all the paragraphs in the document
	var listofspans = document.getElementsByTagName("span");
	var textHtml;
	var i;
	// find the one with our special text
	for(i = 0; i < listofspans.length; i++)
	{
		textHtml = "";
		if(listofspans[i].id == "special")
		{
			// found a special <span class="special">
			textHtml = textHtml + '<table class="productListing-special"><tr><td class="productListing-special-ruby"><p title="' + textPopupHelpTitle + '">' + textAnnotate + '</p></td></tr>';
			textHtml = textHtml + '<tr><td class="productListing-special">' + listofspans[i].innerHTML + '</td></tr></table><br />';
			listofspans[i].innerHTML = textHtml;
	  	}
	}
}

// eof- DHTML PAGE MODIFICATIONS OF Comersus Store pages for chembuild.co.uk


//############################################################
//#   Note:	Rod Dines - Cookie management
//############################################################


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);
}

//############################################################
//#   Note:	Rod Dines - rest was taken from three.co.uk web site
//############################################################



//###############################
//# function name:	getDate
//# parameters: 		none
//#	description:		write date and time to page
//#		                uses span tag for netscape 
//#				and TD for ie
//#	date created:		8.04.2002
//#	author:			rubus - taken from three.co.uk web site
//#	date modified:	        15.04.2002
//#				included ticking time.
//###############################
function getDate() {
var time = new Date();
var day = time.getDate();
var monthNumber = time.getMonth()+1;

if (monthNumber == 1) month = "January";
if (monthNumber == 2) month = "February";
if (monthNumber == 3) month = "March";
if (monthNumber == 4) month = "April";
if (monthNumber == 5) month = "May";
if (monthNumber == 6) month = "June";
if (monthNumber == 7) month = "July";
if (monthNumber == 8) month = "August";
if (monthNumber == 9) month = "September";
if (monthNumber == 10) month = "October";
if (monthNumber == 11) month = "November";
if (monthNumber == 12) month = "December";


var year = time.getFullYear();
var hours = time.getHours();
var minutes = time.getMinutes();
var amOrPm = "am";
	if (hours > 11) amOrPm = "pm";
	if (hours > 12) hours = hours - 12;
	if (hours == 0) hours = 12;
	if (minutes <= 9) minutes = "0" + minutes;
	dispTime = day + "&nbsp;" +month+"&nbsp;"+ year; //+ "&nbsp;|&nbsp;" +hours + ":" + minutes + amOrPm;
	if (document.layers) { //if netscape 4
		navDispTime="<font class='dateTime'>"+dispTime+"</font>";
		document.layers.timeTag.document.write(navDispTime);
		document.layers.timeTag.document.close();
	}
	else if (document.all){// ie
		ieTimeTag.innerHTML = dispTime;
	}
	else if(document.getElementById){ //netscape 6
		document.getElementById('timeTag').innerHTML = dispTime;
	}
	//setTimeout("getDate()", 1000);
}

//###############################
//# function name:	openWin
//# parameters: 		URL, winName, width, height, resize, scroll
//#	description:		open new popup window passing
//#									the url to open, window name 
//#									plus height and width of popup.
//#									and status of resizing and scrolling 
//#	date created:		8.04.2002
//#	author:					rubus
//#	date modified:	15.04.2002
//#									scrolling option added
//#										set focus to new winow so appears at the 
//#										front when new link clicked
//###############################
function openWin(URL,winName,width,height,resize,scroll){
			settings = 'toolbar=no,location=no,personalbar=no,status=no,menubar=no,scrollbars=' + scroll + ',resizable='+resize+',height=' + height + ',width='+ width +'';
			newWin = document.open(URL,winName,settings);
			newWin.focus();
			return false;
}

//###############################
//#   function name:		openStatusWin
//# 	 parameters: 		URL, winName, width, height, resize, scroll
//#	description:		open new popup window passing
//#				the url to open, window name 
//#				plus height and width of popup.
//#				with status bar
//#	date created:		23.06.2003
//#	author:			rubus
//#			
//#	
//###############################
function openStatusWin(URL,winName,width,height,resize,scroll){
			settings = 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=' + scroll + ',resizable='+resize+',height=' + height + 'px,width='+ width +'px';
			newWin = document.open(URL,winName,settings);
			newWin.focus();
			return false;
}

//###############################
//# function name:	openPrintWin
//# parameters: 		URL, winName, width, height, resize, scroll
//#	description:		open new popup window passing
//#									the url to open, window name 
//#									plus height and width of popup.
//#									and status of resizing and scrolling 
//#	date created:		8.04.2002
//#	author:					rubus
//#	date modified:	15.04.2002
//#									scrolling option added
//#										set focus to new winow so appears at the 
//#										front when new link clicked
//###############################
function openPrintWin(URL,winName,width,height,resize,scroll){
	settings = 'toolbar=yes,location=no,status=no,menubar=yes,scrollbars=' + scroll + ',resizable='+resize+',height=' + height + 'px,width='+ width +'px';
	newPrintWin = document.open(URL,winName,settings);
	newPrintWin.focus();
}

//###############################
//# function name:	printWin
//# parameters: 		
//#
//#
//#	date created:	10.04.2002
//#	author:					rubus
//#	date modified:	10.04.2002
//###############################
function printWin(){
	if(is_ie4){
		alert('To print please right click on the page with your mouse and select print.');
	}
	else{
		window.print();
	}
}
