var accordionItems = new Array();


function init() {

      // Grab the accordion items from the page
      var divs = document.getElementsByTagName( 'div' );
      for ( var i = 0; i < divs.length; i++ ) {
        if ( divs[i].className == 'photobox' || divs[i].className == 'jreview' || divs[i].className == 'lyrics' || divs[i].className == 'sheets' ) accordionItems.push( divs[i] );
      }


      
    }
    

    
    
function toggleItem(id) {
	
	
	var elem, vis, flag;
  		if( document.getElementById ) // this is the way the standards work
	    elem = document.getElementById( id );
  	else if( document.all ) // this is the way old msie versions work
    	elem = document.all[id];
  	else if( document.layers ) // this is the way nn4 works
    	elem = document.layers[id];
  	vis = elem.style;
	
  	if (vis.display == 'block') flag = 1;
	
	
	// Hide all accordion item bodies except the first
      for ( var i = 0; i < accordionItems.length; i++ ) {
       accordionItems[i].style.display = 'none';
 
      }
      
   	if (flag != 1) showlayer();
      
  
  function showlayer () {
	  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
	}
      
  }
	
    
    
function getFirstChildWithTagName( element, tagName ) {
      for ( var i = 0; i < element.childNodes.length; i++ ) {
        if ( element.childNodes[i].nodeName == tagName ) return element.childNodes[i];
      }
    }

    
function changeselect()
	{
	var mdiv=document.getElementById('subartpublicationothername');
	var ndiv=document.getElementById('subartpublicationothercountry');
	var cdiv=document.getElementById('subartpublication');
	if(cdiv.options[cdiv.selectedIndex].value=='other')
		{
		mdiv.style.display='inline';
		ndiv.style.display='inline';
		}
	else
		{
		mdiv.style.display='none';
		ndiv.style.display='none';
		}
	} 
	
	
	function addgigselect()
	{
	var mdiv=document.getElementById('addgigshowother');
	var cdiv=document.getElementById('addgigshow');
	if(cdiv.options[cdiv.selectedIndex].value=='other')
		{
		mdiv.style.display='inline';
		}
	else
		{
		mdiv.style.display='none';
		}
	} 
	
function addgigselect2()
	{
	var mdiv=document.getElementById('addgigothercountry');
	var cdiv=document.getElementById('addgigcountry');
	if(cdiv.options[cdiv.selectedIndex].value=='other')
		{
		mdiv.style.display='inline';
		}
	else
		{
		mdiv.style.display='none';
		}
	} 
	

function presschangeselect()
	{
	var mdiv=document.getElementById('pressformpublicationother');
	var ndiv=document.getElementById('pressformcountry');
	var cdiv=document.getElementById('pressformpublication');
	if(cdiv.options[cdiv.selectedIndex].value=='1')
		{
		mdiv.style.display='inline';
		ndiv.style.display='inline';
		}
	else
		{
		mdiv.style.display='none';
		ndiv.style.display='none';
		}
	} 
	
 
	
	
function ShowMenu(num, menu, maxi)
{
	for(i = 1; i <= num; i++){
		var menu2 = menu + i;
		document.getElementById(menu2).style.display = 'block';
	}
	var num2 = num; num2++;
	while(num2 <= maxi){
		var menu3 = menu + num2;
		document.getElementById(menu3).style.display = 'none';
		num2=num2+1;
	}
}


function confirmCommentdelete() 
{
	var agree=confirm("Do you wish to delete this comment?");
	if (agree)
		return true ;
	else
		return false ;
}


function reviewdelayer()
{
    window.location = "reviews.php?mode=view&amp;id=<?php echo $redirect_id; ?>"
}


// form validation //

// news //

function checkNewsForm() {
	headline = document.getElementById("newsheadinput").value;
  	story = document.getElementById("newstext").value;
 
  	if (headline == "") {
	  	hideNewsErrors();
		document.getElementById("headlineError").style.display = "block";
		document.getElementById("newsheadinput").select();
		document.getElementById("newsheadinput").focus();
		window.scrollBy(0,-169);
  		return false;
  	}
  	else if (story == "") {
		hideNewsErrors();
		document.getElementById("storyError").style.display = "block";
		document.getElementById("newstext").select();
		document.getElementById("newstext").focus();
		window.scrollBy(0,-169);
  		return false;
  	} 
  	return true;
}
 
function hideNewsErrors() {
	document.getElementById("storyError").style.display = "none"
	document.getElementById("headlineError").style.display = "none"
}


// gigs //

function checkGigsForm() {
	day = document.getElementById("gigformday").value;
  	month = document.getElementById("gigformmonth").value;
  	year = document.getElementById("gigformyear").value;
  	show = document.getElementById("addgigshow").value;
  	othershow = document.getElementById("addgigshowother").value;
  	venue = document.getElementById("addgigvenue").value;
  	town = document.getElementById("addgigtown").value;
  	country = document.getElementById("addgigcountry").value;
  	othercountry = document.getElementById("addgigothercountry").value;
 
  	if (day == "" || month == "" || year =="") {
	  	hideGigsErrors();
		document.getElementById("dateError").style.display = "block";
		document.getElementById("gigformday").focus();
		window.scrollBy(0,-169);
  		return false;
  	}
  	else if (show == "" || (show == "Other" && othershow == "")) {
		hideGigsErrors();
		document.getElementById("showError").style.display = "block";
		document.getElementById("addgigshow").focus();
		window.scrollBy(0,-169);
  		return false;
  	} 
  	else if (venue == "") {
		hideGigsErrors();
		document.getElementById("venueError").style.display = "block";
		document.getElementById("addgigvenue").select();
		document.getElementById("addgigvenue").focus();
		window.scrollBy(0,-169);
  		return false;
  	}
  	else if (town == "") {
		hideGigsErrors();
		document.getElementById("townError").style.display = "block";
		document.getElementById("addgigtown").select();
		document.getElementById("addgigtown").focus();
		window.scrollBy(0,-169);
  		return false;
  	} 
  	else if (country == "" || (country == "Other" && othercountry == "")) {
		hideGigsErrors();
		document.getElementById("countryError").style.display = "block";
		document.getElementById("addgigcountry").focus();
		window.scrollBy(0,-169);
  		return false;
  	} 
  	
  	return true;
}
 
function hideGigsErrors() {
	document.getElementById("dateError").style.display = "none";
	document.getElementById("venueError").style.display = "none";
	document.getElementById("showError").style.display = "none";
	document.getElementById("townError").style.display = "none";
	document.getElementById("countryError").style.display = "none";
}

// sheet music //

function checkSheetForm() {
	song = document.getElementById("sheetselect").value;
  	file = document.getElementById("sheetupload").value;
 
  	if (song == "") {
	  	hideSheetErrors();
		document.getElementById("songError").style.display = "block";
		document.getElementById("sheetselect").focus();
		window.scrollBy(0,-169);
  		return false;
  	}
  	else if (file == "") {
		hideSheetErrors();
		document.getElementById("fileError").style.display = "block";
		window.scrollBy(0,-169);
  		return false;
  	} 
  	return true;
}
 
function hideSheetErrors() {
	document.getElementById("songError").style.display = "none"
	document.getElementById("fileError").style.display = "none"
}

// photo upload //

function checkPhotoForm() {
	show = document.getElementById("photoselect").value;
  	photo1 = document.getElementById("photo1").value;
  	photo2 = document.getElementById("photo2").value;
  	photo3 = document.getElementById("photo3").value;
  	photo4 = document.getElementById("photo4").value;
 	photo5 = document.getElementById("photo5").value;
 
  	
 	if (show != "" && (photo1 != "" || photo2 != "" || photo3 != "" || photo4 !="" || photo5 != "")) {
 		return true;
	}
	else {
	 	if (show == "") {
	  		hidePhotoErrors();
			document.getElementById("showError").style.display = "block";
			document.getElementById("photoselect").focus();
			window.scrollBy(0,-169);
  			return false;
  		}
  		else {
			hidePhotoErrors();
			document.getElementById("fileError").style.display = "block";
			window.scrollBy(0,-169);
  			return false;
  		}
	} 
}
 
function hidePhotoErrors() {
	document.getElementById("showError").style.display = "none"
	document.getElementById("fileError").style.display = "none"
}

// reviews //

function checkReviewForm() {
	mytitle = document.getElementById("revtitleinput").value;
  	review = document.getElementById("reviewtext").value;
  	show = document.getElementById("reviewselect").value;
 
  	if (show == "") {
	  	hideReviewErrors();
		document.getElementById("showError").style.display = "block";
		document.getElementById("reviewselect").focus();
		window.scrollBy(0,-169);
  		return false;
  	}
  	else if (mytitle == "") {
		hideReviewErrors();
		document.getElementById("titleError").style.display = "block";
		document.getElementById("revtitleinput").select();
		document.getElementById("revtitleinput").focus();
		window.scrollBy(0,-169);
  		return false;
  	} 
  	else if (review == "") {
		hideReviewErrors();
		document.getElementById("reviewError").style.display = "block";
		document.getElementById("reviewtext").select();
		document.getElementById("reviewtext").focus();
		window.scrollBy(0,-169);
  		return false;
  	} 
  	return true;
}
 
function hideReviewErrors() {
	document.getElementById("showError").style.display = "none"
	document.getElementById("titleError").style.display = "none"
	document.getElementById("reviewError").style.display = "none"
}

// press //

function checkPForm() {
	var day = document.getElementById("pressformday").value;
  	var month = document.getElementById("pressformmonth").value;
  	var year = document.getElementById("pressformyear").value;
  	var headline = document.getElementById("pressformheadline").value;
  	var pub = document.getElementById("pressformpublication").value;
  	var mytype = document.getElementById("pressformtype").value;
  	var article = document.getElementById("pressformarticle").value;
  	var mysource = document.getElementById("pressformsource").value;
 
  	if (day == "" || month == "" || year =="") {
	  	hidePressErrors();
		document.getElementById("dateError").style.display = "block";
		document.getElementById("pressformday").focus();
		window.scrollBy(0,-169);
  		return false;
  	}
  	else if (headline == "") {
	  	hidePressErrors();
		document.getElementById("headlineError").style.display = "block";
		document.getElementById("pressformheadline").focus();
		document.getElementById("pressformheadline").select();
		window.scrollBy(0,-169);
  		return false;
	}
	else if (pub == "") {
		hidePressErrors();
		document.getElementById("pubError").style.display = "block";
		document.getElementById("pressformpublication").focus();
		window.scrollBy(0,-169);
  		return false;
	}
	else if (mytype == "") {
		hidePressErrors();
		document.getElementById("typeError").style.display = "block";
		document.getElementById("pressformtype").focus();
		window.scrollBy(0,-169);
  		return false;
	}
	else if (article == "") {
		hidePressErrors();
		document.getElementById("articleError").style.display = "block";
		document.getElementById("pressformarticle").focus();
		document.getElementById("pressformarticle").select();
		window.scrollBy(0,-169);
  		return false;
	}
	else if (mysource == "") {
		hidePressErrors();
		document.getElementById("sourceError").style.display = "block";
		document.getElementById("pressformsource").focus();
		document.getElementById("pressformsource").select();
		window.scrollBy(0,-169);
  		return false;
	}
  	
  	
  	return true;
}
 
function hidePressErrors() {
	document.getElementById("dateError").style.display = "none";
	document.getElementById("headlineError").style.display = "none";
	document.getElementById("pubError").style.display = "none";
	document.getElementById("typeError").style.display = "none";
	document.getElementById("articleError").style.display = "none";
	document.getElementById("sourceError").style.display = "none";
}
