// Javascript for Faithnet East


/* ***********************************************************
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
  }
}
function getInsideWindowHeight() {
  if (window.innerHeight) {
    return window.innerHeight
  } else {
//    if(document.body.clientHeight>0) { return document.body.clientHeight } // this is returning the height of body, not the height of the window!
    return document.documentElement.clientHeight
  }
}


// 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){
  return(document.getElementById(ID).offsetWidth);
}





// 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 retval=document.getElementById(ID).offsetHeight;      
  if(retval==0)alert("Height of " + ID + "returning as zero");
  return(retval);
}







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;
}



// revise font size and line height in body for Win32 s Miaindra different from Optima

if(navigator.platform.indexOf("Win32")>-1){
   document.write("<style>body{font-size: 11px;line-height:155%;}</style>");
}



var width_of_1ex;

function setup_mainwrapper(){
  var width=80;
  if(arguments.length>0)width=arguments[0];


  document.write("<div id='test_1ex' style='width: 1ex;'></div>");
  width_of_1ex=getWidthOfID("test_1ex");
  mainwrapper_width=width*width_of_1ex;
  var max_space=getInsideWindowWidth();
  if(max_space<mainwrapper_width)mainwrapper_width=max_space;

  var sstr="<style>.mainwrapper{width: " + mainwrapper_width + "px;}</style>";
  document.write(sstr);
}



// stuff for side images

function left_img(){
  document.write("<div style='position:relative; top:0px; left:0px;'>");
  document.write("  <div style='position: absolute;width:200px; top:90px; left:10px;'>");
  document.write("  <img class=sideimg src='sideimg/phil1_OLEM_Interior_Light_nave-sq.jpg' width=200><br>");
  document.write("  <img class=sideimg src='sideimg/jonny_Catholic_Catholics_and_Protestants_Simply_as_Christians_in_Sikh_Gurud-sq.jpg' width=200><br>");
  document.write("  <img class=sideimg src='sideimg/jonny_Hindu_Priest_on_Diwali_at_Mandir_In_Luton-sq.jpg' width=200>");
  document.write("  </div>");
  document.write("</div>");
}

function right_img(){
  document.write("<div style='position:relative; top:90px; left:0px;'>");
  document.write("  <div style='position: absolute;width:200px; top:10px; right:10px;'>");
  document.write("  <img class=sideimg src='sideimg/phil2_Peterborough_Mosque_Dome_Detail_5-sq.jpg' width=200><br>");
  document.write("  <img class=sideimg src='sideimg/phil1_Wesley_Interior_with_Bible_3-sq.jpg' width=200><br>");
  document.write("  <img class=sideimg src='sideimg/jonny_A_Sikh_Priest_reciting_from_the_Sikh_Scriptures_reverr-2-sq.jpg' width=200>");
  document.write("  </div>");
  document.write("</div>");
}



var blatstrs=new Array();

blatstrs["Di"]="";
blatstrs["Di"]+="di.m";
blatstrs["Di"]+="itch";
blatstrs["Di"]+="ell@";
blatstrs["Di"]+="fait";
blatstrs["Di"]+="hnet";
blatstrs["Di"]+="east";
blatstrs["Di"]+=".org";
blatstrs["Di"]+=".uk";

blatstrs["eefc"]="";
blatstrs["eefc"]+="eef";
blatstrs["eefc"]+="c@c";
blatstrs["eefc"]+="amb";
blatstrs["eefc"]+="cat";
blatstrs["eefc"]+="aly";
blatstrs["eefc"]+="st.";
blatstrs["eefc"]+="co.";
blatstrs["eefc"]+="uk";

blatstrs["enq"]="";     
blatstrs["enq"]+="enq";
blatstrs["enq"]+="uir";
blatstrs["enq"]+="ies";
blatstrs["enq"]+="@fa";
blatstrs["enq"]+="ith";
blatstrs["enq"]+="net";
blatstrs["enq"]+="eas";
blatstrs["enq"]+="t.o";
blatstrs["enq"]+="rg.u";
blatstrs["enq"]+="k";



function blat(pers){
  document.write("<a href='mailto:" + blatstrs[pers] + "'>" + blatstrs[pers] + "</a>");
}


function countMsg(theForm){
  textCount = theForm.char_count;
  textMsg = theForm.message;
  var maxlength = 2000;
  var charRemain = 0;
  var charRemain = maxlength - textMsg.value.length;
  if (charRemain < 0 ){
  textMsg.value = textMsg.value.substring(0,maxlength);
  charRemain = 0;
  }
  textCount.value = charRemain;
}



var submstr="";
submstr+="<inpu";
submstr+="t ty";
submstr+="pe=s";
submstr+="ubmi";
submstr+="t val";
submstr+="ue='s";
submstr+="ubmi";
submstr+="t'>";

function subfun(){
  document.write(submstr);
}


function checkform(){
  var errors=0;


  if(document.newentry.name.value.length==0){
    alert("Please fill in the Name box before submitting your entry.");
    errors++;
  }

  if((document.newentry.email.value.length==0) && (errors==0)){
    alert("Please fill in the Email box before submitting your entry.")
    errors++;
  }

  if((document.newentry.title.value.length==0) && (errors==0)){
    alert("Please fill in the Title box before submitting your entry.")
    errors++;
  }


  if((document.newentry.message.value.length==0) && (errors==0)){
    alert("Please fill in the box with your posting before submitting your entry.")
    errors++;
  }

  if(
    (document.newentry.section[0].checked=="false") &&
    (document.newentry.section[1].checked=="false") &&
    (document.newentry.section[2].checked=="false") &&
    errors==0
    )
    {
    alert("Please indicate which section of the noticeboard your submission is for");
    errors++;
  }

  if(errors>0){return false;}else{return true;}
}


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 eraseCookie(name){
  createCookie(name,"",-1);
}


function reload_iframe(){
  if(readCookie("reload")!=null){
//alert(readCookie("reload"));
    if(readCookie("reload").length>0)location.reload(true);
  }
  eraseCookie("reload");
}
