var INPUTCOLOR = "#b3c2ca"; //colore del bordo dell'input di default var GIORNI = Array("lun","mar","mer","gio","ven","sab","dom"); var REGBR = new RegExp("
","g"); var ADDALERT = false; // Eventi nella pagina function addEvent(obj, evType, fn){ if (obj.addEventListener){ obj.addEventListener(evType, fn, true); return true; } else if (obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r; } else { return false; } } //------------------------------------------------------------ // Trasforma i campi di un form in un uri function buildUri(obj){ var strUri = ""; for(var n=0; n= 0) return true; return false; } } function convDate(data){ dummy2 = data.split("-").reverse().join("-"); return dummy2; } function controlField(nome,id,id2,tipo){ switch(tipo){ case "_": // controlla se il campo = vuoto if(document.getElementById(id).value == false){ alertWinScroll(id, 400, ""+nome+": campo mancante"); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF9900"; return false; }else{ return true; } break; case "__": // controlla se il campo = vuoto con "" if(document.getElementById(id).value == ""){ alertWinScroll(id, 400, ""+nome+": campo mancante"); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF9900"; return false; }else{ return true; } break; case "@": // controlla la validita del campo mail if(!indirizzoEmailValido(document.getElementById(id).value)){ alertWinScroll(id, 400, ""+nome+": formato non valido"); document.getElementById(id).style.border = "1px solid #FF9900"; document.getElementById(id).focus(); return false; }else{ return true; } break; case "=": // confronta due campi if(document.getElementById(id).value != document.getElementById(id2).value){ //alertWin("Le "+nome+" non Coincidono"); alertWinScroll(id, 400, ""+nome+": non coincidenti"); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF9900"; document.getElementById(id2).value = ""; return false; }else{ return true; } break; case "h": // controlla se il campo hidden = vuoto if(document.getElementById(id2).value == false){ alertWinScroll(id, 400, ""+nome+": campo mancante"); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF9900"; return false; }else{ return true; } break; case "hS": // controlla se il campo autoSuggest = vuoto if(document.getElementById(id2).value == ""){ if(document.getElementById(id).value == false){ alertWinScroll(id, 400, ""+nome+": campo mancante"); }else{ alertWinScroll(id, 400, ""+nome+": non presente tra i dati disponibili"); } document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF0000"; return false; }else{ return true; } break; case "c": // controlla se il campo e' piu' lungo di un tot if(document.getElementById(id).value.length > id2){ var c = "caratteri"; if(id2==1) c = "carattere"; alertWinScroll(id, 400, ""+nome+": il campo deve contenere un massimo di "+id2+" "+c); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF9900"; return false; }else{ return true; } break; case "c<": // controlla se il campo e' piu' corto di un tot if(document.getElementById(id).value.length < id2){ alertWinScroll(id, 400, ""+nome+": lunghezza minima " +id2+ " caratteri"); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF0000"; return false; }else{ return true; } break; case "n=": // controlla se il campo e' lungo n if(document.getElementById(id).value.length != id2){ var c = "caratteri"; if(id2==1) c = "carattere"; alertWinScroll(id, 400, ""+nome+": il campo deve contenere " +id2+ " "+c); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF0000"; return false; }else{ return true; } break; case "n": // controlla se il campo e' un numero if(isNaN(document.getElementById(id).value.replace(',','.'))){ alertWin(nome+": il campo deve contenere solo numeri"); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF0000"; return false; }else{ return true; } case "v<": // controlla se il valore del campo e' < di tot if(parseInt(document.getElementById(id).value)>id2){ alertWin(nome+": il valore del campo deve essere inferiore a "+id2); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF0000"; return false; }else{ return true; } case "v>": // controlla se il valore del campo e' > di tot if(parseInt(document.getElementById(id).value)=": // controlla se il valore del campo e' >= di tot if(parseInt(document.getElementById(id).value)= del I if(convDate(document.getElementById(id).value)>convDate(document.getElementById(id2).value)){ alertWin(nome+": il campo deve essere superiore o uguale al precedente"); document.getElementById(id2).focus(); document.getElementById(id2).style.border = "1px solid #FF0000"; return false; }else{ return true; } break; case "doc": // controllo se il file = un doc obj = document.getElementById(id); var extensions = new Array(); extensions[1] = "doc"; extensions[0] = "docx"; extensions[2] = "pdf"; extensions[3] = "rtf"; /*extensions[4] = "bmp";*/ var image_file = obj.value; var image_length = image_file.length; var pos = image_file.lastIndexOf('.') + 1; var ext = image_file.substring(pos, image_length); var final_ext = ext.toLowerCase(); for (i = 0; i < extensions.length; i++){ if(extensions[i] == final_ext){ return true; } } alertWinScroll(id, 400, ""+nome+": formato non valido"); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF9900"; return false; break; case "img": // controllo se il file = una img obj = document.getElementById(id); var extensions = new Array(); extensions[1] = "jpg"; extensions[0] = "jpeg"; extensions[2] = "gif"; extensions[3] = "png"; /*extensions[4] = "bmp";*/ var image_file = obj.value; var image_length = image_file.length; var pos = image_file.lastIndexOf('.') + 1; var ext = image_file.substring(pos, image_length); var final_ext = ext.toLowerCase(); for (i = 0; i < extensions.length; i++){ if(extensions[i] == final_ext){ return true; } } alertWin("Seleziona un'immagine con una delle seguenti estensioni:\n\n gif, jpeg, jpg"); return false; break; default: alertWin("tipo non riconosciuto"); return false; } } function normalizeCampo(obj){ obj.style.borderColor = INPUTCOLOR; } function viewMex(mex){ sc = document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset || 0;//document.documentElement.scrollTop; dTop = sc+200; document.getElementById('loader').innerHTML = "
 "+mex+"
"; document.getElementById('loader').style.top = dTop+"px"; document.getElementById('loader').style.display = "block"; } function alertWin(mex){ sc = document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset || 0; dTop = sc+200; sx = (window.screen.width - 20)/2 - 200; if(sx <0) sx = 0; document.getElementById('win').innerHTML = '
'+ '
'+ ''+ ''+ '
'+ '
'+ '
'+ '
'+mex+'
'+ '
'+ '
'; document.getElementById('win').style.top = dTop+"px"; document.getElementById('win').style.left = sx+"px"; document.getElementById('win').style.display = "block"; setTimeout("jQuery('#win').fadeOut();",3000); } function hideWin(){ document.getElementById('win').style.display = "none"; document.getElementById('win').innerHTML = ""; } function hideMex(cont,dbg){ if(dbg){ document.getElementById('loader').innerHTML = cont; }else{ document.getElementById('loader').style.display = "none"; document.getElementById('loader').innerHTML = ""; } } function hideMex(cont,dbg){ if(dbg){ document.getElementById('loader').innerHTML = cont; }else{ document.getElementById('loader').style.display = "none"; document.getElementById('loader').innerHTML = ""; } } function ctrlKey(e,o){ if(e.keyCode==13) document.getElementById(o).click(); } function getPosX(obj) { var curleft = 0; if (obj.offsetParent) { while (obj.offsetParent) { curleft += obj.offsetLeft obj = obj.offsetParent; } } else if (obj.x) curleft += obj.x; return curleft; } function getPosY(obj) { var curtop = 0; if (obj.offsetParent) { while (obj.offsetParent) { curtop += obj.offsetTop obj = obj.offsetParent; } } else if (obj.y) curtop += obj.y; return curtop; } function openDivEvent(w,urlAj,corrX,corrY,doEvent){ this.win = document.getElementById('win'); xx = corrX;//getPosX(document.getElementById(idOpen))+corrX; sc = document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset || 0;//document.documentElement.scrollTop; yy = corrY+sc;//getPosY(document.getElementById(idOpen))+corrY+document.body.scrollTop; win.style.width = w+"px"; viewMex("Caricamento in corso..."); myajax.post(urlAj,""); myajax.echoFunction=function(response){ hideMex(response,0); if(win.style.display !="block"){ win.style.top=yy+"px"; win.style.left=xx+"px"; } win.innerHTML = response; win.style.display="block"; Drag.init(document.getElementById("handle"),document.getElementById('win')); doEvent(); } } function loadDivContent(obj,urlAj,uriAj,doEvent,dbg){ obj = document.getElementById(obj); viewMex("Caricamento in corso..."); myajax.post(urlAj,uriAj); myajax.echoFunction=function(response){ hideMex(response,dbg); obj.innerHTML = response; doEvent(); } } function openSelect(w,h,idName,idValue,urlAj,corrX,corrY,multi,any){ this.win = document.getElementById('select'); //selIds = ""; selIds = document.getElementById(idValue).value; selNames = document.getElementById(idName).value; if(!multi){ document.onmouseup=function(e){ e = e || window.event; trg = e.srcElement || e.target; if(trg.id!="select"){ document.getElementById('select').style.display='none'; document.onmouseup=''; } } }else { //selIds = document.getElementById(idValue).value; } xx = getPosX(document.getElementById(idName))+corrX; yy = getPosY(document.getElementById(idName))+corrY; win.style.width = w+"px"; win.style.height = h+"px"; win.style.overflow = "auto"; viewMex("Caricamento in corso..."); myajax.post(urlAj,'idName='+idName+'&idValue='+escape(idValue)+'&multi='+multi+'&any='+any+'&selIds='+selIds+'&selNames='+escape(selNames)); myajax.echoFunction=function(response){ hideMex(response,0); win.style.top=yy+"px"; win.style.left=xx+"px"; win.style.textAlign = "left"; win.innerHTML = response; win.style.display="block"; } } function openSelectEvent(w,h,idName,idValue,urlAj,corrX,corrY,multi,any,doEvent){ this.win = document.getElementById('select'); selIds = ""; if(!multi){ document.onmouseup=function(){ document.getElementById('select').style.display='none'; document.onmouseup=''; } }else { selIds = document.getElementById(idValue).value; } xx = getPosX(document.getElementById(idName))+corrX; yy = getPosY(document.getElementById(idName))+corrY; win.style.width = w+"px"; win.style.height = h+"px"; win.style.overflow = "auto"; viewMex("Caricamento in corso..."); myajax.post(urlAj,'idName='+idName+'&idValue='+escape(idValue)+'&multi='+multi+'&any='+any+'&selIds='+selIds); myajax.echoFunction=function(response){ hideMex(response,0); win.style.top=yy+"px"; win.style.left=xx+"px"; win.style.textAlign = "left"; win.innerHTML = response; win.style.display="block"; doEvent(); } } function setControl(val, obj){ var parentObj = obj.parentNode.childNodes; for(i=0; i