var IE6  = (navigator.appVersion.indexOf("MSIE 6.0") != -1) ? true : false;

// USED TO INITIALISE DROP DOWN MENUS
function startList() 
{
	if (IE6)
	{
		if (document.all&&document.getElementById) 
		{
			navRoot = document.getElementById("nav");
			for (i=0; i<navRoot.childNodes.length; i++) 
			{
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") 
				{
					node.onmouseover=function() 
					{
						this.className+=" over";
					}
					node.onmouseout=function() 
					{
						this.className=this.className.replace(" over", "");
					}
				}
			}
		}
	}
}
//window.onload=startList;

var sfHover = function(){
    var sfEls = document.getElementById("nav").getElementsByTagName("li");
    for (var i=0; i<sfEls.length; i++){
        sfEls[i].onmouseover=function(){this.className+=" sfhover";}
        sfEls[i].onmouseout=function(){this.className=this.className.replace(new RegExp(" sfhover\\b"), "");}
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function ShowHide()
{
    var panel = document.getElementById("eventsearch");
    if (panel.style.display == "none")
    {
        panel.style.display = "block";
        document.getElementById("eventToogleLink").innerHTML = "Hide advanced search";
    }
    else
    {
        panel.style.display = "none";
        document.getElementById("eventToogleLink").innerHTML = "Show advanced search";
    }
    return false;
}

function clickButton(e, buttonid){ 
      var evt = e ? e : window.event;
      var bt = document.getElementById(buttonid);
      if (bt){ 
          if (evt.keyCode == 13){ 
                bt.click(); 
                return false; 
          } 
      } 
}

function openWindow() {
  url='/EmailFriend.aspx?op=' + document.location.href;
  w=540;
  h=430;
  LeftPosition=20;
  TopPosition=20;
  win = window.open(url,'Access','menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,screenX='+LeftPosition+',screenY='+TopPosition+',left='+LeftPosition+',top='+TopPosition+',width='+w+',height='+h+'');
  if(win.focus){win.focus();}
}

function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '');
}
function validateEmail(valfield)   // true if required
{
  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;
  if (!email.test(tfld)) {
    alert('Please enter a valid e-mail address');
    valfield.focus();
    return false;
  }

  return true;
}

function openDisclaimer() {
  url='/TicketingDetails.aspx';
  w=480;
  h=180;
  LeftPosition=20;
  TopPosition=20;
  win = window.open(url,'USUOnline','menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=no,screenX='+LeftPosition+',screenY='+TopPosition+',left='+LeftPosition+',top='+TopPosition+',width='+w+',height='+h+'');
  if(win.focus){win.focus();}
}

// text resize functions -------------------------------------------------
var currentTextSize = null;
//var currentLineHeight = null;
// check for cookie
//if (get_text_cookie("usufontsize")) {
//    currentTextSize = parseFloat(get_text_cookie("usufontsize"));
//} else {
    currentTextSize = parseFloat("1");
//    createCookie("usufontsize",currentTextSize,1000);
//}
//currentLineHeight = currentTextSize + 5;

// creates a cookie with the given parameters
function createCookie(name,value,days){
        if (days){
                var date = new Date();
                date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
                var expires = "; expires=" + date.toGMTString();
        } else {
                var expires = "";
        }
        document.cookie = name + "=" + value + expires + "; path=/";
}

function textSize(dir) {
    if (dir == 'up') {
        if (parseFloat(currentTextSize) < parseFloat("1.5")) {
            currentTextSize = parseFloat(currentTextSize) + parseFloat("0.25");
        }
    } else if (dir == 'down') {
        if (parseFloat(currentTextSize) > parseFloat("1.0")) {
            currentTextSize = parseFloat(currentTextSize) - parseFloat("0.25");
        }
    }
    //currentLineHeight = currentTextSize + 5;
    document.getElementById('contentcontainer').style.fontSize = currentTextSize + 'em';
    //document.getElementById('content').style.lineHeight = currentLineHeight + 'em';
    // write/rewrite cookie
   // createCookie("usufontsize",currentTextSize,1000);
}

function get_text_cookie ( cookie_name )
{
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

  if ( results ) {
    return ( unescape ( results[1] ) );
  }
  else { return null; }
}