/*
###################### MENU ######################
*/
function currentmenu(ID,AREE){
   
   	var i = 0;
	var ARRAY_AREE = AREE.split('-'); 
	
	while(i < ARRAY_AREE.length){
		if(ARRAY_AREE[i] && ARRAY_AREE[i] != 0){
    		if(ARRAY_AREE[i] == ID){
				document.getElementById('area' + ARRAY_AREE[i]).className = 'current';
    		} else {
				document.getElementById('area' + ARRAY_AREE[i]).className = '';
			}
		}
		i++;
	}
	
	i = 0;
	
	while(i < ARRAY_AREE.length){
		if(ARRAY_AREE[i]){
    		if(ARRAY_AREE[i] == ID){
				document.getElementById('divmenu' + ARRAY_AREE[i]).style.display = 'block';
			} else {
				document.getElementById('divmenu' + ARRAY_AREE[i]).style.display = 'none';
			}
		}
		i++;
	}
	
    return true;
}


/*
###################### TABELLA VISUALIZZA ######################
*/
//evidenzia una riga della tabella visualizza
function seleziona(ID, CLASSNAME){
	if(document.getElementById(ID).className == 'selezionata'){
		document.getElementById(ID).className = CLASSNAME;
	} else {
		document.getElementById(ID).className = 'selezionata';
	}
}

function set_pointer(ID, CLASSNAME){
	if(document.getElementById(ID).className != 'selezionata'){
		document.getElementById(ID).className = CLASSNAME;
	}
}

/*
###################### VARIE ######################
*/

function popup(URL,NOME,WIDTH,HEIGHT,PROPRIETA) {
	if(PROPRIETA == ''){
		PROPRIETA = 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0';
	}
	win = window.open(URL,NOME,PROPRIETA + ',width=' + WIDTH + ',height=' + HEIGHT + '');
	
	//qui ridimensiono il popup...così se lo stesso popup è già aperto gli cambio le dimensioni...
	H = parseInt(HEIGHT) + 59; 
	W = parseInt(WIDTH) + 10;
	win.resizeTo(W,H);
	win.focus();
}
 
//conferma
function conferma(MESSAGGIO, URL){
	if(confirm(MESSAGGIO)) location.href = URL;
}

function submitForm(FORMID, BUTTONID, INPUTID, ACTION, MEX){
	document.getElementById(INPUTID).value = ACTION;
	document.getElementById(BUTTONID).value = MEX;
	document.getElementById(BUTTONID).disabled = true;
	document.getElementById(FORMID).submit();
}

function visualizzaNascondiTr(TRID){
	document.getElementById('visualizzaScheda' + TRID).style.display = (document.getElementById('visualizzaScheda' + TRID).style.display == 'none')?'':'none';
	document.getElementById('nascondiScheda' + TRID).style.display = (document.getElementById('nascondiScheda' + TRID).style.display == 'none')?'':'none';
	document.getElementById('scheda' + TRID).style.display = (document.getElementById('scheda' + TRID).style.display == 'none')?'':'none';
}

function checkTutti(FORM, STATO){
	var form = document.getElementById(FORM);
	for(i = 0 ; i < form.length ; i++){
      	if(form[i].type == 'checkbox'){
	  		form[i].checked = STATO;
		}
	}
}

function showHide(ID){
	if(document.getElementById(ID).style.display == 'inline' || document.getElementById(ID).style.display == 'block'){
		document.getElementById(ID).style.display = 'none';
	} else {
		document.getElementById(ID).style.display = 'block';
	}
}	

function showHide2(ID,ID2){
	if(document.getElementById(ID).style.display == 'inline'){
		document.getElementById(ID).style.display = 'none';
		document.getElementById(ID2).style.display = 'inline';
	} else {
		document.getElementById(ID).style.display = 'inline';
		document.getElementById(ID2).style.display = 'none';
	}
}	


function controllaAcquisto(FORM){
	var form = document.getElementById(FORM);
	var quantita = 0, error = 0;
	for(i = 0 ; i < form.length ; i++){
		if(form[i].type == 'checkbox'){
			quantita = document.getElementById('quantita' + form[i].value).value;
			if(form[i].checked == true){
				//è checcato...controllo la quantità associata...se è != da 0 va bene...
				quantita = document.getElementById('quantita' + form[i].value).value;
    			if(quantita <= 0 || !is_numeric(quantita)){
					error = 1;
    			}
			} else {
				//non è checcato...se ho indicato una quantità c'è un errore...
				if(quantita > 0 && is_numeric(quantita)){
					error = 1;
				}
			}
		}
	}
	if(error == 0){
		form.submit();
	} else {
		alert("Controlla i prodotti selezionati e le quantità indicate");
	}
}


function is_numeric(num){
	var exp = new RegExp("^[0-9-.]*$","g");
	return exp.test(num);
}


function redirectOpener(URL){
	opener.location.href = URL; 
}






// CHECK ALL / UNCHECK ALL
var checkflag = "false";

	function check(field) 
	{
		if (checkflag == "false") {
		
			for (i = 0; i < field.length; i++) {
				field[i].checked = true;
			}
			
		checkflag = "true";		
		return "deseleziona tutto";
		 
		} else {
		
			for (i = 0; i < field.length; i++) {
				field[i].checked = false; 
			}
			
			checkflag = "false";
			return "seleziona tutto"; 
		}
	}
	
	
	
	

	
	function cambioNazione(selectNazione, selectProvincia, inputProvincia){
		//alert(selectNazione);
		var nazione = document.getElementById(selectNazione);
		var provincia = document.getElementById(selectProvincia);
		var provincia2 = document.getElementById(inputProvincia);
		
		if(nazione[nazione.selectedIndex].value == 106){
			provincia.style.display = 'inline';
			provincia2.style.display = 'none';
		} else {
			provincia2.style.display = 'inline';
			provincia.style.display = 'none';
		}
	
	}