
/* ***********************************************************
Example 4-5 (DHTMLapi.js)
"Dynamic HTML:The Definitive Reference"
by Danny Goodman
Published by O'Reilly & Associates  ISBN 1-56592-494-0
http://www.oreilly.com
Copyright 1998 Danny Goodman.  All Rights Reserved.
************************************************************ */
// DHTMLapi.js custom API for cross-platform
// object positioning by Danny Goodman (http://www.dannyg.com)

// Global variables
var isNav, isIE
var coll = ""
var styleObj = ""
if (parseInt(navigator.appVersion) >= 4) {
  if (navigator.appName == "Netscape") {
    isNav = true
  } else {
    isIE = true
    coll = "all."
    styleObj = ".style"
  }
}

// Convert object name string or object reference
// into a valid object reference
function getObject(obj) {
  var theObj
  if (typeof obj == "string") {
    theObj = eval("document." + coll + obj + styleObj)
  } else {
    theObj = obj
  }
  return theObj
}

// Positioning an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
  var theObj = getObject(obj)
  if (isNav) {
    theObj.moveTo(x,y)
  } else {
    theObj.pixelLeft = x
    theObj.pixelTop = y
  }
}

// Moving an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
  var theObj = getObject(obj)
  if (isNav) {
    theObj.moveBy(deltaX, deltaY)
  } else {
    theObj.pixelLeft += deltaX
    theObj.pixelTop += deltaY
  }
}

// Setting the z-order of an object
function setZIndex(obj, zOrder) {
  var theObj = getObject(obj)
  theObj.zIndex = zOrder
}

// Setting the background color of an object
function setBGColor(obj, color) {
  var theObj = getObject(obj)
  if (isNav) {
    theObj.bgColor = color
  } else {
    theObj.backgroundColor = color
  }
}

// Setting the visibility of an object to visible
function show(obj) {
  var theObj = getObject(obj)
  theObj.visibility = "visible"
}

// Setting the visibility of an object to hidden
function hide(obj) {
  var theObj = getObject(obj)
  theObj.visibility = "hidden"
}

// Retrieving the x coordinate of a positionable object
function getObjectLeft(obj)  {
  var theObj = getObject(obj)
  if (isNav) {
    return theObj.left
  } else {
    return theObj.pixelLeft
  }
}

// Retrieving the y coordinate of a positionable object
function getObjectTop(obj)  {
  var theObj = getObject(obj)
  if (isNav) {
    return theObj.top
  } else {
    return theObj.pixelTop
  }
}

// Utility function returns the available content width space in browser window
function getInsideWindowWidth(){
  var ih=1000;
  if(window.innerWidth)ih=window.innerWidth;
  if(ih==1000){
    if(document.documentElement.clientWidth){
      if(document.documentElement.clientWidth>0)ih=document.documentElement.clientWidth;
    }
  }
  if(ih==1000){
    if(document.body.clientWidth)ih=document.body.clientWidth;
  }
  return ih;
}



// Utility function returns the available content height space in browser window
function getInsideWindowHeight(){
  var ih=1000;
  if(window.innerHeight)ih=window.innerHeight;
  if(ih==1000){
    if(document.documentElement.clientHeight){
      if(document.documentElement.clientHeight>0)ih=document.documentElement.clientHeight;
    }
  }
  if(ih==1000){
    if(document.body.clientHeight)ih=document.body.clientHeight;
  }
  return ih;
}


// mta stuff
function spacer(x,y){
  document.write("<img src='images/5x5.gif' width=" + x + " height=" + y + ">");
}
function spacer2(x,y){
  document.write("<img src='../images/5x5.gif' width=" + x + " height=" + y + ">");
}






/* *********************************************************** */
// MTA new stuff



// procs fo allow pages wrongly called outside of frames to reposition themselves

function BreakOutOfFrames(){
  if (window != top) top.location.href = location.href;
}


// function to force very soft reloading of pages when browser resizes

function onResizeProc(){window.history.go(0);}







// function to get the width of an element by using its ID
// (e.g.   <div class=menu2 id=menuitem2> becomes getWidthOfID("menuitem2")

function getWidthOfID(ID){
  if(arguments.length!=1)alert("Wrong number of arguments to getWidthOfID()");
  var ns6=document.getElementById&&!document.all
  var ie=document.all

  if((!ie)&&(!ns6)){
    var AlertStr="Alert you appear to be running an outdated browser. ";
    AlertStr=AlertStr+"Please upgrade to a more recent browser. ";
    AlertStr=AlertStr+"Some things on this site will not work properly with your current browser.";
    alert(AlertStr);
  }

  if(ns6){
    return(document.getElementById(ID).offsetWidth);
  }

  if(ie){

return(document.getElementById(ID).offsetWidth);
    //return(eval("document.all." + ID + ".offsetWidth"));
    //return(eval("document.all." + ID + ".clientWidth"));
  }

  return(50);
}




// function to get the height of an element by using its ID
// (e.g.   <div class=menu2 id=menuitem2> becomes getHeightOfID("menuitem2")

function getHeightOfID(ID){
  if(arguments.length!=1)alert("Wrong number of arguments to getHeightOfID()");
  var ns6=document.getElementById&&!document.all
  var ie=document.all

  if((!ie)&&(!ns6)){
    var AlertStr="Alert you appear to be running an outdated browser. ";
    AlertStr=AlertStr+"Please upgrade to a more recent browser. ";
    AlertStr=AlertStr+"Some things on this site will not work properly with your current browser.";
    alert(AlertStr);
  }

  if(ns6){
    return(document.getElementById(ID).offsetHeight);
  }

  if(ie){
    return(eval("document.all." + ID + ".clientHeight"));
  }

  return(50);
}




// function to get the offsetLeft of an element by using its ID
// (e.g.   <div class=menu2 id=menuitem2> becomes getoffsetLeftOfID("menuitem2")

function getoffsetLeftOfID(ID){
  if(arguments.length!=1)alert("Wrong number of arguments to getoffsetLeftOfID()");
  var ns6=document.getElementById&&!document.all
  var ie=document.all

  if((!ie)&&(!ns6)){
    var AlertStr="Alert you appear to be running an outdated browser. ";
    AlertStr=AlertStr+"Please upgrade to a more recent browser. ";
    AlertStr=AlertStr+"Some things on this site will not work properly with your current browser.";
    alert(AlertStr);
  }

  if(ns6){
    return(document.getElementById(ID).offsetLeft);
  }

  if(ie){
    return(eval("document.all." + ID + ".offsetLeft"));
  }

  return(50);
}



// function to get the offsetTop of an element by using its ID
// (e.g.   <div class=menu2 id=menuitem2> becomes getoffsetTopOfID("menuitem2")

function getoffsetTopOfID(ID){
  if(arguments.length!=1)alert("Wrong number of arguments to getoffsetTopOfID()");
  var ns6=document.getElementById&&!document.all
  var ie=document.all

  if((!ie)&&(!ns6)){
    var AlertStr="Alert you appear to be running an outdated browser. ";
    AlertStr=AlertStr+"Please upgrade to a more recent browser. ";
    AlertStr=AlertStr+"Some things on this site will not work properly with your current browser.";
    alert(AlertStr);
  }

  if(ns6){
    return(document.getElementById(ID).offsetTop);
  }

  if(ie){
    return(eval("document.all." + ID + ".offsetTop"));
  }

  return(50);
}






function getInnerHTML(ID){
  if(arguments.length!=1)alert("getInnerHTML needs 1 argument");

  var ns6=document.getElementById&&!document.all
  var ie=document.all

  if(ie){
    return(eval("document.all." + ID + "innerHTML"));
    }
  else{
    if(ns6){
      return(document.getElementById(ID).innerHTML);
    }
  }
}






// function to turn visibility on and off for a given element
// syntax: setvisibility([element id] [visibility status (hidden|visible)]))

function setvisibility(element,status){
//alert("setvisibility: element " + element + ", status: " + status);
  if(arguments.length!=2)alert("two arguments needed: [element id] [visibility status (hidden|visible)]");
  var ns6=document.getElementById&&!document.all
  var ie=document.all
  var ele;

  if(ie){
    ele=(eval("document.all." + element));
    }
  else{
    if(ns6){
      ele=(document.getElementById(element));
    }
  }
  ele=ele.style;
  ele.visibility=status;
}


// function to set color for a given element
// syntax: setcolor ([element id] [color]

function setcolor(element,color){
//alert("setcolor: element " + element + ", color: " + color);
  if(arguments.length!=2)alert("two arguments needed: [element id] [color]");
  var ns6=document.getElementById&&!document.all
  var ie=document.all
  var ele;

  if(ie){
    ele=(eval("document.all." + element));
    }
  else{
    if(ns6){
      ele=(document.getElementById(element));
    }
  }
  ele=ele.style;
  ele.color=color;
}




// proc to set innerhtml of an element

function setInnerHTML(ID,str){
  var ns6=document.getElementById&&!document.all
  var ie=document.all
  var objfound;

  if((!ie)&&(!ns6)){
    var AlertStr="Alert you appear to be running an outdated browser. ";
    AlertStr=AlertStr+"Please upgrade to a more recent browser. ";
    AlertStr=AlertStr+"Some things on this site will not work properly with your current browser.";
    alert(AlertStr);
  }


  if(ns6){
    objfound=document.getElementById(ID);
  }

  if(ie){
    objfound=eval("document.all." + ID);
  }
  objfound.innerHTML=str;
}


var menuarr=new Array("eventsinner","facilitiesinner","aboutinner","howtoinner","supportinner");

function resetproc(){
  var i;
  var ele;
  for(i in menuarr){
    ele=document.getElementById(menuarr[i]);   
    ele.style.visibility="hidden";
  }
}

function setproc(){
  resetproc();
  var i;
  var ele=document.getElementById(arguments[0]);   
  ele.style.visibility="visible";
}



function setUcheldreSize(){

  var slogan_toppad=14;
  if(navigator.platform.indexOf("Win32")==0)slogan_toppad=22;
  document.getElementById("slogan").style.padding= slogan_toppad + "px 0px 8px 0px";


}


// functions to do vertical respacing


// this is a little odd: need to screw in actual values as Safari gets them wrong
//  => need to also record whether bottom row is supressed

var BottomRowShown=1;

function HideBottomRowIfNecessary(){
  // hide bottom row if windw less than 585 px deep
  // or if maindivinner deep enough to make adding pics at the bottom look silly.

  if(arguments.length>0)BottomRowShown=0

  if(document.getElementById("maindivinner")){
    if(getHeightOfID("maindivinner")>470)BottomRowShown=0;
  }

  if(getInsideWindowHeight()<516){
    BottomRowShown=0;
  }
  if(arguments.length>0){
    if(arguments[0]==1)BottomRowShown=0;
  }

// altered from hiding bittom row by setting innerHTML to makein it invisible
// as IE was giving error message as the
//  if(BottomRowShown==0)setInnerHTML("bottomrow","");
//  if(arguments.length>0)setInnerHTML("bottomrow","");    

  if(BottomRowShown==0){
    var bottrow=document.getElementById("bottomrow");
    var sty=bottrow.style;
    sty.position="absolute";
    sty.visibility="hidden";
    document.getElementById("outertable").rows[0].vAlign="top";

  }
}




function Adjust_vspace(){

  // safari gets the height of outertable very wrong, so screw in real value
  // passed from arguments (so different pages can be different)

  var outertable_height=540;

  if(arguments.length>0){outertable_height=arguments[0];}

  var maindivinner_h=0;

  if(document.getElementById("maindivinner")){
    maindivinner_h=getHeightOfID("maindivinner");
    if(maindivinner_h>278){
      outertable_height=outertable_height+maindivinner_h-278;
    }
  }


  if(BottomRowShown==0)outertable_height-=110;

  var vspace=getInsideWindowHeight()-outertable_height;

  vspace=Math.round(vspace*0.45);
  if(vspace<10)vspace=10;
  document.getElementById("outertable").style.margin= vspace + "px auto 0px auto";

// now deal with moving side images if the mai table is very deep
// (this only happens if we've already passed the boint where bottom images are suppressed
// so no need to worry about them)

  if(BottomRowShown==0){
    var sideimage_height=412;  // screw this in as IE & safari get it wrong
    if(maindivinner_h>0){
      var side_img_top=maindivinner_h-sideimage_height-10;

      if((getInsideWindowHeight()-20)<sideimage_height)side_img_top=0;

      document.getElementById("leftimages").style.paddingTop=side_img_top + "px";
      document.getElementById("rightimages").style.paddingTop=side_img_top + "px";

    }
  }

}


function maindivinner_scroll(){
  var maindiv_maxheight=getInsideWindowHeight()-210;

  if(getHeightOfID("maindivinner")>maindiv_maxheight){
    var mdsty=document.getElementById("maindivinner").style;
    var mdh=maindiv_maxheight;
    mdsty.height=mdh + "px";
    mdsty.overflow="auto";
  }
}



function setup_intext(){
}



var blatstr_root="";
blatstr_root+="uch";
blatstr_root+="eld";
blatstr_root+="re.o";
blatstr_root+="rg";

var blatstrs=new Array();
blatstrs["box"]="bo" + "x-of" + "fice@" + blatstr_root;
blatstrs["enquiries"]="enq" + "uir" + "ies@" + blatstr_root;

function blat(arg){
  document.write("<a href='mailto:" + blatstrs[arg] + "'>" + blatstrs[arg] + "</a>");
}


// generic blat for other email addresses
function blat2(){
  var i;
  var addr="";
  for(i=0;i<arguments.length;i++){
    addr+=arguments[i];
  }
  document.write("<a href='mailto:" + addr + "'>" + addr + "</a>");
}




// for mouseovers for side images
function imgshow(ID){
  document.getElementById(ID).style.visibility="visible";
}

function imghide(ID){                                           
  document.getElementById(ID).style.visibility="hidden";
}

var imgarr=new Array("i0","i1","i2","i3","i4","i5","i6","i7","i8","i9");

function resetimg(){
  var i;
  for(i=0;i<imgarr.length;i++){
    document.getElementById(imgarr[i]).style.visibility="hidden";
  }
}


function welshover(){
  setvisibility("EnglishWelshNotice","visible");
}

function welshout(){
  setvisibility("EnglishWelshNotice","hidden");
}


function Adjust_maindivw(){
  var maindiv_w=document.getElementById("maindiv").offsetWidth;
  var menutable_w=document.getElementById("menutable").offsetWidth;
  var maindivinner=document.getElementById("maindivinner");
  if(maindivinner.offsetWidth<maindiv_w)maindivinner.style.width=maindiv_w + "px";
  if(maindivinner.offsetWidth<menutable_w)maindivinner.style.width=menutable_w + "px";
}



var evmonths=new Array();
evmonths[1]="Jan";
evmonths[2]="Feb";
evmonths[3]="Mar";
evmonths[4]="Apr";
evmonths[5]="May";
evmonths[6]="Jun";
evmonths[7]="Jul";
evmonths[8]="Aug";
evmonths[9]="Sep";
evmonths[10]="Oct";
evmonths[11]="Nov";
evmonths[12]="Dec";


// function only to list forthcoming dates in events menu

function oldevitem(yr,mon,day,id){
  var timenow=new Date();
  var timeevent=new Date(yr+2000,mon-1,day,23,59,00);
  var showmon=mon+"";
  if(mon<10)showmon="0" + mon;

  var showday=day+"";
  if(day<10)showday="0" + day;

  if(timeevent>timenow){
    var tstr="<a href='#" + yr + showmon + showday + "'>" + evmonths[mon] + " " + day + "</a><br>";
    document.getElementById(id).innerHTML+=tstr + "<br>";
  }
}



function strip_leading_space(str){
  while(str.substr(0,1)=="0"){
    if(str.length==1)return(str);
    str=str.substr(1);
  }
  return(str);
}


function show_evitem(yr,mon,day,str){
  var timenow=new Date();
  var timeevent=new Date(yr,mon,day,23,59,00);

//alert(str);
 // if(timeevent>timenow){
    document.write(str);
 // }
}




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 expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function loadscript(filename,scriptid){
  var fileref=document.createElement('script');
  fileref.setAttribute("type","text/javascript");
  fileref.setAttribute("src",filename);
  fileref.setAttribute("id",scriptid);
  document.getElementsByTagName("head")[0].appendChild(fileref);
 if(arguments.length=3){
    fileref.onload=function(){editflagstatus(1);}
  }
}

function editflagstatus(val){
  var editflag=document.getElementById("editflag");
  if(editflag){
    var sty=editflag.style;
    if(val>0){
      sty.visibility="visible";
      sty.position="relative";
      }
    else{
      sty.visibility="hidden";
      sty.position="absolute";
    }
    // hide editflag if we are not in allevent.htm
    if(location.pathname.indexOf("allevent.htm")<0){
      sty.visibility="hidden";
      sty.position="absolute";
    }
  }
}




