function enableLink(linkName){
  allLinks=document.links;
  for(i=0;i<allLinks.length;i++){
    if(allLinks[i].name==linkName){
      allLinks[i].onclick=null;
    }
  }
}
function disableLink(linkName){
  allLinks=document.links;
  for(i=0;i<allLinks.length;i++){
    if(allLinks[i].name==linkName){
      allLinks[i].onclick=function(){return false};
    }
  }
}

startList = function() {
if (document.all&&document.getElementById) {
	if(document.getElementById("nav")){
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
	FormOff();
this.className+=" over";
  }
  node.onmouseout=function() {
	FormOn();
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
 if (document.all&&document.getElementById) {
	 if(document.getElementById("new")){
newRoot = document.getElementById("new");
for (i=0; i<newRoot.childNodes.length; i++) {
node = newRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
	FormOff();
this.className+=" over";
  }
  node.onmouseout=function() {
	  FormOn();
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
 }
  if (document.all&&document.getElementById) {
	  if(document.getElementById("mymenu")){
mymenuRoot = document.getElementById("mymenu");
for (i=0; i<mymenuRoot.childNodes.length; i++) {
node = mymenuRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
	FormOff();
this.className+=" over";
  }
  node.onmouseout=function() {
	  FormOn();
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
  }
  if (document.all&&document.getElementById) {
	  if(document.getElementById("popular")){
popularRoot = document.getElementById("popular");
for (i=0; i<popularRoot.childNodes.length; i++) {
node = popularRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
	FormOff();
this.className+=" over";
  }
  node.onmouseout=function() {
	  FormOn();
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
  }
   if (document.all&&document.getElementById) {
	   if(document.getElementById("options")){
optionsRoot = document.getElementById("options");
for (i=0; i<optionsRoot.childNodes.length; i++) {
node = optionsRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
	FormOff();
this.className+=" over";
  }
  node.onmouseout=function() {
	  FormOn();
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
   }
 if (document.all&&document.getElementById) {
	 if(document.getElementById("viewed")){
viewedRoot = document.getElementById("viewed");
for (i=0; i<viewedRoot.childNodes.length; i++) {
node = viewedRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
	FormOff();
this.className+=" over";
  }
  node.onmouseout=function() {
	  FormOn();
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
 }
  if  (document.getElementById('supersize')){
		document.getElementById('supersize').style.visibility = 'visible';
	} 
}
window.onload=startList;


	function FormOff()
	{
		var selNodes = document.getElementsByTagName('select')
		var i=0;
		if (!selNodes.item(0))
			{
			return false;
			}
		else
			{
			do{selNodes.item(i).style.visibility = 'hidden';}
			while(++i < selNodes.length);
			}
	}

	function FormOn()
	{
		var selNodes = document.getElementsByTagName('select')
		var i=0;
		if (!selNodes.item(0))
			{
			return false;
			}
		else
			{
			do{selNodes.item(i).style.visibility = 'visible';}
			while(++i < selNodes.length);
			}

	}


  var tabFlag = 0;

  function changeDetailPageTab(imgIndex, tabCount) {
	  createCookie(location.href,imgIndex,1);
    for (var i=0; i<tabCount; i++) {

      document.getElementById('tab'+i).className="taboff";
      document.getElementById('div'+i).style.display = "none";
    }

    document.getElementById('tab'+imgIndex).className="tabon";
    document.getElementById('div'+imgIndex).style.display = "block";
    tabFlag = imgIndex;

  }

function tabenter(id) {
	if(	document.getElementById(id).className=="taboff"){
		document.getElementById(id).className="taboff2";}
}
function tableave(id) {
	if(	document.getElementById(id).className=="taboff2"){
		document.getElementById(id).className="taboff";}
}


var jumpURL;
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];}}
}
MM_preloadImages('template_images/nav/tm1_ov.gif','template_images/nav/tm2_ov.gif','template_images/nav/tm3_ov.gif','template_images/nav/tm4_ov.gif','template_images/nav/tm5_ov.gif','template_images/nav/tm6_ov.gif','template_images/nav/tm7_ov.gif','template_images/nav/tm8_ov.gif');
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 MM_reloadPage(init) {  //reloads the window if Nav4 resized
 if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
function MM_jumpMenu(targ,selObj,restore){ //v3.0
 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
 if (restore) selObj.selectedIndex=0;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
  return false;
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
 if (restore) selObj.selectedIndex=0;
}
function toggle(id,objName,on,off){
 el = document.getElementById(id);
 var display = el.style.display ? '' : 'none';
 el.style.display = display;
 if (display=='') { MM_setTextOfLayer(objName,'',on); }
 if (display=='none') { MM_setTextOfLayer(objName,'',off); }
}
function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}
function lMenv(obj){
 obj.style.overflow = 'visible';
}
function lMent(obj){
 obj.style.overflow = 'hidden';
}
function urlJump(){
 if(jumpURL){
  window.location = jumpURL;
 }
}
function lMover(obj,lBg,winLoc){
 obj.style.backgroundColor = lBg;
 jumpURL = winLoc;
}
function lMout(obj,lBg){
 obj.style.backgroundColor = lBg;
 jumpURL = '';
}
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}
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);
}
addEvent(window, "load", sortables_init);

var SORT_COLUMN_INDEX;

function sortables_init() {
    // Find all tables with class sortable and make them sortable
    if (!document.getElementsByTagName) return;
    tbls = document.getElementsByTagName("table");
    for (ti=0;ti<tbls.length;ti++) {
        thisTbl = tbls[ti];
        if (((' '+thisTbl.className+' ').indexOf("sortable") != -1) && (thisTbl.id)) {
            //initTable(thisTbl.id);
            ts_makeSortable(thisTbl);
        }
    }
}

function ts_makeSortable(table) {
    if (table.rows && table.rows.length > 0) {
        var firstRow = table.rows[0];
    }
    if (!firstRow) return;
    
    // We have a first row: assume it's the header, and make its contents clickable links
    for (var i=0;i<firstRow.cells.length;i++) {
        var cell = firstRow.cells[i];
        var txt = ts_getInnerText(cell);
        cell.innerHTML = '<a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">'+txt+'<span class="sortarrow"></span></a>';
    }
}

function ts_getInnerText(el) {
	if (typeof el == "string") return el;
	if (typeof el == "undefined") { return el };
	if (el.innerText) return el.innerText;	//Not needed but it is faster
	var str = "";
	
	var cs = el.childNodes;
	var l = cs.length;
	for (var i = 0; i < l; i++) {
		switch (cs[i].nodeType) {
			case 1: //ELEMENT_NODE
				str += ts_getInnerText(cs[i]);
				break;
			case 3:	//TEXT_NODE
				str += cs[i].nodeValue;
				break;
		}
	}
	return str;
}

function ts_resortTable(lnk) {
    // get the span
    var span;
    for (var ci=0;ci<lnk.childNodes.length;ci++) {
        if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci];
    }
    var spantext = ts_getInnerText(span);
    var td = lnk.parentNode;
    var column = td.cellIndex;
    var table = getParent(td,'TABLE');
    
    // Work out a type for the column
    if (table.rows.length <= 1) return;
    var itm = ts_getInnerText(table.rows[1].cells[column]);
    sortfn = ts_sort_caseinsensitive;
    if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date;
    if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date;
    if (itm.match(/^[£$]/)) sortfn = ts_sort_currency;
    if (itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric;
    SORT_COLUMN_INDEX = column;
    var firstRow = new Array();
    var newRows = new Array();
    for (i=0;i<table.rows[0].length;i++) { firstRow[i] = table.rows[0][i]; }
    for (j=1;j<table.rows.length;j++) { newRows[j-1] = table.rows[j]; }

    newRows.sort(sortfn);

    if (span.getAttribute("sortdir") == 'down') {
        ARROW = '';
        newRows.reverse();
        span.setAttribute('sortdir','up');
    } else {
        ARROW = '';
        span.setAttribute('sortdir','down');
    }
    
    // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
    // don't do sortbottom rows
    for (i=0;i<newRows.length;i++) { if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortbottom') == -1))) table.tBodies[0].appendChild(newRows[i]);}
    // do sortbottom rows only
    for (i=0;i<newRows.length;i++) { if (newRows[i].className && (newRows[i].className.indexOf('sortbottom') != -1)) table.tBodies[0].appendChild(newRows[i]);}
    
    // Delete any other arrows there may be showing
    var allspans = document.getElementsByTagName("span");
    for (var ci=0;ci<allspans.length;ci++) {
        if (allspans[ci].className == 'sortarrow') {
            if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us?
                allspans[ci].innerHTML = '';
            }
        }
    }
        
    span.innerHTML = ARROW;
}

function getParent(el, pTagName) {
	if (el == null) return null;
	else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())	// Gecko bug, supposed to be uppercase
		return el;
	else
		return getParent(el.parentNode, pTagName);
}
function ts_sort_date(a,b) {
    // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
    if (aa.length == 10) {
        dt1 = aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2);
    } else {
        yr = aa.substr(6,2);
        if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
        dt1 = yr+aa.substr(3,2)+aa.substr(0,2);
    }
    if (bb.length == 10) {
        dt2 = bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2);
    } else {
        yr = bb.substr(6,2);
        if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
        dt2 = yr+bb.substr(3,2)+bb.substr(0,2);
    }
    if (dt1==dt2) return 0;
    if (dt1<dt2) return -1;
    return 1;
}

function ts_sort_currency(a,b) { 
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
    return parseFloat(aa) - parseFloat(bb);
}

function ts_sort_numeric(a,b) { 
    aa = parseFloat(ts_getInnerText(a.cells[SORT_COLUMN_INDEX]));
    if (isNaN(aa)) aa = 0;
    bb = parseFloat(ts_getInnerText(b.cells[SORT_COLUMN_INDEX])); 
    if (isNaN(bb)) bb = 0;
    return aa-bb;
}

function ts_sort_caseinsensitive(a,b) {
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).toLowerCase();
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).toLowerCase();
    if (aa==bb) return 0;
    if (aa<bb) return -1;
    return 1;
}

function ts_sort_default(a,b) {
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
    if (aa==bb) return 0;
    if (aa<bb) return -1;
    return 1;
}


function addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}
var gAutoPrint = true; 
function printSpecial()
{
	if (document.getElementById != null)
	{
		var html = '<HTML>\n<HEAD>\n';

		if (document.getElementsByTagName != null)
		{
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}
		
		html += '\n</HE' + 'AD>\n<BODY>\n';
		
		var printReadyElem = document.getElementById("printReady");
		
		if (printReadyElem != null)
		{
				html += printReadyElem.innerHTML;
		}
		else
		{
			alert("Could not find the printReady section in the HTML");
			return;
		}
			
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';
		
		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint)
			printWin.print();
	}
	else
	{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
}



  // Browser Detection
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
	if (IEmac && IE4)  // IE 4.5 blows out on testing window.onload
	{
		window.onload = SafeOnload;
		gSafeOnload[gSafeOnload.length] = f;
	}
	else if  (window.onload)
	{
		if (window.onload != SafeOnload)
		{
			gSafeOnload[0] = window.onload;
			window.onload = SafeOnload;
		}		
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
		window.onload = f;
}
function SafeOnload()
{
	for (var i=0;i<gSafeOnload.length;i++)
		gSafeOnload[i]();
}

function getSuggestions(keyword, usePaging, pageIndex, pageSize, callbackMethod)
        {
           
		   new Ajax.Request('auto_complete_product_name2.php?qu='+keyword,   
		   {     
		   		method:'get',     onSuccess: function(transport)
				{       
					var response = transport.responseText || "no response text";       ajaxresult=response;
					 var jsonData=ajaxresult;        
				
           callbackMethod(jsonData);     
				}, onFailure: function()
				{ 
					alert('Something went wrong...') 
				}   
			}); 

		  
        }
function ajax_it(ajaxdiv,pagetoload)
{
	new Ajax.Updater(ajaxdiv, pagetoload, {asynchronous:true});
}

function add_email_alert2(postpage,formname)
{
	var params = Form.serialize($(formname));
	new Ajax.Updater('stock_email_alert_div', postpage,{asynchronous:true, parameters: params});
}