// -------------------- emptyCheck ------------------ // Joduba: 18/06/2004 // // Original from: http://www.jsmadeeasy.com/ // Tested on IE6, Mozilla Firebird. // -------------------------------------------------- // ca_ES function emptyCheck(elementID) { // checks if the field is empty var filter = /^.*[A-Za-z0-9]\w*.*$/; if (!filter.test(elementID.value)) { alert("Sisplau omple els camps obligatoris"); elementID.focus(); return false; } return true; }; function emptyCheckField(elementID,name) { // checks if the field is empty var filter = /^.*[A-Za-z0-9]\w*.*$/; if (!filter.test(elementID.value)) { alert("Camp"+": "+strName+"\n"+"Sisplau omple els camps obligatoris"); elementID.focus(); return false; } return true; }; function checkboxCheckField(elementID,name) { if (!elementID.checked) { alert ("El Checkbox és necessari per enviar aquest formulari"); elementID.focus(); return false; } return true; } // -------------------- nameCheck ------------------ // Joduba: 18/06/2004 // // Original from: http://www.jsmadeeasy.com/ // Tested on IE6, Mozilla Firebird. // -------------------------------------------------- function nameCheck(elementID) { // checks if the field is empty var filter = /^.*[A-Za-z]\w*.*$/; if (!filter.test(elementID.value)) { alert("Sisplau omple els camps obligatoris"); elementID.focus(); return false; } return true; }; function nameCheckField(elementID,strName) { if (elementID.value!="") return true; else{ alert("Camp"+": "+strName+"\n"+"Sisplau omple els camps obligatoris"); elementID.focus(); return false; } /* // checks if the field is empty var filter = /^.*[A-Za-z]\w*.*$/; if (!filter.test(elementID.value)) { alert("Camp"+": "+strName+"\n"+"Sisplau omple els camps obligatoris"); elementID.focus(); return false; } return true; */ }; // -------------------- usernameCheck ------------------ // Joduba: 12/10/2004 // // Original from: http://www.jsmadeeasy.com/ // Tested on IE6, Mozilla Firebird. // -------------------------------------------------- function usernameCheck(elementID) { // checks if the field is empty var filter = /^[a-z0-9]+[a-z_.\-0-9]*[a-z0-9]+$/; if (!filter.test(elementID.value)) { alert("Sisplau omple els camps obligatoris"); elementID.focus(); return false; } return true; }; function usernameCheckField(elementID,strName) { if (elementID.value=="") { alert("Camp"+": "+strName+"\n"+"Sisplau omple els camps obligatoris"); elementID.focus(); return false; } // checks if the field is empty var filter = /^[a-z0-9]+[a-z_.\-0-9]*[a-z0-9]+$/; if (!filter.test(elementID.value)) { alert("Camp"+": "+strName+"\n"+"Format no vàlid... Usa minúscules, números i caràcters com -_-, ---, -.- (guió, guió baix, punt...)\n"+strName+"ha de comencar amb una lletra i acabar amb una lletra o digit"); elementID.focus(); return false; } return true; }; // -------------------- domainCheck ------------------ // Joduba: 31/10/2004 // // Original from: http://www.jsmadeeasy.com/ // Tested on IE6, Mozilla Firebird. // -------------------------------------------------- function domainCheck(elementID) { // checks if the field is empty var filter=/^((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; if (!filter.test(elementID.value)) { alert("Sisplau omple els camps obligatoris"); elementID.focus(); return false; } return true; }; function domainCheckField(elementID,strName) { if (elementID.value=="") { alert("Camp"+": "+strName+"\n"+"Sisplau omple els camps obligatoris"); elementID.focus(); return false; } // checks if the field is empty var filter=/^((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; if (!filter.test(elementID.value)) { alert("Camp"+": "+strName+"\n"+"Format no vàlid... Usa minúscules, números i caràcters com -_-, ---, -.- (guió, guió baix, punt...)\n"+strName+"ha de comencar amb una lletra i acabar amb una lletra o digit"); elementID.focus(); return false; } return true; }; // -------------------- identifierCheck ------------------ // jmserra: 04/04/2007 // -------------------------------------------------- function identifierCheck(elementID) { var filter = /^[a-zA-Z]+([a-zA-Z0-9]|[-]|[_])*$/; if (!filter.test(elementID.value)) { alert("Sisplau omple els camps obligatoris"); elementID.focus(); return false; } return true; }; function identifierCheckField(elementID,strName, required) { if (!required){ if (elementID.value=="") return true; } if (elementID.value=="") { alert("Camp"+": "+strName+"\n"+"Sisplau omple els camps obligatoris"); elementID.focus(); return false; } // checks if the field is empty var filter = /^[a-zA-Z]+([a-zA-Z0-9]|[-]|[_]|[@]|[.])*$/; if (!filter.test(elementID.value)) { alert("Camp"+": "+strName+"\n"+"S\'han trobat caràcters invàlids. Si us plau, utilitzi només lletres (sense accents), nombres, guions normals o baixos ( - o _ ) y punts\n"+strName+"ha de comencar amb una lletra i acabar amb una lletra o digit"); elementID.focus(); return false; } return true; }; // -------------------- Comprovar si es email------------------ // Joduba: 03/02/2004 // // Original from: http://www.jsmadeeasy.com/ // Tested on IE6, Mozilla Firebird. // ---------------------------------------------------------- /*//Versio anterior function emailCheck(elementID) { // checks if the e-mail address is valid //var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; var filter=/^([a-zA-Z0-9_.-+])+@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; if (!filter.test(elementID.value)) { alert("El teu email sembla incorrecte. Torna a intentar-ho (comproba la \'@\' i \'.\'s a l\' adreça email)"); elementID.focus(); return false; } return true; } */ //He trobat el seguent codi per inet, esta molt lograt // Email Validation Javascript // copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd function emailCheck(elementID) { addr=elementID.value; //function validateEmail(addr,man,db) { //Head anterior man=1;//per defecte db=1;//per defecte if (addr == '' && man) { alert("és obligatori indicar una adreça electrònica"); elementID.focus(); return false; } var invalidChars = '\/\'\\ ";:?!()[]\{\}^|'; for (i=0; i -1) { alert("l\'adreça electrònica conté caràcters no vàlids"); elementID.focus(); return false; } } for (i=0; i127) { alert("l\'adreça electrònica conté caràcters que no són ascii (de l\'anglès American Standard Code for Information Interchange, un stàndar, de fet, internacional)"); elementID.focus(); return false; } } var atPos = addr.indexOf('@',0); if (atPos == -1) { alert("L\'adreça electrònica ha de contenir una @"); elementID.focus(); return false; } if (atPos == 0) { alert("L\'adreça electrònica no ha de començar amb @"); elementID.focus(); return false; } if (addr.indexOf('@', atPos + 1) > - 1) { alert("una adreça electrònica només pot tenir UNA @"); elementID.focus(); return false; } if (addr.indexOf('.', atPos) == -1) { alert("L\'adreça electrònica ha de contenir un punt després de @xxx (el nom del domini)"); elementID.focus(); return false; } if (addr.indexOf('@.',0) != -1) { alert("Un punt no pot seguir a @ en l\'adreça electrònica"); elementID.focus(); return false; } if (addr.indexOf('.@',0) != -1){ alert("un punt no pot estar abans de la @ en una adreça electrònica"); elementID.focus(); return false; } if (addr.indexOf('..',0) != -1) { alert("2 punts no es poden adjuntar a una adreça electrònica"); elementID.focus(); return false; } var suffix = addr.substring(addr.lastIndexOf('.')+1); if (suffix.length != 2 && suffix != 'com' && suffix != 'cat' && suffix != 'es' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') { //if (db) alert("Domini (post@-.?.-) invàlid a l\'adreça electrònica"); elementID.focus(); //} if (db) return false; } return true; } function noRequiredEmailCheck(elementID) { // Check if empty if (elementID.value=="") return true; // checks if the e-mail address is valid var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; if (!filter.test(elementID.value)) { alert("El teu email sembla incorrecte. Torna a intentar-ho (comproba la \'@\' i \'.\'s a l\' adreça email)"); elementID.focus(); return false; } return true; } // -------------------- Password Generator ------------------ // Joduba: 04/09/2004 // // Original from: http://www.jsmadeeasy.com/ // Tested on IE6, Mozilla Firebird. // ---------------------------------------------------------- // -- Original: Rob Kroll (rkroll@istar.ca) function pwgen(l) { var selectionarray=new Array(62) var length=62; var i,j; var tmpstr; selectionarray[1]="A"; selectionarray[2]="B"; selectionarray[3]="C"; selectionarray[4]="D"; selectionarray[5]="E"; selectionarray[6]="F"; selectionarray[7]="G"; selectionarray[8]="H"; selectionarray[9]="I"; selectionarray[10]="J"; selectionarray[11]="K"; selectionarray[12]="L"; selectionarray[13]="M"; selectionarray[14]="N"; selectionarray[15]="O"; selectionarray[16]="P"; selectionarray[17]="Q"; selectionarray[18]="R"; selectionarray[19]="S"; selectionarray[20]="T"; selectionarray[21]="U"; selectionarray[22]="V"; selectionarray[23]="W"; selectionarray[24]="X"; selectionarray[25]="Y"; selectionarray[26]="Z"; selectionarray[27]="0"; selectionarray[28]="1"; selectionarray[29]="2"; selectionarray[30]="3"; selectionarray[31]="4"; selectionarray[32]="5"; selectionarray[33]="6"; selectionarray[34]="7"; selectionarray[35]="8"; selectionarray[36]="9"; selectionarray[37]="a"; selectionarray[38]="b"; selectionarray[39]="c"; selectionarray[40]="d"; selectionarray[41]="e"; selectionarray[42]="f"; selectionarray[43]="g"; selectionarray[44]="h"; selectionarray[45]="i"; selectionarray[46]="j"; selectionarray[47]="k"; selectionarray[48]="l"; selectionarray[49]="m"; selectionarray[50]="n"; selectionarray[51]="o"; selectionarray[52]="p"; selectionarray[53]="q"; selectionarray[54]="r"; selectionarray[55]="s"; selectionarray[56]="t"; selectionarray[57]="u"; selectionarray[58]="v"; selectionarray[59]="w"; selectionarray[60]="x"; selectionarray[61]="y"; selectionarray[62]="z"; tmpstr=""; i=0; do { var randscript = -1; while (randscript < 1 || randscript > length || isNaN(randscript)) { randscript = parseInt(Math.random()*(length)); } j=randscript; tmpstr=tmpstr+selectionarray[j]; i=i+1; } while (i<6) { alert ("La contrasenya ha de tenir al menys 6 caràcters"); elementIDpw1.focus(); return false; } return true; } //Markus -> li passem un nou parametre, required, per validar si es correcte el mail introduit //en cas que no sigui requerit function checkNewPw(elementIDpw1,elementIDpw2,required) { if(!required){ if (elementIDpw1.value=="" && elementIDpw1.value==elementIDpw2.value) return true; } if (elementIDpw1.value=="") { alert ("La capsa de password no pot estar buida. Si us plau entra el password"); elementIDpw1.focus(); return false; } if (elementIDpw1.value != elementIDpw2.value) { alert ("No has entrat dos cops la mateixa contrasenya nova"); elementIDpw1.focus(); return false; } if (elementIDpw1.value.length<6) { alert ("La contrasenya ha de tenir al menys 6 caràcters"); elementIDpw1.focus(); return false; } return true; } // To generate an scrolling news text function IwithScroll_start() { var IwithScrollIdSupported = false; IwithScrollId_WIDTH = document.getElementById(IwithScrollId).style.width; var img = ""; if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1) { document.getElementById(IwithScrollId).innerHTML = "
"+img+" "+img+"
"; IwithScrollIdSupported = true; } if (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1) { document.getElementById(IwithScrollId).innerHTML = "
"+img+""+img+"
"; IwithScrollIdSupported = true; } if(!IwithScrollIdSupported) document.getElementById(IwithScrollId).outerHTML = ""; else { document.getElementById(IwithScrollId).scrollLeft = IwithScrollDirection ? document.getElementById(IwithScrollId).scrollWidth - document.getElementById(IwithScrollId).offsetWidth : 0; document.getElementById(IwithScrollId+"-iwspace").innerHTML = IwithScrollContent; document.getElementById(IwithScrollId).style.display="block"; IwithScroll_do(); } } function IwithScroll_do() { if(!IwithScrollPause) document.getElementById(IwithScrollId).scrollLeft += IwithScrollSpeed * (IwithScrollDirection ? -1 : 1); if(IwithScrollDirection && document.getElementById(IwithScrollId).scrollLeft <= 0) document.getElementById(IwithScrollId).scrollLeft = document.getElementById(IwithScrollId).scrollWidth - document.getElementById(IwithScrollId).offsetWidth; if(!IwithScrollDirection && document.getElementById(IwithScrollId).scrollLeft >= document.getElementById(IwithScrollId).scrollWidth - document.getElementById(IwithScrollId).offsetWidth) document.getElementById(IwithScrollId).scrollLeft = 0; window.setTimeout("IwithScroll_do()", 30); } // -------------------- Comprovar si es Phone number------------------ // Markus: 15/07/2006 // // Original from: http://www.jsmadeeasy.com/ // Tested on IE6, Mozilla Firebird. // ---------------------------------------------------------- function phoneCheckField(elementID,strName,required) { // checks if the phone number is valid if (!required){ if (elementID.value=="") return true; } var filter=/^\+?(\d|\w|-|.)*\d$/; if (!filter.test(elementID.value)) { alert("Camp"+": "+strName+"\n"+"El teu numero de telèfon sembla incorrecte. Intenta-ho un altre cop utilitzant \'+\',\'.\',\'-\',\'numeros\' "); elementID.focus(); return false; } return true; } // -------------------- Comprovar si es Number------------------ // Markus: 15/07/2006 // // Original from: http://www.jsmadeeasy.com/ // Tested on IE6, Mozilla Firebird. // ---------------------------------------------------------- function numberCheckField(elementID,strName,required) { // checks if the number is valid if (!required){ if (elementID.value=="") return true; } //antes ->> ^\d(\d|'|,|.|e|E|\+|-)*\d$ var filter=/^(-)*\d(\d|\,|\'|\.)*(e|\�)?$/; if (!filter.test(elementID.value)) { alert("Camp"+": "+strName+"\n"+"El nombre sembla incorrecte."); elementID.focus(); return false; } return true; } // --- Comprovar si es REALNumber--- // jsmerra: 21/05/2007 // --------------------------------- function realnumberCheckField(elementID,strName,required) { if (!required){ if (elementID.value=="") return true; } var filter=/^(\d|'|,|.|e|E|\+|-)*\d$/; if (!filter.test(elementID.value)) { alert("Camp"+": "+strName+"\n"+"El nombre sembla incorrecte."); elementID.focus(); return false; } return true; } // -------------------- Comprovar si es NumberRange------------------ // Markus: 15/07/2006 // // Original from: http://www.jsmadeeasy.com/ // Tested on IE6, Mozilla Firebird. // ---------------------------------------------------------- function numberrangeCheckField(elementID,min,max,strName,required) { // checks if the numberrange is valid, min<=elementID.value or elementID.value<=max if (!required){ if (elementID.value=="") return true; } if (!(min<=elementID.value && elementID.value<=max)){ alert("Camp"+": "+strName+", "+"la gamma és"+": ["+min+"-"+max+"]\n"+"El nombre sembla incorrecte."); elementID.focus(); return false; } return true; } // -------------------- Comprovar si Integer------------------ // Markus: 15/07/2006 // // Original from: http://www.jsmadeeasy.com/ // Tested on IE6, Mozilla Firebird. // ---------------------------------------------------------- function integerCheckField(elementID,strName,required) { // checks if the integer is valid if (!required){ if (elementID.value=="") return true; } var filter=/^(\d)*\d$/; if (!filter.test(elementID.value)) { alert("Camp"+": "+strName+"\n"+"El nombre sembla incorrecte"); elementID.focus(); return false; } return true; } // -------------------- Comprovar si Decimal------------------ // Markus: 15/07/2006 // // Original from: http://www.jsmadeeasy.com/ // Tested on IE6, Mozilla Firebird. // ---------------------------------------------------------- function decimalCheckField(elementID,strName,required) { // checks if the integer is valid if (!required){ if (elementID.value=="") return true; } //nomenclatura UE -> decimal (,|') //USA -> decimal (.) var filter=/^(\d)*('|,|.)(\d)*\d$/; if (!filter.test(elementID.value)) { alert("Camp"+": "+strName+"\n"+"Els decimals semblen incorrectes"); elementID.focus(); return false; } return true; } // -------------------- Comprovar si URL ------------------ // Markus: 15/07/2006 // // Original from: http://www.webbedwonder.com // Tested on IE6, Mozilla Firebird. // ---------------------------------------------------------- function urlCheckField(elementID,strName,required){ if (!required){ if (elementID.value=="") return true; } // Know bug, doesn't accept URLs without www or other starting word, has to have at leat 3 var filter=/^((http(s)?|ftp):(\d)*\/\/)?([\%\_\-\+a-z0-9]*)\.(\w*)/; var filter_relatives=/^\//; if (!filter.test(elementID.value) && !filter_relatives.test(elementID.value)) { alert("Camp"+": "+strName+"\n"+"L\'adreça web -url- sembla incorrecta."); elementID.focus(); return false; } return true; } // -------------------- Comprovar si la hora es correcte----- // Markus: 16/07/2006 // // Original from: my mind, juasjuas // Tested on IE6, Mozilla Firebird. // ---------------------------------------------------------- function check_time_h(elementID,strName,required){ if(!required){ if (elementID.value=="") return true; } if (elementID.value==""){ alert("Camp"+": "+strName+"\n"+"Sisplau omple els camps obligatoris"); elementID.focus(); return false; } if (!(0<=elementID.value && elementID.value<=23)){ alert("Camp"+": "+strName+"\n"+"La hora sembla incorrecta"); elementID.focus(); return false; } return true; } function check_time_m(elementID,strName,required){ if(!required){ if (elementID.value=="") return true; } if (elementID.value==""){ alert("Camp"+": "+strName+"\n"+"Sisplau omple els camps obligatoris"); elementID.focus(); return false; } if (!(0<=elementID.value && elementID.value<=59)){ alert("Camp"+": "+strName+"\n"+"La hora (els minuts) sembla incorrecta"); elementID.focus(); return false; } return true; } // -------------------- Comprovar si la data es correcte----- // Markus: 16/07/2006 // // Original from: my mind, juasjuas // Tested on IE6, Mozilla Firebird. // ---------------------------------------------------------- function dateCheckField(elementID, strName,required){ if(!required){ if (elementID.value=="") return true; } var filter=/^\d{2,4}(\-|\/)\d{2}\1\d{2,4}$/; if (!filter.test(elementID.value)) { alert("Camp"+": "+strName+"\n"+"La data sembla incorrecta."); elementID.focus(); return false; } return true; } // -------------------- Comprovar si la data es correcte----- // Markus: 16/07/2006 // // Original from: my mind, juasjuas // Tested on IE6, Mozilla Firebird. // ---------------------------------------------------------- function emptyTextCheck(elementID,strName) { // Check if empty if (elementID.value==""){ alert("Camp"+": "+strName+"\n"+"Sisplau omple els camps obligatoris"); elementID.focus(); return false; } return true; } function optionCheck(elementID,strName){ //elementID.value ens dona el valor de la key selected. if (elementID.value==""){ alert("Camp"+": "+strName+"\n"+"Sisplau omple els camps obligatoris"); elementID.focus(); return false; } return true; } //------------------------------------------------ // toogleDiv: Hide and make visible a given division // author: Joduba // date: 15/07/2006 //-------------------------------------------------- function iwith_toggleDiv(divId, iconId, headerId, collapse, expand) { if (collapse==undefined ) collapse="Fes click aquí per reduir aquesta secció"; if (expand==undefined ) expand="Fes click aquí per expandir aquesta secció"; divElement = document.getElementById(divId); imgElement = document.getElementById(iconId); tableElement = document.getElementById(headerId); if (divElement.nextSibling.style.display != "none") { divElement.nextSibling.style.display = "none"; imgElement.src="/i-images/collapserright.gif"; imgElement.title=expand; tableElement.title=expand; } else { divElement.nextSibling.style.display = "block"; imgElement.src="/i-images/collapserdown.gif"; imgElement.title=collapse; tableElement.title=collapse; } } //------------------------------------------------ // Form functions, tools to work in forms. // author: Joduba // date: 24/12/2007 //-------------------------------------------------- function iwith_form_select_SwapOptions(optionsArray, select_to_change_id, index) { the_array=optionsArray[index]; if (!the_array) return; cselect=document.getElementById(select_to_change_id); iwith_form_select_setOptionText(cselect, the_array); } function iwith_form_select_setOptionText(the_select, the_array) { for (loop=the_select.length; loop>0 ; loop--) { the_select.options[loop-1]=null; } for (var key in the_array) { var newOpt = new Option(the_array[key],key); the_select.options[the_select.length]=newOpt; } } function iwith_form_select_selectOption(selectid,myOption) { select=document.getElementById(selectid); for(i=0;imaxlen){ alert("Camp"+": "+strName+"\n"+"Té un tamany màxim de: "+maxlen); elem.focus(); return false; } else{return true;} }