Main Page | Modules | Directories | File List | File Members

utils.js

Go to the documentation of this file.
00001 /*
00002 * The Zapatec DHTML utils library
00003 *
00004 * Copyright (c) 2004-2005 by Zapatec, Inc.
00005 * http://www.zapatec.com
00006 * 1700 MLK Way, Berkeley, California,
00007 * 94709, U.S.A.
00008 * All rights reserved.
00009 * $Id: utils.js 2245 2006-03-24 03:30:17Z ken $
00010 *
00011 *
00012 * Various utility functions
00013 */
00014 
00015 // This can be defined in other modules
00016 if (typeof Zapatec == 'undefined') {
00018   Zapatec = {};
00019 }
00020 
00022 Zapatec.Utils = {};
00023 
00036 Zapatec.Utils.getAbsolutePos = function(el) {
00037         var SL = 0, ST = 0;
00038         var is_div = /^div$/i.test(el.tagName);
00039         if (is_div && el.scrollLeft)
00040                 SL = el.scrollLeft;
00041         if (is_div && el.scrollTop)
00042                 ST = el.scrollTop;
00043         var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
00044         if (el.offsetParent) {
00045                 var tmp = this.getAbsolutePos(el.offsetParent);
00046                 r.x += tmp.x;
00047                 r.y += tmp.y;
00048         }
00049         return r;
00050 };
00051 
00056 Zapatec.Utils.fixBoxPosition = function(box) {
00057         if (box.x < 0)
00058                 box.x = 0;
00059         if (box.y < 0)
00060                 box.y = 0;
00061         var cp = Zapatec.Utils.createElement("div");
00062         var s = cp.style;
00063         s.position = "absolute";
00064         s.right = s.bottom = s.width = s.height = "0px";
00065         window.document.body.appendChild(cp);
00066         var br = Zapatec.Utils.getAbsolutePos(cp);
00067         window.document.body.removeChild(cp);
00068         if (Zapatec.is_ie) {
00069                 br.y += window.document.body.scrollTop;
00070                 br.x += window.document.body.scrollLeft;
00071         } else {
00072                 br.y += window.scrollY;
00073                 br.x += window.scrollX;
00074         }
00075         var tmp = box.x + box.width - br.x;
00076         if (tmp > 0) box.x -= tmp;
00077         tmp = box.y + box.height - br.y;
00078         if (tmp > 0) box.y -= tmp;
00079 };
00080 
00101 Zapatec.Utils.isRelated = function (el, evt) {
00102         evt || (evt = window.event);
00103         var related = evt.relatedTarget;
00104         if (!related) {
00105                 var type = evt.type;
00106                 if (type == "mouseover") {
00107                         related = evt.fromElement;
00108                 } else if (type == "mouseout") {
00109                         related = evt.toElement;
00110                 }
00111         }
00112         try {
00113                 while (related) {
00114                         if (related == el) {
00115                                 return true;
00116                         }
00117                         related = related.parentNode;
00118                 }
00119         } catch(e) {};
00120         return false;
00121 };
00122 
00126 Zapatec.Utils.removeClass = function(el, className) {
00127         if (!(el && el.className)) {
00128                 return;
00129         }
00130         var cls = el.className.split(" ");
00131         var ar = [];
00132         for (var i = cls.length; i > 0;) {
00133                 if (cls[--i] != className) {
00134                         ar[ar.length] = cls[i];
00135                 }
00136         }
00137         el.className = ar.join(" ");
00138 };
00139 
00143 Zapatec.Utils.addClass = function(el, className) {
00144         Zapatec.Utils.removeClass(el, className);
00145         el.className += " " + className;
00146 };
00147 
00152 Zapatec.Utils.getElement = function(ev) {
00153         if (Zapatec.is_ie) {
00154                 return window.event.srcElement;
00155         } else {
00156                 return ev.currentTarget;
00157         }
00158 };
00159 
00164 Zapatec.Utils.getTargetElement = function(ev) {
00165         if (Zapatec.is_ie) {
00166                 return window.event.srcElement;
00167         } else {
00168                 return ev.target;
00169         }
00170 };
00171 
00175 Zapatec.Utils.stopEvent = function(ev) {
00176         ev || (ev = window.event);
00177         if (ev) {
00178                 if (Zapatec.is_ie) {
00179                         ev.cancelBubble = true;
00180                         ev.returnValue = false;
00181                 } else {
00182                         ev.preventDefault();
00183                         ev.stopPropagation();
00184                 }
00185         }
00186         return false;
00187 };
00188 
00202 Zapatec.Utils.addEvent = function(el, evname, func) {
00203         if (el.attachEvent) { // IE
00204                 el.attachEvent("on" + evname, func);
00205         } else if (el.addEventListener) { // Gecko / W3C
00206                 el.addEventListener(evname, func, false);
00207         } else {
00208                 el["on" + evname] = func;
00209         }
00210 };
00211 
00214 Zapatec.Utils.removeEvent = function(el, evname, func) {
00215         if (el.detachEvent) { // IE
00216                 el.detachEvent("on" + evname, func);
00217         } else if (el.removeEventListener) { // Gecko / W3C
00218                 el.removeEventListener(evname, func, false);
00219         } else {
00220                 el["on" + evname] = null;
00221         }
00222 };
00223 
00239 Zapatec.Utils.createElement = function(type, parent, selectable) {
00240         var el = null;
00241         if (window.self.document.createElementNS)
00242                 // use the XHTML namespace; IE won't normally get here unless
00243                 // _they_ "fix" the DOM2 implementation.
00244                 el = window.self.document.createElementNS("http://www.w3.org/1999/xhtml", type);
00245         else
00246                 el = window.self.document.createElement(type);
00247         if (typeof parent != "undefined" &&parent != null)
00248                 parent.appendChild(el);
00249         if (!selectable) {
00250                 if (Zapatec.is_ie)
00251                         el.setAttribute("unselectable", true);
00252                 if (Zapatec.is_gecko)
00253                         el.style.setProperty("-moz-user-select", "none", "");
00254         }
00255         return el;
00256 };
00257 
00258 // Cookie management
00259 
00268 Zapatec.Utils.writeCookie = function(name, value, domain, path, exp_days) {
00269         value = escape(value);
00270         var ck = name + "=" + value, exp;
00271         if (domain)
00272                 ck += ";domain=" + domain;
00273         if (path)
00274                 ck += ";path=" + path;
00275         if (exp_days) {
00276                 exp = new Date();
00277                 exp.setTime(exp_days * 86400000 + exp.getTime());
00278                 ck += ";expires=" + exp.toGMTString();
00279         }
00280         document.cookie = ck;
00281 };
00282 
00290 /* ? inside regular expression is not supported in IE 5.0
00291 Zapatec.Utils.getCookie = function(name) {
00292         var re = new RegExp("(^|;\\s*)" + name + "\\s*=(.*?)(;|$)");
00293         if (re.test(document.cookie)) {
00294                 var value = RegExp.$2;
00295                 value = unescape(value);
00296                 return (value);
00297         }
00298         return null;
00299 };
00300 */
00301 
00302 Zapatec.Utils.getCookie = function(name) {
00303         var pattern = name + "=";
00304         var tokenPos = 0;
00305         while (tokenPos < document.cookie.length) {
00306                 var valuePos = tokenPos + pattern.length;
00307                 if (document.cookie.substring(tokenPos, valuePos) == pattern) {
00308                         var endValuePos = document.cookie.indexOf(";", valuePos);
00309                         if (endValuePos == -1) { // Last cookie
00310                                 endValuePos = document.cookie.length;
00311                         }
00312                         return unescape(document.cookie.substring(valuePos, endValuePos));
00313                 }
00314                 tokenPos=document.cookie.indexOf(" ",tokenPos)+1;
00315                 if (tokenPos == 0) { // No more tokens
00316                         break;
00317                 }
00318         }
00319         return null;
00320 };
00321 
00330 Zapatec.Utils.makePref = function(obj) {
00331         function stringify(val) {
00332                 if (typeof val == "object" && !val)
00333                         return "null";
00334                 else if (typeof val == "number" || typeof val == "boolean")
00335                         return val;
00336                 else if (typeof val == "string")
00337                         return '"' + val.replace(/\22/, "\\22") + '"';
00338                 else return null;
00339         };
00340         var txt = "", i;
00341         for (i in obj)
00342                 txt += (txt ? ",'" : "'") + i + "':" + stringify(obj[i]);
00343         return txt;
00344 };
00345 
00353 Zapatec.Utils.loadPref = function(txt) {
00354         var obj = null;
00355         try {
00356                 eval("obj={" + txt + "}");
00357         } catch(e) {}
00358         return obj;
00359 };
00360 
00367 Zapatec.Utils.mergeObjects = function(dest, src) {
00368         for (var i in src)
00369                 dest[i] = src[i];
00370 };
00371 
00372 // based on the WCH idea
00373 // http://www.aplus.co.yu/WCH/code3/WCH.js
00374 
00376 
00377 
00378 Zapatec.Utils.__wch_id = 0;     
00399 Zapatec.Utils.createWCH = function(element) {
00400         var f = null;
00401         element = element || window.self.document.body;
00402         if (Zapatec.is_ie && !Zapatec.is_ie5) {
00403                 var filter = 'filter:progid:DXImageTransform.Microsoft.alpha(style=0,opacity=0);';
00404                 var id = "WCH" + (++Zapatec.Utils.__wch_id);
00405                 element.insertAdjacentHTML
00406                         ('beforeEnd', '<iframe id="' + id + '" scroll="no" frameborder="0" ' +
00407                          'style="z-index:0;position:absolute;visibility:hidden;' + filter +
00408                          'border:0;top:0;left:0;width:0;height:0;" ' +
00409                          'src="javascript:false;"></iframe>');
00410                 f = window.self.document.getElementById(id);
00411         }
00412         return f;
00413 };
00414 
00424 Zapatec.Utils.setupWCH_el = function(f, el, el2) {
00425         if (f) {
00426                 var pos = Zapatec.Utils.getAbsolutePos(el),
00427                         X1 = pos.x,
00428                         Y1 = pos.y,
00429                         X2 = X1 + el.offsetWidth,
00430                         Y2 = Y1 + el.offsetHeight;
00431                 if (el2) {
00432                         var p2 = Zapatec.Utils.getAbsolutePos(el2),
00433                                 XX1 = p2.x,
00434                                 YY1 = p2.y,
00435                                 XX2 = XX1 + el2.offsetWidth,
00436                                 YY2 = YY1 + el2.offsetHeight;
00437                         if (X1 > XX1)
00438                                 X1 = XX1;
00439                         if (Y1 > YY1)
00440                                 Y1 = YY1;
00441                         if (X2 < XX2)
00442                                 X2 = XX2;
00443                         if (Y2 < YY2)
00444                                 Y2 = YY2;
00445                 }
00446                 Zapatec.Utils.setupWCH(f, X1, Y1, X2-X1, Y2-Y1);
00447         }
00448 };
00449 
00459 Zapatec.Utils.setupWCH = function(f, x, y, w, h) {
00460         if (f) {
00461                 var s = f.style;
00462                 (typeof x != "undefined") && (s.left = x + "px");
00463                 (typeof y != "undefined") && (s.top = y + "px");
00464                 (typeof w != "undefined") && (s.width = w + "px");
00465                 (typeof h != "undefined") && (s.height = h + "px");
00466                 s.visibility = "inherit";
00467         }
00468 };
00469 
00475 Zapatec.Utils.hideWCH = function(f) {
00476         if (f)
00477                 f.style.visibility = "hidden";
00478 };
00479 
00481 
00483 
00484 
00489 Zapatec.Utils.getPageScrollY = function() {
00490         return window.pageYOffset ||
00491                         document.documentElement.scrollTop ||
00492                         (document.body ? document.body.scrollTop : 0) ||
00493                         0;
00494 };
00495 
00496 // Object setup.
00497 Zapatec.ScrollWithWindow = {};
00498 Zapatec.ScrollWithWindow.list = [];
00499 // Set to a number between 0 and 1, lower means longer scrolling.
00500 Zapatec.ScrollWithWindow.stickiness = 0.25;
00501 
00508 Zapatec.ScrollWithWindow.register = function(node) {
00509         var top = parseInt(node.style.top) || 0;
00510         var scrollY = window.pageYOffset || document.body.scrollTop ||
00511                 document.documentElement.scrollTop || 0;
00512         top -= scrollY;
00513         if (top < 0) top = 0;
00514         Zapatec.ScrollWithWindow.list[Zapatec.ScrollWithWindow.list.length] = {
00515                 node: node,
00516                 origTop: top
00517         };
00518 };
00519 
00525 Zapatec.ScrollWithWindow.unregister = function(node) {
00526         for (var count = 0; count < Zapatec.ScrollWithWindow.list.length; count++) {
00527                 var elm = Zapatec.ScrollWithWindow.list[count];
00528                 if (node == elm.node) {
00529                         Zapatec.ScrollWithWindow.list.splice(count, 1);
00530                         return;
00531                 }
00532         }
00533 };
00534 
00540 Zapatec.ScrollWithWindow.handler = function(newScrollY) {
00541         // Move oldScrollY towards newScrollY, evening up if the difference is small.
00542         oldScrollY += ((newScrollY - oldScrollY) * this.stickiness);
00543         if (Math.abs(oldScrollY - newScrollY) <= 1) oldScrollY = newScrollY;
00544         for (var count = 0; count < Zapatec.ScrollWithWindow.list.length; count++) {
00545                 var elm = Zapatec.ScrollWithWindow.list[count];
00546                 var node = elm.node;
00547                 if (!elm.origTop) {
00548                         elm.origTop = Zapatec.Utils.getAbsolutePos(node).y;
00549                         node.style.position = 'absolute';
00550                 }
00551                 node.style.top = elm.origTop + parseInt(oldScrollY) + 'px';
00552         }
00553 };
00554 
00555 // Processed scroll position & Event hook.
00556 var oldScrollY = Zapatec.Utils.getPageScrollY();
00557 setInterval(
00558         'var newScrollY = Zapatec.Utils.getPageScrollY(); ' +
00559         'if (newScrollY != oldScrollY) { ' +
00560                 'Zapatec.ScrollWithWindow.handler(newScrollY); ' +
00561         '}', 50);
00562 
00564 
00571 Zapatec.Utils.destroy = function(el) {
00572         if (el && el.parentNode)
00573                 el.parentNode.removeChild(el);
00574 };
00575 
00587 Zapatec.Utils.newCenteredWindow = function(url, windowName, width, height, scrollbars){
00588         var leftPosition = 0;
00589         var topPosition = 0;
00590         if (screen.width)
00591                 leftPosition = (screen.width -  width)/2;
00592         if (screen.height)
00593                 topPosition = (screen.height -  height)/2;
00594         var winArgs =
00595                 'height=' + height +
00596                 ',width=' + width +
00597                 ',top=' + topPosition +
00598                 ',left=' + leftPosition +
00599                 ',scrollbars=' + scrollbars +
00600                 ',resizable';
00601         var win = window.open(url,windowName,winArgs);
00602         return win;
00603 };
00604 
00611 Zapatec.Utils.getWindowSize = function() {
00612   var iWidth = 0;
00613   var iHeight = 0;
00614   if (document.compatMode && document.compatMode == 'CSS1Compat') {
00615     // Standards-compliant mode
00616     if (window.opera) {
00617         iWidth = document.body.clientWidth || 0;
00618         iHeight = document.body.clientHeight || 0;
00619     } else {
00620         iWidth = document.documentElement.clientWidth || 0;
00621         iHeight = document.documentElement.clientHeight || 0;
00622     }
00623   } else {
00624     // Non standards-compliant mode
00625         iWidth = window.innerWidth || document.body.clientWidth ||
00626          document.documentElement.clientWidth || 0;
00627         iHeight = window.innerHeight || document.body.clientHeight ||
00628          document.documentElement.clientHeight || 0;
00629   }
00630         return {
00631           width: iWidth,
00632           height: iHeight
00633         };
00634 };
00635 
00636 
00646 Zapatec.Utils.selectOption = function(sel, val, call_default) {
00647         var a = sel.options, i, o;
00648         for (i = a.length; --i >= 0;) {
00649                 o = a[i];
00650                 o.selected = (o.val == val);
00651         }
00652         sel.value = val;
00653         if (call_default) {
00654                 if (typeof sel.onchange == "function")
00655                         sel.onchange();
00656                 else if (typeof sel.onchange == "string")
00657                         eval(sel.onchange);
00658         }
00659 };
00660 
00674 Zapatec.Utils.getNextSibling = function(el, tag, alternateTag) {
00675         el = el.nextSibling;
00676         if (!tag) {
00677                 return el;
00678         }
00679         tag = tag.toLowerCase();
00680         if (alternateTag) alternateTag = alternateTag.toLowerCase();
00681         while (el) {
00682                 if (el.nodeType == 1 && (el.tagName.toLowerCase() == tag ||
00683                  (alternateTag && el.tagName.toLowerCase() == alternateTag))) {
00684                         return el;
00685                 }
00686                 el = el.nextSibling;
00687         }
00688         return el;
00689 };
00690 
00702 Zapatec.Utils.getFirstChild = function(el, tag, alternateTag) {
00703   if (!el) {
00704     return null;
00705   }
00706         el = el.firstChild;
00707   if (!el) {
00708     return null;
00709   }
00710         if (!tag) {
00711                 return el;
00712         }
00713         tag = tag.toLowerCase();
00714         if (el.nodeType == 1) {
00715                 if (el.tagName.toLowerCase() == tag) {
00716                         return el;
00717                 } else if (alternateTag) {
00718                         alternateTag = alternateTag.toLowerCase();
00719                         if (el.tagName.toLowerCase() == alternateTag) {
00720                                 return el;
00721                         }
00722                 }
00723         }
00724         return Zapatec.Utils.getNextSibling(el, tag, alternateTag);
00725 };
00726 
00734 Zapatec.Utils.getChildText = function(objNode) {
00735         if (objNode == null) {
00736                 return '';
00737         }
00738         var arrText = [];
00739         var objChild = objNode.firstChild;
00740         while (objChild != null) {
00741                 if (objChild.nodeType == 3) { // Node.TEXT_NODE
00742                         arrText.push(objChild.data);
00743                 }
00744                 objChild = objChild.nextSibling;
00745         }
00746         return arrText.join(' ');
00747 };
00748 
00757 Zapatec.Utils.insertAfter = function(oldNode, newNode) {
00758         if(oldNode.nextSibling) {
00759                 oldNode.parentNode.insertBefore(newNode, oldNode.nextSibling);
00760         } else {
00761                 oldNode.parentNode.appendChild(newNode);
00762         }
00763 }
00764 
00765 Zapatec.Utils._ids = {};        
00778 Zapatec.Utils.generateID = function(code, id) {
00779         if (typeof id == "undefined") {
00780                 if (typeof this._ids[code] == "undefined")
00781                         this._ids[code] = 0;
00782                 id = ++this._ids[code];
00783         }
00784         return "zapatec-" + code + "-" + id;
00785 };
00786 
00800 Zapatec.Utils.addTooltip = function(target, tooltip) {
00801 return new Zapatec.Tooltip(target, tooltip);
00802 };
00803 
00804 Zapatec.isLite=true;
00805 
00806 Zapatec.Utils.checkActivation = function() {
00807         if (!Zapatec.isLite)    return true;
00808 
00809         var arrProducts=[]
00810 
00811         add_product=function(script, webdir_in, name_in)
00812         {
00813         arrProducts[script]={webdir:webdir_in, name:name_in, bActive:false}
00814         }
00815 
00816         add_product('calendar.js', 'prod1',   'Calendar')
00817         add_product('menu.js',     'prod2',   'Menu')
00818         add_product('tree.js',     'prod3',   'Tree')
00819         add_product('form.js',     'forms',   'Forms')
00820         add_product('effects.js',  'effects', 'Effects')
00821         add_product('hoverer.js',  'effects', 'Effects - Hoverer')
00822         add_product('slideshow.js','effects', 'Effects - Slidshow')
00823         add_product('zpgrid.js',   'grid',    'Grid')
00824         add_product('slider.js',   'slider',  'Slider')
00825         add_product('zptabs.js',   'tabs',    'Tabs')
00826         add_product('zptime.js',   'time',    'Time')
00827         add_product('window.js',   'windows', 'Window')
00828 
00829 
00830         var strName, arrName, i
00831         var bProduct=false // Flag yes if we have a zapatec script
00832         var scripts = document.getElementsByTagName('script');
00833         for (i=0; i<scripts.length; i++)
00834         {
00835                 // If wizard then do NOT do link back check, which makes wizard err out
00836                 if (/wizard.js/i.test(scripts[i].src))
00837                         return true
00838 
00839                 arrName=scripts[i].src.split('/')
00840                 if (arrName.length==0)
00841                         strName=scripts[i]
00842                 else
00843                         strName=arrName[arrName.length-1]
00844                 strName=strName.toLowerCase()
00845                 // Get each active product
00846                 if (typeof arrProducts[strName] != 'undefined')
00847                         {
00848                         bProduct=true
00849                         arrProducts[strName].bActive=true
00850                         }
00851         }
00852 
00853         // Is a LITE product even being used?
00854         if (!bProduct) return true;
00855 
00856 
00857         var anchors = document.getElementsByTagName('A');
00858         for(i = 0; i < anchors.length; i++)
00859                 if (/(dev|www)\.zapatec\.com/i.test(anchors[i].href))
00860                         return true;
00861 
00862         var strMsg='You are using the Free version of the Zapatec Software.\n'+
00863         'While using the Free version, a link to www.zapatec.com in this page is required.'
00864 
00865         for (i in arrProducts)
00866                 // Get each active product
00867                 if (arrProducts[i].bActive==true)
00868                         strMsg+='\nTo purchase the Zapatec ' + arrProducts[i].name + ' visit www.zapatec.com/website/main/products/' + arrProducts[i].webdir + '/'
00869 
00870         alert(strMsg)
00871 
00872         return false;
00873 }
00874 
00875 // Browser sniffing
00876 
00878 Zapatec.is_opera = /opera/i.test(navigator.userAgent);
00879 
00881 Zapatec.is_ie = ( /msie/i.test(navigator.userAgent) && !Zapatec.is_opera );
00882 
00884 Zapatec.is_ie5 = ( Zapatec.is_ie && /msie 5\.0/i.test(navigator.userAgent) );
00885 
00887 Zapatec.is_mac_ie = ( /msie.*mac/i.test(navigator.userAgent) && !Zapatec.is_opera );
00888 
00890 Zapatec.is_khtml = /Konqueror|Safari|KHTML/i.test(navigator.userAgent);
00891 
00893 Zapatec.is_konqueror = /Konqueror/i.test(navigator.userAgent);
00894 
00896 Zapatec.is_gecko = /Gecko/i.test(navigator.userAgent);
00897 
00901 if (!Function.prototype.call) {
00902         Function.prototype.call = function () {
00903                 var self = arguments[0];
00904                 self._this_func = this;
00905                 var args = new Array();
00906                 for (var i=1; i < arguments.length; i++) {
00907                         args[args.length] = 'arguments[' + i + ']';
00908                 }
00909                 var ret = eval('self._this_func(' + args.join(',') + ')');
00910                 self._this_func = null;
00911                 return ret;
00912         };
00913 }
00914 
00918 if (!Array.prototype.pop) {
00919         Array.prototype.pop = function() {
00920                 var last;
00921                 if (this.length) {
00922                         last = this[this.length - 1];
00923                         this.length -= 1;
00924                 }
00925                 return last;
00926         };
00927 }
00928 
00932 if (!Array.prototype.push) {
00933         Array.prototype.push = function() {
00934                 for (var i = 0; i < arguments.length; i++) {
00935                         this[this.length] = arguments[i];
00936                 }
00937                 return this.length;
00938         };
00939 }
00940 
00944 if (!Array.prototype.shift) {
00945         Array.prototype.shift = function() {
00946                 var first;
00947                 if (this.length) {
00948                         first = this[0];
00949                         for (var i = 0; i < this.length - 1; i++) {
00950                                 this[i] = this[i + 1];
00951                         }
00952                         this.length -= 1;
00953                 }
00954                 return first;
00955         };
00956 }
00957 
00961 if (!Array.prototype.unshift) {
00962         Array.prototype.unshift = function() {
00963                 if (arguments.length) {
00964                         var i, len = arguments.length;
00965                         for (i = this.length + len - 1; i >= len; i--) {
00966                                 this[i] = this[i - len];
00967                         }
00968                         for (i = 0; i < len; i++) {
00969                                 this[i] = arguments[i];
00970                         }
00971                 }
00972                 return this.length;
00973         };
00974 }
00975 
00979 if (!Array.prototype.splice) {
00980         Array.prototype.splice = function(index, howMany) {
00981                 var elements = [], removed = [], i;
00982                 for (i = 2; i < arguments.length; i++) {
00983                         elements.push(arguments[i]);
00984                 }
00985                 for (i = index; (i < index + howMany) && (i < this.length); i++) {
00986                         removed.push(this[i]);
00987                 }
00988                 for (i = index + howMany; i < this.length; i++) {
00989                         this[i - howMany] = this[i];
00990                 }
00991                 this.length -= removed.length;
00992                 for (i = this.length + elements.length - 1; i >= index + elements.length;
00993                  i--) {
00994                         this[i] = this[i - elements.length];
00995                 }
00996                 for (i = 0; i < elements.length; i++) {
00997                         this[index + i] = elements[i];
00998                 }
00999                 return removed;
01000         };
01001 }
01002 
01012 Zapatec.Log = function(objArgs) {
01013   // Check arguments
01014   if (!objArgs) {
01015     return;
01016   }
01017   // Form error message
01018   var strMessage = objArgs.description;
01019   if (objArgs.severity) {
01020     strMessage = objArgs.severity + ':\n' + strMessage;
01021   }
01022   // Display error message
01023   alert(strMessage);
01024 };
01025 
01027 Zapatec.Utils.Array = {};
01028 
01039 Zapatec.Utils.Array.insertBefore = function (arr, el, key, nextKey) {
01040         var tmp = new Array();
01041         for(var i in arr) {
01042                 if (i == nextKey) {
01043                         if (key) {
01044                                 tmp[key] = el;
01045                         } else {
01046                                 tmp.push(el);
01047                         }
01048                 }
01049                 tmp[i] = arr[i];
01050         }
01051         return tmp;
01052 }