if( navigator.appVersion.indexOf( "Mac" ) != -1 && document.all ) {
	function fixmac() {
		var divs = document.getElementsByTagName( "DIV" );
		for( var i = 0; i < divs.length; i++ ) {
			if( divs[i].className.indexOf( "clearfix" ) != -1 ) {
				divs[i].innerHTML += "<br class=\"mac-clearfix\" />";
			}
		}
	}
	window.onload = fixmac;
}
else addEvent( window, "load", init );

function addEvent(obj, evType, fn){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
  } else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
	return false;
  }
}

// Toggle the gift tag form on and off
function toggleForm()
	{
		if (document.getElementById('giftTagSelected').checked)
			{
				document.getElementById('giftBoxFields').style.display="block";
			}
		else
			{
				document.getElementById('giftBoxFields').style.display="none";
			}
	}

// Clear, them resubmit the gift tag form if it has been opened, modified and then closed
function checkForResubmit()
	{
		if (! document.getElementById('giftTagSelected').checked)
			{
				document.getElementById('giftTagForm').submit();
			}
	}

function init() {
	
	if ( !document.getElementsByTagName ) return;
		var anchors = document.getElementsByTagName("a");

		for ( var i=0; i<anchors.length; i++ ) {
			var anchor = anchors[i];
			if (anchor.getAttribute("href") &&
				anchor.getAttribute("rel") == "external")
				anchor.target = "_blank";
			}
	
	if( document.all && document.getElementById && document.getElementById( "listoptions" ) ) {
		var materialMenuItems = document.getElementById( "listoptions" ).getElementsByTagName( "li" );
		
		for( var i=0;i<materialMenuItems.length;i++ ) {
			var subMenu = materialMenuItems[i].getElementsByTagName( "ul" );
			if( subMenu.length > 0 ) {
				materialMenuItems[i].onmouseover = function() { this.className = "hover"; };
				materialMenuItems[i].onmouseout = function() { this.className = ""; };
			}
		}
	}

	if( document.getElementById("searchbox") ) {
		document.getElementById("searchbox").onclick = function(e) {
			if (!e) var e = window.event;
			var tg = (e.target) ? e.target : e.srcElement;
			if( tg.value == "Product search" ) tg.value = "";
		}
		document.getElementById("searchbox").form.onsubmit = function() {
			return ( this.searchbox.value.length > 0 );
		}
	}
	
	if( window.print ) {
		if( document.getElementById( "productdetails" ) ) {
			var printLink = document.createElement( "A" );
			var shareLink = document.createElement( "DIV" );
			printLink.className = "printbutton";
			printLink.href = "javascript:window.print()";
			printLink.appendChild( document.createTextNode( "Print this page" ) );
			document.getElementById( "productdetails" ).appendChild( printLink );
			
		}
		if( document.getElementById( "confirmation" ) ) {
			var parentDiv = document.getElementById( "confirmation" );
			var printLink = document.createElement( "A" );
			printLink.className = "printbutton";
			printLink.href = "javascript:window.print()";
			printLink.appendChild( document.createTextNode( "Print this page" ) );
			parentDiv.insertBefore( printLink, parentDiv.getElementsByTagName( "p" )[0] );
		}
	}
	
	document.getElementById("body").style.marginTop = document.getElementById("navwrapper").clientHeight - 1 + "px";
}

	var displayValue;
	var insuranceStyles;
	function calculateCost(){
		if (document.getElementById('insurance').checked)
			{
				displayValue=parseFloat(document.getElementById('mainCost').value)+parseFloat(document.getElementById('insuranceCost').value);
				displayValue = displayValue.toString().replace(/\$|\,/g,'');
				if(isNaN(displayValue))
				displayValue = "0";
				sign = (displayValue == (displayValue = Math.abs(displayValue)));
				displayValue = Math.floor(displayValue*100+0.50000000001);
				cents = displayValue%100;
				displayValue = Math.floor(displayValue/100).toString();
				if(cents<10)
				cents = "0" + cents;
				for (var i = 0; i < Math.floor((displayValue.length-(1+i))/3); i++)
				displayValue = displayValue.substring(0,displayValue.length-(4*i+3))+','+
				displayValue.substring(displayValue.length-(4*i+3));
				document.getElementById('displayPrice').innerHTML = '&pound;' + displayValue + '.00';
				insuranceStyles = document.getElementById('insuranceInfoText');
				insuranceStyles.style.color = '#002F46';
			}
		else
			{
				displayValue=parseFloat(document.getElementById('mainCost').value);
				displayValue = displayValue.toString().replace(/\$|\,/g,'');
				if(isNaN(displayValue))
				displayValue = "0";
				sign = (displayValue == (displayValue = Math.abs(displayValue)));
				displayValue = Math.floor(displayValue*100+0.50000000001);
				cents = displayValue%100;
				displayValue = Math.floor(displayValue/100).toString();
				if(cents<10)
				cents = "0" + cents;
				for (var i = 0; i < Math.floor((displayValue.length-(1+i))/3); i++)
				displayValue = displayValue.substring(0,displayValue.length-(4*i+3))+','+
				displayValue.substring(displayValue.length-(4*i+3));
				document.getElementById('displayPrice').innerHTML =  '&pound;' + displayValue + '.00';
				insuranceStyles = document.getElementById('insuranceInfoText');
				insuranceStyles.style.color = '#9F9F9F';
			}
	}

function printCheckBox() { 
// If it is IE ...
if(navigator.userAgent.indexOf('MSIE') > -1) {
   // If it is Windows ...
   if (navigator.userAgent.indexOf('Windows') > -1) {
      document.write('<input');
      document.write(' type="checkbox"');
      document.write(' name="WordWrap"');
      document.write(' onclick="doWordWrap(this.form)">');
      document.write('Word Wrap<br>');
      }
   }
}

function doWordWrap(d) {
if(d.WordWrap.checked == true)
   { d.message.wrap = 'soft'; }
else
   { d.message.wrap = 'off';  }
}

function TAlimit(s) {
var maxlength = 100; // Change number to your max length.
if (s.value.length > maxlength) 
s.value = s.value.substring(0,maxlength);
}




