
var title;
var titleElements;

function jsInclude(filename) {
    document.write('<script type="text/javascript" src="' + filename + '"></scr' + 'ipt>');

}

function setActiveStyleSheet() {
    if (titleElements[0] == null || titleElements[0] == "" || titleElements[0] == "null" || titleElements[0] == "default") {
        titleElements[0] = "small";

    }
    if (titleElements[1] == null || titleElements[1] == "" || titleElements[1] == "null") {
        titleElements[1] = "default";

    }

    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;
            if (a.getAttribute("title") == titleElements[0] + "_" + titleElements[1]) a.disabled = false;

        }

    }

}

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

    }
    return null;

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

    }
    return null;

}

function createCookie(name, value, days, domain) {
    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=/; domain="+ ((domain!=null) ? domain : ".stpatricksparish.co.uk" )+";";
    /*document.cookie = name + "=" + value + expires;*/


}

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 changeStyle(size, colour) {
    if (size != null && size != '') titleElements[0] = size;
    if (colour != null && colour != '') titleElements[1] = colour;
    setActiveStyleSheet();
    createCookie("style", titleElements[0] + "_" + titleElements[1], 365, '.stpatricksparish.co.uk');

}

function textOnly()
 {
    if (!document.styleSheets.disabled) {
        for (var i = document.styleSheets.length - 1; i >= 0; --i) {
            document.styleSheets[0].disabled = true;

        }

    }
    else
    {
        document.styleSheets[0].disabled = false;

    }

}

$('document').ready(function(e) {

    if (document.getElementById("accessibility")) {
        var accessOptions = '<a onclick="changeStyle(\'small\',\'\')" rel="internal" title="small text" accesskey="0" class="small" style="cursor: pointer">a</a> ';
        accessOptions += '<a onclick="changeStyle(\'medium\',\'\')" rel="internal" title="medium text" accesskey="0" class="medium" style="cursor: pointer">a</a> ';
        accessOptions += '<a onclick="changeStyle(\'large\',\'\')" rel="internal" title="large text" accesskey="0" class="large" style="cursor: pointer">a</a>';
        /*accessOptions += '<a onclick="changeStyle(\'basic\',\'\')" rel="internal" title="basic text" accesskey="0" class="basic" style="cursor: pointer">a</a>';*/
        accessOptions += ' <a onclick="textOnly()" rel="internal" title="basic text" accesskey="0" class="basic" style="cursor: pointer">b</a>';
        accessOptions += ' | <a href="display.htm" title="Click to view options page." rel="internal" accesskey="0">Display options</a>';
        document.getElementById("accessibility").innerHTML = accessOptions;


    }
    var cookie = readCookie("style");
    title = cookie ? cookie: getPreferredStyleSheet();
    titleElements = [title.substring(0, title.indexOf("_")), title.substring(title.indexOf("_") + 1, title.length)];
    setActiveStyleSheet();

   /* if (document.getElementById("emailform")) {
        document.getElementById("emailform").onsubmit = function() {
            var validated = validateMe();
            if (document.getElementById("wf07_confemail")) {
                if (document.getElementById("wf07_confemail").value != document.getElementById("wf07_email").value) {
                    validated = false;
                    alert("Your confirmation email address does not match your email address - please check your submission and try again.");

                }

            }
            if (!validated) {
                return false;

            }
            if (document.getElementById("submit")) {
                document.getElementById("submit").disabled = true;

            }
            return true;

        }

    }*/
    
    /*if($("#hp-intro").length){
	 if(readCookie("ofcomhomepage")==null){
	 	//allow the user to set this as their homepage
	 	$('body').append($('<div/>').css({"position":"absolute","top":0,"left":0,"background":"#555555","width":"100%","height":"100%","opacity":0.5}).attr("id","popupBg"));
	 	var popup = $('<div/>').css({"position":"absolute","top":150,"background":"#FFFFFF","width":300,"height":150,"border-top":"10px solid #cccccc","padding":"5px"}).attr("id","popupBox").text('We recently changed our website structure - would you prefer to make this your default Ofcom landing page?');
	 	var yesBtn = $('<a/>').text('Yes, make this my Ofcom landing page').css({"padding":"2px","background":"#E7DDE7","border":"1px solid #927992","border-right":"2px solid #927992","border-bottom":"3px solid #927992","cursor":"pointer","display":"block","white-space":"nowrap"});
	 	var noBtn = $('<a/>').text('No, don\'t make this my Ofcom landing page').css({"padding":"2px","background":"#E7DDE7","border":"1px solid #927992","border-right":"2px solid #927992","border-bottom":"3px solid #927992","cursor":"pointer","display":"block","white-space":"nowrap"});
	 	yesBtn.click(function(){
	 		createCookie('ofcomhomepage','info',365,'.ofcom.org.uk');
	 		$('#popupBg,#popupBox').fadeOut('fast').remove();
	 	});
	 	noBtn.click(function(){
	 		createCookie('ofcomhomepage','consumer',365,'.ofcom.org.uk');
	 		$('#popupBg,#popupBox').fadeOut('fast').remove();
	 	});
	 	$('body').append(popup.append($('<br/>')).append($('<br/>')).append(yesBtn).append($('<br/>')).append(noBtn));
	 	popup.css("left",($('body').width()/2) - (popup.width()/2));
	 } else if(readCookie("ofcomhomepage")=='consumer') {
	 	if($('#functions').length){
	 		var setLPBtn = $('<a/>').text('Set as my Ofcom landing page').css({"cursor":"pointer"}).click(function(){
	 			createCookie('ofcomhomepage','info',365,'.ofcom.org.uk');
				$(this).text('Landing page set').animate({opacity: 1.0},200).fadeOut('slow');
	 		});
	 		$('#functions').append(' | ').append(setLPBtn);
	 	}
	 }
	}*/

});
