// JavaScript Document



if (typeof(widget) == "undefined") widget = {};





/*
AC Class ----------------------------------------------------------------
*/


/**
 * Constructor for the AC Class
 *
 * @param   fld      HTML Input element type="text"
 * @param   params   Object containing parameters
 */
widget.AC = function (fld, params)
{
	// save parameters
	this.params = params;
	
	// default parameters
	// saltRequest means add a timestamp to the AJAX request to stop browsers caching the result
	var defs = {saltRequest: true, minChars: 2};
	
	for (var a in defs)
	{
		if (typeof(this.params[a]) == "undefined") this.params[a] = defs[a];
	}
	
	
	
	
	
	// init some attributes
	this.sVal = null;                            // String            - value in field
	this.idDelayTimer = null;                    // Integer           - setTimeout id
	this.idClearTimer = null;                    // Integer           - setTimeout id
	this.aReqs = new Array();                    // Array             - contains previous ACRequests
	this.divList = null;                         // XHTML DIV Node    - container for list
	this.aResults = new Array();                 // Array             - contains item LIs from result list
	this.iHigh = 0;                              // Integer           - index of highlighted list item (0 = no highlight, 1 = first list item)
	
	
	// get text inputfield
	var f = this.fld = widget.DOM.gE( fld );
	
	// set up field
	f.className = "txtSearchSite";
	f.setAttribute('autocomplete', 'off');
	
	// preload waiting graphic
	var imgWaiting = new Image();
	imgWaiting.src = "/assets/images/wait-sm.gif";
	
	
	
	var p = this;
	
	
	
	// set up document event listeners
	
	widget.addEvent( window, "resize", function () { p.positionList(); } );
	
	
	// capture document keypresses
	this.docOnKeyDown = function (ev) { return p.handleKeyDown(ev); };
	widget.addEvent( document, "keydown", this.docOnKeyDown );

	
	// clear list when fld loses focus
	this.docOnClick = function (ev) { p.clearList(); return false; };
	
	
	
	
	
	
	
	// set up field key listeners
	f.onkeypress = function (ev) { return p.handleFieldKeyPress(ev); };
	f.onkeyup = function (ev) { return p.handleFieldKeyUp(ev); };
};






/**
 * Public method to force the AC Widget to carry out a query
 *
 * @param   query   String containing the complete URI & query
 */
widget.AC.prototype.doQuery = function (query)
{
	var q = query.substring(query.indexOf('=')+1, query.indexOf('&'));
	
	// set field value to query value
	this.fld.value = q;
	
	// dim list, if there
	if (this.divList)
		this.divList.className += " dim";
	
	// do ajax request
	this.doAjaxRequest( q, query );
}






/* Input handlers */

widget.AC.prototype.handleKeyDown = function (ev)
{
	// set responses to keydown events in the field
	// this allows the user to use the arrow keys to scroll through the results
	// ESCAPE clears the list
	// TAB sets the current highlighted value
	//
	
	
	
	if (!this.divList)
		return true;
	
	
	var RETURN = 13;
	var TAB = 9;
	var ESC = 27;
	var ARRUP = 38;
	var ARRDN = 40;
	// Safari has weird arrow key codes
	var ARRUP_SAF = 63232;
	var ARRDN_SAF = 63233;
	
	
	var k = widget.getKey(ev) - 0;
	
	
	if (k == ARRUP_SAF)  k = ARRUP;
	if (k == ARRDN_SAF)  k = ARRDN;
	
	var ret = true;
	
	
	
	switch(k)
	{
		case ARRUP:
			ret = this.handleUpDown(ev, -1);
			break;
		
		case ARRDN:
			ret = this.handleUpDown(ev, 1);
			break;
			
		case RETURN:
			ret = this.handleEnter(ev);
			break;

		case ESC:
			this.clearList();
			ret = false;
			break;
	}
	
	
	
	return ret;
};



widget.AC.prototype.handleFieldKeyPress = function (ev)
{
	var RETURN = 13;
	var ARRUP = 38;
	var ARRDN = 40;
	// Safari has weird arrow key codes
	var ARRUP_SAF = 63232;
	var ARRDN_SAF = 63233;
	
	var k = widget.getKey(ev) - 0;
	
	if (k == ARRUP_SAF)  k = ARRUP;
	if (k == ARRDN_SAF)  k = ARRDN;
	
	
	var ret = true;
	
	
	if (k == RETURN && this.divList)
	{
		ret = this.handleEnter(ev);
	}
	else if (this.divList && k == ARRDN || k == ARRUP)
	{
		widget.stopEvent(ev);
		ret = false;
	}
	else if (k == ARRDN && !this.divList)
	{
		this.showSuggestions(0);
	}
	
	return ret;
};



widget.AC.prototype.handleFieldKeyUp = function (ev)
{
	var BACKSPACE = 8;
	var SPACE = 32;
	var k = widget.getKey(ev);
	
	
	if (k > 40 && k < 224 || k == SPACE || k == BACKSPACE || k == 0)
	{
		this.showSuggestions(this.gP('inputDelay'));
	}
	
	return true;
};



widget.AC.prototype.handleUpDown = function (ev, dir)
{
	// UP = -1, DOWN = 1
	if (this.divList)
	{
		widget.stopEvent(ev);
		return this.changeHighlight(dir);
	}
	else if (dir == 1)
	{
		// no list shown, down button pressed
		// show results list with a delay of 0 (immediately!)
		this.showSuggestions(0);
	}
	
	return true;
}



widget.AC.prototype.handleEnter = function (ev)
{
	// if a list item is hightlighted, we get the href of the first link in the highlighted item
	if (this.divList)
	{
		if (this.iHigh)
		{
			
			this.openLink(this.aResults[this.iHigh-1]);
			
			widget.stopEvent(ev);
			
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		// let the event through
		return true;
	}
};






/* Request methods */

widget.AC.prototype.showSuggestions = function (delay)
{
	// clear the time out
	clearTimeout(this.idDelayTimer);
	
	// clear the list
	this.clearList();
	
	this.sVal = this.fld.value;
	
	if ( this.sVal.length < this.gP('minChars') )
		return true;// not enought input to trigger suggestions
	
	this.startRequestTimer(delay);
	
	return true;
};



widget.AC.prototype.startRequestTimer = function (delay)
{
	var p = this;
	var val = this.sVal;
	var query = this.gP('getURI')(this.sVal);
	
	// set timeout to call the request after param-defined delay
	// if the user changes the value in the field, the timer will be reset, and this request will never be sent
	if (delay)
		this.idDelayTimer = setTimeout( function() { p.doAjaxRequest(val, query) }, delay );
	else
		p.doAjaxRequest(val, query);
};



widget.AC.prototype.doAjaxRequest = function (val, query)
{
	// check if query is in local cache
	// if not, result is an empty string
	var result = this.getResultFromCache(query);
	
	if (result)
	{
		this.showList(result);
	}
	else
	{
		// do an ajax request with this query
		
		var p = this;
		
		var req = new widget.ACRequest( val, query, function (r) { p.cbWait(r) }, function (r) { p.cbData(r) }, function (r) { p.cbError(r) }, this.gP("saltRequest") );
		this.aReqs.push( req );
		
		req.doRequest();
	}
};



widget.AC.prototype.getResultFromCache = function (query)
{
	var result = "";
	
	for (var i=this.aReqs.length;--i>=0;)
	{
		if (this.aReqs[i].query == query)
		{
			result = this.aReqs[i].result;
			i=-1;
		}
	}
	
	return result;
};






/* AJAX callback methods */

widget.AC.prototype.cbWait = function (acreq)
{
	this.showWaitingGraphic();
};



widget.AC.prototype.cbData = function (acreq)
{
	this.showSearchGraphic();
	
	// if value in field is the same as the value in the request, show the list
	if (this.fld.value == acreq.value)
	{
		this.showList(acreq.result);
	}
};



widget.AC.prototype.cbError = function (acreq)
{
	this.showSearchGraphic();
};






/* Graphic Status methods */

widget.AC.prototype.showWaitingGraphic = function ()
{
	// show waiting graphic
	var  f = this.fld,  cn = f.className,  n = cn.indexOf(" waiting");
	if (n == -1) { f.className += " waiting"; }
};



widget.AC.prototype.showSearchGraphic = function ()
{
	// show search graphic
	var  f = this.fld,  cn = f.className,  n = cn.indexOf(" waiting");
	if (n > -1) { f.className = cn.substr(0, n); }
};






/* List methods */

widget.AC.prototype.showList = function (result)
{
	var p = this, dl;
	
	
	
	if (!this.divList)
	{
		// create list, hiding it to prevent a flash of unstyled content
		dl = this.divList = widget.DOM.cE('div', {id:'ACList'}, result, true);
		dl.style['top'] = "-1000px";
		
		// add to DOM
		document.getElementsByTagName('body')[0].appendChild( dl );
		
		// event handlers
		dl.onmouseover = function() { p.handleListMouseOver(); };
		dl.onmouseout = function() { p.handleListMouseOut(); };
		dl.onclick = function (ev) { return p.handleListClick(ev); };
		
		widget.addEvent( document, "click", this.docOnClick );
	}
	else
	{
		dl = this.divList;
		
		dl.innerHTML = result;
		
	}
	
	
	// stop next and prev links with an onclick handler from propagating in I.E.
	var ul = dl.getElementsByTagName( "ul" )[0];
	var as = ul.getElementsByTagName("a");
	for (var i=0;i<as.length;i++)
	{
		if (as[i].onclick != undefined)
		{
			widget.addEvent( as[i], "click", function (ev) { widget.stopEvent(ev); } );
		}
	}
	
	
	// set class name
	dl.className = "ac_mode_" + this.gP("alignMode");
	
	
	// berea street's rounded corners
	widget.cornerElement(dl.getElementsByTagName('ul')[0]);
	
	this.positionList();
	
	
	// filter all item LIs out of the list and save in an array
	var all = this.divList.getElementsByTagName('li');
	var ind = 0;
	this.aResults = new Array();
	
	for (var i=0; i<all.length; i++)
	{
		if (all[i].className == "item")
		{
			this.aResults.push( all[i] );
			ind++;
			all[i].setAttribute('id', 'item'+ind);
			all[i].onmouseover = function () { p.setHighlight(this.id.substr(4)); };
			all[i].onclick = function () { p.openLink(this); return false; };
		}
	}
	
	
	// no item is highlighted
	this.iHigh = 0;
	
	// highlight first item
	if (this.aResults.length && this.gP('highlightFirst') !== false)
		this.setHighlight(1);
	
	
	this.fld.onblur = function () { p.clearList(); };
};



widget.AC.prototype.clearList = function ()
{
	var p = this;

	if (this.divList)
	{
		widget.DOM.remE(this.divList);
		this.divList = null;
		this.iHigh = 0;
		
		this.fld.onblur = null;
		
		widget.removeEvent( document, "click", this.docOnClick );
	}
};



widget.AC.prototype.positionList = function ()
{
	// get position
	var dl = this.divList;
	if (dl)
	{
		var pos = widget.DOM.getPos( this.fld );
		var dlw = dl.offsetWidth;
		var fldw = this.fld.offsetWidth;
		var l;
		switch (this.gP('alignMode'))
		{
			case "l":
				l = pos.x - 5;
				break;
	
			case "c":
				l = Math.round( pos.x + (fldw/2) - (dlw/2) ) - 3;
				break;
	
			default:
				l = pos.x - dlw + fldw + 10;
		}
		dl.style['left'] = l + "px";
		dl.style['top'] = (pos.y + this.fld.offsetHeight) + "px";
	}
};



widget.AC.prototype.handleListMouseOver = function ()
{
	// kill fld onblur handler to prevent list being hidden when link in list is clicked
	this.fld.onblur = null;
};



widget.AC.prototype.handleListMouseOut = function ()
{
	var p = this;
	
	// kill highlighted LI
	this.setHighlight(0);
	
	// reset fld onblur handler
	this.fld.onblur = function () { p.clearList(); };
};



widget.AC.prototype.handleListClick = function (ev)
{
	// stop event propogation, because document onclick handler removes list
	// but return true so that links in the list work
	
	widget.stopEvent(ev);
	return true;
};



widget.AC.prototype.openLink = function (item)
{
	var p = this;
	var cb = this.gP("callback");
	var dolink = true;
	
	if (typeof(cb) == "function")
	{
		dolink = cb(item);
	}
	
	if (dolink)
		document.location = item.getElementsByTagName('a')[0].href;
	
	// remove the list after a delay
	// if we remove it now, other elements listening to the event (e.g. the input field onKeyPress), will think that there is no list there and may submit the form when enter was pressed
	this.idClearTimer = setTimeout( function () { p.clearList() }, 50 );
};






/* Highlighting methods */

widget.AC.prototype.changeHighlight = function (dir)
{
	// if no list visible
	// return true to allow the arrow key event
	if (!this.divList)
		return true;
	
	
	if (this.iHigh == 1 && dir == -1)
	{
		// first item is highlighted und up key is pressed - move up and out of list
		this.clearList();
	}
	else
	{
		this.setHighlight(  Math.max( 1, Math.min( this.aResults.length, this.iHigh+dir ) )  );
	}
	
	
	return false;
};



widget.AC.prototype.setHighlight = function (newh)
{
	
	if (newh != this.iHigh)
	{
		if (this.iHigh)
			this.aResults[this.iHigh-1].className = "item";
		
		this.iHigh = newh-0;
		
		if (this.iHigh)
			this.aResults[this.iHigh-1].className = "item highlight";
	}
};




/* Parameter methods */

/**
 * Get parameter
 *
 * @param   p   String containing name of parameter to get
 * @return      Mixed - value of parameter
 */
widget.AC.prototype.gP = function (p)
{
	return (typeof(this.params[p]) != "undefined") ? this.params[p] : "";
};






/*
ACRequest Class ----------------------------------------------------------------
*/

/**
 * A XMLHTTPRequest wrapper Class for the AutoComplete Widget.
 *
 * @param   val       String - value in the field at time of request
 * @param   query     String - the complete query
 * @param   onwait    Function - on wait callback. Takes instance of ACRequest as argument.
 * @param   ondata    Function - on data callback. Takes instance of ACRequest as argument.
 * @param   onerror   Function - on error callback. Takes instance of ACRequest as argument.
 */
widget.ACRequest = function (val, query, onwait, ondata, onerror, salt)
{
	this.value = val;
	this.query = query;
	this.cb_wait = onwait;
	this.cb_data = ondata;
	this.cb_error = onerror;
	this.salt = salt ? true : false;
	
	this.req = this.getAJAX();
	this.result = "";
};



widget.ACRequest.prototype.doRequest = function ()
{
	var nocacheuri = this.query + "&ts=" + new Date().getTime();
	var r = this.req;
	var doneWait = false;
	var p = this;
	
	r.open( "GET", nocacheuri, true );
	
	r.onreadystatechange = function ()
	{
		/*
		0 = uninitialized
		1 = loading
		2 = loaded
		3 = interactive
		4 = complete
		*/
		
		
		if (r.readyState < 4)
		{
			if (!doneWait)
			{
				p.onWait( r );
				doneWait = true;
			}
		}
		else
		{
			switch (r.status)
			{
				case 200: // "OK"
					p.onData( r );
					break;
				
				case 304: // "Not modified" - should happen because we are avoiding the browser cache
				
					break;
				
				default:
					p.onError( r );
			}
		}
	};
	
	r.send( null );
};



widget.ACRequest.prototype.getAJAX = function ()
{
	var oXHR;
	
	// Returns a new Ajax object (cross-browser) if available, false if not.
	try
	{  
		oXHR = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (e)
	{
		try
		{
			oXHR = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (e2)
		{
			try
			{
				oXHR = new XMLHttpRequest();
			}
			catch (e3)
			{
				oXHR = false;
			}
		}
	}
	
	return oXHR;
};



widget.ACRequest.prototype.onWait = function (oXHR)
{
	this.cb_wait( this );
};



widget.ACRequest.prototype.onData = function (oXHR)
{
	this.result = this.req.responseText;
	this.cb_data( this );
};



widget.ACRequest.prototype.onError = function (oXHR)
{
	this.cb_error( this );
};






/*
DOM Helpers ----------------------------------------------------------------
*/


if (typeof(widget.DOM) == "undefined")
	widget.DOM = {};



/* create element */
widget.DOM.cE = function ( type, attr, cont, html )
{
	var ne = document.createElement( type );
	if (!ne)
		return 0;
		
	for (var a in attr)
		ne[a] = attr[a];
	
	var t = typeof(cont);
	
	if (t == "string" && !html)
		ne.appendChild( document.createTextNode(cont) );
	else if (t == "string" && html)
		ne.innerHTML = cont;
	else if (t == "object")
		ne.appendChild( cont );

	return ne;
};



/* get element */
widget.DOM.gE = function ( e )
{
	var t=typeof(e);
	if (t == "undefined")
		return 0;
	else if (t == "string")
	{
		var re = document.getElementById( e );
		if (!re)
			return 0;
		else if (typeof(re.appendChild) != "undefined" )
			return re;
		else
			return 0;
	}
	else if (typeof(e.appendChild) != "undefined")
		return e;
	else
		return 0;
};



/* remove element */
widget.DOM.remE = function ( ele )
{
	var e = this.gE(ele);
	
	if (!e)
		return 0;
	else if (e.parentNode.removeChild(e))
		return true;
	else
		return 0;
};



/* get position */
widget.DOM.getPos = function ( e )
{
	var e = this.gE(e);

	var obj = e;

	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	
	var obj = e;
	
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;

	return {x:curleft, y:curtop};
};







/*
Other Helpers ----------------------------------------------------------------
*/
widget.getKey = function (ev)
{
	return (window.event) ? window.event.keyCode : ev.keyCode;
};



widget.addEvent = function ( o, type, fn )
{
	if (o.addEventListener)
		o.addEventListener( type, fn, false );
	else if (o.attachEvent)
	{
		o["e"+type+fn] = fn;
		o[type+fn] = function() { o["e"+type+fn]( window.event ); }
		o.attachEvent( "on"+type, o[type+fn] );
	}
};



widget.removeEvent = function ( o, type, fn )
{
	if (o.removeEventListener)
		o.removeEventListener( type, fn, false );
	else if (o.detachEvent)
	{
		o.detachEvent( "on"+type, o[type+fn] );
		o[type+fn] = null;
		o["e"+type+fn] = null;
	}
};



widget.stopEvent = function (ev)
{
	// stop event propagation
	if (!ev) ev = window.event;
	ev.cancelBubble = true;
	if (ev.stopPropagation) ev.stopPropagation();
};





// reworked berea street corners script. Smaller, isn't it?
widget.cornerElement = function (oElement)
{
	var oElement, oOuter, tempId;
	var cE = widget.DOM.cE;

	oOuter = cE("div", {className: oElement.className.replace( new RegExp("(^|\\s)cbb(\\s|$)"), '$1cb$2' )});

	// Give the new div the original element's id if it has one
	if (oElement.getAttribute("id"))
	{
		tempId = oElement.id;
		oElement.removeAttribute('id');
		oOuter.setAttribute('id', tempId);
	}
	
	// Change the original element's class name and replace it with the new div
	oElement.className = 'i3';
	oElement.parentNode.replaceChild(oOuter, oElement);

	// Create two new div elements and insert them into the new div
	oOuter.appendChild( cE( "div", {className:"i1"}, cE("div", {className:"i2"}, oElement) ) );

	// Insert the top and bottom divs
	oOuter.insertBefore( cE("div", {className:"bt"}, cE("div")), oOuter.firstChild );
	oOuter.appendChild( cE("div", {className:"bb"}, cE("div")) );
};

function getAJAX() {
    var oXHR;
    // create the Ajax object (IE6/IE7/FF)
    try {
        oXHR = new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch (e)
    {
        try {
            oXHR = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch (e2)
        {
            try {
                oXHR = new XMLHttpRequest();
            }
            catch (e3) {
                oXHR = false;
            }
        }
    }
    return oXHR;
}

function appendHTML(elt, html) {
    var e = document.createElement("div");
    e.innerHTML = html;
    var c = e.firstChild;
    while(c) {
        elt.appendChild( c.cloneNode(true) );
        c = c.nextSibling;
    }
}
function deleteChildNode(parentNode,childNodeID) {
    if(oNode = document.getElementById(childNodeID)) {
        parentNode.removeChild(document.getElementById(childNodeID));
        return true;
    } else {
        return false;
    }
}

function getResource(uri, alt_uri, wait_callback, data_callback, error_callback, timeout) {
    var doneWait = false;
    var tryAgain = function () {
      getResource(uri, wait_callback, data_callback, error_callback, timeout);
    }
    var r = getAJAX();
    var timer = setTimeout(
        function() {
            r.abort();
            r.onreadystatechange = null;
            setTimeout(tryAgain, timeout);
        },
        timeout);
    r.open("GET", uri, true);
    r.onreadystatechange = function() {
        if (r.readyState != 4) {
            // Ignore non-loaded readyStates
            // ...will timeout if do not get to "Loaded"
            if(!doneWait) {
                wait_callback();
                doneWait = true;
            }
            return;
        }
        clearTimeout(timer);  // readyState==4, no more timer
        if (r.status==200) {  // "OK status"
              data_callback(r.responseText, r.responseXML);
        }
        else if (r.status==304) {
            // "Not Modified": No change to display
        }
        else if (r.status >= 400 && r.status < 500) {
            // Client error, probably bad URI
            error_callback(r,uri,alt_uri)
        }
        else if (r.status >= 500 && r.status < 600) {
            // Server error, try again after delay
            setTimeout(tryAgain, timeout);
        }
        else {
            error_callback(r,uri,alt_uri);
        }
    }
    r.send(null);
    return r;
}


// Search hints helper functions
function doReq(query) {
    // if query doesn't not include searchURI, add it
    if (query.indexOf(ac_searchURI) < 0)  query = ac_searchURI + query;
    ac_widget.doQuery(query);
}
var ac_getURI = function (value) {
    var gE = widget.DOM.gE;
    return ac_searchURI + '?q=' + encodeURI(value) + '&l=' + gE('fSearch_l').value + '&i=' + gE('fSearch_i').value + '&m=' + ac_alignMode;
};

// Community Link builder functions
var ac_lbGetURI = function (value) {
    var gE = widget.DOM.gE;
    return ac_searchURI + '?q=' + encodeURI(value) + '&l=' + gE('fSearch_l').value + '&i=' + gE('fSearch_i').value + '&m=' + ac_alignMode + '&hc=1';
};
var ac_lbUpdate = function(li) {
    var gE = widget.DOM.gE;
    var sLocURI = (li.getElementsByTagName('a')[0].href);
    var sLocName = removeTags(li.getElementsByTagName('a')[0].innerHTML);

    oInpBox = gE('fBuilder_loc');
    oInpBox.value = sLocName;

    oSelLocAnc = gE('lb_selAnchor');
    oSelLocAnc.href = sLocURI;
    oSelLocAnc.innerHTML = sLocName;

    oPrevLocAnc = gE('lb_preAnchor');
    oPrevLocAnc.href = sLocURI;
    oPrevLocAnc.title = 'Visit ' + sLocName + ' on yourlocalweb.co.uk';
	
	oPrevLocAnc2 = gE('lb_preAnchor2');
    oPrevLocAnc2.href = sLocURI;
    oPrevLocAnc2.innerHTML = sLocName;
    oPrevLocAnc2.title = oPrevLocAnc.title;
    
    oPrevLocAnc3 = gE('lb_preAnchor3');
    oPrevLocAnc3.href = sLocURI;
    oPrevLocAnc3.title = oPrevLocAnc.title;
    oPrevLocAnc3.innerHTML = 'Visit ' + sLocName + '<br />on yourlocalweb.co.uk';
    
    oPrevLocAnc3 = gE('lb_preAnchor4');
    oPrevLocAnc3.href = sLocURI;
    oPrevLocAnc3.title = oPrevLocAnc.title;
    
    gE('lb_codeURI').innerHTML = sLocURI;
    gE('lb_codeAncTip').innerHTML = oPrevLocAnc.title;
    
    gE('lb_codeURI2').innerHTML = sLocURI;
    gE('lb_codeAncTip2').innerHTML = oPrevLocAnc.title;
    
    gE('lb_codeURI3').innerHTML = sLocURI;
    gE('lb_codeAncTip3').innerHTML = oPrevLocAnc.title;
    
    gE('lb_codeURI4').innerHTML = sLocURI;
    gE('lb_codeAncTip4').innerHTML = oPrevLocAnc.title;
    
    gE('lb_codeAncTip5').innerHTML = oPrevLocAnc.title;
    
    gE('lb_codeAncText').innerHTML = sLocName;

    return false;
};

function lb_toggleCodeBlock (block_id) {
	
	switch(block_id) {
		case 'code_classic':
			$('code_classic').style.display = 'block';
			$('code_text').style.display = 'none';
			$('code_logo').style.display = 'none';
			break;
		case 'code_logo':
			$('code_classic').style.display = 'none';
			$('code_text').style.display = 'none';
			$('code_logo').style.display = 'block';
			break;
		case 'code_text':
			$('code_classic').style.display = 'none';
			$('code_text').style.display = 'block';
			$('code_logo').style.display = 'none';
			break;
	}
	
	return false;
	
};
