// Script for image rollovers, make sure to preload images in <body> tag
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_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];}}}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.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];}}

// Left menu expand and collapse script
var ie4 = false;
if(document.all) { ie4 = true; }
function getObject(id) {
  if (ie4) {
    return document.all[id]; }
  else {
    return document.getElementById(id); } }
function toggle(link, divId) {
  var lText = link.innerHTML; var d = getObject(divId);
  if (lText == '+') {
    link.innerHTML = '±'; d.style.display = 'block'; }
  else {
    link.innerHTML = '+'; d.style.display = 'none'; } }

// Call function as setCookie("cookiename", cookievalue, lifetime, cookiepath) with the lifetime required in days, -1 to delete a cookie or zero for a temporary cookie. The Cookie Path is optional.
function setCookie(cookie_name, cookie_value, cookie_life, cookie_path) {
  var today = new Date()
  var expiry = new Date(today.getTime() + cookie_life * 24*60*60*1000)
  if (cookie_value != null && cookie_value != ""){
    var cookie_string =cookie_name + "=" + escape(cookie_value)
    if(cookie_life){ cookie_string += "; expires=" + expiry.toGMTString()}
    if(cookie_path){ cookie_string += "; path=" + cookie_path}
 	document.cookie = cookie_string } }

// Call function as getCookie("cookiename") It returns the value of a cookie if set or null. Beware of potential ambiguities in names of cookies - getCookie is simple and will match the end of a string so xyname will also be matched by yname and ame.
function getCookie(name) {
  var index = document.cookie.indexOf(name + "=")
  if (index == -1) { return null}
  index = document.cookie.indexOf("=", index) + 1
  var end_string = document.cookie.indexOf(";", index)
  if (end_string == -1) { end_string = document.cookie.length }
  return unescape(document.cookie.substring(index, end_string)) }

// Toggles the cookie value for the given submenu item, if cookie is unset, using this function will default to showing the menu
function menuToggle(name) {
  if (getCookie(name) == "show")
    setCookie(name, "hide", 0, "/")
  else
    setCookie(name, "show", 0, "/") }

if (self != top) {
    if (document.images)
        top.location.replace(window.location.href);
    else
        top.location.href = window.location.href;
}

// CAPTCHA Script
function new_captcha()
{
	// loads new captcha image
	if(document.getElementById)
	{
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("captcha").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("captcha").src = thesrc+"?"+Math.round(Math.random()*100000);
	} else {
		alert("Sorry, cannot autoreload CAPTCHA image\nSubmit the form and a new image will be loaded");
	}
}
