function duplicateTree(source, destdocument) {
	var nw = destdocument.createElement(source.tagName);
	for(var j = 0, len = source.attributes.length; j < len; j++) {
		var node = source.attributes.item(j);
		nw.setAttribute(node.nodeName, node.nodeValue);
	}
	
	var clazz = source.getAttribute('class');
	if(clazz != null) {
		nw.className = clazz;
	}
	
	if(typeof source.innerHTML != 'undefined') {
		nw.innerHTML = source.innerHTML;
	} else if(false && Prototype.Browser.IE && typeof source.xml != 'undefined') {
		var ch = source.childNodes;
		var htmls = [];
		for(var i = 0, len = ch.length; i < len; i++) {
			htmls.push(ch[i].xml);
		}
		nw.innerHTML = htmls.join('');
	} else {
		duplicateTreeHelper(source, nw, destdocument);
	}
	
	return nw;
}

function duplicateTreeHelper(source, target, destdocument) {
	var ch = source.childNodes;
	
	for(var i = 0, len = ch.length; i < len; i++) {
		var n = ch[i];
		
		switch(n.nodeType) {
			case 1: // Node.ELEMENT_NODE
				if(n.tagName == 'script') {
					continue;
				}
				
				var nw = destdocument.createElement(n.tagName);
				
				for(var j = 0, len2 = n.attributes.length; j < len2; j++) {
					var node = n.attributes.item(j);
					nw.setAttribute(node.nodeName, node.nodeValue);
				}
				
				if(n.getAttribute('class') != null) nw['className'] = n.getAttribute('class');
				if(n.getAttribute('onclick') != null) nw['onClick'] = n.getAttribute('onclick');
				//alert(n.getAttribute('onclick'));
				if(n.getAttribute('colspan') != null) nw['colSpan'] = n.getAttribute('colspan');
				if(n.getAttribute('target') != null) nw['target'] = n.getAttribute('target');
				
				// check if the table contains a tbody
				var mytarget = target;
				
				if(n.tagName == 'table') {
					var hastbody = false;
					for(var j = 0; !hastbody && j < n.childNodes.length; j++) {
						var chch = n.childNodes[j];
						
						if(chch.nodeType == 1 && chch.tagName == 'tbody') {
							hastbody = true;
						}
					}
					
					if(!hastbody) {
						target.appendChild(nw);
						mytarget = nw;
						
						nw = destdocument.createElement('tbody');
					}
				}
				
				if(n.hasChildNodes()) {
					duplicateTreeHelper(n, nw, destdocument);
				}
				
				mytarget.appendChild(nw);
				
				break;
			case 3: // Node.TEXT_NODE
				// replace large amounts of white space. it confuses Internet Explorer
				var text = n.nodeValue;
				text = text.replace(/\s+/g, ' ');
				
				var nw = destdocument.createTextNode(text);
				target.appendChild(nw);
				break;
		}
	}
}

function getNodeContents(node) {
	var ch = node.childNodes, c = '';
	
	for(var i = 0; i < ch.length; i++) {
		switch(ch[i].nodeType) {
			case 1:
				c += getNodeContents(ch[i]);
				break;
			case 3:
				c += ch[i].nodeValue;
				break;
		}
	}
	
	return c;
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	var i, j;
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(getClassName(els[i])) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function getClassName(node) {
	return node.getAttribute('class') == null ? node.className : node.getAttribute('class');
}

function setClassName(node, mclass) {
	node.setAttribute('class', mclass);
	node.className = mclass;
}

// COOKIE FUNCTIONS
function setCookie(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;
}

function getCookie(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));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function decrypt(s) {
	var n=0;
	var r='';
	for(var i=0; i < s.length; i++) {
		n=s.charCodeAt(i);
		if (n>=8364) {n = 128;}
		r += String.fromCharCode(n-(1));
	}
	return r;
}

function jsdecryptreplace(obj, linkhref, text) {
	var link = document.createElement('a');
	link.href = decrypt(linkhref);
	link.appendChild(document.createTextNode((typeof(text) != 'undefined') ? decrypt(text) : decrypt(r1)));
	
	obj.parentNode.insertBefore(link, obj);
	obj.parentNode.removeChild(obj);
}

Element.addMethods({
	clear : function(element) {
		while(element.firstChild) {
			element.removeChild(element.firstChild);
		}
	},
	
	getText : function(element) {
		return getNodeContents(element);
	}
});

var Translator = Class.create({
	map : null,
	
	initialize : function() {
		this.map = new Hash();
	},
	
	add : function(english, localized) {
		this.map.set(english, localized);
	},
	
	get : function(english) {
		var res = this.map.get(english);
		
		if(Object.isUndefined(res)) {
			return english;
		}
		
		return res;
	}
});

translator = new Translator();