//<script>

var keyValue=0;
function checkPasswordLength(textValue){

	passBoxError = document.getElementById('passwordBox');
	if(textValue.length < 8){
		passBoxError.style.display = 'block';
		passBoxError.style.color = 'red';
		passBoxError.innerText = 'Password Less Than 8 Characters';
	}else{
		passBoxError.style.display = 'none';
		passBoxError.innerText = '';		
	}
}
function checkPasswordMatch(textValue){

	passBoxMatch = document.getElementById('mainPassword');
	passBoxError2 = document.getElementById('passwordConfirmBox');

	if(passBoxMatch.value != textValue){
		passBoxError2.style.display = 'block';
		passBoxError2.style.color = 'red';
		passBoxError2.innerText = 'Passwords Do Not Match';
	}else{
		passBoxError2.style.display = 'none';
		passBoxError2.innerText = '';		
	}
}
function showHidePassword(){
	passwordBoxes = document.getElementsByClassName('passwordBox');
	passwordButton = document.getElementsByClassName('showPassword');
	for(var i=0, n=passwordBoxes.length;i<n;i++) {
		if (passwordBoxes[i].getAttribute("type") === "password"){
			passwordBoxes[i].type ="text";
		}else{
			passwordBoxes[i].type ="password";
		}
	}
	for(var i=0, n=passwordButton.length;i<n;i++) {
		if(passwordButton[i].innerText == 'Show Password'){
			passwordButton[i].innerText = 'Hide Password';
		}else{
			passwordButton[i].innerText = 'Show Password';
		}
	}
}
function checkEntry(t, rangeLocked){
	value = t.value;
	if((parseFloat(value) >-0.01 && !isNaN(value)) || value=='0'){
		if(rangeLocked==1 && t.value > 99.99){
			t.value=99.99;
		}	
	} else { 
		if(rangeLocked==1 && t.value > 99.99){
			t.value=99.99;
		} else {
			t.value=keyValue;
		}
	} 
}
	
function recordEntry(t){
	 keyValue = t.value;
}

function checkCard(val){
	if(val==12){
		document.getElementById('cardPayment').style.display="none";
	} else {
		document.getElementById('cardPayment').style.display="inline";
	}
	if(val!=6) {
		document.getElementById('stDt').style.display="none";
		document.getElementById('issueNum').style.display="none";
	}else{
		document.getElementById('stDt').style.display="inline";
		document.getElementById('issueNum').style.display="inline";
	}
}
window.onresize = center_gallery;
function silentErrorHandler() {return true;}

var gallery_open = false;
var inter = false;
var imgPointer = 1;
var cc=0;
var which=0;
var maxHeight = 0;
var maxWidth = 0;
var sizes = new Array();
var types_array = new Array();
var images_array = new Array();
var captions_array= new Array();
var descriptions_array = new Array();



function center_gallery(){
	alertSize();
	var ic = document.getElementById('gallery_image_container');
	var cw = window.clientWidth;
	var ch = window.clientHeight;
	tb = document.getElementById('gallery_table');
	if(ic){
		l=(sizes['width']/2)-(ic.offsetWidth/2)+36;
		tb.style.left=l+"px";
		h=(sizes['height']/2)-(ic.offsetHeight/2)+18;
	
		tb.style.visibility="visible";
	
		tb.style.top=h+"px";
	}
}

function resizeOverlay(height){
	if (height==0){
		growElementHeight('content_frame', 1, sizes['height']);
	} else {
		if (height<sizes['height']){
			growElementHeight('content_frame', 1, height);
		} else {
			growElementHeight('content_frame', 1, sizes['height']);
		}
	}

	document.getElementById('gallery_caption').style.display="none";
}

function growElementHeight(elm, height, maxHeight){
	el = document.getElementById(elm);
	if (height<maxHeight){
		height=Math.round(height+(maxHeight-height)/2)+1;
		el.height=height+"px";
		setTimeout("growElementHeight('"+elm+"', "+height+", "+maxHeight+");",1);
	} else {
		el.height=height+"px";
		document.getElementById('content_frame').style.visibility="visible";
	}
	center_gallery();
}

function growElementWidth(elm, width, maxWidth){
	el = document.getElementById(elm);
	if (width<maxWidth){
		width=Math.round(width+(maxWidth-width)/3)+1;
		el.width=width+"px";
		setTimeout("growElementWidth('"+elm+"', "+width+", "+maxWidth+");",1);
	} else {
		el.width=width+"px";
	}
	center_gallery();
}

function shrinkElementWidth(elm, width, minWidth){
	el = document.getElementById(elm);
	if (width>minWidth){
		width=Math.round(width-(minWidth-width)/3)+1;
		el.width=width+"px";
	} else {
		el.width=width+"px";
	}
	center_gallery();
}

function openOverlay(url, width, height, forceSize, hideClose){
	if(hideClose==1){
		document.getElementById('closeX').style.display='none';
	} else {
		document.getElementById('closeX').style.display='inline';
	}
	alertSize();
	if (width<1){
		width=sizes['width'];
	}
	if (height<1){
		height=sizes['height'];
	}
	if (forceSize!=1){
		height=0;
	}

	embed = "<iframe class='fancybox-skin' src='"+url+"' width="+width+"px height="+height+"px frameborder=none style='border:0px;border-style:none;visibility:hidden;' id='content_frame'></iframe>";
	vc=document.getElementById('video_container');
	vc.style.display="inline";
	vc.style.offsetWidth=width+"px";
	vc.style.offsetHeight=height+"px";
	vc.innerHTML = embed;
	
	setTimeout("window.frames['content_frame'].location = '"+url+"';", 1);
	gallery_open=true;
	document.getElementById('page_protector').style.display="inline";
	if(document.getElementById('float_basket')){
		document.getElementById('float_basket').style.display="none";
	}	
	document.getElementById('gallery_table').style.display="inline";
	document.getElementById('gallery_caption').style.width=width;
	document.getElementById('gallery_image').style.display="none";
	document.getElementById('gallery_caption').style.display="block";
	document.getElementById('gallery_caption').innerHTML="<center><img src='/inc/modules/gallery/images/loading.gif'><br>Loading...</div>";
	document.getElementById('gallery_description').style.display="none";
	document.getElementById('gallery_table').style.zIndex=900000;
	center_gallery();

	open_gallery_loop(1);
}

function open_gallery(img,a,w){

	if (types_array[w][img]==1){

		embed = "<object width='640' height='385'><param name='movie' value='http://www.youtube.com/v/"+images_array[w][img]+"&hl=en_GB&fs=1&autoplay=1'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/"+images_array[w][img]+"&hl=en_GB&fs=1&autoplay=1' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='640' height='385'></embed></object>";
		vc=document.getElementById('video_container');
		vc.style.display="inline";
		vc.innerHTML = embed;


		gallery_open=true;
		which=w;
		if (!img){
			img=0;
		}
		imgPointer=img;
		i = document.getElementById('gallery_image_holder');
		if(document.getElementById('float_basket')){
			document.getElementById('float_basket').style.display="none";
		}
		document.getElementById('page_protector').style.display="inline";
		document.getElementById('gallery_table').style.display="inline";
		document.getElementById('gallery_image').style.display="none";
		document.getElementById('gallery_caption').innerHTML=captions_array[w][img];
		document.getElementById('gallery_description').innerHTML=descriptions_array[w][img];
		center_gallery();
		setTimeout("center_gallery();", 50);

	} else {
		document.getElementById('gallery_image').style.display="inline";
		var gallery_open=true;
		var which=w;
		if (!img){
			var img=0;
		}
		var imgPointer=img;
		var i = document.getElementById('gallery_image_holder');

		document.getElementById('gallery_caption').innerHTML="Loading...";
		document.getElementById('gallery_description').innerHTML="";
		document.getElementById('page_protector').style.display="inline";
		if(document.getElementById('float_basket')){
			document.getElementById('float_basket').style.display="none";
		}		
		document.getElementById('gallery_image_holder').src="/inc/modules/gallery/preview.php?image="+images_array[w][img]+"&width="+sizes['width']+"&height="+sizes['height'];
		document.getElementById('gallery_table').style.display="inline";
		document.getElementById('gallery_image_holder').onload=function(){
			document.getElementById('gallery_image').src = document.getElementById('gallery_image_holder').src;
			document.getElementById('gallery_caption').innerHTML=captions_array[w][img];
			document.getElementById('gallery_description').innerHTML=descriptions_array[w][img];
		}
		document.getElementById('gallery_image').onload=function(){
			center_gallery();
		}
		
	}
	document.getElementById('gallery_table').style.zIndex=900000;
	open_gallery_loop(1);
	center_gallery();
}



function gallery_forward(){
	close_gallery();
	imgPointer=parseInt(imgPointer)+1;
	open_gallery(imgPointer,0,which);
}
function gallery_back(){
	close_gallery();
	imgPointer=parseInt(imgPointer)-1;
	open_gallery(imgPointer,0,which);
}

function IsImageOk(img) {
	if (!img.complete) {
		return false;
	}
	if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
		return false;
	}
	return true;
}


function open_gallery_loop(a){
	if (a<40){
		a=a+20;
		SetOpacity("page_protector", a);
		setTimeout("open_gallery_loop("+a+");", 5);
	}
}

function close_gallery(a,b){
	document.getElementById('gallery_caption').innerHTML="<center><img src='/inc/modules/gallery/images/loading.gif'><br>Loading...</center>";
	vc=document.getElementById('video_container');
	vc.style.display="none";
	vc.innerHTML = "nbsp;";
	
	if (b==1){
		document.getElementById('gallery_image').src="/inc/modules/gallery/images/loading.gif";
		document.getElementById('gallery_caption').innerHTML="Loading...";
	}
	if (a==100){
		document.getElementById('gallery_table').style.display="none";
		document.getElementById('gallery_table').style.visibility="hidden";	
	}
	if (a>-5){
		a=a-20;
		SetOpacity("page_protector", (a/2));
		setTimeout("close_gallery("+a+");", 5);
	} else {
		document.getElementById('page_protector').style.display="none";
		if(document.getElementById('float_basket')){
			document.getElementById('float_basket').style="inline";
		}
	}
	gallery_open=false;
}

function SetOpacity(elm, opacityAsInt){
    elem = document.getElementById(elm);
	var opacityAsDecimal = opacityAsInt;
    
    if (opacityAsInt > 100)
        opacityAsInt = opacityAsDecimal = 100; 
    else if (opacityAsInt < 0)
        opacityAsInt = opacityAsDecimal = 0; 
    
    opacityAsDecimal /= 100;
    if (opacityAsInt < 1)
        opacityAsInt = 1;
    
    elem.style.opacity = (opacityAsDecimal);
    elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}

function init(){
	
	if (document.getElementById('float_basket')!=null){
		window.onscroll = moveSearch;
	}

	image = images_array[0];

	urlBase=document.location.protocol+"//"+document.location.host;

	divOverlay = document.createElement("div");
	divOverlay.id='overlay';
	divOverlay.style.position="fixed";
	divOverlay.style.left="0px";
	divOverlay.style.top="0px";	

	div = document.createElement("div");
	div.id='page_protector';
	div.style.backgroundColor="black";
	div.style.position="fixed";
	div.style.left="0px";
	div.style.top="0px";
	div.style.width="100%";
	div.style.height="100%";
	div.style.display="none";	
	div.style.zIndex="7000";
	div.innerHTML="&nbsp;";
    div.style.opacity = (.5);
    div.style.filter  = "alpha(opacity=50)";
	div.setAttribute("onclick", "close_gallery(100,1);");

	table = document.createElement("table");
	table.id="gallery_table";
	table.setAttribute("cellpadding","0");
	table.setAttribute("cellspacing","0");
	table.style.zIndex="9009999";
	table.style.position="fixed";
	table.style.fontSize="1px";
	table.style.left="0px";
	table.style.top="0px";
	table.style.display="none";
	table.style.visibility="hidden";
	
	tableRow_1 = document.createElement("tr");
	tableTd_1 = document.createElement("td");
	tableTd_1.style.background="url('"+urlBase+"/inc/modules/gallery/images/c1.png') bottom left no-repeat";
	tableTd_1.style.width="14px";
	tableTd_1.innerHTML="<img src='"+urlBase+"/inc/modules/gallery/images/1px.gif' width='14px' height='14px'>";
	tableTd_2 = document.createElement("td");
	tableTd_2.style.background="url('"+urlBase+"/inc/modules/gallery/images/t.png') bottom left repeat-x";
	tableTd_2.innerHTML="<img src='"+urlBase+"/inc/modules/gallery/images/1px.gif' width='14px' height='14px'>";	
	tableTd_3 = document.createElement("td");
	tableTd_3.style.background="url('"+urlBase+"/inc/modules/gallery/images/c2.png') bottom left no-repeat";
	tableTd_3.innerHTML="<img src='"+urlBase+"/inc/modules/gallery/images/close.png' width='32px' height='32px' style=';position:relative;left:-12px;top:14px;cursor:pointer;z-index:99999999' onclick='close_gallery(100,1)' id='closeX'>";	
	tableRow_1.appendChild(tableTd_1);
	tableRow_1.appendChild(tableTd_2);
	tableRow_1.appendChild(tableTd_3);
	table.appendChild(tableRow_1);

	tableRow_2 = document.createElement("tr");
	tableTd_12 = document.createElement("td");
	tableTd_12.style.background="url('"+urlBase+"/inc/modules/gallery/images/l.png')";
	tableTd_12.style.width="14px";
	tableTd_12.innerHTML="<img src='"+urlBase+"/inc/modules/gallery/images/1px.gif' width='14px' height='14px'>";
	tableTd_22 = document.createElement("td");
	tableTd_22.id="gallery_image_container";
	tableTd_22.width="150px";
	tableTd_22.style.background="white";
	tableTd_22.valign="middle";
	tableTd_22.align="center";
	tableTd_22.style.fontSize="13px";


	tableTd_22.innerHTML="<div id='video_container' style='display:none;'>&nbsp;</div><img src='/inc/modules/gallery/images/loading.gif' id='gallery_image'><br><div id='gallery_caption' style='font-weight:900;'>Loading...</div><div id='gallery_description'></div><img src='/inc/modules/gallery/images/loading.gif' id='gallery_image_holder' style='display:none;'>";	
	tableTd_32 = document.createElement("td");
	tableTd_32.style.background="url('"+urlBase+"/inc/modules/gallery/images/r.png') repeat-y";
	tableTd_32.innerHTML="<img src='"+urlBase+"/inc/modules/gallery/images/1px.gif' width='14px' height='14px'>";	
	tableRow_2.appendChild(tableTd_12);
	tableRow_2.appendChild(tableTd_22);
	tableRow_2.appendChild(tableTd_32);
	table.appendChild(tableRow_2);

	tableRow_3 = document.createElement("tr");
	tableTd_13 = document.createElement("td");
	tableTd_13.style.background="url('"+urlBase+"/inc/modules/gallery/images/c4.png')";
	tableTd_13.style.width="14px";
	tableTd_13.innerHTML="<img src='"+urlBase+"/inc/modules/gallery/images/1px.gif' width='14px' height='13px'>";
	tableTd_23 = document.createElement("td");
	tableTd_23.style.background="url('"+urlBase+"/inc/modules/gallery/images/b.png')";
	tableTd_23.innerHTML="<img src='"+urlBase+"/inc/modules/gallery/images/1px.gif' width='14px' height='13px'>";	
	tableTd_33 = document.createElement("td");
	tableTd_33.style.background="url('"+urlBase+"/inc/modules/gallery/images/c3.png') no-repeat";
	tableTd_33.innerHTML="<img src='"+urlBase+"/inc/modules/gallery/images/1px.gif' width='14px' height='13px'>";	
	tableRow_3.appendChild(tableTd_13);
	tableRow_3.appendChild(tableTd_23);
	tableRow_3.appendChild(tableTd_33);
	table.appendChild(tableRow_3);


	
	
	if (document.all){
		document.body.appendChild(divOverlay);
		document.getElementById('overlay').innerHTML=div.outerHTML;
		document.getElementById('overlay').innerHTML=document.getElementById('overlay').innerHTML+table.outerHTML;
	} else {
		document.body.appendChild(table);
		document.body.appendChild(div);
	}
	
	sizes = alertSize();
}


function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  sizes['width']=(myWidth)-100;
  sizes['height']=(myHeight)-100;
  return sizes;
}

function resize(){
	sizes = alertSize();
}

var timer="";
function moveSearch(){
	var topPos = document.body.scrollTop || window.pageYOffset  || (document.body.parentElement ? document.body.parentElement.scrollTop:0);
	if (topPos>70){
		if(document.getElementById('page_protector').style.display=="none"){
			document.getElementById('float_basket').style.display="inline";
		}
	} else {
		document.getElementById('float_basket').style.display="none";
	}

}
function updateSearchDpt(val, valbox, elm){
	elmId = elm.replace("searchResults", "");
	if (document.getElementById("dpt"+elmId)){
		dptW = document.getElementById("dpt"+elmId).offsetWidth+4;
		dpt = document.getElementById("dpt"+elmId).value;
	} else {
		dptW=0;
		dpt="";
	}
	if(elm=="searchResults"){
		t = document.getElementById('sBox');	
	} else {
		t = document.getElementById('sBox_2');	
	}

	sr = document.getElementById(elm);
	sr.style.top = (parseInt(t.offsetTop)+parseInt(t.offsetHeight)+4)+"px";
	sr.style.left = (t.offsetLeft)+"px";
	sr.style.width = (t.offsetWidth+dptW)+"px";
		
	value2 = document.getElementById(valbox).value;
	if (value2.length>0){
		makePOSTRequest("/inc/rpc/search.php", "q="+value2+"&elm="+elm+"&dpt="+val);
	}
}
function searchRpc(t, elm){
	allowed=false;
	clearTimeout(timer);
	timer=setTimeout(function(){doSearch(t, elm);}, 250);
}
var oldStr="";
function doSearch(t, elm){
	elmId = elm.replace("searchResults", "");
	if (document.getElementById("dpt")){
		dptW = document.getElementById("dpt"+elmId).offsetWidth+4;
		dpt = document.getElementById("dpt"+elmId).value;
	} else {
		dptW=0;
		dpt="";
	}
	if (t.value!=oldStr){
		sr = document.getElementById(elm);
		sr.style.top = (parseInt(t.offsetTop)+parseInt(t.offsetHeight)+4)+"px";
		sr.style.left = (t.offsetLeft)+"px";
		sr.style.width = (t.offsetWidth+dptW)+"px";
		if (t.value.length>0){
			makePOSTRequest("/inc/rpc/search.php", "q="+t.value+"&elm="+elm+"&dpt="+dpt);
		} else {
			closeDrop(elm);
		}
		oldStr = t.value;
	}
}


var http_request = false;
function makePOSTRequest(url, parameters) {
  http_request = false;
  if (window.XMLHttpRequest) {
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		http_request.overrideMimeType('text/xml');
	 }
  } else if (window.ActiveXObject) {
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
  }
  if (!http_request) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
  }
  http_request.onreadystatechange = alertContents;
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.send(parameters);
}

function alertContents() {
  if (http_request.readyState == 4) {
	 if (http_request.status == 200) {
		eval(http_request.responseText);
	 } 
  }
}
var c=1;
var cc=1;
var isOpen = false;
var webLinks = new Array();
function openDrop(elm){
	if(elm=="searchResults"){
		if(document.getElementById("searchResults_2")){
			document.getElementById("searchResults_2").style.display="none";
		}	
	} else {
		if(document.getElementById("searchResults")){
			document.getElementById("searchResults").style.display="none";
		}
	}
	c=0;
	cc=1;
	sr = document.getElementById(elm);
		isOpen = true;		
		sr.style.zIndex="999999";
		sr.style.textAlign='left';
		sr.style.display="inline";
	webLinks = new Array();
	sr.innerHTML="<span style='float:right;margin:6px;cursor:pointer;' onclick=\"document.getElementById('"+elm+"').style.display='none';\"><img src='/images/cross_small.png'></span>";

}

function closeDrop(elm){
	c=0;
	cc=0;
	webLinks = new Array();
	sr = document.getElementById(elm);
	sr.style.display="none";
	sr.innerHTML="";
	isOpen = false;
}

function addProduct(name, web_link, image, price, elm){
	sr = document.getElementById(elm);
	c++;
	webLinks[c]=web_link;
	var line="<div class='searchRow' id='rolly_"+c+"' onmousedown=\"gotoUrl("+c+");\" onmouseover=\"selectThis("+c+");\" onmouseout=\"unselectThis("+c+");\"><table width=100%><tr><td width=40><img src=\""+image+"\" style='vertical-align:middle;'></td><td>"+name+"</td>";
	if(price){
		line+="<td class='product_price' style='font-size:15px;padding-right:6px;' width=80 align=right>"+price+"</td>";
	}
	line+="</tr></table></div>";
	
	sr.innerHTML = sr.innerHTML + line;
}

function addFooter(count, string, url, topS, elm){
	c++;
	sr = document.getElementById(elm);
	webLinks[c]=url;
	if(parseInt(count) < parseInt(topS)){
		topS = count;
		var topTxt = "<b>Display All Results For  '"+string+"'</b><br>";		
		var showing = "";
	} else {
		var topTxt = "<b>Display All Results For  '"+string+"'</b><br>";
		var showing = "Showing "+topS+" Results";
	}
	sr.innerHTML=sr.innerHTML+"<div class='searchHeader' id=\"rolly_"+c+"\" onmousedown=\"gotoUrl("+c+");\" onmouseover=\"selectThis("+c+");\" onmouseout=\"unselectThis("+c+");\">"+topTxt+count+" results found. "+showing+"</div>";
	allowed=true;
}

function addPageResult(title, url, description, elm){
	sr = document.getElementById(elm);
	c++;
	webLinks[c]=url;
	var line="<div class='searchRow' id='rolly_"+c+"' onmousedown=\"gotoUrl("+c+");\" onmouseover=\"selectThis("+c+");\" onmouseout=\"unselectThis("+c+");\"><h3>"+title+"</h3>"+description+"</div>";
	
	sr.innerHTML = sr.innerHTML + line;
	allowed=true;
}
function addDescriptor(title, elm){
	sr = document.getElementById(elm);
	var line="<div class='searchRow'><h2>"+title+"</h2></div>";
	
	sr.innerHTML = sr.innerHTML + line;		
}
function addFooter_web(count, string, url, already, elm){
}

function addOptGroup(elm, groupHead){
	sr = document.getElementById(elm);
	sr.innerHTML=sr.innerHTML+"<div class='searchGroupHeader'><h3>"+groupHead+"</h3></div>";
	allowed=true;	
}

document.onkeydown = WhichKeyPress;

var allowed = false;

function WhichKeyPress(e) {
	 if (!e) {
	  if (window.event) {
			e = window.event;
		 } else {
		   return;
		 }
	 }
    if (typeof (e.keyCode) == 'number') {
      e = e.keyCode;
    } else if (typeof (e.which) == 'number') {
      e = e.which;
    } else if (typeof (e.charCode) == 'number') {
      e = e.charCode;
    } else {
      return;
    }
	if (e==38 && isOpen)
	{	
		if (cc>1)
		{
			cc=cc-1;
			document.getElementById("rolly_"+cc).style.backgroundColor="#eeeeee";
			document.getElementById("rolly_"+cc).focus();
			if (document.getElementById("rolly_"+(cc+1)))
			{
				document.getElementById("rolly_"+(cc+1)).style.backgroundColor="transparent";	
			}
		}
	

		return false;
	}
	if (e==40 && isOpen)
	{
		if (cc<=c){
			cc=cc+1;
		document.getElementById("rolly_"+cc).style.backgroundColor="#eeeeee";
		if (document.getElementById("rolly_"+(cc-1)))
		{
			document.getElementById("rolly_"+(cc-1)).style.backgroundColor="transparent";
		}

		document.getElementById("rolly_"+cc).focus();
		}

		return false;
	}
	if (e==13 && isOpen && cc>=0){
		document.location.href=webLinks[cc];
		return false;
	} 
}

function clearAll(){
	var all = document.getElementsByTagName("table");

	for (var i = 0; i < all.length; i++) {
		if (all[i].id.match('rolly')) { 
			thisId = all[i].id;
			document.getElementById(thisId).style.backgroundColor="transparent";
		} 
	}

}

function unselectThis(t) {
		cc=t;
		document.getElementById("rolly_"+cc).style.backgroundColor="transparent";
		cc=0;
}

function selectThis(t) {
		clearAll();
		cc=t;
		document.getElementById("rolly_"+cc).style.backgroundColor="#eeeeee";
		document.getElementById("rolly_"+cc).focus();
}

function gotoUrl(t){
	document.location.href=webLinks[t];
}

function returnKey(e){
   if (typeof (e.keyCode) == 'number') {
      ev = e.keyCode;
   } else if (typeof (e.which) == 'number') {
      ev = e.which;
   } else if (typeof (e.charCode) == 'number') {
      ev = e.charCode;
   } else {
      return;
   }
   return ev;
}

function searchFilter(field,nextLevel,standAlone){
	var str="";
	if(standAlone){
		var standAloneFilter = true;
	}else{
		var standAloneFilter = false;	
	}
	str = document.getElementById("search_query").value+"/";
	if(standAloneFilter == false){
		if (document.getElementById("search_filter_brand")){
			brand_value = document.getElementById("search_filter_brand").value;
			if (brand_value.length>0){
				str=str+"brand/"+brand_value+"/";
			}
		}
		if (document.getElementById("search_filter_type")){
			type_value = document.getElementById("search_filter_type").value;
			if (type_value.length>0){
				str=str+"type/"+type_value+"/";
			}
		}
		if (document.getElementById("search_filter_category") && field!="type"){
			category_value = document.getElementById("search_filter_category").value;
			if (category_value.length>0){
				str=str+"category/"+category_value+"/";
			}
		}
		if (document.getElementById("search_filter_range")){
			range_value = document.getElementById("search_filter_range").value;
			if (range_value.length>0){
				str=str+"range/"+range_value+"/";
			}
		}
		if (document.getElementById("search_filter_collection")){
			collection_value = document.getElementById("search_filter_collection").value;
			if (collection_value.length>0){
				str=str+"collection/"+collection_value+"/";
			}
		}
		if (document.getElementById("search_filter_colour")){
			colour_value = document.getElementById("search_filter_colour").value;
			if (colour_value.length>0){
				str=str+"colour/"+colour_value+"/";
			}
		}
	}else{
		if (document.getElementById("search_filter_brand_alone")){
			brand_value = document.getElementById("search_filter_brand_alone").value;
			if (brand_value.length>0){
				str=str+"brand/"+brand_value+"/";
			}
		}
		if (document.getElementById("search_filter_type_alone")){
			type_value = document.getElementById("search_filter_type_alone").value;
			if (type_value.length>0){
				str=str+"type/"+type_value+"/";
			}
		}
		if (document.getElementById("search_filter_category_alone") && field!="type"){
			category_value = document.getElementById("search_filter_category_alone").value;
			if (category_value.length>0){
				str=str+"category/"+category_value+"/";
			}
		}
		if (document.getElementById("search_filter_range_alone")){
			range_value = document.getElementById("search_filter_range_alone").value;
			if (range_value.length>0){
				str=str+"range/"+range_value+"/";
			}
		}
		if (document.getElementById("search_filter_collection_alone")){
			collection_value = document.getElementById("search_filter_collection_alone").value;
			if (collection_value.length>0){
				str=str+"collection/"+collection_value+"/";
			}
		}
		if (document.getElementById("search_filter_colour_alone")){
			colour_value = document.getElementById("search_filter_colour_alone").value;
			if (colour_value.length>0){
				str=str+"colour/"+colour_value+"/";
			}
		}
		
	}
	if(nextLevel !=''){
				str=str+nextLevel+"/";
	}
	str = str.replace("//", "/");
	document.location.href=str;
}


function clearFilterSingle(field){
	var str="";
	str = document.getElementById("search_query").value+"/";
	
	if (document.getElementById("search_filter_brand")){
		brand_value = document.getElementById("search_filter_brand").value;
		if (brand_value.length>0){
			str=str+"brand/"+brand_value+"/";
		}
	}
	if (document.getElementById("search_filter_type")){
		type_value = document.getElementById("search_filter_type").value;
		if (type_value.length>0){
			str=str+"type/"+type_value+"/";
		}
	}
	if (document.getElementById("search_filter_category") && field!="type"){
		category_value = document.getElementById("search_filter_category").value;
		if (category_value.length>0){
			str=str+"category/"+category_value+"/";
		}
	}
	if (document.getElementById("search_filter_range")){
		range_value = document.getElementById("search_filter_range").value;
		if (range_value.length>0){
			str=str+"range/"+range_value+"/";
		}
	}
	if (document.getElementById("search_filter_collection")){
		collection_value = document.getElementById("search_filter_collection").value;
		if (collection_value.length>0){
			str=str+"collection/"+collection_value+"/";
		}
	}
	if (document.getElementById("search_filter_colour")){
		colour_value = document.getElementById("search_filter_colour").value;
		if (colour_value.length>0){
			str=str+"colour/"+colour_value+"/";
		}
	}
	if (field=='brand'){
		brand_value = document.getElementById("search_filter_brand").value;
		str = str.replace("brand/"+brand_value+"/","");
		str = str+"brand/";
	}
	if (field=='type'){
		type_value = document.getElementById("search_filter_type").value;
		str = str.replace("type/"+type_value+"/","");
		category_value = document.getElementById("search_filter_category").value;
		str = str.replace("category/"+category_value+"/","");
		str = str+"type/";
	}
	if (field=='category'){
		category_value = document.getElementById("search_filter_category").value;
		str = str.replace("category/"+category_value+"/","");
		str = str+"category/";
	}
	if (field=='collection'){
		collection_value = document.getElementById("search_filter_collection").value;
		str = str.replace("collection/"+collection_value+"/","");
		str = str+"collection/";
	}
	if (field=='range'){
		range_value = document.getElementById("search_filter_range").value;
		str = str.replace("range/"+range_value+"/","");
		str = str+"range/";
	}
	str = str.replace("//", "/");
	document.location.href=str;
}
function searchFilterBrandBar(val){
	var loc = window.location;
	loc = loc+"";
	tmp = loc.split("//");
	elms = tmp[1].split("/");
	var brandFound=0;
	var browseFound=0;
	var url = '';
	for(i=0; i<elms.length; i++){
		if(elms[i]=="browse"){
			browseFound++;	
		}
		if(elms[i]=="brand" || elms[i]=="Brand" || brandFound==1){
			brandFound++;
		} else {
			if(elms[i]){
				url+=elms[i]+"/";
			}
		}
	}
	if(val!="*"){
		var out = tmp[0] + "//" + url + (browseFound<1?"browse/":"") + "brand/" + val + "/";
	} else {
		var out = tmp[0] + "//" + url;	
	}
	window.location=out;
}

var radioBasePrice = 0;
var radioWasPrice = 0;

function updatePrice(w, price, id, type, was_price, mustComit, attribId){		
		if(mustComit==1){
		var all = document.getElementsByTagName("input");
		var checkCount = 0;
		var doCalc=false;
		for (var i = 0; i < all.length; i++) {			
			if(all[i].name.match(attribId)){
				if(all[i].checked){
					checkCount++;
				}
			}
		}
		
		if(checkCount < 1){
			w.checked=true;
			alert("Sorry you need to have at least one option selected");
		} else {
			thisChecked=w.checked;
			if (type==1){
				if(thisChecked==true){
					radioArray[id]=price;
					radioWasArray[id]=was_price;
				} else {
					radioArray[id]=0;
					radioWasArray[id]=0;
				}
			}
			if (type==0){
				radioArray[id]=price;
				radioWasArray[id]=was_price;
			}				
			doCalc=true;
		}
	} else {
		doCalc=true;
	}
	if(doCalc){
		thisChecked=w.checked;
		if (type==1){
			if(thisChecked==true){
				radioArray[id]=price;
				radioWasArray[id]=was_price;
			} else {
				radioArray[id]=0;
				radioWasArray[id]=0;
			}
		}
		if (type==0){
			radioArray[id]=price;
			radioWasArray[id]=was_price;
		}			
		calculatePrice(w);		
	}
}

function calculateDim(w, t, mn, mx, ck){
	if (isNaN(t.value) || t.value<mn || t.value>mx){
		if (ck==1){
			if (t.value<mn)
			{
				t.value=mn;
			}
			if (t.value>mx)
			{
				t.value=mx;
			}
			if (isNaN(t.value))
			{
				t.value=1000;
			}
			calculatePrice(w);
		}
		
		return false;
	} else {
		calculatePrice(w);
	}
}

function calculatePrice(w){
	if(document.getElementById('qty')){
		var qty = document.getElementById('qty').value;
	} else {
		var qty = 1;
	}
	if (document.getElementById('lmm')){
		lmm = document.getElementById('lmm').value;
	}
	if (document.getElementById('wmm')){
		wmm = document.getElementById('wmm').value
	}
	if (document.getElementById('hmm')){
		hmm = document.getElementById('hmm').value
	}
	nbaseWasPrice=baseWasPrice;
	nbasePrice=basePrice;
	if (document.getElementById('wmm')){
		nbaseWasPrice=baseWasPrice*(wmm/1000);
		nbasePrice=basePrice*(wmm/1000);
	}
	if (document.getElementById('hmm') && document.getElementById('wmm')){
		nbaseWasPrice=baseWasPrice*((wmm/1000)*(hmm/1000));
		nbasePrice=basePrice*((wmm/1000)*(hmm/1000));
	}
	
	_wasPrice=0;
	radioBasePrice=0;
	radioWasPrice=0;
	for (i=0;i<radioArray.length;i++){
		if (radioArray[i])
		{
			radioBasePrice = radioBasePrice+parseFloat(radioArray[i]);
			radioWasPrice = radioWasPrice+parseFloat(radioWasArray[i]);
		}
	}

	showWasPrice = Math.round((nbaseWasPrice*100)+(radioWasPrice*100))/100*qty;
	showPrice = Math.round((nbasePrice*100)+(radioBasePrice*100))/100*qty;
	
	_basePrice=formatCurrency(showPrice);
	if (elm = document.getElementById('was_price')){
		_wasPrice=formatCurrency(showWasPrice);
	}
	setTimeout(function(){setPrice(_wasPrice,_basePrice,w)},1);
}


function setPrice(w,b,wh){
	if (elm = document.getElementById('was_price')){
		elm.innerHTML=w;
	}
	if(b=="0.00"){
		if(document.getElementById('currency')){
			document.getElementById('currency').style.display="none";	
		}
		document.getElementById('basePrice').innerHTML="Please Select";
	} else {
		if(document.getElementById('currency')){
			document.getElementById('currency').style.display="inline";	
		}		
		document.getElementById('basePrice').innerHTML=b;
	}
	if (wh!=null){
		wh.disabled=false;
	}
	if(document.getElementById("youSave")){
		w=w.replace(",", "");
		b=b.replace(",", "");
		document.getElementById("youSave").innerHTML = formatCurrency(w-b)
	}
}


var code_ext = new Array()
var code_ext_HTML ="";
function updatePriceSelect(w, str){
	vari = str.split("\|");
	variables = vari[0];

	vars = variables.split("-");
	if (vars[5]=="70")
	{
		code_ext[vars[3]]=vars[6];
	}
	updatePrice(w, vars[1], vars[3], vars[4], vars[2]);
	code_ext_HTML="";
	for (i=0;i<code_ext.length;i++){
		if (typeof(code_ext[i])!="undefined"){
			code_ext[i] = code_ext[i].replace("_MINUS_", "-");
			
			code_ext_HTML=code_ext_HTML+code_ext[i];
		}
		
	}
	document.getElementById('pcex').innerHTML=code_ext_HTML;
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}

var closedElm = true;
var boxSize=35;
var closeSpeed = 3;

function fn_openColours(){
	colourBoxes = fn_getElementsByClassName("f_colour_box");
	for (var i=0, j=colourBoxes.length; i<j; i++){
		colourBoxes[i].style.display="inline";
		fn_openColourBox(parseInt(colourBoxes[i].style.width), parseInt(colourBoxes[i].style.height), colourBoxes[i]);
	}	
	closedElm=false;
}

function fn_changeColour(t,st,cid, range_id, type_id, category_id, catalogue_id, product_range_id, product_id,classRequest=''){
	var url = String(document.URL);
	var findCust = url.search("/customise/");
	
	$(this).removeClass("f_colour_box").addClass("f_colour_box_selected");
	if (closedElm){
		colourBoxes = fn_getElementsByClassName("f_colour_box");
		for (var i=0, j=colourBoxes.length; i<j; i++){
			if (colourBoxes[i]!=t){
				console.log(classRequest);
				colourBoxes[i].style.display="inline";
				colourBoxes[i].classList.add("f_colour_box_selected");
				fn_openColourBox(0,0,colourBoxes[i]);
			}
		}	
		closedElm=false;	
	} else {
		
		fn_hideFullView(0);
		colourBoxes = fn_getElementsByClassName("f_colour_box");
		for (var i=0, j=colourBoxes.length; i<j; i++)
			if (colourBoxes[i]!=t)
				fn_closeColourBox(boxSize,boxSize,colourBoxes[i]);
		if(findCust > 0){
			fn_closeColourBox(boxSize,boxSize,classRequest,true);
		}
		closedElm=true;
		document.getElementById('f_colour_style').innerHTML="Cabinet Colour "+st;
		$(classRequest).css({ display: "inline" });
		makePOSTRequest("/inc/modules/furniture/set_carcase.php", "carcase_id="+cid+"&type_id="+type_id+"&category_id="+category_id+"&catalogue_id="+catalogue_id+"&product_range_id="+product_range_id+"&range_id="+range_id+"&product_id="+product_id);
		document.getElementById('carcase_id').value=cid;
	}
}

var cbubble =false;

function fn_openSubDrop(w){
	cbubble = true;
	var elm = w.replace("_sub", "");
	document.getElementById(w).style.width = (document.getElementById(elm).offsetWidth-2)+"px";
	document.getElementById(w).style.display='inline';
	setTimeout(function(){cbubble=false;}, 500);
}
function fn_closeSubDrop(w){
	setTimeout(function(){document.getElementById(w).style.display='none';}, 200);
}


function fn_updateHandles(w,v,txt,elm, catalogue, range, product_code){
	if(product_code.length > 0){
		txt+=" ("+product_code+")";	
	}
	document.getElementById(elm).innerHTML=txt;
	makePOSTRequest("/inc/modules/furniture/set_handle.php", "what="+w+"&handle_id="+v+"&range="+range+"&catalogue="+catalogue+"&pc="+product_code);
	document.getElementById(elm+"_sub").style.display="none";

}

function fn_closeColourBox(w,h,elm,idField=''){

	document.getElementById("f_choose").style.display="none";
	document.getElementById('f_colour_style').style.display="inline";
	if(idField){
		if (w>closeSpeed){
			w=w-closeSpeed;
			h=h-closeSpeed;
			document.getElementById(elm).style.height=h;
			document.getElementById(elm).style.width=w;
			fn_SetOpacity(elm, w, true);
			setTimeout(function(){fn_closeColourBox(w,h,elm,true)}, 1);
		} else {
			document.getElementById(elm).style.display="none";
			document.getElementById("f_change").style.display="inline";
			document.getElementById('f_main_box').style.display="inline";
			document.getElementById(elm).style.display="inline";
			document.getElementById(elm).style.opacity="1";
		}	
	}else{

		if (w>closeSpeed){
			w=w-closeSpeed;
			h=h-closeSpeed;
			elm.style.height=h;
			elm.style.width=w;
			fn_SetOpacity(elm, w);
			setTimeout(function(){fn_closeColourBox(w,h,elm)}, 1);
		} else {
			elm.style.display="none";
			document.getElementById("f_change").style.display="inline";
			document.getElementById('f_main_box').style.display="inline";
		}
	}
}

function fn_openColourBox(w,h,elm){
	document.getElementById("f_change").style.display="none";
	document.getElementById("f_choose").style.display="inline";
	document.getElementById('f_colour_style').style.display="none";
	document.getElementById('f_main_box').style.display="none";
	if (w<boxSize-closeSpeed){
		w=w+closeSpeed;
		h=h+closeSpeed;
		elm.style.height=h;
		elm.style.width=w;
		fn_SetOpacity(elm, w*closeSpeed);
		setTimeout(function(){fn_openColourBox(w,h,elm)}, 30);
	} else {
		elm.style.height=boxSize+"px";
		elm.style.width=boxSize+"px";
		fn_SetOpacity(elm, 100);
	}
}

function fn_getElementsByClassName(classname, node)  {
    if(!node)
		node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))
			a.push(els[i]);
    return a;
}

function fn_SetOpacity(elem, opacityAsInt, isID=''){
	var opacityAsDecimal = opacityAsInt;
    if (opacityAsInt > 100)
        opacityAsInt = opacityAsDecimal = 100; 
    else if (opacityAsInt < 0)
        opacityAsInt = opacityAsDecimal = 0; 
    opacityAsDecimal /= 100;
    if (opacityAsInt < 1)
        opacityAsInt = 1;
    
	if(isID){
		document.getElementById(elem).style.opacity = (opacityAsDecimal);
		document.getElementById(elem).style.filter  = "alpha(opacity=" + opacityAsInt + ")";
	}else{
		elem.style.opacity = (opacityAsDecimal);
		elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
	}
}

function fn_showFullView(t,img,txt){
	ot = parseInt(t.offsetTop);
	ol = parseInt(t.offsetLeft);
	fv = document.getElementById('f_full_view');
	fv.style.display="inline";
	fv.innerHTML="<div style='padding:4px;text-align:center;'><b>"+txt+"</b></div><img src='/_furniture/carcase/swatches/"+img+"' onload=\"fn_repositionFullView('"+ot+"','"+ol+"')\" style='overflow:hidden;width:130px;height:130px;'>";
	tw = parseInt(fv.offsetWidth);
	th = parseInt(fv.offsetHeight);
	fv.style.top=(ot+(38))+"px";
	cb=document.getElementById('f_colour_bar');
	cbml=(parseInt(cb.offsetWidth))-parseInt(fv.offsetWidth)-11;

	pl=ol-(boxSize/2)-(tw/2)+boxSize;
	if (pl>cbml){
		pl = cbml-1;
	}
	if (pl<12){
		pl=13;
	}
	fv.style.left=pl+"px";
}
function fn_repositionFullView(ot,ol){
	fv = document.getElementById('f_full_view');
	tw = parseInt(fv.offsetWidth);
	th = parseInt(fv.offsetHeight);

	cb=document.getElementById('f_colour_bar');
	cbml=(parseInt(cb.offsetWidth))-parseInt(fv.offsetWidth)-11;

	pl=ol-(boxSize/2)-(tw/2)+boxSize;
	if (pl>cbml)
	{
		pl = cbml-1;
	}
	if (pl<12)
	{
		pl=13;
	}
	fv.style.left=pl+"px";
}

function fn_hideFullView(t){
	fv = document.getElementById('f_full_view');
	fv.style.display="none";
	fv.innerHTML="&nbsp;";
}

var priceArray = new Array();
var qtyArray = new Array();
function fn_updateValues(id, price, qty){
	basePrice = 0.00;
	baseQty = 0;

	priceArray[id]=parseFloat(price);
	qtyArray[id]=parseFloat(qty);
	for (i=0;i<priceArray.length;i++){
		if (priceArray[i]){
			basePrice = basePrice + (priceArray[i]*qtyArray[i]);
			baseQty = baseQty + qtyArray[i];
		}
	}
	document.getElementById('priceBoxS').innerHTML=formatCurrency(basePrice);
	document.getElementById('qtyBox').innerHTML=baseQty;
}

function fn_updatePrice(){

	var inputs = document.getElementsByTagName("input");
	var url = String(document.URL);
	var findCust = url.search("/customise/");
	
	basePrice = 0.00;
	baseQty = 0;
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].id.match("~")){
			keys = inputs[i].id.split("\~");
			if (inputs[i].value>0){
				priceArray[keys[1]]=parseFloat(document.getElementById(keys[0]).value);
				qtyArray[keys[1]]=parseFloat(inputs[i].value);
			}
		}
	}
	for (i=0;i<priceArray.length;i++){
		if (priceArray[i]){
			basePrice = basePrice + (priceArray[i]*qtyArray[i]);
			baseQty = baseQty + qtyArray[i];
		}
	}
	
	if(findCust > 0){
				
	}else{
		document.getElementById('priceBoxS').innerHTML=formatCurrency(basePrice);
		document.getElementById('qtyBox').innerHTML=baseQty;	
	}
}

function fn_updateValues2(id, price, qty){
	basePrice = 0.00;
	baseQty = 0;

	priceArray[id]=parseFloat(price);
	qtyArray[id]=parseFloat(qty);
	for (i=0;i<priceArray.length;i++){
		if (priceArray[i]){
			basePrice = basePrice + (priceArray[i]*qtyArray[i]);
			baseQty = baseQty + qtyArray[i];
		}
	}
	document.getElementById('priceBoxS').innerHTML=formatCurrency(basePrice);
	document.getElementById('qtyBox').innerHTML=baseQty;
	document.getElementById('priceBoxS2').innerHTML=formatCurrency(basePrice);
	document.getElementById('qtyBox2').innerHTML=baseQty;
	document.getElementById('priceBoxS3').innerHTML=formatCurrency(basePrice);
	document.getElementById('qtyBox3').innerHTML=baseQty;
}
function fn_checkQty(){
	qty = document.getElementById('qtyBox').innerHTML;
	if (parseInt(qty)<1){
		openOverlay("/inc/modules/furniture/add_products_warning.php", 300, 50);
		return false;
	}
}

function fn_checkQty_cmz(){
	qty = document.getElementById('qty').value;
	if (parseInt(qty)<1){
		openOverlay("/inc/modules/furniture/add_products_warning2.php", 300, 50);
		return false;
	}
} 

function checkForm(){
	elms = document.getElementsByTagName('select');
	halt=false;
	for (i=0;i<elms.length;i++){
		if (elms[i].name.match("prod_opt")){
			elmVars = elms[i].value.split("-");
			if (parseInt(elmVars[0])<1){
				halt=true;
			}
		}
	}
	if (halt==true){
		openOverlay('/inc/modules/ecomms/alert.php?comment=Please complete all options, before clicking the buy button.',440,122);
		return false;
	} else {
		return true
	}
	
}

var dims = new Array();
function f_calculatePrice(dim, elm, deflt, type) {
	if(type==1){
		if (elm.value!=deflt){
			dims[dim] = 1;
		} else {
			dims[dim] = 0;
		}
		f_calcDims();
	}
	if(type==2){
		var w = parseFloat(document.getElementById('attrib_width').value);
		var h = parseFloat(document.getElementById('attrib_height').value);
		var b = parseFloat(document.getElementById('price_meter').value);
		var t = b * (w / 1000) * (h / 1000);
		document.getElementById('base_price').innerHTML = formatCurrency(t);
	}
} 

function f_calcDims(){
	var url = String(document.URL);
	var findCust = url.search("/customise/");
	var dim_rule="1";
	var add = "";
	var customised = 0;
	if (dims[0]==1){
		dim_rule=dim_rule+"1";
		customised = 1;
	} else {
		dim_rule=dim_rule+"0";
	}
	if (dims[1]==1){
		dim_rule=dim_rule+"1";
		customised = 1;
	} else {
		dim_rule=dim_rule+"0";
	}
	if (dims[2]==1){
		dim_rule=dim_rule+"1";
		customised = 1;

	} else {
		dim_rule=dim_rule+"0";
	}
	if(findCust > 0){
		document.getElementById('customised').value=customised;
		document.getElementById('priceBoxS').innerHTML = formatCurrency((parseFloat(dim_calc_rules[dim_rule])+surcharge_amt));		
	}else{
		document.getElementById('customised').value=customised;
		document.getElementById('base_price').innerHTML = formatCurrency((parseFloat(dim_calc_rules[dim_rule])+surcharge_amt));
	}
}
function checkBoxCk(tt) {
	vars=tt.split("_");
	if(vars[1]==1){
		document.getElementById('option_box').style.visibility="visible";
	} else {
		document.getElementById('option_box').style.visibility="hidden";
	}
}

function addToBasket(loc){
	sep = "&";
	str="rpc=true"+sep;
	
	var selects = document.getElementsByTagName("select");
	for (var i = 0; i < selects.length; i++) {
		str += selects[i].name+"="+selects[i].value+sep;
	}

	var inputs = document.getElementsByTagName("input");
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].name!="q"){
			if ((inputs[i].type=="radio" && inputs[i].checked==true) || (inputs[i].type=="checkbox" && inputs[i].checked==true) || inputs[i].type=="text" || inputs[i].type=="hidden"){
				str += inputs[i].name+"="+inputs[i].value+sep;
			}
		}
	}
	makePOSTRequest("/inc/modules/"+loc, str);
}


var tooltip=function(){
	var id = 'tt';
	var top = 2;
	var maxw = 300;
	var speed = 3;
	var timer = 15;
	var endalpha = 100;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w,obj,aleft,atop){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(c);
				tt.appendChild(t);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
			}
			c.innerHTML = v;
			tt.style.display = 'block';
			
			tt.style.width = w ? w + 'px' : 'auto';

			if (atop && aleft){
				document.onmousemove = "";
				tt.style.top=atop-tt.offsetHeight + top+34+"px";
				tt.style.left=aleft-(tt.offsetWidth/2)+"px";
				b.style.marginLeft = (tt.offsetWidth/2)-6 + 'px';
				t.style.marginLeft = (tt.offsetWidth/2)-5 + 'px';
				t.style.top = "-1px";
				b.style.top = "-8px";
			} else {
				if (typeof(obj)=="object"){
					tt.parentWindow = obj;
					document.onmousemove = this.fix;			
				} else {
					document.onmousemove = this.pos;
				}
			}
	

			if(!w && ie){
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);			


		},
		set:function(v){
			if(tt != null){
				c.innerHTML = v;
			}	
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tl = (l - (tt.offsetWidth/2)-2);
			if (tl<3){
				ol=tl;
				tl=3;
			} else {
				ol =0;
			}
			tt.style.left = tl + 'px';
			b.style.marginLeft = (tt.offsetWidth/2)-6+ (ol) + 'px';
			t.style.marginLeft = (tt.offsetWidth/2)-5+ (ol)  + 'px';
			t.style.top = "-1px";
			b.style.top = "-8px";
		},
		fix:function(e){
			var u = findPosU(tt.parentWindow)+8;
			var l = findPosL(tt.parentWindow)+(tt.parentWindow.offsetWidth/2);
			tt.style.top = (u - h) + 'px';
			tl = (l - (tt.offsetWidth/2)-2);
			if (tl<3){
				ol=tl;
				tl=3;
			} else {
				ol =0;
			}
			tt.style.left = tl + 'px';
			b.style.marginLeft = (tt.offsetWidth/2)-6+ (ol) + 'px';
			t.style.marginLeft = (tt.offsetWidth/2)-5+ (ol)  + 'px';
			t.style.top = "-1px";
			b.style.top = "-8px";
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();


function findPosU(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		do {
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return curtop;
	}
}
function findPosL(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
		} while (obj = obj.offsetParent);
		return curleft;
	}
}

function changeVat(check){
	if(check==true){
		document.location="vat-form/";	
	} else {
		document.location="/inc/modules/ecomms/vat.php?include=yes";	
	}
}

function checkBoxChange(catRefs){
	placeResults("Loading...");
	var urlStr = "";
	var urlBuild = new Array()
	
	urlBuild['type']="";
	urlBuild['colour']="";
	urlBuild['finish']="";
	urlBuild['door-style']="";
	urlBuild['price-group']="";
	urlBuild['range']="";
	urlBuild['catalogue']="";
	
	elms = document.getElementsByTagName("input");
	for(i=0;i<elms.length;i++){
		if(elms[i].name.match("FB_") && elms[i].checked){
			name = elms[i].name.replace("FB_", "");
			if(urlBuild[name]){
				urlBuild[name] = urlBuild[name]+"|"+elms[i].value;
			} else {
				urlBuild[name] = elms[i].value;	
			}
		}
	}
	
	url = "type="+urlBuild['type']+"&colour="+urlBuild['colour']+"&finish="+urlBuild['finish']+"&door-style="+urlBuild['door-style']+"&price-group="+urlBuild['price-group']+"&range="+urlBuild['range']+"&catalogue="+urlBuild['catalogue']+"&catalogues="+catRefs;
	makePOSTRequest("/inc/modules/furniture_browser/rpc/results.php", url);
}

function placeResults(str){
	document.getElementById('rangeResults').innerHTML = str;
}
function noResults(){
	document.getElementById('rangeResults').innerHTML = "Sorry no furniture ranges found";
}


var keyValue=0;
function checkScQty(t, rangeLocked, rangeLow, rangeHigh){
	value = t.value;
	if((parseInt(value) >-1 && !isNaN(value)) || value=='0'){
		if(rangeLocked && t.value > rangeHigh){
			t.value=rangeHigh;
		}
		if(rangeLocked && t.value < rangeLow){
			t.value=rangeLow;
		}			
	} else { 
		t.value=keyValue;
	}
	totalQtyPrice();
}

function totalQtyPrice(){
	var total = 0;
	var qty = 0;
	elms = document.getElementsByTagName("input");
	for(i=0;i<elms.length;i++){
		if(elms[i].name.match("qty_") && elms[i].value > 0){
			name = elms[i].name.replace("qty_", "");
			total=total + (parseInt(elms[i].value) * parseFloat(document.getElementsByName('price_'+name)[0].value));
			qty+=parseInt(elms[i].value);
		}
	}
	document.getElementById('scTotalBox').innerHTML=formatCurrency(total);
	document.getElementById('addToBasket').disabled=(qty>0?false:true);
}

function setQtyVal(elm, c, lowRange, highRange){
	var elm = document.getElementsByName(elm)[0];
	var b = parseInt(elm.value)
	if(isNaN(b)){
		b=0;
	}
	b=b+c;
	if(b>highRange){
		b = highRange;	
	}
	if(b<lowRange){
		b = lowRange;	
	}	
	elm.value=b;
	totalQtyPrice();
	return false;
}				
function addSCToBasket(){
	var urlStr='action=addToBasket';
	elms = document.getElementsByTagName("input");
	var qty = 0;
	for(i=0;i<elms.length;i++){
		if(elms[i].name.match("qty_") && elms[i].value > 0){
			name = elms[i].name.replace("qty_", "");
			urlStr = urlStr + "&"+name+"="+elms[i].value;
			qty+=parseInt(elms[i].value);
		}
	}
	urlStr+="&qty="+qty;
	document.getElementById('scformContent').value=urlStr;
	document.forms["scForm"].submit();	
}
