/* *********************************************************************** */

var com = com ? com : {}
    com.bigllc  = com.bigllc ? com.bigllc : {};   
    
/* *********************************************************************** */

if(!com.bigllc.lang) {
    
com.bigllc.lang  = com.bigllc.lang ? com.bigllc.lang : {};

/* *********************************************************************** */

com.bigllc.lang.BootStrap = function() {
  this.boot();   
}

/* *********************************************************************** */

com.bigllc.lang.BootStrap.prototype = {
  
  boot: function() {
    Function.prototype.method = function (name, func) {
        this.prototype[name] = func;
        return this;
    };
  
    if(!this.isFunction(Array.prototype.push)) {
      Array.method('push', function () {
        this.splice.apply(this,
          [this.length, 0].concat(Array.prototype.slice.apply(arguments)));
          return this.length;
      });
    }
  
    if(!this.isFunction(Array.prototype.clear)) {
      Array.method('clear', function () {
        this.splice(0, this.length);
      });
    }

    if(!this.isFunction(String.prototype.trim)) {
      String.method('trim', function () {
        a = this.replace(/^\s+/, '');
        return a.replace(/\s+$/, '');
      });
    }
    
  },
  
  isFunction: function(a) {
    return typeof a == 'function';
  }
  

}

new com.bigllc.lang.BootStrap();

/* *********************************************************************** */
  
com.bigllc.lang.System_ = function() {
  if(com.bigllc.lang.System) return com.bigllc.lang.System;
  return this;
}

/* *********************************************************************** */

com.bigllc.lang.System_.prototype = {
  
  isFunction: function(a) {
    return typeof a == 'function';
  },
  
  isUndefined: function(a) {
    return typeof a == 'undefined';
  },
  
  addEvent: function(elm, evType, fn, useCapture) 
  {   
    if (elm.addEventListener) 
    {  
        elm.addEventListener(evType, fn, useCapture);  
        return true;   
    } 
    else if (elm.attachEvent)
    {  
        var r = elm.attachEvent("on"+evType, fn);  
        return r;   
    } 
    else 
    {  
      alert("Handler could not be added " + elm.tagName + " " + evType);   
    } 
  },      
  
  getParameter: function (name) {
     var url = window.location.href;
     var paramsStart = url.indexOf("?");
  
     if(paramsStart != -1){
  
        var paramString = url.substr(paramsStart + 1);
        var tokenStart = paramString.indexOf(name);
  
        if(tokenStart != -1){
  
           paramToEnd = paramString.substr(tokenStart + name.length + 1);
           var delimiterPos = paramToEnd.indexOf("&");
  
           if(delimiterPos == -1){
              return paramToEnd;
           }
           else {
              return paramToEnd.substr(0, delimiterPos);
           }
        }
     }
  },

  fireEvent: function(elm,evType)
  {
    if(typeof elm.fireEvent != "undefined") {
      elm.fireEvent("on" + evType);
    }
    else
    {
      var evt = document.createEvent("HTMLEvents");
      evt.initEvent(evType,true,true)
      elm.dispatchEvent(evt);
    }
  },

  

  getElementsByTagAndClassName: function(tag, className) {
    var children = document.getElementsByTagName(tag);
    var elements = [];

    for (var i = 0; i < children.length; i++) {
        var child = children[i];
        var classNames = child.className.split(' ');
        for (var j = 0; j < classNames.length; j++) {
            if (classNames[j] == className) {
                elements.push(child);
                break;
            }
        }
    }

    return elements;
  },
   
  insertAfter: function(referenceNode, node) {
    var parent = referenceNode.parentNode;
    if(referenceNode.nextSibling) {
      parent.insertBefore(node, referenceNode.nextSibling);
    }
    else {
      parent.appendChild(node);
    }
  },
  
  getWinHeight: function () { 
    return document.documentElement.clientHeight ? 
      document.documentElement.clientHeight : 
      window.innerHeight != null ? innerHeight : 
      document.body['clientHeight']; 
  },	
  
  getWinWidth: function() { 
    return document.documentElement.clientWidth ? 
      document.documentElement.clientWidth : 
      window.innerHeight != null ? innerWidth : 
      document.body['clientWidth']; 
  },	
  
  getScrollX: function() { 
     return document.documentElement.scrollLeft != null ? 
      document.documentElement.scrollLeft : 
      window.innerHeight != null ? pageXOffset : 
      document.body['scrollLeft']; 
  },
  	
  getScrollY: function() { 
    return document.documentElement.scrollTop != null ? 
      document.documentElement.scrollTop : 
      window.innerHeight != null ? pageYOffset : 
      document.body['scrollTop']; 
  },
  
	getPosition:  function(o) {
		if (o==null) {
			return null;
		}
		
		var left = 0;
		var top = 0;
		var width = 0;
		var height = 0;
		var parentNode = null;
		var offsetParent = null;
	
		offsetParent = o.offsetParent;
		var originalObject = o;
		var el = o; // "el" will be nodes as we walk up, "o" will be saved for offsetParent references
		while (el.parentNode!=null) 
		{
			el = el.parentNode;
			if (el.offsetParent!=null) {
				var considerScroll = true;
				if (window.opera) {
					if (el==originalObject.parentNode || el.nodeName=="TR") {
						considerScroll = false;
					}
				}
				if (considerScroll) {
					if (el.scrollTop && el.scrollTop>0)   top -= el.scrollTop;
					if (el.scrollLeft && el.scrollLeft>0) left -= el.scrollLeft;
				}
			}
			
			if (el == offsetParent) {
				left += o.offsetLeft;
				if (el.clientLeft && el.nodeName!="TABLE") { 
					left += el.clientLeft;
				}
				
				top += o.offsetTop;
				if (el.clientTop && el.nodeName!="TABLE") {
					top += el.clientTop;
				}
				
				o = el;
				if (o.offsetParent==null) {
					if (o.offsetLeft) {
						left += o.offsetLeft;
					}
					if (o.offsetTop) {
						top += o.offsetTop;
					}
				}
				offsetParent = o.offsetParent;
			}
		}
		
		if (originalObject.offsetWidth) {
			width = originalObject.offsetWidth;
		}
		if (originalObject.offsetHeight) {
			height = originalObject.offsetHeight;
		}
		
		return {'left':left, 'top':top, 'width':width, 'height':height};
	},
  	
  setCookie: function(name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
    document.cookie = curCookie;
  },
  
  
  getCookie: function(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
      begin = dc.indexOf(prefix);
      if (begin != 0) return null;
    } else
      begin += 2;
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
      end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
  },
  
  deleteCookie: function (name, path, domain) {
    if (this.getCookie(name)) {
      document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
  }
}

com.bigllc.lang.System = new com.bigllc.lang.System_();
  
/* *********************************************************************** */

com.bigllc.lang.Event = function(event) {
  
  this.event = event;
  this.eventModel = this.__getEventModel__(event);
  if(!this.event) { this.event=window.event; }
  
  this.clientX  = this.__getClientX__();
  this.clientY  = this.__getClientY__();;
  this.viewX  = this.__getViewX__();
  this.viewY  = this.__getViewY__();;
  
  this.target   = this.event.srcElement ? this.event.srcElement : this.event.target;
  this.which    = this.__getKeyCode__();
  this.shiftKey = this.__getShiftKey__();
  this.ctrlKey  = this.__getCtrlKey__();
  this.altKey   = this.__getAltKey__();
  //this.escapeKey = (event) ? e.DOM_VK_ESCAPE  : (this.which == 27)
};
      
/* *********************************************************************** */

com.bigllc.lang.Event.prototype = {
  
  getKeyChar: function() {
    var key = this.which;
    return key ? String.fromCharCode(key) : null;
  },
  
  cancelEvent: function() {
    if(this.event.preventDefault) {
      this.event.preventDefault();
      this.event.stopPropagation();
    }
    else {
      this.event.cancelBubble = true;
      this.event.returnValue = false;
    }
  },
  
  isControlKey: function() {
    var key = this.which;
    if((key==null) || (key==0) || (key==8) ||
       (key==9)    || (key==13) || (key==27) ) 
    {
      return true;
    }
    return false;
  },
  
  __getKeyCode__: function() {
    if (this.event.keyCode) return this.event.keyCode;
    else if (!com.bigllc.lang.System.isUndefined(this.event.which)) return this.event.which;
    return null;
  },
  
  __getShiftKey__: function() {
    return (this.event.shiftKey) ? this.event.shiftKey :
      this.event.modifiers ? this.event.modifiers | 4 : false;
  },

  __getAltKey__: function() {
    return (this.event.altKey) ? this.event.altKey :
      this.event.modifiers ? this.event.modifiers | 1 : false;
  },

  __getCtrlKey__: function() {
    return (this.event.ctrlKey) ? this.event.ctrlKey :
      this.event.modifiers ? this.event.modifiers | 2 : false;
  },
  
  __getClientX__: function() {
    return (this.event.clientX) ? this.event.clientX : 
           (this.event.pageX) ? this.event.pageX : null;
  },

  __getClientY__: function() {
    return (this.event.clientY) ? this.event.clientY : 
           (this.event.pageY) ? this.event.pageY : null;
  },

  __getViewX__: function() {
    return (this.eventModel == "IE4+") ? 
      this.clientX  +  com.bigllc.lang.System.getScrollX() :
      this.clientX;
  },

  __getViewY__: function() {
    return (this.eventModel == "IE4+") ? 
      this.clientY  +  com.bigllc.lang.System.getScrollY() :
      this.clientY;
  },
  
  __getEventModel__: function(e) {
    if (e != null) {//Netscape 4 or W3C DOM event model
      if(e.eventPhase != null) { return "W3C"; }
      else { return  "NN4" };
    }
    else if (window.event != null) {
      return emod = "IE4+";
    }

    return "UNKNOWN";
  }
};

/* *********************************************************************** */

}