/********************************************************* * Name: Melvin D. Nava * Website: http://mdnava.network.com.ve/ * E-mail: melvinnava@ifrance.com * Phone: 0414-6374337 * Location: Maracaibo, Venezuela ********************************************************** [2002.Oct.03 - My JavaScript Utils] ********************************************************** Feel free to use or modify this script to fit your needs If you need any help send me an Email and I'll be more than glad to help you out. If you think it have been useful to you and you own a website, I'll appreciate if you link back to my website ********************************************************** Puedes usar o modificar estos scripts libremente según tus necesidades. Si necesitas ayuda enviame un Correo y estaré mas que dispuesto de echarte una mano. Si crees que ha sido de ayuda y tienes un sitio Web, apreciare si haces un link de vuelta a mi sitio web. P.D.: todos mis programas siempre los comento en ingles. *********************************************************/ // 2004-03-09 -> added fit_window_size() // 2003-02-20 -> added DisableForm() :: got this snippet and the next from some perl billing software var isIE = document.all?true:false; var isNS = document.layers?true:false; var hostname = window.parent.location.hostname // returns the server hostname function random_number(len) { return whichquote = Math.floor(Math.random()*(len)); } // return a randon number function w(s) { return document.write(s); } // short document.write function a(s) { return window.alert(s); } // short window.alert function error_handler(msg, url, line){ // handle any error that could raise, veeery handy! ...buy me a pizza window.status="Exception Handled (Mel!)"; //TODO: open a small window to report the error //alert(msg+" :: "+url+" :: "+line); return true; } window.onerror=error_handler; function toogle_display(src) { // toggle a div display (cool menus) if (src.style.display == "") src.style.display = "none"; else src.style.display= ""; } function fit_window_size() { //fits current window to an image if (isNS) { window.innerWidth = document.layers[0].document.images[0].width; window.innerHeight = document.layers[0].document.images[0].height; } if (isIE) { window.resizeTo(500, 500); width = 500 - (document.body.clientWidth - document.images[0].width); height = 500 - (document.body.clientHeight - document.images[0].height); window.resizeTo(width+20, height+20); window.moveTo((screen.availWidth-(width+20))/2,(screen.availHeight-(height+20))/2); } } //var tmp_color1; //to store current font color before hover function mOvr(src,clrOver) { if (!src.contains(event.fromElement)) { src.style.cursor = 'hand'; src.bgColor = clrOver; //tmp_color1 = src.children.tags('A')[0].style.color; //src.children.tags('A')[0].style.color='blue'; if ((event.srcElement.tagName=='TD')&&(src.children.tags('A')[0])) { window.status = src.children.tags('A')[0]; } } } function mOut(src,clrIn) { if (!src.contains(event.toElement)) { src.style.cursor = 'default'; src.bgColor = clrIn; //src.children.tags('A')[0].style.color = tmp_color1; //''; //tmp_color1 = ''; window.status = ""; } } function mClk(src) { if(event.srcElement.tagName=='TD'){ src.children.tags('A')[0].click(); } } function disable_form(formname) { browser = new String(navigator.userAgent); if (browser.match(/IE/g)) { for (i=1; i= 4) && (hr <= 12)) {document.write("Buenos dias.. ")} else if ((hr > 12) && (hr <= 19)) {document.write("Buenas tardes.. ")} else {document.write("Buenas noches.. ");} } function break_frames() { // break external frames if (parent.location != self.location){ parent.location = self.location.href } } function popimg(img,txt,w,h) { // open image ////////// TODO: ADAPTATION TO maracaibo.com.ve m = window.open("../images/"+img, "popimg1", "width="+w+",height="+h+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0"); m.moveTo(screen.availWidth - screen.availWidth/2 - 140,screen.availHeight - screen.availHeight/2 - 140); m.resizeTo(w+20,h+70); m.document.writeln(""+txt+"") m.document.writeln("
"+txt+"
+txt+
") m.document.writeln("Cerrar") m.document.writeln("
") } function popfla(swf,txt,w,h) { // open flash movie ////////// TODO: ADAPTATION TO maracaibo.com.ve m = window.open("../media/"+swf, "popfla1", "width="+w+",height="+h+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0"); m.moveTo(screen.availWidth - screen.availWidth/2 - 140,screen.availHeight - screen.availHeight/2 - 140); m.resizeTo(w+20,h+70); m.document.writeln(""+txt+"") m.document.writeln("
") m.document.writeln("") m.document.writeln("") m.document.writeln("") m.document.writeln("") m.document.writeln("") m.document.writeln("Cerrar") m.document.writeln("
") } function popup(url,w,h) { // window popup maker var day, id, popw day = new Date(); id = day.getTime(); if(!w) w=640; if(!h) h=480; popw = window.open(url, "_blank", "width="+w+",height="+h+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0"); //m.moveTo(screen.availWidth/2-100,screen.availHeight/2-100) } function openup(url) { // open document or image in new window with no toolars m = window.open(url, "popup", "width=640,height=480,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0"); //if ((width)&&(height)) m.resizeTo(width,height); //if ((posX)&&(posY)) m.moveTo(posX,posY); else m.moveTo(22,22); } function make_bookmark(url, title) { // add a page to favorites if(navigator.appName == "Microsoft Internet Explorer") { window.external.AddFavorite(url, title); }else if(navigator.appName == "Netscape"){ a('Presiona << Enter >> y despues << Control + D >> para agregar esta pagina a tus Bookmarks'); } } function make_homepage(url) { // set the client homepage if(navigator.appName == "Microsoft Internet Explorer") { document.body.setHomePage(url) } else if(navigator.appName == "Netscape") { netscape.security.PrivilegeManager.enablePrivilege('UniversalPreferencesWrite'); navigator.preference('browser.startup.homepage', url); } } function make_deskitem(url) { // makes a desktop item from a url if(navigator.appName == "Microsoft Internet Explorer") { window.external.addDesktopComponent(url,'website'); } else if(navigator.appName == "Netscape") { a('Esta caracteristica solo está disponible para Internet Explorer'); } else{ a('Su navegador no acepta esta opción.') } } function check_email(email) { // returns true if an email is valid var isvalid; var filter=/^.+@.+\..{2,3}$/ if (filter.test(email)) { isvalid = true; } else { isvalid = false; } return (isvalid); } function only_numbers(e) { var _ret = true; if (isIE) { if (window.event.keyCode < 46 || window.event.keyCode > 57) { window.event.keyCode = 0; _ret = false; } } if (isNS) { if (e.which < 46 || e.which > 57) { e.which = 0; _ret = false; } } return (_ret); } function check_length(obj,maxlen){ // write in status the lenght of a textbox or a textarea [maxlen=int] var msg msg = obj.value.length+' Caracteres' if (obj.value.length >= maxlen) msg = msg+" (se ha excedido del limite: "+maxlen+" caracteres)"; window.status = msg if (obj.value.length >= maxlen+1) { //a(obj.name+": \nHay "+msg+" "+"\nLimite = "+maxlen+" Caracteres") var s = obj.value obj.value = s.slice(0,maxlen) } return msg; } // OnKeyDown="javascript:check_length(this,255)" function time_event(event2load,interval,toggle) { // loads an event every interval // interval = 1000 (1 second) var timer; if (toggle == 1) { timer = setInterval(event2load, interval); } else { clearInterval(timer); } } function rclicked(e) { // needed for [disable_rclick] function var msg="Función desabilitada!!"; if (document.all) { if (event.button == 2||event.button==3) a(msg); return false; } if (document.layers) { if (e.which == 3) a(msg); return false; } } function disable_rclick() { // disable mouse right clicks if (document.layers) document.captureEvents(Event.MOUSEDOWN); document.onmousedown=rclicked; } function print_date(lang) { // writes the actual date in the document [en=english,es=espanish] if (!lang) lang = "es"; // set spanish to default var now = new Date(); // actual date var arrDay = new Array(); // day name var arrMonth= new Array(); // month name var arrOf = new Array(); // just a string arrOf[1] = " de "; arrOf[2] = " of "; numDay = now.getDate(); // day number numYear = now.getFullYear(); // year number var i = 0 switch (now.getDay()) { // set day names case 0: arrDay[1] = "Domingo"; arrDay[2] = "Sunday"; break; case 1: arrDay[1] = "Lunes"; arrDay[2] = "Monday"; break; case 2: arrDay[1] = "Martes"; arrDay[2] = "Tuesday"; break; case 3: arrDay[1] = "Miércoles"; arrDay[2] = "Wednesday"; break; case 4: arrDay[1] = "Jueves"; arrDay[2] = "Thursday"; break; case 5: arrDay[1] = "Viernes"; arrDay[2] = "Friday"; break; case 6: arrDay[1] = "Sábado"; arrDay[2] = "Saturday"; break; } switch (now.getMonth()) { // set month names case 0: arrMonth[1] = "Enero"; arrMonth[2] = "January"; break; case 1: arrMonth[1] = "Febrero"; arrMonth[2] = "February"; break; case 2: arrMonth[1] = "Marzo"; arrMonth[2] = "March"; break; case 3: arrMonth[1] = "Abril"; arrMonth[2] = "April"; break; case 4: arrMonth[1] = "Mayo"; arrMonth[2] = "May"; break; case 5: arrMonth[1] = "Junio"; arrMonth[2] = "June"; break; case 6: arrMonth[1] = "Julio"; arrMonth[2] = "July"; break; case 7: arrMonth[1] = "Agosto"; arrMonth[2] = "August"; break; case 8: arrMonth[1] = "Septiembre";arrMonth[2] = "September"; break; case 9: arrMonth[1] = "Octubre"; arrMonth[2] = "October"; break; case 10: arrMonth[1] = "Noviembre"; arrMonth[2] = "November"; break; case 11: arrMonth[1] = "Diciembre"; arrMonth[2] = "December"; break; } switch (lang) { // choose language case 'es': i = 1; break; // spanish case 'en': i = 2; break; // english } document.write(arrDay[i]); document.write(", "); document.write(numDay); document.write(arrOf[i]); document.write(arrMonth[i]); if (lang!= "en") document.write(arrOf[i]); else document.write(" "); document.write(numYear); document.write(""); } function preload_images(images) { // preload images separated by commas [img1.gif,img4.jpg,...] if (!images) return false; var i; var img = new Array(); images = images.split(","); for (i in images) { img[i]=new Image; img[i].src=images[i]; } return true; } function static_statusbar(str) { // static message to status bar window.status = str; setTimeout("static_statusbar(" & str & ")"); } function select_textarea(obj_name) { // select text from a textarea [form_name.textarea_name], use in a link var tempval = eval("document." + obj_name); tempval.focus(); tempval.select(); } function count_chars(obj_name,int_limit) { // count characters from a form field [form_name.field_name] //if (eval("document." + obj_name) == false) return false; var str = obj_name.value; // value of the string var lng = str.length; // lenght of the string var msg = "Total de caracteres: "+lng // message1 if (int_limit) { var dif = int_limit - lng //check if the string is greater than the limit allowed if (dif <= -1) { msg += "\n\r Son mas del limite permitido: "+int_limit; //return false; } } a(msg); //return true; } function maximize_window() { // maximize current window self.moveTo(0,0); self.resizeTo(screen.availWidth,screen.availHeight); self.focus(); } function print_page() { // print current page, only for IE if (window.print) { window.print(); } else { a("Su explorador no soporta esta función"); } } // JAVASCRIPT VERSION OF VBSCRIPT HANDY FUNCTIONS // ------------------------------------------------------------------------------------------------ function trim() { // like vbscript trim, will clean up spaces from left and right of a string var tmpStr, atChar; if (tmpStr.length > 0) atChar = tmpStr.charAt(0); while (isSpace(atChar)) { tmpStr = tmpStr.substring(1, tmpStr.length); atChar = tmpStr.charAt(0); } if (tmpStr.length > 0) atChar = tmpStr.charAt(tmpStr.length-1); while (isSpace(atChar)) { tmpStr = tmpStr.substring(0,( tmpStr.length-1)); atChar = tmpStr.charAt(tmpStr.length-1); } return tmpStr; } function isSpace(inChar) { // for use with by the trim() function return (inChar == ' ' || inChar == '\t' || inChar == '\n'); } function left(inLen) { // will return the left of a string - inLen digits, use: string.left(int) return this.substring(0,inLen); } function right(inLen) { // will return the right of a string - inLen digits, use: string.left(int) return this.substring((this.length-inLen),this.length); } function mid(inStart,inLen) { // will return the middle of a string starting from inStart and minus inLen digits // use: string.mid(1,1); var iEnd; if (!inLen) iEnd = this.length; else iEnd = inStart + inLen; return this.substring(inStart,iEnd); } // ------------------------------------------------------------------------------------------------