
// main javascript functions for Parkhouse award (after elysian)



/* ***********************************************************
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(){
  if (isNav) {
    return window.innerWidth
  } else {
    return document.body.clientWidth
  }
}
// // Utility function returns the available content height space in browser window
// function getInsideWindowHeight() {
//   if (isNav) {
//     return window.innerHeight
//   } else {
//     return document.body.clientHeight
//   }
// }


// Utility function returns the available content height space in browser window
function getInsideWindowHeight() {
  if (isNav) {
    return window.innerHeight
  } else {
    var retval=0;
    if(document.body.clientHeight){
      if(document.body.clientHeight>retval)retval=document.body.clientHeight;
    }
    if(document.documentElement.clientHeight){
      if(document.documentElement.clientHeight>retval)retval=document.documentElement.clientHeight;
    }
    return retval;
  }
}





// ****************************
// * mta stuff //



// 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(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);
    }
  }
}



// use blat for masking email address
var str1="parkh";
var str2="ouse@g";
var str1b="musi";
var str2b="c@g";
var str3="bz";
var str4=".de";
var str5="mon";
var str6=".co.";
var str7="uk";

function blat(){
  var i;
  document.write("<a href='mailto:");
  for(i=0;i<arguments.length;i++){
    document.write(arguments[i]);
  }
  document.write("'>");

  for(i=0;i<arguments.length;i++){
    document.write(arguments[i]);
  }
  document.write("</a>");
}

// blat2 covers anything
function blat2(){
  var i;
  for(i=0;i<arguments.length;i++){
    document.write(arguments[i]);
  }
}








// 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;
}



// cookie stuff


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 deleteCookie(name){

  var date = new Date();
  date.setTime(date.getTime()-(1*24*60*60*1000));
  var expires = "; expires="+date.toGMTString();

  document.cookie = name+"=empty"+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 onResizeProc(){history.go(0);}




// stuff for changeable strings

changestrs=[
"Return to home page",
"Information on the pianist David Parkhouse, in whose memory this award was established",
"Details of the award, which is given every two years",
"Information on Dimension, winners of the 2005 Parkhouse Award",
"Winners of the competition since it was founded in 1991",
"How to contact the Parkhouse award, and enter in 2007"
]


function showstr(){
  if(arguments.length==0){
    SetInnerHTML("variable","&nbsp;");
    setvisibility("variable", "hidden");
    }
  else{
    SetInnerHTML("variable",changestrs[arguments[0]]);
    setvisibility("variable", "visible");
  }

  return false;
}




// *** Menu stuff ******************************************************************
//
// set menu font size (set here so it can be dynamically set in javascript on each page)

var menufontsize = 11;

// function to set the style for the menutable.
// This tales three arguments:

// logoandsloganheight -- height of the logo and slogan underneath
// menuheight          -- height of the actual menu
// hspace              -- horizontal space of logo
//
// in case IE misbehaves, hspace should be determined just before exection, by:
//   var hspace=getWidthOfID("logo")-getWidthOfID("menu");
//
// defaults are
//
// logoandsloganheight 150 (80 on index.htm)
// menuheight          214


var deflogoandsloganheight=150;
var defmenuheight=214;


function define_menutable(logoandsloganheight,menuheight,hspace){
  var screenheight=screen.availHeight-20;

  // get window height -- being oicky so menu doesn't move as you
  // go from screen to screen in IE
  var ih=900;
  var dbc=900;
  var ddec=900;
  if(window.innerHeight)ih=window.innerHeight;
  if(document.body.clientHeight)dbc=document.body.clientHeight;
  if(document.documentElement.clientHeight)ddec=document.documentElement.clientHeight;

  innerheight=ih;
  if(dbc<innerheight)innerheight=dbc;
  if(ddec<innerheight)innerheight=ddec;


  if(innerheight>screenheight)innerheight=screenheight;
  var usedheight=logoandsloganheight+menuheight;
  var available=innerheight-usedheight;
  var padtop=Math.round(available*0.4);

  // for no obvious reason there is a border appearing, so this forces it to 0 width and background colour, so it can't be seen

  var sstr=".menutable{ border: 0px solid; margin-left: auto; margin-right: auto; border-color: green;"
  sstr+="font-size: 12px;"
  sstr+="padding-top: " + padtop + "px;";

  if(hspace>0){
    var hmar=Math.round(hspace/2);
    sstr+="margin-left: " + hmar + "px;"
  }
  sstr+="}";
  document.write("<style>" +  sstr + "</style>");
}




// function to define mainwidth, imitating max-width ************
// this requires width_of_1em to have been defined before the function is called.
// use the following:

// document.write("<div id=test style='width: 1em; height: 0px;'></div>");
// var width_of_1em=getWidthOfID("test");
// if(width_of_1em<1)width_of_1em=16;
//


// there are two arguments: <width_of_1em><total width of all pther elements n page>

function define_mainwidth(width_of_1em,totalwidth){

  // width of window is minimum of 860 (set by two transparent gifs), so
  var windowwidth=getInsideWindowWidth();
  if(windowwidth<860)windowwidth=860;

  var availablewidth=windowwidth-totalwidth-70;  // 70 for margins

  var maxwid=32; // in ems ( should be 26: this is to allow for IE seeminq to show things at a small fontsize
  var rawwidth=width_of_1em*maxwid;


  width=rawwidth;
  if(width>availablewidth)width=availablewidth;
  if(width<200)width=200;

  var stylestr="";
  stylestr+=".mainwidth{width: " + width + "px; margin-left: auto; margin-right: auto;}";
  document.write("<style>" + stylestr + "</style>");
}



var lastsmallwin=null;

function openarticle(surl){
  var url= "art/" + surl + ".htm";
  var wwidth=width_of_1em*40; // allow width of 30 em
  wwidth+=40; // allow for 2 lots of padding

  if(wwidth>(screen.availWidth*0.7))wwidth=Math.round(screen.availWidth*0.7); // stop it getting too large

  var xpos=screen.availWidth-wwidth-10;

  var flist="directories=no,location=no,menubar=no,scrollbars=yes";
  flist +=",width=" + wwidth;
  flist +=",top=0, screenY=0"
  flist +=",left=" + xpos ;
  flist +=",screenX=" + xpos +"";
  if(lastsmallwin!=null)lastsmallwin.close();
  lastsmallwin=open(url,"article",flist);
}




// function to print up a notice if an article appears out of context

function checkarticlefile(){
  if(self.name.indexOf("article")!=0){
    var wstr="";
    wstr+="<div class=articleopenmaincontainer>";
    wstr+="<div class=articleopenmain>";
    wstr+="This article forms part of the web site of the Parkhouse Award, which is an ";
    wstr+="international competition for ensembles of piano and strings.";
    wstr+="<p>";
    wstr+="To visit the main web site for the award, <a href='javascript:openhome();'>";
    wstr+="click here</a>";
    wstr+="</p>";
    wstr+="</div>";
    wstr+="</div>";
    document.write(wstr);
  }
}


// function to print up a notice if an winner info appears out of context

function checkwinnerfile(){
  if(self.name.indexOf("winners")!=0){
    var wstr="";
    wstr+="<p>&nbsp;<div class=articleopenmaincontainer>";
    wstr+="<div class=articleopenmain>";
    wstr+="This article forms part of the web site of the Parkhouse Award, which is an ";
    wstr+="international competition for ensembles of piano and strings";
    wstr+="<p>";
    wstr+="For more information on the Parkhouse Award, and to find out about other winners <a href='javascript:openhome();'>";
    wstr+="click here</a>";
    wstr+="</p>";
    wstr+="</div>";
    wstr+="</div>";
    document.write(wstr);
  }
}

// function to open home page
function openhome(){
  var flist="directories=yes,location=yes,menubar=yes,scrollbars=yes";
  flist +=",width=" + Math.round(screen.availWidth*0.7);
  flist +=",top=0, screenY=0 left=0 screenX=0";
  open("../index.htm","parkhouse",flist);
}



function openwinner(surl){
  var url= "winners/" + surl + ".htm";
  var wwidth=width_of_1em*40; // allow width of 30 em
  wwidth+=40; // allow for 2 lots of padding

  if(wwidth>(screen.availWidth*0.7))wwidth=Math.round(screen.availWidth*0.7); // stop it getting too large

  var xpos=screen.availWidth-wwidth-10;

  var flist="directories=no,location=no,menubar=no,scrollbars=yes";
  flist +=",width=" + wwidth;
  flist +=",top=0, screenY=0"
  flist +=",left=" + xpos ;
  flist +=",screenX=" + xpos +"";
  if(lastsmallwin!=null){lastsmallwin.close();}
  lastsmallwin=open(url,"winners",flist);
}



function closer(){
  if((self.name.indexOf("article")!=0)||(self.name.indexOf("winners")!=0)){
    document.write("<div class=closer><i>to close <a href='javascript:self.close();'>click here</a></i></div>");
  }
}


