var century = 2000; var cutOffYear = 2029; var alertsCount = 0; var confirmsCount = 0; var hexChars = "0123456789ABCDEF" var Common = { // ------------------------------------------------------------------------------------------------- // Navegador // ------------------------------------------------------------------------------------------------- isFirefox: function() { return (window.navigator.appName == "Netscape"); }, isIE6: function() { var myregex = /MSIE 6\.0/i; var myArray = navigator.appVersion.match(myregex); return ((window.navigator.appName == "Microsoft Internet Explorer") && (myArray) && (myArray.length > 0)); }, isIE7: function() { var myregex = /MSIE 7\.0/i; var myArray = navigator.appVersion.match(myregex); return ((window.navigator.appName == "Microsoft Internet Explorer") && (myArray) && (myArray.length > 0)); }, // ------------------------------------------------------------------------------------------------- // Eventos // ------------------------------------------------------------------------------------------------- // Esta funcion sirve para attachear una funcion a un evento de un objeto HTML // En firefox las funciones de este tipo normalmente pasan como parametro el objeto event que representa al evento // Si se utiliza new Function(), dentro de la funcion anonima creada de esta forma el objeto event no existe // por otro lado el IE no soporta agregar eventHandlers como si fueran un atributo mas setEventHandler: function(obj, eventName, functionText) { eventName = eventName.replace("on", ""); if(Common.isFirefox()) obj.setAttribute("on" + eventName, functionText); else eval("obj.on" + eventName + " = new Function(\"" + functionText + "\")"); }, // Este metodo solo puede usarse con manejadores de eventos puros que no reciben parametros // o solo reciben el evento en el caso del firefox addEventListener: function(obj, eventName, functionObject, capture) { eventName = eventName.replace("on", ""); // Firefox if(obj.addEventListener) obj.addEventListener(eventName, functionObject, capture); // IE else obj.attachEvent("on" + eventName, functionObject); }, // Esta funcion es utilizada para manejar el evento mouseout independizandose del navegador // Devuelve el objeto del que se salio getSrcElement: function(ev) { if(Common.isFirefox()) return ev.target; else return ev.srcElement; }, // Esta funcion es utilizada para manejar el evento mouseout independizandose del navegador // Devuelve el objeto en donde se termino getTargetElement: function(ev) { if(Common.isFirefox()) return ev.explicitOriginalTarget; else return ev.toElement; }, // Esta funcion sirve para chequear si se presiono el boton izquierdo del mouse // analizando el evento ocurrido leftButton: function(ev) { /* if(Common.isFirefox()) return (ev.button==0); else return (ev.button == 1); */ if (ev.which == null) /* IE case */ return (ev.button < 2); else /* All others */ return (ev.which < 2); }, cancelBubble: function(ev) { // IE ev.returnValue = false; ev.cancelBubble = true; // Mozilla if(ev.preventDefault) ev.preventDefault(); if(ev.stopPropagation) ev.stopPropagation(); }, // --------------------------------------------------------------------------------------------- // Position / Size // --------------------------------------------------------------------------------------------- // Devuelve las coordenadas del mouse getMouseCoords: function(ev) { if(ev.pageX || ev.pageY) { return {x:ev.pageX, y:ev.pageY}; } return { x:ev.clientX + document.body.scrollLeft - document.body.clientLeft, y:ev.clientY + document.body.scrollTop - document.body.clientTop }; }, getPosition: function(ev) { var left = 0; var top = 0; while (ev.offsetParent) { left += ev.offsetLeft - ev.scrollLeft; top += ev.offsetTop - ev.scrollTop; ev = ev.offsetParent; } left += ev.offsetLeft; top += ev.offsetTop; return {x:left, y:top}; }, setPosition: function(obj, x, y) { obj.style.left = x + "px"; obj.style.top = y + "px"; // Common.setStyleAttribute(obj, "left", x); // Common.setStyleAttribute(obj, "top", y); }, // Funci�n que devuelve el ancho y alto del window de acuerdo al tipo de explorador. getWindowSize: function() { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } return { width:myWidth, height:myHeight } }, // Funci�n que devuelve el ancho y alto del window de acuerdo al tipo de explorador. getDocumentSize: function() { var docWidth; var docHeight; if(Common.isIE7) { docWidth = document.body.scrollWidth; docHeight = document.body.scrollHeight; } else { docWidth = document.documentElement.scrollWidth; docHeight = document.documentElement.scrollHeight; } // Si el tama�no de la ventana es mayor que el area de scroll del documento devuelvo ese valor // esto es verdad para valores negativos del scroll (cuando no hay scroll) var winSize = Common.getWindowSize(); if(winSize.width>docWidth) docWidth = winSize.width; if(winSize.height>docHeight) docHeight = winSize.height; return { width:docWidth, height:docHeight } }, getDocumentScrollTop: function() { return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; }, // Devuelve el tama�o de un objeto getObjectSize: function(obj) { var indexwidth = obj.style.width.toString().indexOf("px", 0); if (indexwidth < 1) var auxwidth = obj.style.pixelWidth; else var auxwidth = obj.style.width.toString().substring(0, indexwidth); var indexheight = obj.style.height.toString().indexOf("px", 0); var auxheight = obj.style.height.toString().substring(0, indexheight); if (auxwidth == 0) auxwidth = obj.style.pixelWidth; if (auxheight == 0) auxheight = obj.style.pixelHeight; // En explorer 7 no puedo recuperar de ninguna forma el alto de un div que // no lo tenga definido explicitamente if(auxheight == 0) auxheight = 500; return { width: auxwidth, height: auxheight } }, // Devuelve el tama�o de un objeto setObjectSize: function(obj, width, height) { obj.style.width = width + "px"; obj.style.height = height + "px"; }, getCenterPosition: function(obj, scrollable) { var left = 0; var winSize = Common.getWindowSize(); var objSize = Common.getObjectSize(obj); if (winSize.width > objSize.width){ left = (winSize.width / 2) - (objSize.width / 2); } var top = 0; if (winSize.height > objSize.height){ top = (winSize.height / 2) - (objSize.height / 2); } if(scrollable) top += Common.getDocumentScrollTop(); return { x: left, y: top } }, // Trae al frente a cualquier objeto por sobre todo lo que haya en la pagina // El segundo parametro indica si el objeto es una ventana flotante // Las ventanas siempre estan por sobre todos los objetos de la pagina bringToFront: function(obj, isFloatingWindow) { obj.style.zIndex = Common.getMaxZIndex(isFloatingWindow) + ((isFloatingWindow) ? 2 : 1); }, // Manda al fondo al objeto sendToBack: function(obj) { if (obj) obj.style.zIndex = 0; }, // -------------------------------------------------------------- // Funciones de style y colores // -------------------------------------------------------------- getBgColor: function(obj) { if(obj.currentStyle) { var hexColor = obj.currentStyle.backgroundColor; var r = Common.hex2Dec(hexColor.substring(1,3)); var g = Common.hex2Dec(hexColor.substring(3,5)); var b = Common.hex2Dec(hexColor.substring(5,7)); return {red: r, green: g, blue: b}; } else if(document.defaultView) { var strRgbColor = document.defaultView.getComputedStyle(obj, '').getPropertyValue("background-color"); strRgbColor = strRgbColor.replace("rgb", ""); strRgbColor = strRgbColor.replace("(", ""); strRgbColor = strRgbColor.replace("(", ""); var rgb = strRgbColor.split(','); return {red: parseInt(rgb[0]), green: parseInt(rgb[1]), blue: parseInt(rgb[2])}; } else { return "Don\'t know how to get color"; } }, setBgColor: function(obj, rgbColor) { var newBgColor = "#" + Common.dec2Hex(rgbColor.red) + Common.dec2Hex(rgbColor.green) + Common.dec2Hex(rgbColor.blue); obj.style.backgroundColor = newBgColor; }, // -------------------------------------------------------------- // Funciones de rollover // -------------------------------------------------------------- on: function(obj) { if( (obj.tagName == "IMG") && (obj.getAttribute("srcOn")) ){ obj.setAttribute("srcOff", obj.src); obj.src = obj.getAttribute("srcOn"); } if(obj.getAttribute("classRollOver")) { obj.setAttribute("originalClass", obj.className); obj.className = obj.getAttribute("classRollOver"); } }, off: function(obj) { if( (obj.tagName == "IMG") && (obj.getAttribute("srcOff")) ) { obj.src = obj.getAttribute("srcOff"); } if(obj.getAttribute("originalClass")) { obj.className = obj.getAttribute("originalClass"); } }, setRollovers: function() { for(var i=0; i maxLen) { obj.value = obj.value.substring(0, maxLen); } }, urlencode: function(str) { var div = document.createElement('div'); var text = document.createTextNode(str); div.appendChild(text); return div.innerHTML; }, // ----------------------------------------------------------------------------------------------------- // Funciones privadas // ----------------------------------------------------------------------------------------------------- resizeModalLayer: function() { var modalLayer = document.getElementById("__modallayer"); var docSize = Common.getDocumentSize(); if(modalLayer) Common.setObjectSize(modalLayer, docSize.width, docSize.height); }, applyInherit: function(original, interface) { for (method in interface) original[method] = interface[method]; return original; }, getMaxZIndex: function(isFloatingWindow) { return Common.getMaxZIndexChilds(document.body, isFloatingWindow); }, getMaxZIndexChilds: function(node, isFloatingWindow) { var elements = node.childNodes; var maxZIndex = -1; for (var i = 0; i < elements.length; i++) { if (elements[i].nodeName != "#text" && elements[i].nodeName != "#comment") { if (isFloatingWindow || !elements[i].getAttribute("floatingWindow")) { if(elements[i].style.zIndex) zIndex = parseInt(elements[i].style.zIndex); else zIndex = 0; if (zIndex > maxZIndex) maxZIndex = zIndex; } if (elements[i].hasChildNodes) { var tmp = Common.getMaxZIndexChilds(elements[i]); if (tmp > maxZIndex) maxZIndex = tmp; } } } return maxZIndex; }, dec2Hex : function (decVal) { var a = decVal % 16; var b = (decVal - a) / 16; hex = "" + hexChars.charAt(b) + hexChars.charAt(a); return hex; }, hex2Dec : function(hexVal) { hexVal = hexVal.toUpperCase(); var decVal = 0; var temp = hexVal.substring(0,1); decVal = (hexChars.indexOf(temp) * 16); temp = hexVal.substring(1); decVal += hexChars.indexOf(temp); return decVal; } } // --------------------------------------------------------------------------------------------------------------------- // Efectos // --------------------------------------------------------------------------------------------------------------------- var Effect = { setOpacity: function(obj, value) { if(Common.isFirefox()) Common.setStyleAttribute(obj, "opacity", value); else Common.setStyleAttribute(obj, "filter", "alpha(Opacity=" + value*100 + ")"); } } // --------------------------------------------------------------------------------------------------------------------- // Funciones Agregadas a la clase String // --------------------------------------------------------------------------------------------------------------------- // agrego la funcion trim a los strings String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,'') } String.prototype.htmlEncode = function() { var value = this; value = value.replace(/"/g, """) value = value.replace(//g, ">"); value = value.replace(/\r\n/g, "&enter;"); value = value.replace(/&/g, "&"); return value; } // agrego los rollovers a las imagenes que correspondan // Common.addEventListener(document, "load", Common.setRollovers, false); // Common.addEventListener(window, "load", Common.setRollovers, false);