/*** script to prevent framing of website ***/
if (parent.frames.length > 0) {
    parent.location.href = self.document.location;
}


/*** rewrite external links to open in new window ***/
function externalLinks() { 
    if (!document.getElementsByTagName) {
        return; }

    var anchors = document.getElementsByTagName("a"); 
    for (var i=0; i<anchors.length; i=i+1) { 
        var anchor = anchors[i]; 
        if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") { 
            anchor.target = "_blank"; }
    } 


    var forms = document.getElementsByTagName("form"); 
    for(var i = 0; i < forms.length; i=i+1) { 
       var form = forms[i]; 
       if(form.getAttribute("action").substring(0, 4) == "http") {
          form.target = "_blank"; 
       } 
     } 
} 
//  window.onload = externalLinks;
// event added using setup() function 


/*** anti-spam script ***/
var show, name, dom, m;
function ns(show, name, dom) { 
   m = "<a class=\"link\" href=\"mailto:" +name+"@"+dom+"\" title=\"send mail to "+show+"\"  ";
   m += "onmouseover=\"window.status='Send mail to "+ show+"'; return true;\" ";
   m += "onmouseout=\"window.status=''; return true;\" ";
   m += "onfocusout=\"window.status='opening e-mail program'; return true;\">";
   m += show+"</a>";
   document.write(m);
}


/*** toggle div ***/
function toggle(d){ 
    style = document.getElementById(d).style ; 
    if(style.display == "block") { 
        style.display = "none"; 
    } else { 
        style.display = "block"; 
    } 
} 


/*** 
   scroll to top of page: Dave Lindquist
   http://www.octavioheredia.com/blog/archives/2005/10/javascript-back-to-top-links.php  
***/
    function top() {
        var x1 = x2 = x3 = 0;
        var y1 = y2 = y3 = 0;

        if (document.documentElement) {
            x1 = document.documentElement.scrollLeft || 0;
            y1 = document.documentElement.scrollTop || 0;
        }

        if (document.body) {
            x2 = document.body.scrollLeft || 0;
            y2 = document.body.scrollTop || 0;
        }

        x3 = window.scrollX || 0;
        y3 = window.scrollY || 0;

        var x = Math.max(x1, Math.max(x2, x3));
        var y = Math.max(y1, Math.max(y2, y3));

        window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

        if (x > 0 || y > 0) {
            window.setTimeout("top()", 36);
        }
    }

function scroll()
{
window.scrollTo(0,250);
}
function scroll2()
{
window.scrollTo(0,450);
}


/* *** function to apply focus to an element *** */
function getfocus(){
    document.getElementById('heading').focus()
}


/* *** OPEN NEW WINDOW SCRIPTS *** */
        function contact(data) {
           visit = 'http://www.bwysouth.org.uk/contact.htm';
           theURL = visit + data;
           newwindow = window.open(theURL, 'contact', 'width=560,height=510,resizable=0,status=1,left=25, top=25, location=0,scrollbars=1'); 
           if ( window.focus ) { newwindow.focus(); }
        }

        function contact2(data) {
           visit = 'http://www.bwysouth.org.uk/contact2.htm';
           theURL = visit + data;
           newwindow = window.open(theURL, 'contact', 'width=560,height=510,resizable=0,status=1,left=25, top=25, location=0,scrollbars=1'); 
           if ( window.focus ) { newwindow.focus(); }
        }


/*********************************
   Duvien text sizer
/*********************************/
var prefsLoaded = false;
/* var defaultFontSize = 75; */
var defaultFontSize = 69;
var currentFontSize = defaultFontSize;

function revertStyles(){
	currentFontSize = defaultFontSize;
	changeFontSize(0);
}
/*
function toggleColors(){
	if(currentStyle == "White"){
		setColor("Black");
	}else{
		setColor("White");
	}
}
*/
function changeFontSize(sizeDifference) {
	currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference * 5);

	if(currentFontSize > 100) {
		currentFontSize = 100;
	}else if(currentFontSize < 69) {
		currentFontSize = 69;
	}
	setFontSize(currentFontSize);
};

function setFontSize(fontSize) {
	var stObj = (document.getElementById) ? document.getElementById('content_area') : document.all('content_area');
	document.body.style.fontSize = fontSize + '%';
	//alert (document.body.style.fontSize);
};


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 setUserOptions() {
	if(!prefsLoaded) {
		cookie = readCookie("fontSize");
		currentFontSize = cookie ? cookie : defaultFontSize;
		setFontSize(currentFontSize);
		
		prefsLoaded = true;
	}
}

function saveSettings() {
	createCookie("fontSize", currentFontSize, 365);
}

// window.onload = setUserOptions;
window.onunload = saveSettings;

/*** script to initiate javascripts  ***/
 function setup() {
//    getfocus();
    externalLinks();
    setUserOptions();
}
window.onload=setup;



var xmlhttp; if (window.ActiveXObject) { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } else { xmlhttp = new XMLHttpRequest(); } function fetch(serverPage, objID) { var obj = document.getElementById(objID); xmlhttp.open("GET", serverPage); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { obj.innerHTML = xmlhttp.responseText; } }; xmlhttp.send(null); }

