/* _______ __ __ .__ __. ______ __ ______ .__ __. _______ _______. | ____|| | | | | \ | | / || | / __ \ | \ | | | ____| / | | |__ | | | | | \| | | ,----'| | | | | | | \| | | |__ | (----` | __| | | | | | . ` | | | | | | | | | | . ` | | __| \ \ | | | `--' | | |\ | | `----.| | | `--' | | |\ | | |____.----) | |__| \______/ |__| \__| \______||__| \______/ |__| \__| |_______|_______/ ______ ______ .___ ___. __ __ .__ __. _______ _______. / | / __ \ | \/ | | | | | | \ | | | ____| / | | ,----'| | | | | \ / | | | | | | \| | | |__ | (----` | | | | | | | |\/| | | | | | | . ` | | __| \ \ | `----.| `--' | | | | | | `--' | | |\ | | |____.----) | \______| \______/ |__| |__| \______/ |__| \__| |_______|_______/ */ function trim(str, chars) { return ltrim(rtrim(str, chars), chars); } function ltrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), ""); } function rtrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("[" + chars + "]+$", "g"), ""); } function replace(texto,s1,s2){ return texto.split(s1).join(s2); } function contarPalabras(s) { var tmp = s; tmp = replace(tmp, ".", " "); tmp = replace(tmp, ",", " "); tmp = replace(tmp, ";", " "); tmp = replace(tmp, "\n", " "); tmp = replace(tmp, " ", " "); tmp = trim(tmp); var p = tmp.split(" "); //alert(s.length + "; " + p.length); return(p.length); } function mailValido(str) { var tmp = str.split(" "); if (tmp.length==1) { var w = new Array(3) w[0] = ""; w[1] = ""; w[2] = ""; encArroba=false; encPunto=false; for (i=0; i < str.length && !encArroba; i++) { if (str.charAt(i) == '@') encArroba=true; else w[0]+=str.charAt(i) } if (encArroba) { for (; i < str.length && !encPunto; i++) { if (str.charAt(i) == '.') encPunto=true; else w[1]+=str.charAt(i) } for (j=0; j < w[1].length; j++) { if (w[1].charAt(j) == '@') w[1]=""; } } if (encPunto) { for (; i < str.length; i++) { w[2]+=str.charAt(i) } for (j=0; j < w[2].length; j++) { if (w[2].charAt(j) == '@') w[2]=""; } } return (encArroba && encPunto && w[0].length>0 && w[1].length>0 && w[2].length>0); } else { return false; } } function esEmailValido(str) { var tmp = str.split(" "); if (tmp.length==1) { var w = new Array(3) w[0] = ""; w[1] = ""; w[2] = ""; encArroba=false; encPunto=false; for (i=0; i < str.length && !encArroba; i++) { if (str.charAt(i) == "@") encArroba=true; else w[0]+=str.charAt(i) } if (encArroba) { for (; i < str.length && !encPunto; i++) { if (str.charAt(i) == ".") encPunto=true; else w[1]+=str.charAt(i) } for (j=0; j < w[1].length; j++) { if (w[1].charAt(j) == "@") w[1]=""; } } if (encPunto) { for (; i < str.length; i++) { w[2]+=str.charAt(i) } for (j=0; j < w[2].length; j++) { if (w[2].charAt(j) == "@") w[2]=""; } } return (encArroba && encPunto && w[0].length>0 && w[1].length>0 && w[2].length>0); } else { return false; } } function escapejson (val) { if (typeof(val)!="string") return val; return val .replace(/[\\]/g, '\\\\') .replace(/[\/]/g, '\\/') .replace(/[\b]/g, '\\b') .replace(/[\f]/g, '\\f') .replace(/[\n]/g, '\\n') .replace(/[\r]/g, '\\r') .replace(/[\t]/g, '\\t') .replace(/[\"]/g, '\\"') .replace(/\\'/g, "\\'"); } function serializeToJson(serializer){ var _string = '{'; for(var ix in serializer) { var row = serializer[ix]; _string += '"' + row.name + '":"' + escapejson(row.value) + '",'; } var end =_string.length - 1; _string = _string.substr(0, end); _string += '}'; console.log('_string: ', _string); return JSON.parse(_string); } function audioPlayer(url) { window.open(url, 'audio-' + Math.random(), 'width=422,height=110'); }