// JavaScript Document


ddaccordion.init({
	headerclass: "expandable", //Shared CSS class name of headers group that are expandable
	contentclass: "categoryitems", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", "openheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})



ddaccordion.init({
	headerclass: "expandable2", //Shared CSS class name of headers group that are expandable
	contentclass: "categoryitems2", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", "openheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})





function showMenuItem(e)
{
document.getElementById(e).style.display='block';
}

function hideMenuItem(e)
{
document.getElementById(e).style.display='none';
}



function dropDownMenuShow(obj,a)
{
obj.style.display='block'; 
document.getElementById(a).style.backgroundImage='url(http://www.wybostonlakes.co.uk/images/willows-training-centre/menu-1.jpg)';
}


function dropDownMenuHide(obj,a,revert_colour)
{
obj.style.display='none'; 
if (revert_colour=='true')
	{
	document.getElementById(a).style.backgroundImage='url(http://www.wybostonlakes.co.uk/images/willows-training-centre/menu11.jpg)';
	}
}



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

//-------set font size-------



function setFontSize(intSize,button) {

   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
         var s = intSize;
      p[i].style.fontSize = s+"px"
   }

   var h = document.getElementsByTagName('h1');
   for(i=0;i<h.length;i++) {
         var s = intSize+14;
      h[i].style.fontSize = s+"px"
   }

   var l = document.getElementsByName('menu_item');

   for(i=0;i<l.length;i++) {
         var s = intSize;
      l[i].style.fontSize = s+"px"
   }

   Set_Cookie('intSize',intSize, '1', '/', '', '' );
   setButtons(button);

}


function setDefaultSelectedSize() {

  var s = Get_Cookie('intSize');

if (s!=null)
{

   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {	 
      p[i].style.fontSize = s+"px"
   }

   var h = document.getElementsByTagName('h1');
   for(i=0;i<h.length;i++) {
         var s1 = parseInt(s)+14;
      h[i].style.fontSize = s1+"px"
   }

   var l = document.getElementsByName('menu_item');

   for(i=0;i<l.length;i++) {
         var s2 = s;
      l[i].style.fontSize = s2+"px"
   }


   
   if (s=='12')
   {
   setButtons('small');
   }
   else    if (s=='15')
   {
   setButtons('medium');
   }
      else    if (s=='17')
   {
   setButtons('large');
   }

}
}



function setButtons(button)
{
	   if (button=='small')
   {
	   MM_swapImage('font_small','','http://www.wybostonlakes.co.uk/images/willows-training-centre/small11.jpg','font_medium','','http://www.wybostonlakes.co.uk/images/willows-training-centre/medium1.jpg','font_large','','http://www.wybostonlakes.co.uk/images/willows-training-centre/large1.jpg',1)
   }
   else if (button=='medium')
   {
	   MM_swapImage('font_small','','http://www.wybostonlakes.co.uk/images/willows-training-centre/small1.jpg','font_medium','','http://www.wybostonlakes.co.uk/images/willows-training-centre/medium11.jpg','font_large','','http://www.wybostonlakes.co.uk/images/willows-training-centre/large1.jpg',1)
   }
   else if(button=='large')
   {
	   MM_swapImage('font_small','','http://www.wybostonlakes.co.uk/images/willows-training-centre/small1.jpg','font_medium','','http://www.wybostonlakes.co.uk/images/willows-training-centre/medium1.jpg','font_large','','http://www.wybostonlakes.co.uk/images/willows-training-centre/large11.jpg',1)
   }
}


//---cookies--------



// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );

// To use, simple do: Get_Cookie('cookie_name'); 
// replace cookie_name with the real cookie name, '' are required
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
function Set_Cookie( name, value, expires, path, domain, secure ) {

domain =".wybostonlakes.co.uk";

	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


//---------mailing list

function verify() {
var themessage = "You are required to complete the following fields: ";

if (document.ResvRecap.sender.value=="") {
themessage = themessage + "\n - EMail";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {

ValidateForm();
if (document.ResvRecap.holder.value=="on")
{
document.ResvRecap.submit();
}
}
else {
alert("Please enter an email address!");
return false;
   }
}
//  End -->
function ValidateForm(){
	var emailID=document.ResvRecap.sender
	
	if (echeck(emailID.value)==false){

document.ResvRecap.holder.value="off"
		return false;
	}
	
	document.ResvRecap.holder.value="on"
	return true
 }


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid email address!")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid email address!")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid email address!")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid email address!")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid email address!")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid email address!")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid email address!")
		    return false
		 }

 		 return true					
	}



