
var menus = new Array();

menus[0]="item1";
menus[1]="item2";
menus[2]="item3";
menus[3]="item4";
menus[4]="item5";
menus[5]="item6";

function showMenu(lyr){

	for(i=0;i<menus.length;i++){
	document.getElementById(menus[i]+"menu").className = "hide"
	document.getElementById(menus[i]+"Link").className = ""
	}
	
	document.getElementById(lyr+"menu").className = "show"
	document.getElementById(lyr+"Link").className = "selected"

}

window.document.onclick=hideMenu;
window.onload=init;

function init(){
	chkPage();
	getRadioList();
	if(rB.length!=0){findRadioDS();}
	getRecipesList();
	if(rL.length!=0){updateRecipeList();}
	fnAttachColorToggle();
	if(document.getElementById("MainFramework_ElertProfile_ctlStoreLogin_txtUserName")){
		document.getElementById("MainFramework_ElertProfile_ctlStoreLogin_txtUserName").focus();
	}
}

var other;
var address;
var done;
var postcode;

function chkPage(){


if(document.getElementById("template-elert")){

	if(document.getElementById("MainFramework_ElertReg_ctlElertReg_ddTitle")){other = document.getElementById("MainFramework_ElertReg_ctlElertReg_ddTitle");}
	if(document.getElementById("MainFramework_ElertProfile_ctlElertProfile_ddTitle")){other = document.getElementById("MainFramework_ElertProfile_ctlElertProfile_ddTitle");}

	if(document.getElementById("MainFramework_ElertReg_ctlElertReg_ddCountry")){address = document.getElementById("MainFramework_ElertReg_ctlElertReg_ddCountry");}
	if(document.getElementById("MainFramework_ElertProfile_ctlElertProfile_ddCountry")){address = document.getElementById("MainFramework_ElertProfile_ctlElertProfile_ddCountry");}

	if(document.getElementById("MainFramework_ElertReg_ctlElertReg_txtPostcode")){postcode = document.getElementById("MainFramework_ElertReg_ctlElertReg_txtPostcode");}
	if(document.getElementById("MainFramework_ElertProfile_ctlElertProfile_txtPostcode")){postcode = document.getElementById("MainFramework_ElertProfile_ctlElertProfile_txtPostcode");}
	
	
	if(document.getElementById("otherTitle")){
		document.getElementById("otherTitle").style.display = "none";
		showTitle();
	}
	
	if(document.getElementById("field-address") && document.getElementById("field-town") && document.getElementById("field-county")){
		if(done==false){
		document.getElementById("field-postcode").style.display = "block";
		document.getElementById("field-address").style.display = "none";
		document.getElementById("field-town").style.display = "none";
		document.getElementById("field-county").style.display = "none";
		showAddress();
		}
	}		
	
	if(other){other.onchange=showTitle;}
	if(address){address.onchange=showAddress;}
	
	if(document.getElementById("MainFramework_ElertReg_ctlElertReg_txtPostcode")){
		if(document.getElementById("MainFramework_ElertReg_ctlElertReg_txtPostcode").value!=""){
		document.getElementById("MainFramework_ElertReg_ctlElertReg_txtPostcode").focus();
		}
	}

	

	
	
}

if(document.getElementById("template-events-form")){


	if(document.getElementById("otherTitle")){document.getElementById("otherTitle").style.display="none";}
	if(document.getElementById("MainFramework_ConfEventBookStart_ctlConfEventBookStart_ddTitle")){other = document.getElementById("MainFramework_ConfEventBookStart_ctlConfEventBookStart_ddTitle");}
	if(document.getElementById("MainFramework_Donations2_ctlDonations2_ddTitle")){other = document.getElementById("MainFramework_Donations2_ctlDonations2_ddTitle");} /*AT*/
	if(other){other.onchange=showTitle;}

	if(document.getElementById("otherTitle")){
		document.getElementById("otherTitle").style.display = "none";
		showTitle();
	}
	
	if(done==true){
	document.location.href="#jump-form"
	}



}

	
}


function searchOptions(opt){

	var searchOpt = new Array();
	searchOpt[0]="chkGuide";
	searchOpt[1]="chkNews";
	searchOpt[2]="chkEvents";
	searchOpt[3]="chkResearch";
	searchOpt[4]="chkProResources";
	searchOpt[5]="chkSharedPractice";
	searchOpt[6]="chkRecipes";
	searchOpt[7]="chkAboutUs";
	searchOpt[8]="chkHowWeHelp";
	searchOpt[9]="chkSupportUs";
	
	var j=0;
	
	if(opt.checked==true){
	document.getElementById("MainFramework_SiteSearch_ctlSiteSearch_chkAllSite").checked=false;
	}
	
	
	//alert(document.getElementById("MainFramework_SiteSearch_ctlSiteSearch_chkAllSite".selected))

		//for(i=0;i<searchOpt.length;i++){
			//if(document.getElementById("MainFramework_SiteSearch_ctlSiteSearch_"+searchOpt[i])){
				//document.getElementById("MainFramework_SiteSearch_ctlSiteSearch_"+searchOpt[i]).checked=true;
			//}
		//}
	
	
	
}



function showTitle(){
	if(other.options[other.selectedIndex].innerHTML=="Other"){
		document.getElementById("otherTitle").style.display = "block";
	}
	else{
		document.getElementById("otherTitle").style.display = "none";
	}
}

function showAddress(){

	if(address.options[address.selectedIndex].value=="GB" || address.options[address.selectedIndex].value=="NI" || address.options[address.selectedIndex].value=="0"){
		if(done==false){
		document.getElementById("field-address").style.display = "none";
		document.getElementById("field-town").style.display = "none";
		document.getElementById("field-county").style.display = "none";
		}
		document.getElementById("field-postcode").style.display = "block";
		
		if(document.getElementById("MainFramework_ElertReg_ctlElertReg_txtAddress1")){
			document.getElementById("MainFramework_ElertReg_ctlElertReg_txtAddress1").disabled=true;}
		
		if(document.getElementById("MainFramework_ElertReg_ctlElertReg_txtAddress2")){ document.getElementById("MainFramework_ElertReg_ctlElertReg_txtAddress2").disabled=true;}

		
		if(document.getElementById("MainFramework_ElertReg_ctlElertReg_txtAddress3")){ document.getElementById("MainFramework_ElertReg_ctlElertReg_txtAddress3").disabled=true;}

		
		if(document.getElementById("MainFramework_ElertReg_ctlElertReg_txtTown")){ document.getElementById("MainFramework_ElertReg_ctlElertReg_txtTown").disabled=true;}

		
		if(document.getElementById("MainFramework_ElertReg_ctlElertReg_txtCity")){ document.getElementById("MainFramework_ElertReg_ctlElertReg_txtCity").disabled=true;}

		
		
		
		
		
			
		
	}
	else{
		document.getElementById("field-postcode").style.display = "none";
		document.getElementById("field-address").style.display = "block";
		document.getElementById("field-town").style.display = "block";
		document.getElementById("field-county").style.display = "block";

		if(document.getElementById("MainFramework_ElertReg_ctlElertReg_txtAddress1")){
			document.getElementById("MainFramework_ElertReg_ctlElertReg_txtAddress1").disabled=false;}
		
		if(document.getElementById("MainFramework_ElertReg_ctlElertReg_txtAddress2")){ document.getElementById("MainFramework_ElertReg_ctlElertReg_txtAddress2").disabled=false;}

		
		if(document.getElementById("MainFramework_ElertReg_ctlElertReg_txtAddress3")){ document.getElementById("MainFramework_ElertReg_ctlElertReg_txtAddress3").disabled=false;}

		
		if(document.getElementById("MainFramework_ElertReg_ctlElertReg_txtTown")){ document.getElementById("MainFramework_ElertReg_ctlElertReg_txtTown").disabled=false;}

		
		if(document.getElementById("MainFramework_ElertReg_ctlElertReg_txtCity")){ document.getElementById("MainFramework_ElertReg_ctlElertReg_txtCity").disabled=false;}
		
	}
}





function hideMenu(lyr){
	for(i=0;i<menus.length;i++){
		if(document.getElementById(menus[i]+"menu")){document.getElementById(menus[i]+"menu").className = "hide";}
		if(document.getElementById(menus[i]+"Link")){document.getElementById(menus[i]+"Link").className = "";}
	}
}



function altShowMenu(lyr){
	for(i=0;i<menus.length;i++){
	if(document.getElementById(menus[i]+"menu")){
	document.getElementById(menus[i]+"menu").className = "hide"
	document.getElementById(menus[i]+"Link").className = ""
	}
	}
	
	if(document.getElementById(lyr+"menu")){
	document.getElementById(lyr+"menu").className = "show"
	document.getElementById(lyr+"Link").className = "selected"
	//document.getElementById(lyr+"Link").parentNode.className+=" test"
	}
	

	hideSel("hide");

}


function showSlowMenu(lyr){

}



function altHideMenu(lyr){
	for(i=0;i<menus.length;i++){
	if(document.getElementById(menus[i]+"menu")){
	document.getElementById(menus[i]+"menu").className = "hide"
	document.getElementById(menus[i]+"Link").className = ""
	}
	}
	
	
	hideSel("show");
	
}


function clearItem(item){
item.value="";
}

function openwin(href){
window.open(href,'help','width=400,height=500,scrollbars=yes')
}



//Hide seelct boxes in IE for the drop down menus

function hideSel(type){
	var IE = navigator.appName.indexOf("Internet Explorer");
	if(IE!=-1){
		var sels = document.getElementsByTagName("select");
		if(type=="hide"){for(i=0;i<sels.length;i++){sels[i].style.visibility="hidden";}}
		else{for(i=0;i<sels.length;i++){sels[i].style.visibility="visible";}}
	}
}





//RECIPES CHECKBOXES
var rL = new Array();
function getRecipesList(){
	var inp = document.getElementsByTagName("input");
	var j = 0;
	for(i=0;i<inp.length;i++){
		if(inp[i].id.indexOf("MainFramework_Recipes_ctlRecipes_chkCats")!=-1){
			rL[j] = inp[i];
			j++;
		}	
	}
	//alert(rL.length)
}

function updateRecipeList(){
	if(document.getElementById(rL[0].id)){
		targ =rL.length;
		targ--;
		for(i=1;i<targ;i++){rL[i].onclick=untickRecipes;}
	}
}

function untickRecipes(){
var test=false;
for(i=0;i<rL.length;i++){
	if(rL[i].checked==true){test=true;}
}
if(test==true){rL[0].checked=false;}
else{rL[0].checked=true;}



//if(this.id!=rL[0].id){if(this.checked==true){}}
}








//DONATIONS clears radio buttons for 'other' input functionality

// DONATIONS SINGLE

function findRadioDS(){
	if(document.getElementById(rB[0].id)){
	targ =rB.length;
		if(document.getElementById("MainFramework_ctl01_ctl00_txtRoundUpOther")){
			for(i=0;i<targ;i++){rB[i].onclick=clearOtherDS;}	
			rB[3].onclick=null;
		}
		else{
			targ--;
			for(i=0;i<targ;i++){rB[i].onclick=clearOtherDS;}		
		}
		
	}

	
}

function selectOtherDS(){
	targ =rB.length;
	targ--;
	if(document.getElementById("MainFramework_ctl01_ctl00_txtRoundUpOther")){targ--;}
	document.getElementById(rB[targ].id).checked=true;
}

function clearOtherDS(){
	if(rB[0].id.indexOf("Single")!=-1){document.getElementById("MainFramework_DonationsSingle1_ctlDonationsSingle1_txtOther").value="";}
	if(rB[0].id.indexOf("Regular")!=-1){document.getElementById("MainFramework_DonationsRegular1_ctlDonationsRegular1_txtOther").value="";}
	if(rB[0].id.indexOf("RoundUp")!=-1){document.getElementById("MainFramework_ctl01_ctl00_txtRoundUpOther").value="";}
}

var rB = new Array();
function getRadioList(){
	var inp = document.getElementsByTagName("input");
	var j = 0;
	for(i=0;i<inp.length;i++){
		if(inp[i].id.indexOf("rdoContributionList")!=-1 || inp[i].id.indexOf("rdoRoundUp")!=-1){
			rB[j] = inp[i];
			j++;
		}	
	}
	//alert(rB.length);
}







// RADIO BUTTON TOGGLER

// This script will progressively enhance the forms in the page on which it is embedded
// It will scan forms for fieldsets with the attribute   -   class="container-color-change"
// It attaches an onclick function to any radio buttons inside that fieldset
// Selecting the button, either directly or by its label, will colour in its container and blank the others
// For this to be meaningful, each radio button should be in its own containing element
// This ideally would  be a DIV containing the button and its label
// You can change the selected and unselected colours in the variables below


//define global variables
var arFieldsetsToggling = new Array();
var COLORselected = "#F7F7F7";
var COLORunselected = "#FFF";

//window.onload = fnAttachColorToggle;

//cycle through page links and check class
function fnAttachColorToggle() {
	if(!document.getElementsByTagName) return false;
	var arFieldsets = document.getElementsByTagName("fieldset");

	for (i=0, j=arFieldsets.length; i<j; i++) {

		//if tagged with colorToggle then add it to an array of toggleable elements
		if ((arFieldsets[i].getAttribute("class") == "container-color-change") || (arFieldsets[i].getAttribute("className") == "container-color-change")) {
			arFieldsetsToggling[arFieldsetsToggling.length] = arFieldsets[i];

			//scan for input elements
			var arRadioButtons = arFieldsets[i].getElementsByTagName("input");
			for (ii=0, jj=arRadioButtons.length; ii<jj; ii++) {

				//scan for radio buttons
				if (arRadioButtons[ii].getAttribute("type") == "radio") {

					// colours in the background of the the selected radio button
					if (arRadioButtons[ii].checked) {
						arRadioButtons[ii].parentNode.style.backgroundColor = COLORselected;
					} else {
						arRadioButtons[ii].parentNode.style.backgroundColor = COLORunselected;
					}
					
					arRadioButtons[ii].onclick = function() {

					//cycle up through the parents until the containing fieldset is reach again
					var elFieldset = this.parentNode;

					if (elFieldset.getAttribute("className")) {
						while ((elFieldset.getAttribute("className") == null) || (elFieldset.getAttribute("className") != "container-color-change")) {
							elFieldset = elFieldset.parentNode;
						} //while
					} else {
						while ((elFieldset.getAttribute("class") == null) || (elFieldset.getAttribute("class") != "container-color-change")) {
							elFieldset = elFieldset.parentNode;
						} //while
					} //if

					//turn off the background colours of the other radio button elements

					//scan for input elements
					var arLocalRadioButtons = elFieldset.getElementsByTagName("input");
					for (iii=0, jjj=arLocalRadioButtons.length; iii<jjj; iii++) {

						//scan for radio buttons
						if (arLocalRadioButtons[iii].getAttribute("type") == "radio") {
							arLocalRadioButtons[iii].parentNode.style.backgroundColor = COLORunselected;
						} //if
					} //for
						this.parentNode.style.backgroundColor = COLORselected;
					} //if
				} //if
			} //for
		} //if
	} //for
} //fnAttachColorToggle





