/*
*  Globals vars and functions for shopping pages
*/
var winOpts = 'scrollbars=yes,width=600,height=400';

var reduced=true;

function zoomImg(pPage) 
{
	popUpWin = window.open(pPage,'popWin',winOpts);
}

function popUp(pPage) 
{
	popUpWin = window.open(pPage,'popWin',winOpts);
}

function toggleDescr(id)
{
    obj = document.getElementById(id);
    if (reduced) 
    {
    	obj.style.height='';
    	obj.style.overflow='';
    	document.getElementById('continua').innerHTML = 'riduci&raquo;';	
    } 
    else 
    {
    	obj.style.height='225px';
    	obj.style.overflow='hidden';
    	document.getElementById('continua').innerHTML = 'continua&raquo;';
		document.getElementById('continua').focus();
    }
    reduced = !reduced;
}

//disableConsensoTrue: vale true se bisogna disabilitare l'informativa
//occhio che il disable non fa passare i valori degli input
//e il readonly non funziona sui radio button (ne' sui checkbox)
//quindi nel caso disabilitiamo solo quello col "true"
function disableConsensoInformativa(disableConsensoTrue, initialConsensoTrueChecked)
{
	var consenso_true = document.getElementById("consenso2_true");
	var consenso_false = document.getElementById("consenso2_false");
	
	//disabilito o no il radio in base al valore passato
	consenso_true.disabled=disableConsensoTrue;
	
	//occhio che vanno checkati/decheckati qui, ma in caso di disabilitazione
	//e' semplice, invece se sto riabilitando allora devo anche considerare il 
	//valore iniziale dal bean (me lo passa la jsp nel param initialConsensoTrueChecked)
	if (disableConsensoTrue){
    	consenso_true.checked  = false;
	    consenso_false.checked = true;
	} else {
    	consenso_true.checked  = initialConsensoTrueChecked;
	    consenso_false.checked = !initialConsensoTrueChecked;
	}
}

function checkboxAsRadio(obj)
{
	var currentElement = obj;
	// alert("LAST checked: " + currentElement.name + "-" + currentElement.value);
	var allCheckboxInCurrentGroup = document.getElementsByName(currentElement.name);
	for(var i = 0; i < allCheckboxInCurrentGroup.length; i++){		
		var elemCheckbox = allCheckboxInCurrentGroup[i];
		// alert("ELEM: " + elemCheckbox.name + "-" +elemCheckbox.value+ "- checked: " + elemCheckbox.checked); 
		if (elemCheckbox.checked && (elemCheckbox.value != currentElement.value)){
			elemCheckbox.checked = false;
		}
	}
}

//Utilità------------------------------------------------------------------------------------------------------------------------------------------------------
//verifica se una stringa ha lunghezza maggiore di 0 e se include almeno un carattere diverso da " "
function StringIsNotBlank(stringValue) {
	if(!stringValue) return false;
	if(stringValue.length <= 0) return false;
	
	// se la stringa stringValue &egrave; composta da soli spazi allora la funzione ritorna false
	for(var i = 0; i < stringValue.length; i++) {
		var ckChar = stringValue.charAt(i);
		if(ckChar != " ") return true;
	}
	
	return false;
}

//controllo per campo ricerca
function SearchKeywordsAreValid(searchField) {
	//verifica se il campo esiste
	if(!searchField) {
		return false;
	}
	
	//effettua il trim del valore del campo di ricerca
	var keywords = searchField.value;	
	while (keywords.substring(0,1) == ' '){
		keywords = keywords.substring(1, keywords.length);
	}
	while (keywords.substring(keywords.length-1, keywords.length) == ' '){
		keywords = keywords.substring(0, keywords.length-1);
	}
	
	//se il campo di ricerca contiene un argomento valido procedi, altrimenti no
	if(keywords.length < 3) {
		alert("Per effettuare una ricerca deve essere specificata almeno una parola di 3 caratteri");
		return false;
	}
	
	return true;
}

