Object.extend(Array.prototype, {
	_find:function(pattern,param){
		param=(param)?'.'+param:'';
		for(var i=0;i<this.length;i++)
		{
			if(pattern==eval('this[i]'+param))return i;
		}
		return -1;
	},
	_contains:function(pattern,param){
		param=(param)?'.'+param:'';
		for(var i=0;i<this.length;i++)
		{
			if(pattern==eval('this[i]'+param))return true;
		}
		return false;
	},
	_insertAt:function(ind,value){
		this[this.length] = null;
		for(var i=this.length-1;i>=ind;i--)
		{
			this[i] = this[i-1];
		}
		this[ind] = value;
	},
	_without : function(){
		var arr = this.without.apply(this,arguments).compact();
		for(var i=0;i<arr.length;i++){
			this[i] = arr[i];
		}
		this.length = arr.length;
	},
	_remove:function(ind){
		for(var i=ind;i<this.length;i++)
		{
			this[i] = this[i+1]
		}
		this.length--;
	},
	_removes:function(inds){
		for(var i=0;i<inds.length;i++)
		{
			try{
				this[inds[i]] = null;
			}catch(err){}
		}
		var arr = this.compact();
		for(var i=0;i<arr.length;i++){
			this[i] = arr[i];
		}
		this.length = arr.length;
	},
	_swapItems:function(ind1,ind2){
		var tmp = this[ind1];
		this[ind1] = this[ind2]
		this[ind2] = tmp;
	},
	_sort:function(up,param){
		param=(param)?'.'+param:'';
		for(var i=0;i<this.length;i++)
		{
			var m=eval('this[i]'+param);
			var index=i;
			for(var j=i+1;j<this.length;j++)
			{
				tmp=eval('this[j]'+param);
				if(up&&m>tmp){
					m=tmp;
					index=j;
				}
				if(!up&&m<tmp){
					m=tmp;
					index=j;
				}
			}
			if(i<index)this._swapItems(i,index);
		}
	}
});

Element.insertHTML=function(oEdit,_sStr,hideDiv){
	oEdit=oEdit.contentWindow;
	if (_IE) {
		try
		{
			oEdit.focus();
			var selection=oEdit.document.selection;
			$log().debug("selection="+selection);
			var selectedRange;
			if(selection)
			{
				selectedRange = selection.createRange();
				selectedRange = hideDiv.range;
			}
			$log().debug("hideDiv.type="+hideDiv.type);
			$log().debug("selection.type="+selection.type);
			if(hideDiv.type.toLowerCase()=='control'||selection.type.toLowerCase()=='control')
			{
				var node=selectedRange.item(0);
				$log().debug("node="+node);
				var parent=node.parentNode;
				if(node.tagName.toLowerCase()=='img'&&parent.tagName.toLowerCase()=='a')
				{
					node=parent;
					parent=parent.parentNode;
				}
				$log().debug("parent="+parent);
				$log().debug("node="+node);
				node.insertAdjacentHTML('beforeBegin',_sStr);
				parent.removeChild(node);
				oEdit.focus();
			}
			else
			{
				$log().debug("selectedRange.text="+selectedRange.text);
				selectedRange.pasteHTML(_sStr);
				selectedRange.collapse(false);
				selectedRange.select();
				oEdit.focus();
			}
		}catch(err)
		{
			$log().error(err.message);
			$alert(err.message);
		}
	}
	else
	{
	 	oEdit.focus();
		oEdit.document.execCommand('insertHTML', false, _sStr);
	}
	delete hideDiv;
	delete oEdit;
}

if(!_IE)
{
	HTMLElement.prototype.__defineGetter__("innerText",function(){
		/*
		var text=null;
		text = this.ownerDocument.createRange();
		text.selectNodeContents(this);

		text = text.toString();
		return text;
		*/
		return this.textContent;
	});
	HTMLElement.prototype.__defineSetter__("innerText", function (sText) {
//		this.innerHTML = sText.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g,'<br>');
		this.textContent = sText;
	});
	var _emptyTags = {
	   "IMG":   true,
	   "BR":    true,
	   "INPUT": true,
	   "META":  true,
	   "LINK":  true,
	   "PARAM": true,
	   "HR":    true
	};
	HTMLElement.prototype.__defineGetter__("outerHTML", function () {
	   var attrs = this.attributes;
	   var str = "<" + this.tagName;
	   for (var i = 0; i < attrs.length; i++)
	      str += " " + attrs[i].name + "=\"" + attrs[i].value + "\"";
	
	   if (_emptyTags[this.tagName])
	      return str + ">";
	
	   return str + ">" + this.innerHTML + "</" + this.tagName + ">";
	});
	HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
	   var r = this.ownerDocument.createRange();
	   r.setStartBefore(this);
	   var df = r.createContextualFragment(sHTML);
	   this.parentNode.replaceChild(df, this);
	});
	HTMLElement.prototype.__defineGetter__("outerText", function () {
	   var r = this.ownerDocument.createRange();
	   r.selectNodeContents(this);
	   return r.toString();
	});
	HTMLElement.prototype.__defineSetter__("outerText", function (sText) {
	   this.outerHTML = sText.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g,'<br>');
	});
	HTMLElement.prototype.__defineGetter__("uniqueID", function(){
		if(!arguments.callee.count)arguments.callee.count=0;
		var u = "moz_id" + arguments.callee.count++;
//		window[u] = this;
		this.__defineGetter__("uniqueID",function(){return u});
		return u;
	});
};

// Create the loadXML method and xml getter for Mozilla
if ( window.DOMParser &&
	  window.XMLSerializer &&
	  window.Node && Node.prototype && Node.prototype.__defineGetter__ ) {

   if (!Document.prototype.loadXML) {
      Document.prototype.loadXML = function (s) {
         var doc2 = (new DOMParser()).parseFromString(s, "text/xml");
         while (this.hasChildNodes())
            this.removeChild(this.lastChild);

         for (var i = 0; i < doc2.childNodes.length; i++) {
            this.appendChild(this.importNode(doc2.childNodes[i], true));
         }
      };
	}

	Document.prototype.__defineGetter__( "xml",
	   function () {
		   return (new XMLSerializer()).serializeToString(this);
	   }
	 );
}

Object.extend(Form,{
	$ : function(name){
		var v = document.getElementsByName(name);
		if(v.length == 1)return v[0];
		return v;
	},
	$value : function(name){
		var v = document.getElementsByName(name);
		var a = [];
		for ( var i=0 ; i<v.length ; i++ ) {
			var sTmp = Form.Element.getValue(v[i]);
			if ( sTmp!=null && sTmp!=undefined ) {
				a.push(sTmp);
			}
		}
		return (a.length==1) ? a[0] : a;
	}
});

Object.extend(String.prototype, {
	lTrim : function () {
		return this.replace(/^\s*/, "");
	},
	rTrim : function () {
		return this.replace(/\s*$/, "");
	},
	trim : function () {
		return this.rTrim().lTrim();
	},
	endsWith : function(sEnd) {
		return (this.substr(this.length-sEnd.length)==sEnd);
	},
	startsWith : function(sStart) {
		return (this.substr(0,sStart.length)==sStart);
	},
	format : function(){
		var s = this; for (var i=0; i < arguments.length; i++)
		{
			s = s.replace("{" + (i) + "}", arguments[i]);
		}
		return(s);
	},
	encodeAjaxParams : function(){
		return this.replace(/&/g,'__').replace(/=/g,'_').replace(/\./g,'_');
	},
	extractJsScripts:function(){
		var sf='<script\\s+.*src\\s*=\\s*([\'"]?)\\s*([^\\s\'"]+)\\s*\\1.*?>(\n|\r|.)*?<\/script>';
		var matchAll = new RegExp(sf, 'img');
		var matchOne = new RegExp(sf, 'im');
		return (this.match(matchAll) || []).map(function(scriptTag) {
			return (scriptTag.match(matchOne) || ['', '',''])[2];
		});
	},
	extractHrefLinks	: function(){
		var sf='<link\\s+[^>]*href\\s*=\\s*([\'"]?)\\s*([^\\s\'"]+)\\s*\\1[^>]*?/?>';
		var matchAll = new RegExp(sf, 'img');
		var matchOne = new RegExp(sf, 'im');
		return (this.match(matchAll) || []).map(function(linkTag) {
			return (linkTag.match(matchOne) || ['', '',''])[2];
		});
	},
	textScripts : function(){
		return this.extractScripts().map(function(script){
			var eScript=document.createElement('SCRIPT');
			eScript.type='text/javascript';
			eScript.text=script;
			return eScript;
		});
	},
	srcScripts	: function(){
		return this.extractJsScripts().map(function(script){
			var eScript=document.createElement('SCRIPT');
			eScript.type='text/javascript';
			eScript.src=script;
			return eScript;
		});
	},
	evalJsScripts: function() {
		return this.extractJsScripts().map(function(script){
			var eScript=document.createElement('SCRIPT');
			eScript.src=script;
			eScript.type='javascript';
			return eScript;
		});
	},
	byteLength:function(){
		var length = 0;
		this.replace(/[^\x00-\xff]/g,function(){length++;});
		return this.length+length;
	}
});
Object.extend(Element, {
  update: function(element, html) {
	var ele=$(element);
	$removeChilds(ele);
	html = html || '';
    ele.innerHTML = html.stripScripts();
    setTimeout(function() {
		html.srcScripts().each(function(value,index){
			ele.appendChild(value);
		});
		html.textScripts().each(function(value,index){
			void(ele.appendChild(value));
		});
	}, 1);
  },
  removeOuter: function(element) {
	for(;element.childNodes.length>0;){
		var child=element.childNodes[0];
		element.parentNode.insertBefore(child,element);
	}
	element.parentNode.removeChild(element);
  },
  cloneNode : function(element) {
  	if(false){
	  	var eContainer=document.createElement('DIV');
 		eContainer.innerHTML=element.outerHTML;
  		var eReturn=eContainer.childNodes[0];
  		eContainer.removeChild(eReturn);
  		delete eContainer;
  		return eReturn;
  	}
  	else{
  		return element.cloneNode(true);
  	}
  },
  removeIframe : function(eIframe){
	var c = eIframe;
	c.parentNode.removeNode(c);
	c.contentWindow.opener = null;
	c.contentWindow.close();
	c = null;
  }
});
Object.clone = function(_o,_bDeep){
	if(typeof _o!='object'){
		return _o;
	}
	if(!_bDeep){
		if(Array.isArray(_o)){
			return Array.apply(null,_o);
		}
		return Object.extend({},_o);
	}
	else{
		var oReturn = null;
		if(Array.isArray(_o)){
			oReturn = [];
			for(var i=0;i<_o.length;i++){
				oReturn.push(Object.clone(_o[i],true));
			}
		}
		else{
			oReturn = {};
			for(var prop in _o){
				oReturn[prop] = Object.clone(_o[prop],true);
			}
		}
		return oReturn;
	}
};
Array.isArray = function(_object){
	return (_object!=null)&&(_object.constructor!=null)&&(_object.constructor==Array||_object.constructor.toString().trim().indexOf('function Array()')==0);
}
String.isString = function(_object){
	return (typeof _object=="string")||
		((_object!=null)&&(_object.constructor!=null)&&(_object.constructor==String||_object.constructor.toString().trim().indexOf('function String()')==0));
}
Object.isObject = function(_object){
	return (_object!=null)&&(_object.constructor!=null)&&(_object.constructor==Object||_object.constructor.toString().trim().indexOf('function Object()')==0);
}
Boolean.isBoolean = function(_object){
	return (typeof _object=="boolean")||
		((_object!=null)&&(_object.constructor!=null)&&(_object.constructor==Boolean||_object.constructor.toString().trim().indexOf('function Boolean()')==0));
}
Number.isNumber = function(_object){
	return (typeof _object=="number")||
		((_object!=null)&&(_object.constructor!=null)&&(_object.constructor==Number||_object.constructor.toString().trim().indexOf('function Number()')==0));
}
Function.isFunction = function(_object){
	return (typeof _object=="function")||
		((_object!=null)&&(_object.constructor!=null)&&(_object.constructor==Function||_object.constructor.toString().trim().indexOf('function Function()')==0));
}
Object.parseString=function(s){
	if(s==null){
		s='null';
	}
	else if(s==undefined){
		s='undefined';
	}
	else if(typeof s!='string'){
		s=s.toString();
	}
	return s;
};
Object._parseSource=function(e){
	var ss='';
	if(typeof e == 'function'){
		return '[function]';
	}
	else if(e&&Array.isArray(e)){
		var tmp=e.map(function(f){
			return Object._parseSource(f);
		});
		ss='['+tmp.join(',')+']';
	}
	else if(typeof e=='object'){
		ss=Object.parseSource(e);
	}
	else{
		ss=Object.parseString(e);
	}
	return ss;
};
Object.parseSource=function(o){
	try{
		var a=o.toSource();
		return a;
	}catch(err){
		if(typeof o=='function'){
			return '[function]';
		}
		else if(typeof o=='object'){
			var t=[];
			for(var i in o){
				t.push('\n' + i+':'+Object._parseSource(o[i]));
			}
			return '{'+t.join(',')+'\n}';
		}
		else{
			return Object._parseSource(o);
		}
	}
};
function getAllParameters(){
	var query = location.search;
	return query.replace(/\?/,'').parseQuery();
}
var getParameter=function urlParameter(_sName,_sQuery){
	if(_sName ==null ||_sName=='undefined') 
		return '';
	var query = _sQuery ||location.search;
	var aParams=query.replace(/\?/,'').parseQuery();
	
	for(var sParam in aParams){
		if(_sName.toUpperCase()==sParam.toUpperCase()){
			return aParams[sParam];
		}
	}
	return '';
}

function encodeParams(_sParams){
	var oParams		= _sParams || {};
	if(typeof _sParams=='string'){
		oParams		= _sParams.parseQuery();
	}
	var aParams		= [];
	for(var sParam in oParams){
		aParams.push(sParam+'='+encodeURIComponent(oParams[sParam]));
	}
	return aParams.join('&');
}
var TrsCached = [];
Class = {
  create: function(_sClassName) {
	_sClassName	= _sClassName || '';
    return function() {
	  for(var sName in this){
		  if(typeof this[sName] == 'function'){
			  if(_sClassName==''){
				  this[sName]._functionName = sName;
			  }
			  else{
				  this[sName]._functionName = _sClassName + '.' + sName;
			  }
		  }
	  }
      this.initialize.apply(this, arguments);
	  TrsCached.push(this);
    }
  }
}
function ClassName(_oObject , _sClassName) {
	_sClassName	= _sClassName || '';
	for(var sName in _oObject){
		if(typeof this[sName] == 'function'){
			if(_sClassName==''){
				this[sName]._functionName = sName;
			}
			else{
				this[sName]._functionName = _sClassName + '.' + sName;
			}
		}
	}
}

Object.extend = function(destination, source) {
	for (property in source) {
		if(typeof destination[property]=='function'){
			destination[property+'0'] = destination[property];
		}
		destination[property] = source[property];
	}
	return destination;
}
// ge gfc add @ 2006-07-04
String.Empty = '';
Object.extend(String.prototype, {
		trim : function(){
			return this.replace( /^\s*/, String.Empty).replace( /\s*$/, String.Empty);
		},
		isEmpty : function(){
			if (this == String.Empty || this.trim() == String.Empty)
				return true;

			//else
			return false;
		}, 
		getLength : function(){
			var nTotalLen = 0;
			for (var i=0; i < this.length;i++){
				var nCharCode = this.charCodeAt(i
