/////////////////////////////////////////////
//
//	Basic Javascript
//	----------------
//
//	Core functionality, work arounds
//	and key javscript functions.
//
//
//	M.Evans 2006
/////////////////////////////////////////////

/////////////////////////////////////////////////////////
// Toggle Sub UL Class
// On request, toggle the class value of the next highest <ul> node in the DOM
/////////////////////////////////////////////////////////
function toggleSubMenu(_id, _class1, _class2)
{
    var obj = document.getElementById(_id);
    obj = (obj.getElementsByTagName('ul'))[0];
    if (obj.className == _class2)
    {
        obj.className = _class1;
    } else {
        obj.className = _class2;
    }
}

/////////////////////////////////////////////////////////
// Toggle Class by ID
// On request, toggle the class value of a DOM object (ID)
/////////////////////////////////////////////////////////
function toggleClass(_id, _class1, _class2)
{
    var obj = document.getElementById(_id);
    if (obj.className == _class1 || !obj.className || obj.className == "")
    {
        obj.className = _class2;
    } else {
        obj.className = _class1;
    }
}

/////////////////////////////////////////////////////////
// Submit my form
// Searches up the DOM and submits the containing form
// of any element calling this function
/////////////////////////////////////////////////////////
function submitMyForm(btn) {
	finished = false;
	while (!finished) {
		btn = btn.parentNode;
		if (btn == undefined) {
			break;
		} 
		if (btn.submit!=undefined) {
			btn.submit();
			finished = true;
			break;
		}
	}
}

/////////////////////////////////////////////////////////
// Find the form object wrapping an object in the DOM
/////////////////////////////////////////////////////////
function findForm(obj) {
	finished = false;
	while (!finished) {
		obj = obj.parentNode;
		if (obj == undefined) {
			break;
		} 
		if (obj.submit!=undefined) {
			return obj
			finished = true;
			break;
		}
	}
}

function replicateField(aname,avalue) {
	//search all forms for input name of 'aname' and set value 'avalue'
	//useful for pages that might have two input fields for the same info (fold out tell a friend boxes etc.)
	for (var i=0; i<document.forms.length; i++) {
		var obj = eval("document.forms[i]."+aname);
		if (obj) {
			obj.value = avalue;
		}
	}
}

/////////////////////////////////////////////////////////
// tableruler()
// written by Chris Heilmann for alistapart.
// enables a rollover of rows for each table with className "ruler"
// Used on step 1 of the LT reservation process
/////////////////////////////////////////////////////////
function tableruler()
{
	if (document.getElementById && document.createTextNode)
	{
		var tables=document.getElementsByTagName('table');
		for (var i=0;i<tables.length;i++)
		{
			if(tables[i].className=='ruler')
			{
				var trs=tables[i].getElementsByTagName('tr');
				for(var j=0;j<trs.length;j++)
				{
					if(trs[j].parentNode.nodeName=='TBODY')
					{
						trs[j].onmouseover=function(){this.className='ruled';return false}
						trs[j].onmouseout=function(){this.className='';return false}
					}
				}
			}
		}
	}
}


/////////////////////////////////////////////////////////
// Slideshow
//
// Location: Coursetown > slidehows.asp
//////////////////////////////////////////////////////////
var galPix	= new Array()
var thisPic = 0
var imgCt	= 0

function initialiseSlides(count, prefix, start) {
	for (var i=1; i<=count; i++) {
		galPix[i-1] = prefix + i + '.jpg'
	}
	thisPic = (start - 1);
	imgCt	= count;
	document.galPictures.src = galPix[start-1];
	if (document.getElementById("counter"))
	{
	    document.getElementById("counter").innerHTML = (thisPic+1) + " of " + imgCt;
	}
	flip_layer('slidetex', start, count);
}

function chgSlide(direction) {
	if (document.images) {
		thisPic = thisPic + direction
		if (thisPic > imgCt-1) {
			thisPic = 0
		}
		if (thisPic < 0) {
			thisPic = imgCt-1
		}
		if (document.getElementById("counter"))
		{
		    document.getElementById("counter").innerHTML = (thisPic+1) + " of " + imgCt;
		}
		document.galPictures.src=galPix[thisPic]
		flip_layer('slidetex', thisPic+1, imgCt);
	}
}
	
	
function flip_layer(name, id, max)
{
	var viewlayer, layer;
    
	if (document.all) {
		viewlayer	= eval('document.all.'+name+id+'.style');
		activeMenu	= eval('document.all.'+name+id)
		for(i=1;i<max+1;i++) {
			layer = eval('document.all.'+name+i+'.style');
			layer.display = 'none';
		}
		viewlayer.display = 'block';
	} else if (document.getElementById) { 
		viewlayer = document.getElementById(name+id);
		for(i=1;i<max+1;i++) {
			layer = document.getElementById(name+i);
			layer.style.display = 'none';
		}
		viewlayer.style.display = 'block';

	} else if (document.layers) {
		viewlayer = eval('document.layers["'+name+id+'"]');
		for(i=1;i<max+1;i++) {
			layer = eval('document.layers["'+name+i+'"]');
			layer.display = 'none';
		}
		viewlayer.display = 'block';
	}
}


function centerPopup( url, default_left, default_top, width, height, scrollbars, winName) {
	var posX, posY;

	posX = default_left;
	posY = default_top;

	if( parseFloat(navigator.appVersion) >= 4.0 ) {
		posX = parseInt(screen.availWidth / 2.0) - (width / 2.0);
		posY = parseInt(screen.availHeight / 2.0) - (height / 2.0);
	}

	if (scrollbars) {
		var win = window.open( url, (winName==null ? "popupWin" : winName), "width=" + width + ",height=" + height + ",resizable=yes,scrollbars=yes,location=no,status=yes,left=" + posX + ",top=" + posY );
	} else {
		var win = window.open( url, (winName==null ? "popupWin" : winName), "width=" + width + ",height=" + height + ",resizable=yes,scrollbars=no,left=" + posX + ",top=" + posY );
	}

	if( parseFloat(navigator.appVersion) >= 4.0 ) {
		win.moveTo( posX, posY );
		if( navigator.appName.indexOf("Netscape") != -1 )
			win.focus( );
	}
}

// SwitchBox function, to insert content of one tag into another, very useful for switching content.
function switchBox(srcBox,tarBox) {
	if (srcBox!='') document.getElementById(tarBox).innerHTML = document.getElementById(srcBox).innerHTML;
}