// (c) Edd Read Web Design - ERWD.co.uk - 2005


function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}



function preloadImages() { 
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=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 resetForm(frm) {
	document.location = frm.action;
}


function detectEnter(e,evalStr) {
	var characterCode;
	if (e && e.which) { 
		e = e;
		characterCode = e.which;
	} else {
		e = event;
		characterCode = e.keyCode;
	}
	if (characterCode == 13){ 
		eval(evalStr);
		return false;
	} else
		return true;
}

function topSearchSubmit() {
	if ($('search_top_txt').value=='' || $('search_top_txt').value=='Keyword or phrase') {
		//alert('Please enter a keyword to search against');
	} else {
		topSearchFocus(1);
		$('search_top_frm').submit();
	}
}

function toggle(linky, divId, menu, httproot)
{
    var lText = linky.innerHTML;							//Gets HTML from passed object
	var downimg = '<img src="'+httproot+'/images/down_'+menu+'.gif">';	//Stores the HTML for the img based on which menu
	var upimg = '<img src="'+httproot+'/images/up_'+menu+'.gif">';
	var d = $(divId);							//Gets the div ID
	if (d.style.display == 'none')							//If the div is hidden		
    {
        linky.innerHTML = upimg; d.style.display = 'block';	
    }
    else
    {
        linky.innerHTML = downimg; d.style.display = 'none';
    }
}



var submenu_array = new Array(); //Initialises an array to hold the submenu divs

function closemenus(menuname, menu, httproot,ignore)
{
	var check = -1;
	var downimg = '<img src="'+httproot+'/images/down_'+menu+'.gif">';
	var d= new Object;
	var g= new Object;
	
	for (i=0;i<submenu_array.length;i++) {
		check = submenu_array[i].search(menuname);
		if (check > -1 && submenu_array[i] != ignore)  {
			g = $(submenu_array[i]+'_link');
			d = $(submenu_array[i]);
			g.innerHTML = downimg;
			d.style.display = "none";
		}
	}
	
}

function togglemenu(menuname,linky,divId, menu, httproot)
{
    closemenus(menuname, menu, httproot,divId);
	var downimg = '<img src="'+httproot+'/images/down_'+menu+'.gif">';	//Stores the HTML for the img based on which menu
	var upimg = '<img src="'+httproot+'/images/up_'+menu+'.gif">';
	var g = $(linky);
	var d = $(divId);							//Gets the submenu div ID
	if (d.style.display == 'none')							//If the div is hidden		
    {
        g.innerHTML = upimg; d.style.display = 'block';	
    }
    else
    {
        g.innerHTML = downimg; d.style.display = 'none';
    }
}

function Counter(message,counter,text,maxLength) {
  var messageObj=$(message);
  var counterObj=$(counter);
  var length=maxLength - messageObj.value.length;
  if(length <= 0) {
    length=0;
    text='<span class="disable"> '+text+' </span>';
    messageObj.value=messageObj.value.substr(0,maxLength);
  }
  counterObj.innerHTML = text.replace("{CHAR}",length);
}

