//the purpose of this function is to allow the enter key to 
//point to the correct button to click.
 function doGoFilterClick(buttonName,e)
    {
        var key = (window.event ? e.keyCode : e.which);
        if (key == 13) {__doPostBack(buttonName,'');}
   }

function popup(mylink, windowname, width, height, scroll)
{
//alert(scroll);
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	href=mylink;
	else
	href=mylink.href;
	if (scroll==1)
    {
//alert(scroll);
	    window.open(href, windowname, 'scrollbars=yes,status=no,width='+width+',height='+height);
    }
	else
	{
	    window.open(href, windowname, 'scrollbars=no,status=no,width='+width+',height='+height);
    }
	return false;
} 
//link back to the product page
function linkToProduct(link){
	url = link.href;
	if (window.opener && !window.opener.closed) {
	    if(url != "http://www.craftsuperstore.co.uk/"){
		    window.opener.location=url;
		}
	}
	window.close();
}	

// Text Counter
function textCounter(fieldlength, countfield, maxlimit)
{
	if (fieldlength > maxlimit) // if too long...trim it!
	countfield.value='Too long'
	else 
	countfield.value = maxlimit - fieldlength;
}


// basket
function bUpdate()
{
	document.basket.action.value='update';
	document.basket.submit();
}
function bEmpty()
{
	document.basket.action.value='empty';
	document.basket.submit();
}
function bDelete( sID )
{
	eval( 'document.basket.qty_' + sID ).value='0';
	document.basket.action.value='update';
	document.basket.submit();
}
	
	

function changeSize(siz){
	//document.basket_submit.size.value=document.basket_submit.size_id.selectedIndex.value;
	document.basket_submit.size.value=document.basket_submit.size_id.options[document.basket_submit.size_id.selectedIndex].text
}



function changeColour(mylink){
	//window.location=url;
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;
	//window.open(href, 'windowname', 'scrollbars=no,status=no,width=35,height=35');
	window.location=mylink
	return false;
}


// product popup 
function product_popUp(mylink, windowname, width, height )
{
	
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;
	window.open(href, windowname, 'scrollbars=yes,status=no,width='+width+',height='+height);
	return false;
} 


// preload images
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_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_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];}
}
	
	function SetViewAllPage(sViewAll)
		{
			document.forms.searchform.viewall.value = sViewAll;
			document.forms.searchform.submit();			
		}
	
function toggleLayer(whichLayer){
		
		if (document.getElementById)
		{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
		}
		else if (document.all)
		{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
		}
		else if (document.layers)
		{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
		}
}


// show discounts
function showDiscounts(cid,whichLayer){
	
	if (cid==2){
		if (document.getElementById)
		{
			
			var style2 = document.getElementById(whichLayer).style;
			style2.display = "block";
			
		}
		else if (document.all)
		{
			var style2 = document.all[whichLayer].style;
			style2.display = "block";
			
		}
		else if (document.layers)
		{
				var style2 = document.layers[whichLayer].style;
				style2.display = "block";
			
		}
	
	}else{
	
		//var style2 = document.all[whichLayer].style;
		//style2.display = "";
		if (document.getElementById)
		{
			
			var style2 = document.getElementById(whichLayer).style;
			style2.display = "";
			
		}
		else if (document.all)
		{
			var style2 = document.all[whichLayer].style;
			style2.display = "";
			
		}
		else if (document.layers)
		{
				var style2 = document.layers[whichLayer].style;
				style2.display = "";
			
		}
	}


}





// Add bookmark for both browser engines...
function addBookmark(title,url) {
  if (window.sidebar) {
    window.sidebar.addPanel(title, url,"");
  } else if( document.all ) {
    window.external.AddFavorite( url, title);
  } else if( window.opera && window.print ) {
    return true;
  }
}

// setting cookies
function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate)
}

// getting cookies
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
	} 
  }
return null
}

function goBrand(){
	url=document.frmbrowse.brand_lc.options[document.frmbrowse.brand_lc.selectedIndex].value ;
	if (url!=0){
		window.location=url	
	}
}

function goBrand2(){
	url=document.frmbrowse.brand_lc2.options[document.frmbrowse.brand_lc2.selectedIndex].value ;
	if (url!=0){
		window.location=url	
	}
}

function goBrand3(){
	url=document.frmRightbrand.brand_lc.options[document.frmRightbrand.brand_lc.selectedIndex].value ;
	if (url!=0){
		window.location=url	
	}
}

function goRightSelector(){
		//alert(document.frmRightSelector.rightSelector.options[document.frmRightSelector.rightSelector.selectedIndex].value);
	url=document.frmRightSelector.rightSelector.options[document.frmRightSelector.rightSelector.selectedIndex].value ;
	if (url!=0){
		window.location=url	
	}
}

function displayChange(toggleid, buttonOnID, buttonOffClass, buttonOnClass) 
{
	var toggle 		= document.getElementById(toggleid);
	var buttonOn 	= document.getElementById(buttonOnID);
	
	if(toggle.style.display == 'none')
	{
		toggle.style.display = 'block';
		buttonOn.className = buttonOffClass;
	}
	else
	{
		toggle.style.display = 'none';
		buttonOn.className = buttonOnClass;
	}
}

function checkoutBasketOpen () 
	{
  	var basketClosed = document.getElementById("basketClosed");
	var basketArea = document.getElementById("basketArea");
	var showExpandBasket = document.getElementById("showExpandBasket");
	
	// if there is no id=basketArea on this page break from the function and return
	if (!basketArea)
		{
		return false;
		}
	
	// if there is an id=basketClosed on the page use these setting to hide the basket
	if (basketClosed != null)
		{
		basketArea.style.display = 'none';
		showExpandBasket.style.display = 'block';
		}
	
	// if there is not an id=basketClosed on the page use these settings to show the basket
	else
		{
		basketArea.style.display = 'block';
		showExpandBasket.style.display = 'none';
		}
	}	



/* function to change the background image of table td if a checkbox is checked - pete b */
function historyBasketBg ( check, bgChange, hidden, rowcount) 
	{
  	// assign value 'checked' or 'not checked' to variable ifChecked from checkbox onclick
	var ifChecked = document.getElementById(check);
	// get the id of the row to change
	// get array of all tds within the id of the row to change
	var bgChange = document.getElementById(bgChange);
	var tds = bgChange.getElementsByTagName("td");
	

   	
	for (var j=0; j<tds.length; j++) 
		{
    	if ( ifChecked.checked == true )
  			{
			// when checked use blue bg for table row

			tds[j].style.background="url(/common/img/basket/tdBgBlue.gif) no-repeat left bottom";
			}
		else
  			{
			// when unchecked use normal bg for table row

			tds[j].style.background="url(/common/img/basket/tdBg.gif) no-repeat left bottom";
  			}
		
		// always set any bg in the first td to -2px position left out of sight
		tds[0].style.backgroundPosition="-2px bottom";
		}
	}


/* function to reset all checkboxes to unchecked - pete b */
function historyBasketClearCheck()
	{
	var basket = document.getElementById("basket");
	var checkBoxes = basket.getElementsByTagName("input");
	var tds = basket.getElementsByTagName("td");
	
	for ( var i=0; i<checkBoxes.length; i++ ) 
		{
		if ( checkBoxes.checked == true )
			{
			checkBoxes[i].checked = true;
			}
		else
			{
			checkBoxes[i].checked = false;
			}
		}
		
	for ( var j=0; j<tds.length; j++ )
		{
		
		tds[j].style.background="url(/common/img/basket/tdBg.gif) no-repeat left bottom";
 		
		if (tds[j].className == "basketQty" )
			{
			tds[j].style.backgroundPosition="-2px bottom";
			}
			
		//tds[0].style.backgroundPosition="-2px bottom";
		
		}
	}

	
	

/* ***** faqs start ***** */

//declare the last var and set an initial state (to stop errors)
var last = '1';

/* function to get the link called a+which ie a1, a2 ... a10 (the answer that has just been anchored to) 
and change its class name from 'roundedBlue549px' to 'roundedBlue549px on' - to apply the ON state 'background-position:-55px or something' */

function activateTip(which)
	{
 		//remove any existing ON states by calling the toTheTop function below to set all anchors to have class name 'roundedBlue549px'
		//this is used incase another faq is selected from the menu without the 'back to top' link being clicked
 		toTheTop();
 		
		//apply the new ON style so the anchor now has the class names 'roundedBlue549px' AND 'on'
 		document.getElementById('a'+which).className='roundedBlue549px on';
 		
		//set 'last' variable to whatever a1, a2... a10 anchor was given the ON state so we can change it back using the toTheTop function
		last = which;
	}

/* function to set any anchor with an ON state back to its normal state by resetting the the class name */

function toTheTop()
	{
		//reset the background image
		document.getElementById('a'+last).className="roundedBlue549px";
	}

/* ***** faqs end ***** */
	


// hiding active content ie select boxes, from showing through a div placed above

//Here's another way to do it without an IFrame:

//In a script tag define these functions:
function hideSelect()
{if (document.all){document.all.formselect.style.visibility="hidden";}}

function unhideSelect()
{if (document.all){document.all.formselect.style.visibility="visible";}}

//Add the formselect ID to your select box (or the form itself if you have multiple select boxes, as I did):
//<form action="reportpost.cfm" method="post" id="formselect">

//Invoke your script with a mouseover/mouseout:

//<a href="whatever.html" onmouseover="hideSelect()" onmouseout="unhideSelect()">Show or Hide Select</a>

//Works in IE. Not sure about other browsers/platforms but it's pretty simple so give it a try.


function clearCheckBoxesInTable(tbl)
{
    var tbl = document.getElementById(tbl);
    var inputs = tbl.getElementsByTagName('input');
    for (var i=0;i<inputs.length;i++){if (inputs[i].type == 'checkbox'){inputs[i].checked = false;}}
}