function emlrepair(arr){var a="";for(var i=0;i<arr.length;i++){a+=String.fromCharCode(arr[i]);}return a;}function emlexplode(str){var a=new Array();var tmp="";for(var i=0;i<str.length;i++){if(str.substr(i,1)==","||str.substr(i,1)=="."){a[a.length]=parseInt(tmp)-1;tmp="";}else tmp+=str.substr(i,1)}if(tmp)a[a.length]=parseInt(tmp)-1;return a;}function emlwrite(str,msg,css){var x=emlrepair(emlexplode(str));document.write('<a href=javascript:void(0) onclick="window.location=\'mail\u0074o\u003a'+x+'\'">'+(msg?msg:x)+'</a>');}

function showandcenter(obj,width,height) {
	obj.style.position = "absolute";
	obj.style.display = "block";

	if (!width || typeof width == "undefined")
		width = parseInt(obj.clientWidth);
	if (!height || typeof height == "undefined")
		height = parseInt(obj.clientHeight);
		
	obj.style.left = (parseInt(document.documentElement.clientWidth)/2 - parseInt(width)/2 + parseInt(document.documentElement.scrollLeft))+"px";
	obj.style.top = (parseInt(window.innerHeight ? window.innerHeight : document.documentElement.clientHeight)/2 - parseInt(height)/2 + parseInt(document.documentElement.scrollTop))+"px";
}

var gebicache = { };
function $(id,c) {
//	return document.getElementById(id);
	if (!gebicache[id])
		gebicache[id] = document.getElementById(id);
	return gebicache[id];
}

function dropElement(e) {
	if (!e)
		return;
	if (!e.parentNode)
		return;
	if (e.id)
		gebicache[e.id] = null;
	e.parentNode.removeChild(e);
}

function dropAllElements(e) {
	if (!e)
		return;
	var l = e.childNodes;
	while (l.length) {
		dropAllElements(l[0]);
		dropElement(l[0]);
	}
}

function walk(arr, f) {
	var a;
	for (a in arr) {
		if (typeof arr[a] != "function" && a!="error")
			f(a, arr[a]);
	}
}

function print_r(o) {
	if (typeof o == "undefined" || o==null) {
		return "null";
	} if (typeof o == "array") {
		var tmp = "";
		for (var i=0; i<o.length; i++)
			tmp += (tmp?",\n":"")+print_r(o[i]);
		return "[ "+tmp+" ]\n";
	} else if (typeof o == "object") {
		var tmp = "";
		var a;
		for (a in o) {
			var x = print_r(o[a]);
			if (x)
				tmp += (tmp?",\n":"")+a+": "+print_r(o[a]);
		}
		return "{ "+tmp+" }";
	} else if (typeof o == "function")
		return ""; //f()";
	else
		return o;
}

function compare(o1, o2) {
	if (typeof o1 == "number")
		return o1 > o2 ? 1 : o1 < o2 ? -1 : 0;
	else if (typeof o1 == "string")
		return o1.compare(o2);
	else
		return 0;
}

function formatDateTime(d) {
	if (d && d.getMonth) {
		var yr = d.getRealYear();
		var mn = d.getMonth()+1;
		var dy = d.getDate(); 
		var hr = d.getHours();
		var mi = d.getMinutes();
		return (dy<10?"0":"")+dy+"/"+(mn<10?"0":"")+mn+"/"+yr+" "+(hr<10?"0":"")+hr+":"+(mi<10?"0":"")+mi;
	} else
		return " ";
}

function plain(o, exclude) {
	if (!exclude)
		exclude = [ ];
	var res = [ ];
	walk(o, function(a,b) {
		if (typeof b != "function" && !exclude.contains(a))
			res.push(b);
	});
	return res;
}

Object.prototype.plain = function(o, excludefields) {
	if (!excludefields)
		excludefields = [ ];
	var a, result = [ ];
	for (a in this) {
		if (excludefields.contains(a) || typeof o[a] == "function")
			continue;
		result.push(o[a]);
	}
	return result;
}

Object.prototype.ksort = function(asc) {
	var keys = this.keys().plainsort(asc);
	var tmp = { };
	for (var i=0; i<keys.length; i++)
		tmp[keys[i]] = this[keys[i]];
	return tmp;
}

Object.prototype.keys = function() {
	var keys = [ ], a;
	for (a in this) {
		if (typeof this[a] != "function")
			keys.push(a);
	}
	return keys;
}



Array.prototype.contains = function(value) {
	for (var i=0; i<this.length; i++)
		if (this[i]==value)
			return true;
	return false;
}

Array.prototype.append = function(arr) {
	for (var i=0; i<arr.length; i++)
		this[this.length] = arr[i];
	return this;
}

Array.prototype.prepend = function(arr) {
	var res = [];
	for (var i=0; i<arr.length; i++)
		res[i] = arr[i];
	res.append(this);
	for (var i=0; i<res.length; i++)
		this[i] = res[i];
	return this;
}

Array.prototype.reverse = function() {
	var res = [];
	for (var i=this.length-1; i>=0; i--)
		res[res.length] = this[i];
	return res;
}

Array.prototype.slice = function(start, cnt) {
	if (!this.length)
		return [ ];
	if (!cnt)
		cnt = this.length-start;
	if (cnt<0)
		cnt = this.length-start+cnt;
	var res = [ ];
	for (var i=0; i<cnt && start+i<this.length; i++) {
		res[res.length] = this[start+i];
	}
	return res;
}

Array.prototype.unique = function() {
	var res = [ ];
	for (var i=0; i<this.length; i++)
		if (!res.contains(this[i]))
			res[res.length] = this[i];
	return res;
}

Array.prototype.clone = function() {
	var res = [ ];
	for (var i=0; i<this.length; i++)
		res[i] = this[i];
	return res;
}

Array.prototype.hash = function(field) {
	var res = { };
	for (var i=0; i<this.length; i++)
		if (this[i][field])
			res[this[i][field]] = this[i];
	return res;
}

Array.prototype.push = function(value) {
	this[this.length] = value;
}

Array.prototype.remove = function(index) {
	var r = [];
	for (var i=0; i<this.length; i++)
		if (i!=index)
			r.push(this[i]);
	return r;
}

Array.prototype.removevalue = function(val) {
	var r = [];
	for (var i=0; i<this.length; i++)
		if (this[i]!=val)
			r.push(this[i]);
	return r;
}

Array.prototype.sort = function(field, asc) {
	var r = this;
	for (var i=0; i<r.length; i++)
		for (var j=0; j<r.length; j++)
			for (var k=0; k<r.length-1; k++) {
				var e = compare(r[k][field], r[k+1][field]);
				if (asc && e>0 || !asc && e<0) {
					var tmp = r[k];
					r[k] = r[k+1];
					r[k+1] = tmp;
				}
			}
	return r;
}

Array.prototype.plainsort = function(asc) {
	var r = this;
	for (var i=0; i<r.length; i++)
		for (var j=0; j<r.length; j++)
			for (var k=0; k<r.length-1; k++) {
				var e = compare(r[k], r[k+1]);
				if (asc && e>0 || !asc && e<0) {
					var tmp = r[k];
					r[k] = r[k+1];
					r[k+1] = tmp;
				}
			}
	return r;
}

Array.prototype.extract = function(field) {
	var r = [];
	for (var i=0; i<this.length; i++)
		r.push(this[i][field]);
	return r;
}

Array.prototype.lookup = function(val, fld1, fld2) {
	for (var i=0; i<this.length; i++)
		if (this[i][fld1]==val)
			return this[i][fld2];
	return "";
}

String.prototype.rplace = function(from, to) {
	var res = ""+this;
	var idx = 0;
	if (typeof from=="object") {
		var a;
		for (a in from) {
			while (-1 < (p = res.indexOf(a)))
				res = res.substr(0, p)+from[a]+res.substr(p+a.length);
		}
	} else {
		while (-1 < (p = res.indexOf(from)))
			res = res.substr(0, p)+to+res.substr(p+from.length);
	}
	return res;
}

String.prototype.stripTags = function() {
	var res = ""+this;
	var p = 0;
	while (-1 < (p = res.indexOf("<"))) {
		if (-1 < (p1 = res.substr(p).indexOf(">"))) {
			res = res.substr(0, p)+res.substr(p+p1+1);
		}
	}
	return res;
}

String.prototype.explode = function(d,cnt) {
	if (!this.length)
		return [ ];
	var x = ""+this;
	var res = [];
	while (-1 < (p = x.indexOf(d))) {
		res.push(x.substr(0, p));
		x = x.substr(p+d.length);
		if (cnt && res.length==cnt-1)
			break;
	}
	res.push(x);
	return res;
}

String.prototype.compare = function(str) {
	var a = this.toLowerCase();
	var b = str.toLowerCase();
	for (var i=0; i<a.length && i<b.length; i++) {
		if (a.substr(i,1)<b.substr(i,1))
			return -1;
		else if (a.substr(i,1)>b.substr(i,1))
			return 1;
	}
	return a.length < b.length ? -1 : a.length > b.length ? 1 : 0;
}

String.prototype.reverse = function() {
	var str = "";
	for (var i=this.length; i>=0; i--)
		str += this.substr(i,1);
	return str;
}

String.prototype.trim = function() {
	var str = ""+this;
	while (str.substr(0,1)==" " || str.substr(0,1)=="\n" || str.substr(0,1)=="\r")
		str = str.substr(1);
	while (str.substr(str.length-1,1)==" " || str.substr(str.length-1,1)=="\n" || str.substr(str.length-1,1)=="\r")
		str = str.substr(0,str.length-1);
	return str;
}

String.prototype.translate = function(d) {
	var res = this;
	walk(d, function(nm, vl) {
		res = res.rplace("[r:"+nm+"]", vl);
	});
	return res;
}

Date.prototype.getRealYear = function() {
	var y = this.getYear();
	return y < 1900 ? y + 1900 : y;
}

Date.prototype.addDays = function(days) {
	return new Date(this.getRealYear(), this.getMonth(), this.getDate()+days);
//	var x = new Date();
//	x.setTime(this.getTime() + days*24*3600*1000);
//	return x;
}

Date.prototype.addMonths = function(months) {
	return new Date(this.getRealYear(), this.getMonth()+months, this.getDate());
}

Date.prototype.format = function(fmt) {
	if (!fmt)
		fmt = "d/m/Y";
	var yr = this.getRealYear();
	var yrs = (""+yr).substr(2);
	var mn = this.getMonth()+1; if (mn<10) mn = "0"+mn;
	var dys = this.getDate();
	var dy = dys; if (dy<10) dy = "0"+dy;
	var mnw = Dictionary.translateWord("MONTH"+this.getMonth(), "default");
	var mnq = Dictionary.translateWord("SMONTH"+this.getMonth(), "default");
	fmt = fmt.rplace({"j": dys, "d":dy, "m":mn, "y": yrs, "Y":yr, "M":mnw, "Q":mnq});
	return fmt;
}

function addClassName(obj, name) {
	if (!obj)
		return;
	if (-1 < obj.className.indexOf(name))
		return;
	if (obj.className.length)
		obj.className += " "+name;
	else
		obj.className = name;
}

function removeClassName(obj, name) {
	if (!obj)
		return;
	obj.className = obj.className.rplace(name, "").trim();
}