// main javascript functions for AAM web site







/* ***********************************************************

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) {

alert("obj: " + obj + document.getElementById(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

  }

}













// MTA additions





function onUnloadProc(){}



// function to force very soft reloading of pages when browser resizes



function onResizeProc(){history.go(0);}







// onload proc to animate image at top of screen



var change_htm_ns6=document.getElementById&&!document.all;

var change_htm_ie=document.all;

var htm_ind=0;



function change_htm(htm_array,whichdiv){

  var new_htm_ind=0;

  do{

    new_htm_ind=Math.floor((Math.random()*10)%(htm_array.length))

  }while(htm_ind==new_htm_ind);

  htm_ind=new_htm_ind;



  if(change_htm_ie){

    defaulttext=eval("document.all."+whichdiv).innerHTML;

    eval("document.all."+whichdiv).innerHTML=htm_array[htm_ind];

    }

  else{

    if(change_htm_ns6){

      defaulttext=document.getElementById(whichdiv).innerHTML;

      document.getElementById(whichdiv).innerHTML=htm_array[htm_ind];

    }

  }

}







function animate(){

  if((self.name!=="censusdata")&&(self.name!=="pospaper")){

    change_htm(HTML_strings,"banner");

    timeout_id=setTimeout("animate();",1000);

  }

}

var HTML_strings=new Array();

var top_pictures=new Array(

	"photoset/Wesley%20Exterior%20with%20Bikes_resized.JPG",
	"photoset/Peterborough Mosque Main Exterior 2_resized.JPG",
	"photoset/Peterborough Gudwara Prayer 7_resized.JPG",
	"photoset/Jewish Books with Star_resized.JPG",
	"photoset/Hindu Preist on Diwali at Mandir In Luton_resized.jpg"
	

);

var photo_names=new Array(

   "photoset/photo_set_1.jpg",
   "photoset/photo_set_2.jpg",
   "photoset/photo_set_3.jpg",
   "photoset/photo_set_4.jpg",
   "photoset/photo_set_5.jpg",
   "photoset/photo_set_6.jpg",
   "photoset/photo_set_7.jpg",
   "photoset/photo_set_8.jpg"

);


var i;

for(i=0;i<photo_names.length; i++){

  HTML_strings[i]="<center><img src='" + photo_names[i] + "'></center>";

}





function extraOnLoad(){}

if(self.name!="eerameet")createCookie("StateCookie",""); // delete state cookie



function onLoadProc(){



  extraOnLoad();







  var photos=new Array(photo_names.length);

  var i;





  for(i=0;i<photo_names.length;i++){

    photos[i]=new Image();

    photos[i].src=photo_names[i];

  }



  animate();




}







// function to hide email addresses from robots



// create lookup tables





var UID=new Array();

var dom=new Array();



UID["eecn"]="eecn";

dom["eecn"]="cambcatalyst.co.uk";





UID["eefc"]="eefc";

dom["eefc"]="cambcatalyst.co.uk";



UID["mta"]="webmaster";

dom["mta"]="EEFaithsCouncil.org.uk";





UID["hd"]="faithsIThelp";

dom["hd"]="i-trust.org.uk";




UID["ifw"]="enquiries";
dom["ifw"]="interfaithweek.org.uk";

var atstr="@";



function blat(pers){

  var UID_read=UID[pers];

  var dom_read=dom[pers];



  document.write("<A ");

  document.write("href='mailto:" + UID_read + atstr + dom_read +"'>");

  document.write(UID_read + atstr + dom_read + "</a>");

}







function opencensus(url,width){

  openwid=width+20;

  var censusheight=Math.round(screen.availHeight*0.8);

  var args="height=" + censusheight + ",width=" + openwid + ",screenX=0,screenY=0,location=no,left=0,top=0,resizable=yes,status=no,toolbar=no,scrollbars=yes,menubar=no";

  open(url,"censusdata",args);

}





function openposp(url){

  var openwid=550;

  var openheight=Math.round((screen.availHeight-100)*0.9);

  var args="height=" + openheight + ",width=" + openwid + ",screenX=0,screenY=0,location=no,left=0,top=0,resizable=yes,status=no,toolbar=yes,scrollbars=yes,menubar=yes";



  open(url,"pospaper",args);

}







// 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 insert contents page on each page of FITEE



function InsertFITEEContents(){

  document.write("<div class=chapheads id=chapheads>");



  document.write("<div class=chaptitles>");

  document.write("Faith in the East of England");

  document.write("</div>");

  document.write("<div class=fiteeind>");

  document.write("  <a href='index.htm'>Front page</a>  ");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  <a href='forew.htm'>Foreword</a>  ");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  1. <a href='ch01.htm'>Introduction</a>");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  2. <a href='ch02.htm'>The EEDA perspective</a><br>");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  Reflection: <a href='critical.htm'>Critical Partners are the best Partners</a><br>  ");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  3. <a href='ch03.htm'>Why faith communities engage with the wider community</a>");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  4. <a href='ch04.htm'>Makeup of the faith communities in the East of England</a>");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  5. <a href='ch05.htm'>What are they doing?</a>");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  6. <a href='ch06.htm'>How valuable are these activities to the region?</a>");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  7. <a href='ch07.htm'>What more?</a>");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  8. <a href='ch08.htm'>The secular viewpoint</a>");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  9. <a href='ch09.htm'>Barriers, limits and opportunities</a>");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  10. <a href='ch10.htm'>The Future</a>");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  Reflection: <a href='future.htm'>The Future: Faiths and Regional Growth</a><br>");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  Appendix A: <a href='appa.htm'>Methodology</a>");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  Appendix B: <a href='appb.htm'>Social capital associated with worshipping communities</a>");

  document.write("</div>");



  document.write("<div class=fiteeind>");

  document.write("  <a href='bibl.htm'>Bibliography</a>");

  document.write("</div>");



  document.write("</div>");

}




function showrepmenu(){
  document.getElementById("repmenu").style.visibility="visible";
}

function hiderepmenu(){
  document.getElementById("repmenu").style.visibility="hidden";
}



function main_menu(){

  var menustr="";

  menustr+="<table width=100% cellpadding=0 cellspacing=0 style='margin-left: 0px; padding-right: 6px; float: left;'>";

  menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='index.htm'>Home</a></td></tr>";

  menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='about.htm'>About the <br>Faiths Council</a></td></tr>";

  menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='remit.htm'>Remit</a></td></tr>";

  menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='const.htm'>Constitution</a></td></tr>";

  menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='calen.htm'>Faiths&nbsp;calendar&nbsp;2010</a></td></tr>";

  menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='faithn.htm'>Faith<span class=fnenetmenu>Net</span>East</a></td></tr>";

  menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='helpline.htm'>Faiths IT helpline</a></td></tr>";

  menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='interf.htm'>Interfaith week 2009</a></td></tr>";

  <!--menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='pandem.htm'>Pandemic advice</a></td></tr>";-->

  menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='statem.htm'>Statement on rights and responsibilities in relation to freedom of speech</a></td></tr>";


// NB code here is a bit funny: IE positions "Reports" wrongly if things are done in the obvious way

  menustr+="<tr><td class=menu>";
  menustr+="<div class=inmenu onmouseover='showrepmenu();'>";
  menustr+="Reports";
  menustr+="<div style='position: relative;'><div class=repmenu id=repmenu onmouseout='hiderepmenu();'>";
  menustr+="<table cellpadding=0 cellspacing=0>";
  menustr+="";
  menustr+="<tr><td class=smenu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='working.htm'><i>Working and consulting with faith communities in the East of England</i></a></td></tr>";
  menustr+="<tr><td class=smenu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='believe.htm'><i>Believing in our environment</i></a></td></tr>";
  menustr+="<tr><td class=smenu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='safe.htm'><i>Keeping your faith community safe</i></a></td></tr>";
  menustr+="<tr><td class=smenu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='rel_lit.htm'><i>Religious Literacy in the East of England</i></a></td></tr>";
  menustr+="<tr><td class=smenu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='fiee.htm'><i>Faith&nbsp;in&nbsp;the East&nbsp;of&nbsp;England</i> report,&nbsp;summary and&nbsp;commentaries</a></td></tr>";
  menustr+="<tr><td class=smenu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='inact.htm'><i>Faith&nbsp;in&nbsp;Action</i><br>research&nbsp;and&nbsp;report</a></td></tr>";
  menustr+="";
  menustr+="";
  menustr+="</table>";
  menustr+="</div>";   // repmenu
  menustr+="</div>";   // relative
  menustr+="</div>";   // inmenu
  menustr+="</td></tr>";

  menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='faithc.htm'>Faith&nbsp;communities&nbsp;in<br>the&nbsp;East&nbsp;of&nbsp;England</a></td></tr>";
  menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='posp.htm'>Position Papers</a></td></tr>";
  menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='eerameet.htm'>EERA meetings</a></td></tr>";
  menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='glossary.htm'>Glossary of terms and acronyms</a></td></tr>";
  menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='links.htm'>Links</a></td></tr>";
  menustr+="<tr><td class=menu onmouseout='hiderepmenu();'><A class=inmenu target='_top' href='contac.htm'>Contact</a></td></tr>";
  menustr+="</table>";
  document.write(menustr);


}



// writing cookies


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




