// prefissi dei nomi dei controlli nella matrice <controls>
var _text = "txt_";
var _label = "lbl_"

// contiene i nomi dei controlli da validare
controls = new Array();

// popup per testo sql
var sqlDebug = new Boolean();
sqlDebug = true;


function controlStatus(label, text){
    //alert(label + "   " + text);
    if (document.getElementById(text).value != "") {
        document.getElementById(text).style.background = "white";
        document.getElementById(label).style.color = "black";
    }
}

/**
 * Valida tutti i controlli della form contenuti nell' array <controls>
 * ad ogni item a run-time per ottenere il riferimento del controllo viene
 * anteposto il prefisso "txt_" per coloro che sono editabili e "lbl_" per le label
 */
function isValidForm(){
    var head = new String();
    var errCampi = new String();
    var boolRet = true;
	var nomeControllo = new String();

    head = "Campi obbligatori: " + "\n\n";

    for (i = 0; i < controls.length; i++) {
		
		nomeControllo = _text + controls[i];

		if (document.getElementById(nomeControllo) != null) {	
			if (document.getElementById(nomeControllo).value == "") {
				if (boolRet) {
					// coloro la label di rosso
					document.getElementById(_label + controls[i]).style.color = "red";
					// imposto il focus sul controllo da fillare
					document.getElementById(_text + controls[i]).focus();
					document.getElementById(_text + controls[i]).style.background = "yellow";
				}
				errCampi = errCampi + controls[i] + "\n";
				boolRet = false;
			}
		}
    }
	
    if (!boolRet) {
    	alert(head + errCampi);
		return boolRet;
    }
}


// permette di inserire solo numeri in un controllo 
function soloNum(obj){
	
	var o = obj;
    var s = obj.value;
	var lblName = new String();
	
	lblName = obj.id;
	lblName = lblName.replace("txt", "lbl");	
	
    if (isNaN(s)) {
	   alert("Il controllo accetta solo numerici");
	   obj.value = "0";
	   obj.select();
	   obj.focus();
	   obj.style.background = "yellow";

    }
}


// conta i caratteri di un controllo 
function conta(obj, lenMax){

	var val = new String();
	var truncate = new String();
	val = obj.value;
	var total = obj.value.length;
	var code;
	
	if (total > 0) {
		code = val.charCodeAt(total - 1);
	
	}
	
	if (total > lenMax) {
		truncated = val.substr(0, lenMax);
		obj.value = truncated;
		//obj.style.background = "yellow"
	}else{
		//obj.style.background = "white";
	}
}
function evtConta(id, s){
	var obj = document.getElementById(id);
	if (obj.addEventListener) 
	    obj.addEventListener("click", HelloWorld, false);
	else 
	    if (btn.attachEvent) 
	        btn.attachEvent("onclick", HelloWorld);
}

            
function winSql(sql, tabella){
	window.location.href = "VIEW_TABELLA.asp?tabella=" + tabella;
    
	if(sqlDebug){
		myWin=window.open('','','width=500, height=50, resizable=1, scrollbars=1, status=1');
		var tmp = myWin.document;
		tmp.write(sql);
		tmp.close();
		myWin.focus();		
	}
}


		


function getMese(numMese, boolContratto){
	switch(numMese){
		case 0:
			if(boolContratto)
				return "GEN";
			else	
				return "GENNAIO";
		case 1:
			if(boolContratto)
				return "FEB";
			else
				return "FEBBRAIO";
		case 2:
			if(boolContratto)
				return "MAR";					
			else
				return "MARZO"
		case 3:
			if(boolContratto)		
				return "APR";
			else	
				return "APRILE";
		case 4:
			if(boolContratto)		
				return "MAG";
			else
				return "MAGGIO";
		case 5:
			if(boolContratto)		
				return "GIU";
			else	
				return "GIUGNO";
		case 6:
			if(boolContratto)		
				return "LUG";
			else	
				return "LUGlIO";
		case 7:
			if(boolContratto)			
				return "AGO";
			else	
				return "AGOSTO";
		case 8:
			if(boolContratto)		
				return "SET";																		
			else	
				return "SETTE7MBRE";
		case 9:
			if(boolContratto)		
				return "OTT";
			else
				return "OTTOBRE";
		case 10:
			if(boolContratto)		
				return "NOV";
			else
				return "NOVEMBRE";
		case 11:
			if(boolContratto)				
				return "DIC";									
			else
				return "DICEMBRE";
	}
}

function onChangeCombo(url, id){
	if(id != ""){	
		window.location.href= url + id;
	}
	
}
