var needToConfirm = false; window.onbeforeunload = confirmExit; function controlModificat() { needToConfirm = true; } function obteValor (frmElem) { var stmce = frmElem.getAttribute("sviewtype"); if (stmce == null) return sValor = frmElem.value; if (stmce == "tinymce") { var sid = frmElem.getAttribute("id"); var tmce = tinyMCE.getInstanceById(sid); return tmce!= null ? tmce.getHTML() : frmElem.value; } } function confirmExit() { window.focus(); if (typeof(confirmationDisabled) != "undefined") { if (confirmationDisabled) return; } if (needToConfirm) { return 'Il formulario è stato modificato. Se selezioni l’opzione Accettare, perderai i dati; se selezioni l’opzione Cancellare, continuerai nella stessa pagina'; } } function js2wddx( obj ) { wddxSerializer = new WddxSerializer(); return wddxSerializer.serialize(obj); } function validaForm(oForm) { var sValor = ''; var aInterfaces = new Object(); var bValidaNomesPlens = arguments.length>1?arguments[1]:false; for( var ivf = 0; ivf 1 ) { var sValor = ''; var sTextValor = ''; var sAtribut = ''; if (aPartsNomCamp[aPartsNomCamp.length-2] == 'AtributData') { sValor = oForm.elements[ivf].options[oForm.elements[ivf].selectedIndex].value; var sInterface = aPartsNomCamp[0]; for ( var isp = 1; isp < aPartsNomCamp.length-3; isp++) sInterface += "_" + aPartsNomCamp[isp]; sAtribut = aPartsNomCamp[isp]; if ( ! aInterfaces[sInterface] ) { aInterfaces[sInterface] = new Object(); } if ( ! aInterfaces[sInterface][sAtribut.toLowerCase()] ) { aInterfaces[sInterface][sAtribut.toLowerCase()] = "01/01/1800"; } var iDia = aInterfaces[sInterface][sAtribut.toLowerCase()].split("/")[0]; var iMes = aInterfaces[sInterface][sAtribut.toLowerCase()].split("/")[1]; var iAny = aInterfaces[sInterface][sAtribut.toLowerCase()].split("/")[2]; switch (aPartsNomCamp[aPartsNomCamp.length-1]) { case 'iDia' : iDia = sValor.length<2?'0'+sValor:sValor; break; case 'iMes' : iMes = sValor.length<2?'0'+sValor:sValor; break; case 'iAny' : iAny = sValor>999?sValor:1900+parseInt(sValor); iAny = sValor<0?sValor:iAny; break; } aInterfaces[sInterface][sAtribut.toLowerCase()] = iDia + "/" + iMes + "/" + iAny; } else { if (oForm.elements[ivf].tagName.toLowerCase() == 'select') { if (aPartsNomCamp[aPartsNomCamp.length-1] == 'LlistaDoble1') { continue; } for (var i=0; i < oForm.elements[ivf].options.length; i++) { if ( (oForm.elements[ivf].options[i].value < 0) && (oForm.elements[ivf].options[i].selected) ) { oForm.elements[ivf].options[i].selected = false; } else if (oForm.elements[ivf].options[i].selected || ((aPartsNomCamp[aPartsNomCamp.length-1] == 'LlistaDoble2') && (oForm.elements[ivf].options[i].value > 0))) { sValor = sValor + "," + oForm.elements[ivf].options[i].value; sTextValor = sTextValor + "," + oForm.elements[ivf].options[i].innerHTML; } } sValor = sValor.substr(1, sValor.length-1); sTextValor = sTextValor.substr(1, sTextValor.length-1); } else if (oForm.elements[ivf].type && oForm.elements[ivf].type.toLowerCase() == 'radio') { var sInt = aPartsNomCamp[0]; for ( var isp = 1; isp < aPartsNomCamp.length-1; isp++) sInt += "_" + aPartsNomCamp[isp]; sAtribut = aPartsNomCamp[isp]; if (oForm.elements[ivf].checked) { sValor = oForm.elements[ivf].value; } else { if( !aInterfaces[sInt] || aInterfaces[sInt][sAtribut.toLowerCase()]=='' ) { sValor = ''; } else { if ( typeof(aInterfaces[sInt][sAtribut.toLowerCase()]) != 'undefined' ) sValor = aInterfaces[sInt][sAtribut.toLowerCase()]; else sValor = ''; } } } else if (oForm.elements[ivf].type && oForm.elements[ivf].type.toLowerCase() == 'checkbox') { if (aPartsNomCamp[aPartsNomCamp.length-1].substr(0,1) == 'b') { sValor = oForm.elements[ivf].checked?1:0; } else { var sInterface = aPartsNomCamp[0]; for ( var isp = 1; isp < aPartsNomCamp.length-1; isp++) sInterface += "_" + aPartsNomCamp[isp]; sAtribut = aPartsNomCamp[isp]; if (oForm.elements[ivf].checked) { if (typeof(aInterfaces[sInterface])!='undefined') if (typeof(aInterfaces[sInterface][sAtribut.toLowerCase()])=='undefined' || aInterfaces[sInterface][sAtribut.toLowerCase()] == -1) sValor = oForm.elements[ivf].value; else sValor = aInterfaces[sInterface][sAtribut.toLowerCase()] + "," + oForm.elements[ivf].value; else sValor = oForm.elements[ivf].value; } else if (typeof(aInterfaces[sInterface])=='undefined' || typeof(aInterfaces[sInterface][sAtribut.toLowerCase()])=='undefined') sValor = ''; else sValor = aInterfaces[sInterface][sAtribut.toLowerCase()]; } } else sValor = obteValor (oForm.elements[ivf]); var sInterface = aPartsNomCamp[0]; if ( aPartsNomCamp[aPartsNomCamp.length-1] == 'LlistaDoble2' ) aPartsNomCamp.splice(aPartsNomCamp.length-1,1); for ( var isp = 1; isp < aPartsNomCamp.length-1; isp++) sInterface += "_" + aPartsNomCamp[isp]; sAtribut = aPartsNomCamp[isp]; if ( ! aInterfaces[sInterface] ) { aInterfaces[sInterface] = new Object(); } if (typeof(document.getElementsByName(sInterface + '_' + sAtribut)) != 'undefined' && document.getElementsByName(sInterface + '_' + sAtribut).length > 0 && document.getElementsByName(sInterface + '_' + sAtribut)[0].tagName.toUpperCase() == 'INPUT' && (document.getElementsByName(sInterface + '_' + sAtribut)[0].getAttribute('type').toUpperCase() == 'RADIO' || document.getElementsByName(sInterface + '_' + sAtribut)[0].getAttribute('type').toUpperCase() == 'CHECKBOX')) { aInterfaces[sInterface][sAtribut.toLowerCase()] = sValor; aInterfaces[sInterface]["ord_" + sAtribut.toLowerCase()] = ivf; if (sTextValor != '') { aInterfaces[sInterface][sAtribut.toLowerCase().replace('iid','snom')] = sTextValor; } } else { if (typeof(aInterfaces[sInterface][sAtribut.toLowerCase().replace('iid','snom')]) == 'undefined') { aInterfaces[sInterface][sAtribut.toLowerCase()] = sValor; aInterfaces[sInterface]["ord_" + sAtribut.toLowerCase()] = ivf; if (sTextValor != '') { aInterfaces[sInterface][sAtribut.toLowerCase().replace('iid','snom')] = sTextValor; } } } } } } // contendr� informaci�n sobre el primer campo con errores que encuentra var sRetorn = new Array(); sRetorn['sInterface'] = aInterfaces; sRetorn['sCampError'] = ''; sRetorn['iOrdre'] = ''; for ( var interfaceij in aInterfaces ) { if ( eval('typeof(valida' + interfaceij +')') == 'function' ) { var sObjValidat = eval( 'valida' + interfaceij + '(aInterfaces[interfaceij], bValidaNomesPlens)' ); var sCampError = ''; var sMissatge = sObjValidat.sMissatge; if (typeof(sMissatge) != 'undefined' && sMissatge!='') { sCampError = sObjValidat.sNom; } else { sCampError = ''; } } else { var sCampError = ''; } if (sCampError != '') { var sNomCampInterface = sCampError.split("_")[sCampError.split("_").length-1].toLowerCase(); var iOrdre = aInterfaces[interfaceij]["ord_" + sNomCampInterface]; if (!eval("oForm." + sCampError ) ) { if (eval("oForm." + sCampError + "_AtributData_iDia")) sCampError += "_AtributData_iDia"; else if (eval( "oForm." + sCampError + "_AtributData_iMes")) sCampError += "_AtributData_iMes"; else if (eval( "oForm." + sCampError + "_AtributData_iAny")) sCampError += "_AtributData_iAny"; } if ( typeof(sRetorn['iOrdre']) != 'number' || sRetorn['iOrdre'] > iOrdre ) { sRetorn['sInterface'] = aInterfaces; sRetorn['sCampError'] = sCampError; sRetorn['sMissatge'] = sMissatge; sRetorn['iOrdre'] = iOrdre; } } } alertaDiv=tornaLaAlerta(); if ( sRetorn['sCampError'] != '' ) { if(typeof(eval("oForm."+sRetorn['sCampError']))=='object' && eval("oForm."+sRetorn['sCampError']+".focus")) // This will prevent an error when trying to focus an invisible object try { eval("oForm."+sRetorn['sCampError']+".focus()"); } catch (e) { } if(typeof(eval("oForm."+sRetorn['sCampError']))!='undefined' && eval("oForm."+sRetorn['sCampError']+"[0]") && eval("oForm."+sRetorn['sCampError']+"[0].focus")) // This will prevent an error when trying to focus an invisible object try { eval( "oForm." + sRetorn['sCampError'] + "[0].focus()" ); } catch (e) { } if(typeof(eval("oForm."+sRetorn['sCampError']+"_LlistaDoble1"))=='object' && eval("oForm."+sRetorn['sCampError']+"_LlistaDoble1.focus")) // This will prevent an error when trying to focus an invisible object try { eval( "oForm." + sRetorn['sCampError'] + "_LlistaDoble1.focus()" ); } catch (e) { } if(alertaDiv!=null && typeof(alertaDiv)!='undefined') { alertaDiv.style.display = ""; innerHTML="Per favore, controlla i dati introdotti. I campi in rosso devono essere corretti. "; alertaDiv.innerHTML="
"+innerHTML+"
"; } else { alert( sRetorn['sMissatge'] ); } } else { if(alertaDiv!=null && typeof(alertaDiv)!='undefined') { alertaDiv.style.display = "none"; } } if(alertaDiv!=null && typeof(alertaDiv)!='undefined') { document.location.href = "#anch_revision"; } else { document.location.href = "#" + "anch_" + sRetorn['sCampError']; } return sRetorn; } function passaLaCabra( sSelect ) { var oOrigen = document.getElementsByName(sSelect + '_LlistaDoble1')[0]; var oDesti = document.getElementsByName(sSelect + '_LlistaDoble2')[0]; var i = oOrigen.options.selectedIndex; while ( i > -1 ) { var len = oDesti.length; encontrado = 0; for(var x = 0; x < oDesti.length; x++){ if (oOrigen.options[i].value == oDesti.options[x].value) encontrado=1; } if (!encontrado) oDesti.options.add(new Option(oOrigen.options[i].text,oOrigen.options[i].value)); oOrigen.options[i].selected = false; i=oOrigen.options.selectedIndex; } return(true); } function tornaLaCabra( sSelect ) { var oDesti = document.getElementsByName(sSelect + '_LlistaDoble2')[0]; for(var i = (oDesti.options.length-1); i >= 0; i--) if ((oDesti.options[i] != null) && (oDesti.options[i].selected == true)) oDesti.options[i] = null; return(true); } function tornaLaAlerta() { var allDivs = document.getElementsByTagName("div"); var i=0; var count=0; for (i=0; i< allDivs.length; i++) { if (allDivs[i].id == "Alerta") { if (count) { allDivs[i].parentNode.removeChild(allDivs[i]); } count++; } } var sDiv = document.getElementById("Alerta"); if (sDiv==null) return null; else return sDiv; }