/* ******************************************** */
defaultStatus        = "BWY Southern Region, covering Berkshire, Buckinghamshire, Hampshire, Isle of Wight and Oxfordshire"; 
function statbar() {
    window.status = "BWY Southern Region, covering Berkshire, Buckinghamshire, Hampshire, Isle of Wight and Oxfordshire"; 
}
/* ******************************************** */



function go2(f) { 
    window.location.hash=f; 
}

/*************************************
 prevent enter key from submitting form 
function entrytest() {    
   if (event.keyCode == 13)    {        
      event.cancelBubble = true;
      event.returnValue = false;
   }
} 
************************************/


/*** 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=\"mail\" 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);
}
function ns3(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);
}
var show, name, dom, m;
function ns2(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"; 
    } 
} 


/*** kill focus borders  ***/
//add event function
/* ***************************************************
function addEvent(obj, evType, fn) { 
   if (obj.addEventListener) { 
      obj.addEventListener(evType, fn, true); 
      return true; 
   } else if (obj.attachEvent) { 
      var r = obj.attachEvent("on"+evType, fn); 
      return r; 
   } else { 
      return false; 
   } 
}

// Find all link elements and add an onfocus attribute and value
function hideFocusBorders() {
   var theahrefs = document.getElementsByTagName("a");
   if (!theahrefs) {
      return;
   }
   for(var x=0;x!=theahrefs.length;x++) {
      theahrefs[x].onfocus = function stopLinkFocus() {
         this.hideFocus=true;
      };
   }
}
//event added using the addEvent() function above
// addEvent(window, 'load', hideFocusBorders);
***********************************************************/

/*** 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 to apply focus to an element *** */
function getfocus(){
    document.getElementById('heading').focus()
}


/* *** OPEN NEW WINDOW SCRIPTS *** */
        function bkform2(data) {
           visit = 'http://www.bwysouth.org.uk/booking2-info.htm';
           theURL = visit + data;
           newwindow = window.open(theURL, 'booking_form', 'width=560,height=580,resizable=0,status=1,left=25, top=25, menubar=1, toolbar=1, sName=_blank, location=0,scrollbars=1'); 
           if ( window.focus ) { newwindow.focus(); }
        }

        function bkform(data) {
           visit = 'http://www.bwysouth.org.uk/booking_form.php';
           theURL = visit + data;
           newwindow = window.open(theURL, 'booking_form', 'width=560,height=580,resizable=0,status=1,left=25, top=25, menubar=1, toolbar=1, sName=_blank, location=0,scrollbars=1'); 
           if ( window.focus ) { newwindow.focus(); }
        }

        function bookform(data) {
           visit = 'http://www.bwysouth.org.uk/book-info.htm';
           theURL = visit + data;
           newwindow = window.open(theURL, 'booking_form', 'width=560,height=580,resizable=0,status=1,left=25, top=25, menubar=1, toolbar=1, sName=_blank, location=0,scrollbars=1'); 
           if ( window.focus ) { newwindow.focus(); }
        }

        function map(data) {
           visit = 'http://www.bwysouth.org.uk/map.php';
           theURL = visit + data;
           newwindow = window.open(theURL, 'map', 'width=600,height=430,resizable=0,status=0,left=25, top=25, menubar=0, toolbar=0, sName=_blank, location=0,scrollbars=0'); 
           if ( window.focus ) { newwindow.focus(); }
        }


        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(); }
        }





function confirmbooking(data) {
   visit = 'http://bwysouth.org.uk/admin/bookings_confirm.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'contact', 'width=560,height=380,resizable=0,status=1,left=30, top=30, location=0, directories=0, personalbar=0, scrollbars=1'); 
   if ( window.focus ) 
   { 
      newwindow.focus(); 
   }
}

function email(data) {
   visit = 'http://bwysouth.org.uk/admin/bookings_email.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'contact', 'width=560,height=510,resizable=0,status=1,left=30, top=30, location=0, directories=0, personalbar=0, scrollbars=1'); 
   if ( window.focus ) 
   { 
      newwindow.focus(); 
   }
}

function emailall(data) {
   visit = 'http://bwysouth.org.uk/admin/bookings_email_all.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'contact', 'width=560,height=510,resizable=0,status=1,left=30, top=30, location=0, directories=0, personalbar=0, scrollbars=1'); 
   if ( window.focus ) 
   { 
      newwindow.focus(); 
   }
}

function csv(data) {
   visit = 'http://bwysouth.org.uk/admin/bookings_csv.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'csv', 'width=700,height=700,resizable=1,status=1,left=30, top=30, location=0, directories=0, personalbar=0, scrollbars=1'); 
   if ( window.focus ) 
   { 
      newwindow.focus(); 
   }
}

function printregister(data) {
   visit = 'http://bwysouth.org.uk/admin/bookings_print_register.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'csv', 'width=880,height=600,resizable=1,status=1,left=30, top=30, location=0, directories=0, personalbar=0, menubar=1, scrollbars=1'); 
   if ( window.focus ) 
   { 
      newwindow.focus(); 
   }
}

function printsummary(data) {
   visit = 'http://bwysouth.org.uk/admin/bookings_print_summary.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'csv', 'width=880,height=600,resizable=1,status=1,left=30, top=30, location=0, directories=0, personalbar=0, menubar=1, scrollbars=1'); 
   if ( window.focus ) 
   { 
      newwindow.focus(); 
   }
}

function printcertificates(data) {
   visit = 'http://bwysouth.org.uk/admin/bookings_print_certificates.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'csv', 'width=880,height=600,resizable=1,status=1,left=30, top=30, location=0, directories=0, personalbar=0, menubar=1, scrollbars=1'); 
   if ( window.focus ) 
   { 
      newwindow.focus(); 
   }
}

function notes(data) {
   visit = 'http://bwysouth.org.uk/admin/bookings_add_notes.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'csv', 'width=560,height=340,resizable=0,status=1,left=30, top=30, location=0, directories=0, personalbar=0, scrollbars=1'); 
   if ( window.focus ) 
   { 
      newwindow.focus(); 
   }
}



/* *** booking_fncts *** */
function win_close() { 
   setTimeout('window.close()', 600); 
} 





/*********************************
   Duvien text sizer
/*********************************/
var prefsLoaded = false;
var defaultFontSize = 75;
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 written by Drew Noakes -- http://drewnoakes.com
// 11 Dec 2006

function initLinks() {
   for (i in document.links) {
      link = document.links[i];
      if (link.rel && link.rel.indexOf('external')!=-1) {
         link.onclick = onExternalLinkActivate;
         link.onkeypress = onExternalLinkActivate;
      }
   }
}

function onExternalLinkActivate() {
   window.open(this.href);
   return false;
}

// window.onload = initLinks;

/*** 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"; 
       } 
     } 
} 



/*** script to initiate javascripts  ***/
 function setup() {
//    getfocus();
    externalLinks();
    initLinks();
    setUserOptions();
//    addEvent(window, 'load', hideFocusBorders);
}
window.onload=setup;


