var sCodePath = '';
var previmg = 'images/arrowbwd-n.gif';
var nextimg = 'images/arrowfwd-n.gif';
var oPopup, oImage;
var MenuID = 0;
var oXMLHttp;

function refreshCaptchaImage(valImageId)
{
var oImage = document.images[valImageId];
var oNow = new Date();
	if (oImage != undefined) oImage.src = oImage.src.split('?')[0] + '?x=' + oNow.toUTCString();
}

function populateCategoryList(DeptID, oSelect, nStatus)
{
	if (!loadXMLDoc("getCategoryListXML.asp?d=" + DeptID + "&s=" + nStatus))
	{
		alert ("Failed to retrieve categories\n" + oXMLHttp.statusText);
		return false;
	}
	var oNodes = oXMLHttp.responseXML.getElementsByTagName("Category");
	oSelect.options.length=1;
	for (var nNode=0; nNode<oNodes.length; nNode++)
	{
		var oNode = oNodes[nNode];
		var CatID = oNode.getElementsByTagName("CatID")[0].firstChild.nodeValue;
		var CatName = oNode.getElementsByTagName("CatName")[0].firstChild.nodeValue;
		oSelect.options[nNode+1] = new Option (CatName, CatID);
	}	
}

function isCaptchaCodeValid()
{
var sCode = trim(document.getElementById("code").value);
	if (!loadXMLDoc("CheckCaptchaCode.asp?x=" + sCode))
	{
		alert ("Cannot check your verification code. Please telephone for assistance");
		return false;
	}
	var oNodes = oXMLHttp.responseXML.getElementsByTagName("Result");
	if (oNodes.length==0) return false;
	return (oNodes[0].firstChild.nodeValue=="OK");
}

function loadXMLDoc(url)
{
	oXMLHttp = getXMLHttpObject();
	if (oXMLHttp==null) return false;
	oXMLHttp.open ("GET", url, false);
	oXMLHttp.send ();
	return (oXMLHttp.status==200);
}

function getXMLHttpObject()
{
	if (window.XMLHttpRequest) return new XMLHttpRequest();
	if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
	return null;
}


function resizeContent()
{
var ClientHeight = window.innerHeight;
var NewHeight;
var oContent = document.getElementById("content");
var oMenu = document.getElementById("menu");
	ClientHeight = document.body.clientHeight;
	if (ClientHeight==0 || ClientHeight==undefined) ClientHeight = document.body.clientHeight+3;
	NewHeight = ClientHeight - 121;
	if (NewHeight<0) NewHeight = 0;
	if (oContent) oContent.style.height = NewHeight + "px";
	if (oMenu) oMenu.style.height = NewHeight + 20 + "px";
}

function doSearch ()
{
	window.location = "search.asp?Page=1&Text=" + escape(document.getElementById("searchText").value);
	document.getElementById("imgSideBar").src = "../../ruskin/images/sidebar-99.gif";
}

function findPosX (oElement)
{
var nLeft = 0;
	if (oElement.offsetParent)
	{
		while (1)
		{
			nLeft+= oElement.offsetLeft;
  			if (!oElement.offsetParent) break;
  			oElement = oElement.offsetParent;
		}
	}
	else if (oElement.x) nLeft+= oElement.x;
	if (!document.all) --nLeft;
	return nLeft;
}

function findPosY (oElement)
{
var nTop = 0;
	if (oElement.offsetParent)
	{
		while (1)
		{
			nTop+= oElement.offsetTop;
			if (!oElement.offsetParent) break;
			oElement = oElement.offsetParent;
  		}
	}
	else if (oElement.y) nTop+= obj.y;
	return nTop;
}

function trim(str, chars)
{
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars)
{
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars)
{
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function loadGoogleMap()
{
	if (GBrowserIsCompatible())
	{
	var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(52.0335, -1.8814), 13);
	var icon = new GIcon();
		icon.image = "http://www.legbarsofbroadway.co.uk/images/mm_20_red.png";
		icon.shadow = "http://www.legbarsofbroadway.co.uk/images/mm_20_shadow.png";
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
	var bounds = map.getBounds();
	var southWest = bounds.getSouthWest();
	var northEast = bounds.getNorthEast();
	var lngSpan = northEast.lng() - southWest.lng();
	var latSpan = northEast.lat() - southWest.lat();
	var point = new GLatLng(southWest.lat() + latSpan/2, southWest.lng() + lngSpan/2);
		map.addOverlay(new GMarker(point, icon));
	}
}

function subMenuMouseOver(oRow, MenuID)
{
	oRow.style.backgroundColor = "#f8f8f8";
	oRow.style.color = "#9393b3";
	oRow.style.fontWeight = "normal";
	oRow.style.cursor = "pointer"; 
}

function subMenuMouseOut(oRow, MenuID)
{
	oRow.style.backgroundColor = "#fefefe";
	oRow.style.color = "#838383";
	oRow.style.fontWeight = "normal";
	oRow.style.cursor = "default"; 
}

function mainMenuMouseOver(oRow, MenuID)
{return;
var oArrow;
	oRow.style.backgroundColor = "#f0f0f6";
	oRow.style.color = "#404040";
}

function mainMenuClick(MenuID)
{
}

function mainMenuMouseOut(oRow, MenuID)
{return;
	oRow.style.backgroundColor = "#ffffff";
	oRow.style.color = "#838383";
}

function navigateTo(MenuID, CatID, sFolder)
{
var sURL
	if (CatID==0)
	{
		if (sFolder!='') sURL = '/' + escape(sFolder); else sURL = '/?k=' + MenuID;
	}
	else
	{
		sURL = '/catalogue.asp?k=' + MenuID + "&c=" + CatID;
	}
	window.location = sURL;
}

function frameLoadHandler()
{
var oFrame = document.getElementById('vframe');

	oFrame.style.height = oFrame.contentWindow.document.body.scrollHeight + 'px';
	document.getElementById('content').scrollTop=0;
}

ddaccordion.init({
	headerclass: "mainmenu", //Shared CSS class name of headers group
	contentclass: "submenu", //Shared CSS class name of contents group
	revealtype: "mouseover", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content.
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["collapsedmenu", "expandedmenu"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	animatespeed: "normal", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})


