// RAICAM JavaScript Document
// lluis@cresosrl.it

function btn_on(obj){
	obj.style.background = "0 1px url(images/option_hover_bg.gif) repeat-x";
	obj.style.color = "white";
}

function btn_off(obj){
	obj.style.background = "none";
	obj.style.color = "#333";
}

// http://labs.black-tomato.com
function checkForm(form_name,field_list){
    var ff = document[form_name];
    var errors = false;                               
    var fields = field_list.split(",");                                       
    for(var i = 0; i < fields.length; i++){                       
        switch(ff[fields[i]].type){
            case "text":
				if(ff[fields[i]].name == "email"){
					mailreg = ff[fields[i]].value;
					mailreg = mailreg.indexOf('@');
					if (mailreg == -1){
						alert("Attenzione: il conto di email scritto è invalido.");
						errors = true;
					}
				}else{
					if(ff[fields[i]].value == ""){
	                    alert("Il campo "+ff[fields[i]].name+" è obbligatorio.");
	                    errors = true;
	                }//endif	
				}
				break;
            case "textarea":
            case "select-one":
                if(ff[fields[i]].value == ""){
                    alert("Il campo "+ff[fields[i]].name+" è obbligatorio.");
                    errors = true;
                }//endif
                break;
            case "checkbox":
                if(ff[fields[i]].checked == true){
                    alert("Il campo "+ff[fields[i]].name+" è obbligatorio.");
                    errors = true;
                }//endif
                break;
        }//endswitch                           
    }//endfor                   
    if(!errors){
        ff.submit();
    }
}


function change_visivility(theTable) {
	if(document.getElementById(theTable).style.display == 'block'){
		document.getElementById(theTable).style.display = 'none';
	}else{
		document.getElementById(theTable).style.display = 'block';
	}
}