/*-----------------------------Start of Image/Display Functions------------------------------------*/
image1 = new Image();
image1.src = "../../images/lmenuLiOn.gif";

function showDHTML( e, name, description  )
{
	document.getElementById( "bubble" ).style.visibility = "visible";
	document.getElementById( "bubble" ).style.display = "block";
	document.getElementById( "bubble" ).style.left = ( e.clientX - 25 + getBody().scrollLeft ) + "px";//- 23 + getBody().scrollLeft ) + "px";
	document.getElementById( "bubble" ).style.top = ( e.clientY + 20 + getBody().scrollTop )  + "px";//- 185 + getBody().scrollTop )  + "px";
	document.getElementById( "bubblecaption" ).innerHTML = unescape(name);
	document.getElementById( "bubbledescription" ).innerHTML = unescape(description);
}

function hideDHTML()
{
	document.getElementById( "bubble" ).style.left = "0px";
	document.getElementById( "bubble" ).style.top = "0px";
	document.getElementById( "bubble" ).style.visibility = "hidden";
	document.getElementById( "bubble" ).style.display = "none";
}
function getBody(){
	if(document.compatMode && document.compatMode!="BackCompat"){
		return document.documentElement;
	}else{
		return document.body;
	}
}

function helpPopup(width,height,title,content)
{
	if(window.innerWidth)
	{
		LeftPosition =(window.innerWidth-width)/2;
		TopPosition =((window.innerHeight-height)/4)-50;
	}
	else
	{
		LeftPosition =(parseInt(window.screen.width)-	width)/2;
		TopPosition=((parseInt(window.screen.height)-height)/2)-50;
	}
	
	attr = 'resizable=no,scrollbars=yes,width=' + width + ',height=' + height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' + TopPosition + '';
	popWin=open('', 'new_window', attr);
	
	popWin.document.write('<head><title>'+title+'</title>');
	popWin.document.write('<style type="text/css" media="all">body { padding:0;margin:0;font:10px Verdana, Arial, Helvetica, sans-serif;background:url("images/brand_bg.gif"); } #container { margin:10px; padding:0 } #title { border:solid #e00202 1px;color:#ffffff;font-weight:bold;margin:0;padding:7px 0 7px 10px;background:url("images/menuheading2.png") repeat-x; background-color:#e00202; } #description { margin:0; border:solid #e00202 1px; border-top:none; padding:10px; background-color:#ffffff; line-height:17px; filter:alpha(opacity=90);	-moz-opacity:.9;opacity:.90; } #footer { position:absolute; bottom:0; width:100%;background-color: #000000; text-align:right; } #footer a { text-decoration: underline; color:#e00202; } #footer a:hover { text-decoration:none }</style></head>');
	popWin.document.write('<body><div id="container"><div id="title">'+title+'</div><div id="description">'+content+'</div></div><div id="footer"><div style="margin:4px"><a href="javascript:window.close();">Close Window</a></div></div></body></html>');
}

var t;
var code;
function real_lixlpixel_live_preview(id) 
{	
	prev = window.open("","preview"+id);
	prev.document.open();
	prev.document.writeln(code);
	prev.document.close();
}

// this introduces some delay so that the code is not re-evaluated at every  keystroke.
function lixlpixel_live_preview(thecode, id)  {
	if(t) { window.clearTimeout(t) }
	code = thecode;
	t = window.setTimeout("real_lixlpixel_live_preview("+id+")",400);
}

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_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_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];}
}

var min=9;
var max=13;

function adjustText(adjust) 
{
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) 
   {
      if (GetCookie("textsize")!=null)
	  var s = parseFloat(GetCookie("textsize"));
	  else 
	  var s = 10;
	  
	  if (adjust == 'bigger')
      { if(s!=max) {s += 1;} }
	  else if (adjust == 'smaller')
	  { if(s!=min) {s -= 1;} }
	  
	  lheight = s + 8;
      
	  p[i].style.fontSize = s+"px"
	  p[i].style.lineHeight = lheight+"px"
	  
	  if (s < 12)
	  { p[i].style.fontFamily = "Verdana, Tahoma, Arial, Helvetica, sans serif" } 
	  else if (s >= 12)
	  { p[i].style.fontFamily = "Arial, Helvetica, sans serif" }
   }
  setTextCookie(s);
}

function setTextCookie(size)
{
	var exp = new Date();
	exp.setTime(exp.getTime() + (24 * 60 * 60 * 1000 * 365));
	var expstr = "; expires=" + exp.toGMTString();
	document.cookie = "textsize=" + escape(size) + expstr + "; path=/;";	
}

function initImage() 
{
	imageId = 'thephoto';
	image = document.getElementById(imageId);
	setOpacity(image, 0);
	image.style.visibility = "visible";
	fadeIn(imageId,0);
}
function fadeIn(objId,opacity) 
{
	if (document.getElementById) 
	{
		obj = document.getElementById(objId);
		if (opacity <= 100) 
		{
			setOpacity(obj, opacity);
			opacity += 10;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
		}
	}
}
function setOpacity(obj, opacity) 
{
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}
function show(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"none";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"none";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"none";
	}
}
/*------------------------End of Image/Display Functions--------------------------------*/

/*-----------------------------Start of Panel Functions------------------------------------*/
function setPanelCookie(pid, mid, cid, quantity)
{
	var exp = new Date();
	exp.setTime(exp.getTime() + (24 * 60 * 60 * 1000 * 365));
	var expstr = "; expires=" + exp.toGMTString();
	document.cookie = "panel=" + escape(pid+":"+mid+":"+cid+":"+quantity) + expstr + "; path=/;";	
	//alert("cookie set: "+pid+":"+mid+":"+cid+":"+quantity);
}
function clearPanelCookie()
{
	var exp = new Date();
	exp.setTime(exp.getTime() - (24 * 60 * 60 * 1000 * 365));
	var expstr = "; expires=" + exp.toGMTString();
	document.cookie = "panel=" + expstr + "; path=/;";	
}

function lockPanel(panelid)
{
	if (document.order.locked.value == '0')
	{
		document.order.locked.value = panelid;
		document.getElementById(panelid).style.fontWeight = "bold";
		document.getElementById(panelid).style.fontSize = "11px";
		document.getElementById(panelid).style.color = "#e00202";
		document.getElementById(panelid).style.background ="url('images/menuheading.png')";
		document.getElementById('custDetails').style.display = "block";
		document.getElementById('unlock').style.display = "block";
		document.order.quantity.disabled = false; 
		
		var pid = document.order.panelid.value;
		var matid = document.order.matid.value;
		var carid = document.order.carid.value;
		var quantity = document.order.quantity.value;
		
		setPanelCookie(pid, matid, carid, quantity);
	}
}
function initPanel()
{
	if (document.order.panelid.value!="")
	{ 
		var pid = document.order.panelid.value;
		var mid = document.order.matid.value;
		lockPanel('panel'+pid+mid); 
		updateQuantity(document.order.quantity.value);	
		//alert('panel'+pid+mid+'*'+quantity);
	}
}

function unlockPanel()
{
	panelid = document.order.locked.value;
	document.getElementById(panelid).style.fontWeight = "normal";
	document.getElementById(panelid).style.background ="";
	document.getElementById(panelid).style.fontSize = "";
	document.getElementById(panelid).style.color = "";
	document.getElementById('custDetails').style.display = "none";
	document.getElementById('unlock').style.display = "none";
	document.order.locked.value = '0';
	panelOrder('0.00', '0.00', '', 'Nothing Selected!', '', 'Nothing Selected!', '', 'Nothing Selected!');
	clearPanelCookie();
	document.location=document.location;
}

function emptyQuantity()
{
	if(document.order.quantity.value==0) 
	{ return false; }
	else 
	{ return true; }
}

function panelOrder(post, each, cid, car, pid, panel, mid, material, lock)
{
	if (document.order.locked.value == '0')
	{
		document.order.price.value = each;

		document.order.carid.value = cid;
		document.order.matid.value = mid;
		document.order.panelid.value = pid;	
		
		if (each=='0.00')
		{
			document.order.quantity.value = 0; 
			document.order.total.value = 0.00;		
			document.getElementById('displayTotal').innerHTML = "Total:&nbsp&pound;0.00";
			document.getElementById('displaySubTotal').innerHTML = "&pound;0.00";
			document.order.panelcode.value = '';
			document.order.postage.value = "0.00";
			document.getElementById('displayPost').innerHTML = "&pound;0.00";
		}
		else 
		{
			document.order.quantity.value = 1; 
			priceeach = parseFloat(each) + parseFloat(post);
			var subTotal = round_number((priceeach * 1), 2);	 
			var total = round_number(((priceeach * 1)*1.175), 2);	
			
			document.order.total.value = total;	
			document.getElementById('displayTotal').innerHTML = "Total:&nbsp&pound;"+total;
			document.getElementById('displaySubTotal').innerHTML = "&pound;"+subTotal;
			document.order.panelcode.value = 'P'+pid+'-M'+mid;
			document.order.postage.value = round_number(post,2);
			document.getElementById('displayPost').innerHTML = "&pound;"+round_number(post, 2);
		}
	}
}

function updateQuantity(quantity)
{
	quantityRound = round_number(Math.abs(quantity), 0);
	
	if (quantity != quantityRound)
	document.order.quantity.value = quantityRound;	
	
	priceeach = parseFloat(document.order.price.value) + parseFloat(document.order.postage.value);
	
	var subTotal = round_number((priceeach * quantityRound), 2);	
	var total = round_number(((priceeach * quantityRound)*1.175), 2);
	var postage = round_number((document.order.postage.value * quantityRound), 2);
	
	document.order.total.value = total;	
	document.getElementById('displayTotal').innerHTML = "Total:&nbsp&pound;"+total;
	document.getElementById('displayPost').innerHTML = "&pound;"+postage;
	document.getElementById('displaySubTotal').innerHTML = "&pound;"+subTotal;
	
	var pid = document.order.panelid.value;
	var matid = document.order.matid.value;
	var carid = document.order.carid.value;
	
	setPanelCookie(pid, matid, carid, quantityRound);
}
/*-----------------------------End of Panel Functions------------------------------------*/

/*-----------------------------Start of Product Functions------------------------------------*/
function setProdCookie(pid, vid, quantity)
{
	var exp = new Date();
	exp.setTime(exp.getTime() + (24 * 60 * 60 * 1000 * 365));
	var expstr = "; expires=" + exp.toGMTString();
	document.cookie = "product=" + escape(pid+":"+vid+":"+quantity) + expstr + "; path=/;";	
	//alert("Cookie: PID="+pid+"VAR="+vid+"Q="+quantity);
}
function clearProdCookie()
{
	var exp = new Date();
	exp.setTime(exp.getTime() - (24 * 60 * 60 * 1000 * 365));
	var expstr = "; expires=" + exp.toGMTString();
	document.cookie = "product=" + expstr + "; path=/;";	
}
function restartProduct()
{
	clearProdCookie();
	document.location=document.location;
}

function updateProduct(variation)
{
	//Get/Set Variation ID from/in form.
	if (variation=="")
	{ variation = document.order.prodVariation.value; }
	else 
	{ document.order.prodVariation.value = variation; } 
	
	quantity = document.order.quantity.value;
	
	if (quantity == 0) { quantity = 1; document.order.quantity.value = 1; } 
	var quantityRound = round_number(Math.abs(quantity), 0);
	
	if (quantity != quantityRound)
	document.order.quantity.value = quantityRound;
	
	if (document.order.variationProd.length>1)
	{
		for (var i = 0; i < document.order.variationProd.length; i++) 
		{
			if (document.order.variationProd[i].checked) 
			{
				price = document.order.variationProd[i].value;
				document.order.price.value = price
				var prodVariation = i;
				
				break;
			}
		}
	}
	else 
	{
		price = document.order.variationProd.value;
		prodVariation = 0;
	}	

	postage = document.order.postage.value;
	var pricepost = parseFloat(price,2) + parseFloat(postage,2);
	
	document.order.prodCode.value = "RP"+document.order.prodId.value+"-V"+prodVariation;
	//alert(prodVariation);
	
	subtotal = round_number((pricepost * quantityRound),2);
	document.order.subTotal.value = subtotal;	
	document.getElementById('displaySubTotal').innerHTML="&pound;"+subtotal;
	
	//total = Math.round(total*100)/100;
	var total = round_number(((pricepost*1.175)*quantityRound), 2);
	document.order.total.value = total;	
	if (total==0.00) { document.getElementById('buyNowButton').style.display = "none"; }
	document.getElementById('displayTotal').innerHTML="Total:&nbsp;&pound;"+total;

	setProdCookie(document.order.prodId.value, prodVariation, document.order.quantity.value);
	//alert("PID="+document.order.prodId.value+"VAR="+prodVariation+"Q="+document.order.quantity.value);
}
/*---------------------------Start of Product Functions-----------------------------------*/

/*---------------------------Start of Generic Functions-----------------------------------*/
function IsNumeric(sText)
{
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;

for (i = 0; i < sText.length && IsNumber == true; i++) 
{ 
	Char = sText.charAt(i); 
	if 	(ValidChars.indexOf(Char) == -1) 
	{
		IsNumber = false;
	}
}

return IsNumber; 
}

function round_number (num, dec) 
{ // low-level numeric format with upward rounding at 5+ 
 var cDec = '.'; // decimal point symbol 
 if (!(dec >= 0 && dec <= 9)) 
  dec = 2; 
 if (isNaN (num) || num == '') 
 { // zero values are returned in proper decimal format 
  var sdec = ""; 
  for (var i = 0; i < dec; i++) 
   sdec += '0'; 
  return "0" + (sdec != "" ? cDec + sdec : ""); 
 } 
 var snum = new String (num); 
 var arr_num = snum.split (cDec); 
 var neg = ''; 
 var nullify = 0; 
 dec_a = arr_num.length > 1 ? arr_num[1].length : 0; 
 if (dec_a <= dec) 
 { // fill decimal places with trailing zeros if necessary 
  if (!dec_a) 
   arr_num[1] = ""; 
  for (var i = 0; i < dec - dec_a; i++) 
   arr_num[1] += '0'; 
  dec_a = dec; 
 } 
 // total decimal places in value before rounding and formatting 
 dec_i = dec_a; 
 dec_a -= dec; 
 if (arr_num[0].charAt(0) == '-') 
 { // preserve negative symbol, remove from value (calculations) 
  neg = '-'; 
  arr_num[0] = arr_num[0].substring (1, arr_num[0].length); 
 } 
 if (!parseFloat (arr_num[0])) // case when whole value is 0 
 { // nullify a zero whole value for correct decimal point placement 
  arr_num[0] = "1"; // 0 whole # would not preserve amount in calc. 
  nullify = 1; // flag to remove greatest 1 portion from whole # 
 } 
 var whole = parseFloat (arr_num[0] * Math.pow (10, arr_num[1].length)); 
 // remove leading zeros 
 for (i = 0; i < arr_num[1].length; i++) 
  if (arr_num[1].charAt (i) != '0') 
   break; 
 if (arr_num[1].length == i) // decimal portion blank or all zeros 
  return (neg + arr_num[0] + (arr_num[1] != "" ? (cDec + arr_num[1]) : "")); 
 whole += parseFloat (arr_num[1].substring (i, arr_num[1].length)); 
 if (arr_num[1].length != dec) 
 { // round number affecting appropriate cluster of decimal places 
  var diff = ""; 
  var str = new String (whole); 
  for (i = dec_a; i > 0; i--) 
   diff += str.charAt (str.length - i); 
  diff = Math.pow (10, dec_a) - parseFloat (diff); 
  whole += ((diff <= 5 * Math.pow (10, dec_a - 1)) ? diff : 0); 
 } 
 str = new String (whole); 
 var str_f = ""; 
 var j = 0; 
 var k = 0; 
 if (nullify) 
 { 
  arr_num[0] = "0"; // remove 1 from greatest decimal place (restoration) 
  str = (parseFloat (str.charAt(0)) - 1) + str.substring (1, str.length); 
 } 
 else // re-assign whole numeric portion from entire numeric string value 
  arr_num[0] = str.substring (0, str.length - dec_i); 
 for (i = 0; i < str.length; i++) 
 { // combine portions of decimal number (whole, fraction, sign) 
  if (k - 1 > dec) 
   break; // fraction termination case 
  if (j == arr_num[0].length) 
  { 
   if (!j) 
    str_f += 0; 
   str_f += (dec != 0 ? cDec : ''); // insert decimal point 
   --i; // backtrack one character 
   k++; // signal fraction count 
  } 
  else // assign character by character 
   str_f += str.charAt (i); 
  j++; 
  if (k) // fractional counter increment 
   k++; 
 } 
 return neg + str_f; 
}
/*---------------------------End of Generic Functions-----------------------------------*/