// Scripts for church of ireland

/* open/close submenus */
function showMenu(i) {

	// does the element exist?
	if(v = document.getElementById("ls_"+i)) {
		
		if(v.className == 'hide') {
			v.className = 'show';
			//w = document.getElementById("sp_"+i);
			//w.innerHTML = "<a href=\"javascript:showMenu("+i+");\"><img src=\"images/minus.png\" width=\"14\" height=\"11\" border=\"0\" /></a>&nbsp;";
			
		}
		else {
			v.className = 'hide';
			//w = document.getElementById("sp_"+i)
			//w.innerHTML = "<a href=\"javascript:showMenu("+i+");\"><img src=\"images/plus.png\" width=\"14\" height=\"11\" border=\"0\" /></a>";
		}

	}

}

/* external link handler */
//function externalLink(u) { if(confirm("The page you have requested is outside the official Church of Ireland website. Click OK if you wish" + 
//"to visit the new site, or Cancel if you wish to return to your original page.")) location.href = u; }
function externalLink(u) { window.open('http://ireland.anglican.org/external.php?pg='+escape(u)); }


/*  TEXT ONLY STYLE SWITCHER */
function textOnly() { disableAllCSS(); enableCSS("text"); createCookie("textonly","text",365);  }
function fullGraphics() { disableAllCSS(); enableCSS("default"); enableCSS("ie"); createCookie("textonly","graphics",365); }

function enableCSS(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function disableAllCSS() {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = 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;
}

window.onload = function(e) {
  var cookie = readCookie("textonly");
  var test = cookie ? cookie : "graphics";
  if(test == "text") textOnly();
}
