/* GAJAX Javascript Libraly And Ajax Frame Work design by http://www.goragod.com (goragod wiriya) 3-4-53 */ GBrowser = { IE: !!(window.attachEvent && !window.opera), Opera: !!window.opera, WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1, Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1, MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/) }; var domloaded = false; var GClass = { create: function() { return function() { this.initialize.apply(this, arguments); }; } }; Object.extend = function(destination, source) { for(var property in source) { destination[property] = source[property]; }; return destination; }; Object.extend(Object, { isObject: function(object) { return typeof object == "object"; }, isFunction: function(object) { return typeof object == "function"; }, isString: function(object) { return typeof object == "string"; }, isNumber: function(object) { return typeof object == "number"; }, isNull: function(object) { return typeof object == "undefined"; }, isGElement: function(object) { return object != null && typeof object == "object" && 'getDimensions' in object && 'viewportOffset' in object; } } ); GEvent = { isButton: function(event, code) { var buttonMap = {0: 1, 1: 4, 2: 2}; if (GBrowser.IE) { return event.button == buttonMap[code]; } else if (GBrowser.WebKit) { switch (code) { case 0: return event.which == 1 && !event.metaKey; case 1: return event.which == 1 && event.metaKey; default: return false; } } else { return event.which? (event.which === code + 1): (event.button === code); } }, isLeftClick: function(event) {return GEvent.isButton(event, 0)}, isMiddleClick: function(event) {return GEvent.isButton(event, 1)}, isRightClick: function(event) {return GEvent.isButton(event, 2)}, element: function(event) { var node = event.target? event.target: event.srcElement; return event.nodeType == 3? node.parentNode: node; }, keyCode: function(event) { return event.which || event.keyCode; }, stop: function(event) { if(event.stopPropagation) { event.stopPropagation(); event.preventDefault(); } else { event.cancelBubble = true; event.returnValue = false; }; }, pointer: function(event) { return { x: event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)), y: event.pageY || (event.clientY + (document.documentElement.scrollTop || document.body.scrollTop)) }; }, pointerX: function(event) {return GEvent.pointer(event).x}, pointerY: function(event) {return GEvent.pointer(event).y} }; function _Element(elem, src) { var property; if (Object.isString(elem)) { var obj = document.getElementById(elem); if(!obj) { src.elem = elem; return false; }else if(obj.nodeType == 1) { for(property in obj) { try { src[property] = obj[property]; }catch(e) {}; }; src.elem = obj; return true; }; }else if(elem != window) { for(property in elem) { try { src[property] = elem[property]; }catch(e) {}; }; } src.elem = elem; return true; }; GNative = GClass.create(); GNative.prototype = { initialize: function(elem) { _Element(elem, this); } }; GElement = GClass.create(); GElement.prototype = Object.extend(new GNative(), { getDimensions: function() { var display = this.getStyle('display'); if (display != 'none' && display != null) { var originalWidth = this.elem.offsetWidth; var originalHeight = this.elem.offsetHeight; } else { var els = this.elem.style; var originalVisibility = els.visibility; var originalPosition = els.position; var originalDisplay = els.display; els.visibility = 'hidden'; els.position = 'absolute'; els.display = 'block'; var originalWidth = this.elem.clientWidth; var originalHeight = this.elem.clientHeight; els.display = originalDisplay; els.position = originalPosition; els.visibility = originalVisibility; }; var result =[originalWidth, originalHeight]; result.width = originalWidth; result.height = originalHeight; return result; }, viewportOffset: function() { var valueT = this.elem.offsetTop; var valueL = this.elem.offsetLeft; var parentEl = this.elem.offsetParent; while(parentEl != null) { valueT += parentEl.offsetTop; valueL += parentEl.offsetLeft; if (parentEl.offsetParent == document.body && parentEl.style.position == 'absolute') break; parentEl = parentEl.offsetParent; }; var result =[valueL, valueT]; result.left = valueL; result.top = valueT; return result; }, getOffsetParent: function() { if (this.elem.offsetParent) return GElement(this.elem.offsetParent); if (this.elem == document.body) return this.elem; while((element = this.elem.parentNode) && element != document.body) { if (element.style.position != 'static') return GElement(element); }; return GElement(document.body); }, getTop: function() { return this.viewportOffset().top; }, getLeft: function() { return this.viewportOffset().left; }, getWidth: function() { return this.getDimensions().width; }, getHeight: function() { return this.getDimensions().height; }, hide: function() { this.setStyle('visibility', 'hidden'); }, show: function() { this.setStyle('visibility', 'visible'); }, visible: function() { return this.style.visibility != 'hidden'; }, toggle: function() { if (this.visible) { this.hide(); } else { this.show(); }; }, center: function() { var size = this.getDimensions(); this.style.top = (document.viewport.getscrollTop() + ((document.viewport.getHeight() - size.height) / 2)) + 'px'; this.style.left = (document.viewport.getscrollLeft() + ((document.viewport.getWidth() - size.width) / 2)) + 'px'; }, getStyle: function(style) { style = (style == 'float' && this.elem.currentStyle)? 'styleFloat': style; style = (style == 'borderColor')? 'borderBottomColor': style; value = (this.elem.currentStyle)? this.elem.currentStyle[style]: null; value = (!value && window.getComputedStyle) ? document.defaultView.getComputedStyle(this.elem, null).getPropertyValue(style.replace(/([A-Z])/g, "-$1").toLowerCase()) : value; if (style == 'opacity') return value? parseFloat(value): 1.0; return value == 'auto'? null: value; }, setStyle: function(property, value) { if (property == 'opacity') { if (window.ActiveXObject) this.elem.style.filter = "alpha(opacity=" + (value * 100) + ")"; this.elem.style.opacity = value; } else if (property == 'float' || property == 'styleFloat' || property == 'cssFloat') { if (Object.isNull(this.elem.style.styleFloat)) { this.elem.style['cssFloat'] = value; } else { this.elem.style['styleFloat'] = value; }; } else { this.elem.style[property] = value; } }, addEvent: function(type, fn, useCapture) { var obj = this.elem; if (obj.addEventListener) { useCapture = !useCapture? false: useCapture; obj.addEventListener(type, fn, useCapture); }else if (obj.attachEvent) { obj["e"+type+fn] = fn; obj[type+fn] = function() {obj["e"+type+fn](window.event);}; obj.attachEvent("on"+type, obj[type+fn]); }; }, removeEvent: function(type, fn) { if (this.elem.removeEventListener) this.elem.removeEventListener(((type == 'mousewheel' && window.gecko)? 'DOMMouseScroll': type), fn, false); else this.elem.detachEvent('on'+type, fn); }, remove: function() { this.elem.parentNode.removeChild(this.elem); }, copy: function() { return $G(this.elem.cloneNode(true)); }, insert: function(el) { this.elem.appendChild(Object.isGElement(el)? el.elem: el); }, insertBefore: function(el) { this.elem.parentNode.insertBefore(Object.isGElement(el)? el.elem: el); }, insertAfter: function(el) { var parent = this.elem.parentNode; var newElement = Object.isGElement(el)? el.elem: el; if(parent.lastchild == this.elem) { parent.appendChild(newElement); }else { parent.insertBefore(newElement, this.elem.nextSibling); } }, replace: function(el) { this.elem.parentNode.replaceChild(Object.isGElement(el)? el.elem: el, this.elem); }, get: function(prop) { return this.elem.getAttribute(prop); }, set: function(prop, value) { this.elem.setAttribute(prop, value); }, Ready: function(onload) { this.timeout = 0; var temp = this; var preload = function() { if(domloaded && _Element(temp.elem, temp)) { onload.call(temp); }else if(temp.timeout < 1000) { window.setTimeout(preload, 10); temp.timeout++; } }; preload(); } } ); Function.prototype.bind = function(object) { var __method = this; return function() { return __method.apply(object, arguments); } }; function functionReady(func, onload) { var preload = function() { if(domloaded && typeof func != "undefined") { onload.apply(); } else { window.setTimeout(preload, 10); }; }; preload(); }; $G(window).addEvent('load', function() { domloaded = true; } ); if (!Array.prototype.indexOf) Array.prototype.indexOf = function(item, i) { i || (i = 0); var length = this.length; if (i < 0) i = length + i; for (; i < length; i++) if (this[i] === item) return i; return -1; }; function forEach(items, func) { for (var i = 0; i < items.length; i++) { func.call(this, items[i], i); }; }; Object.extend(String.prototype, { hexToRgb: function(array) { var hex = this.match(new RegExp('^[#]{0,1}([\\w]{1,2})([\\w]{1,2})([\\w]{1,2})$')); var rgb =[]; for (var i = 1; i < hex.length; i++) { if (hex[i].length == 1) hex[i] += hex[i]; rgb.push(parseInt(hex[i], 16)); }; var rgbText = 'rgb(' + rgb.join(',') + ')'; if (array) return[parseFloat(rgb[0]), parseFloat(rgb[1]), parseFloat(rgb[2])]; else return rgbText; }, ToRgb: function() { if (this.match(/^#[0-9a-f]{3,6}$/i)) return this.hexToRgb(true); return ((value = this.match(/(\d+),\s*(\d+),\s*(\d+)/)))?[parseFloat(value[1]), parseFloat(value[2]), parseFloat(value[3])]: false; }, entityify: function() { return this. replace(/&/g, '&'). replace(//g, '>'); }, unentityify: function() { return this. replace(/&/g, '&'). replace(/</g, '<'). replace(/>/g, '>'); }, toJSON: function() { try { if (this.length > 4) return eval('(' + this + ')'); } catch (e) {}; return null; }, escapeRegExp: function() { return this.replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1'); }, capitalize: function() { return this.replace(/\b[a-z]/g, function(match) { return match.toUpperCase(); } ); }, evalScript: function() { var regex = /