// pop-up function
var newWin = null;
function closeWin(){
	if (newWin != null){
		if(!newWin.closed)
			newWin.close();
	}
}
function popUp(strURL,strWidth,strHeight) {
	closeWin();
	newWin = window.open(strURL, "gallery", "height="+strHeight+",width="+strWidth);
	newWin.focus();
}

function popWin(strURL,strName,strWidth,strHeight) {
	closeWin();
	newWin = window.open(strURL, strName, "scrollbars=yes,resizable=yes,toolbars=yes,height="+strHeight+",width="+strWidth);
	newWin.focus();
}

// RESIZING TEXT -------------------------------------------------------
// Set Body text size
function setSize(iSize) {
	if (!document.getElementsByTagName) return false;
	var bodyTag = document.getElementsByTagName ("body");
	for (var i=0; i < bodyTag.length; i++) {
		if (!bodyTag[i].style.fontSize) {
		if (!readCookie("resize")) {
		bodyTag[i].style.fontSize = "100%";
		}
		else {
		bodyTag[i].style.fontSize = ((parseFloat(readCookie("resize"))) + "%");
		}
		}
		else {
		if (!readCookie("resize")) {
		bodyTag[i].style.fontSize = "100%";
		}
		else {
		bodyTag[i].style.fontSize = (((parseFloat(iSize)) + (parseFloat(readCookie("resize")))) + "%");
		}
		}
		cookieValue = bodyTag[i].style.fontSize;
		writeCookie("resize", cookieValue, 10000);
	}
}


// Attaches the onclick event to the correct ids to allow resizing
function resizeT(iID, iDir) {
	if (!document.getElementById) return false;
	var incLink = document.getElementById (iID);
	if (iDir == "decrease") {
	incLink.onclick = function() {
		setSize("-10%");
		return false;
	}
	}
	if (iDir == "increase") {
	incLink.onclick = function() {
		setSize("10%");
		return false;
	}
	}   
	if (iDir == "default") {
	incLink.onclick = function() {
		deleteCookie();
		setSize("100%");
		return false;
	}
	}
	
}

// Attaches the text resizer images/script
function attachResizers () {
	if (!document.getElementById) return false;
	var elA = document.getElementById ("accessibility"); 
	var iHTML=elA.innerHTML;
        elA.innerHTML='<a id="stIncrease" title="Increase Text Size" href="#">'
+       '<img src="http://cooksbridgecare.co.uk/images/ExpandText.gif" alt="Expand Text " width="40px" height="32px" /></a>'
+       '<a id="stDefault" title="Restore Default Text Size" href="#">'
+       '<img src="http://cooksbridgecare.co.uk/images/RestoreText.gif" alt="Default Text " width="40px" height="32px" /></a>'
+       '<a id="stDecrease" title="Decrease Text Size" href="#">'
+       '<img src="http://cooksbridgecare.co.uk/images/ShrinkText.gif" alt="Shrink Text " width="40px" height="32px" /></a>'
+ iHTML
}        

function deleteCookie() {
	var d = new Date();    
	d.setTime ( d.getTime() - 1 );

    	document.cookie = "resize=;expires=" + d.toGMTString();
//    	alert(document.cookie);
}

function writeCookie(name, value, hours) {
  var expire = "";
  if(hours != null)  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}


// Read Cookie
// alert( readCookie("myCookie") );
function readCookie(name){
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)  {
    offset = document.cookie.indexOf(search);
    if (offset != -1)    {
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))    }
  }
  return cookieValue;
} 

function externalLinks () {
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
	  	if (links[i].href.substring( 0,7) != "mailto:") {
		var addy = links[i].href;
			if (addy != "") {
			if (addy.indexOf(window.location.hostname) == -1) {
				if (links[i].className == "") {	links[i].className = "externalLink"; }
				else { links[i].className = links[i].className + " externalLink"; }
			if (links[i].title == "") {
			links[i].title = "(external site)";
			}
			else {
			links[i].title = links[i].title + " (external site)";	
			}
			}
			}
		}
      }
}

window.onload=function(){
attachResizers();
resizeT("stIncrease", "increase");
resizeT("stDefault", "default");
resizeT("stDecrease", "decrease");
setSize("100%");
}

