// used in administrator area for editing and viewing/hiding page areas 
function toggleVisibility(e, digit){

 var e=document.getElementById(e);
 var digit=document.getElementById(digit);

  if(e.style.visibility == "visible"){
		e.style.visibility = "hidden";
	  	e.style.display = "none";
  }
  else{
 	  e.style.visibility = "visible";
  	  e.style.display = "";
  }
  
  if(digit.innerHTML =="[+]")
 	digit.innerHTML ="[-]";
  else
	digit.innerHTML ="[+]";
	
	return false;
  
}

// check a form for mandatory fields. Mandatory fields have id's that begin with "m_".
function inputCheck(theform){
var error = new Array();
var x =0;
for (i=0; i<theform.elements.length; i++){
		if (theform.elements[i].type=="text" || theform.elements[i].type=="textarea"){
		 var tempid = theform.elements[i].id;
		 var tempman = tempid.substring(0,2);
				if(tempman == "m_"){

					if (theform.elements[i].value==""){ //if empty field
					
					var idDisplay = capitalSpaces(tempid.substring(2,tempid.length));
					var id = tempid;
					
					error += idDisplay + "\n";
					
					
					x++;
					}
									}
			}
		}
		if(error.length >0){
			alert("You must fill in the following fields \n" + error);
return false;
		}
			
			return true;

}


function capitalSpaces(string){
tmpChar = string.substring(0,1).toUpperCase();
postString = string.substring(1,string.length);
string = tmpChar+postString;
string = string.replace('A', ' A');
string = string.replace('B', ' B');
string = string.replace('C', ' C');
string = string.replace('D', ' D');
string = string.replace('E', ' E');
string = string.replace('F', ' F');
string = string.replace('G', ' G');
string = string.replace('H', ' H');
string = string.replace('I', ' I');
string = string.replace('J', ' J');
string = string.replace('K', ' K');
string = string.replace('L', ' L');
string = string.replace('M', ' M');
string = string.replace('N', ' N');
string = string.replace('O', ' O');
string = string.replace('P', ' P');
string = string.replace('Q', ' Q');
string = string.replace('R', ' R');
string = string.replace('S', ' S');
string = string.replace('T', ' T');
string = string.replace('U', ' U');
string = string.replace('V', ' V');
string = string.replace('W', ' W');
string = string.replace('X', ' X');
string = string.replace('Y', ' Y');
string = string.replace('Z', ' Z');
return string;
}



function toggleClubArea(sel){
		document.getElementById('iusername').value='';
		document.getElementById('ipostcode').value='';
	
	if(sel.options[sel.selectedIndex].value =="uk"){
		document.getElementById('postcodeLogin').style.display = "";
		document.getElementById('usernameLogin').style.display = "none";
	}
	else{
		document.getElementById('postcodeLogin').style.display = "none";
		document.getElementById('usernameLogin').style.display = "";
		
	}
	
}


function showEmailStatus(){
var form = document.getElementById('clubsform');
	for(i=0; i<form.elements.length; i++){
		if(form.elements[i].type=="checkbox"){
			if(form.elements[i].checked){
			document.getElementById('sendEmail').style.display='';
			}
		
		}
		}
	
}


function dropdown(){
	if(document.getElementById('sendmail').checked){
			document.getElementById('dropdown').style.display='';
	}
	else{
				document.getElementById('dropdown').style.display='none';
	
	}
	textareaupdate();
}



function textareaupdate(){
	if(document.getElementById('sendmail').checked){

var selObj = document.getElementById('status');
var div = selObj.options[selObj.selectedIndex].name;
if(!div){
	var div = selObj.options[selObj.selectedIndex].value;
}

div = div.toLowerCase();
var html = document.getElementById(div).innerHTML;

// alert("getting the contents of " + div + " that contains " + html);


tinyMCE.getInstanceById('mce_editor_0').getBody().innerHTML = html;
//tinyMCE.getInstanceById('textarea');
//tinyMCE.setContent('this is test content');

}


}