// JavaScript Document

/*
	Copyright Robert Nyman, http://www.robertnyman.com
	Free to use if this text is included
*/
function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\s)" + strAttributeValue + "(\s|$)") : null;
	var oCurrent;
	var oAttribute;
	for(var i=0; i<arrElements.length; i++){
		oCurrent = arrElements[i];
		oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
		if(typeof oAttribute == "string" && oAttribute.length > 0){
			if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
				arrReturnElements.push(oCurrent);
			}
		}
	}
	return arrReturnElements;
}


//Custom by seed - Luca Botturi

function checkLanguage(checkItem){
//creates an array of selected languages
	var lang_arr = new Array();
		if(document.forms[0].en.checked==true) lang_arr.push("en");
		if(document.forms[0].fr.checked==true) lang_arr.push("fr");
		if(document.forms[0].es.checked==true) lang_arr.push("es");
//sets the default return value as false
	var checkValue = false;
//checks if the item is of one of the languages in the array
	for(k=0; k<lang_arr.length; k++){
		if(checkItem.lang==lang_arr[k]) checkValue=true;
		}
	//alert(checkValue);		
	return checkValue
} //end of function


function displayUpdate(iLang){
//Creates a variable to control that at least 1 document and 1 section is shown
	var atLeastOneDoc = false;
	var atLeastOneSec = false;
//CHECKS FOR DOCUMENT TYPES
	//creates array for types of media
		var cp_arr = getElementsByAttribute(document.body, "div", "name", "cp");
		var pdf_arr = getElementsByAttribute(document.body, "div", "name", "pdf");
		var vid_arr = getElementsByAttribute(document.body, "div", "name", "video");
		var aud_arr = getElementsByAttribute(document.body, "div", "name", "audio");
		var doc_arr = getElementsByAttribute(document.body, "div", "name", "doc");
		
		//cp
		for(i=0; i<cp_arr.length; i++){ 
			if(document.forms[0].cp.checked!=true || !checkLanguage(cp_arr[i])) cp_arr[i].className="invisible"; 
			else {
				cp_arr[i].className="visible";
				atLeastOneDoc = true;
				}
			}	
		//pdf
		for(i=0; i<pdf_arr.length; i++){ 
			if(document.forms[0].pdf.checked!=true || !checkLanguage(pdf_arr[i])) pdf_arr[i].className="invisible"; 
			else {
				pdf_arr[i].className="visible"; 
				atLeastOneDoc = true;
				}
			}
		//video
		for(i=0; i<vid_arr.length; i++){ 
			if(document.forms[0].vid.checked!=true || !checkLanguage(vid_arr[i])) vid_arr[i].className="invisible"; 
			else {
				vid_arr[i].className="visible"; 
				atLeastOneDoc = true;
				}
			}
		//audio
		for(i=0; i<aud_arr.length; i++){ 
			if(document.forms[0].aud.checked!=true || !checkLanguage(aud_arr[i])) aud_arr[i].className="invisible"; 
			else {
				aud_arr[i].className="visible"; 
				atLeastOneDoc = true;
				}
			}
		//other docs
		for(i=0; i<doc_arr.length; i++){ 
			if(document.forms[0].doc.checked!=true || !checkLanguage(doc_arr[i])) doc_arr[i].className="invisible"; 
			else {
				doc_arr[i].className="visible"; 
				atLeastOneDoc = true;
				}
			}

//CHECKS FOR COUNTRY BLOCKS
	//GENERAL	
	if(document.forms[0].gene.checked!=true) {
		document.getElementById("box_gene").className="invisible";
		}
	else {
		document.getElementById("box_gene").className="visible";
		atLeastOneSec = true;
		}
	
	//BOLIVIA	
	if(document.forms[0].boli.checked!=true) {
		document.getElementById("box_boli").className="invisible";
		}
	else {
		document.getElementById("box_boli").className="visible";
		atLeastOneSec = true;
		}
		
	//INDIA
	if(document.forms[0].indi.checked!=true) {
		document.getElementById("box_indi").className="invisible";
		}
	else {
		document.getElementById("box_indi").className="visible";
		atLeastOneSec = true;
		}
	//MALI
	if(document.forms[0].mali.checked!=true) {
		document.getElementById("box_mali").className="invisible";
		}
	else {
		document.getElementById("box_mali").className="visible";
		atLeastOneSec = true;
		}
	
	//alert(atLeastOneDoc);
	//alert(atLeastOneSec);
	//1=en 2=fr 3=es
	var fdbck ="<p><i>";
	//alert(iLang);
	if(!atLeastOneDoc || !atLeastOneSec) {
		if(iLang==2) fdbck +="S.v.p. sélectionnez une combinaison (au moins une par colonne)."; 
		else if(iLang==3) fdbck +="P.f. escojan una combinación (por lo menos una por columna).";
		else fdbck +="Please select a combination (at least one in each column).";		
		}
	
//	if(!atLeastOneSec) {
	//	if(iLang==2) fdbck +="At least one country block should be selected.<br>";
	//	else if(iLang==3) fdbck +="At least one country block should be selected.<br>";
	//	else fdbck +="At least one country block should be selected.<br>";
	//	}
		
	fdbck += "</i></p>"
	//alert(fdbck);
	document.getElementById("feedback").innerHTML=fdbck;

} //end of function


function showFolder(folder){
	if(document.getElementById(folder).className=="invisible folder"){
		document.getElementById(folder).className="visible folder";
		}
	else document.getElementById(folder).className="invisible folder";
	} //end of function