


		/* ----------------------------------------------------------------------------------------
		 * Copyright 2005-2006 gPremper S.A. de C.V
		 * Developed by Niels Fröhling
		 */

		var MSIE  = false;
		var DOM2  = false;
		var CSS1  = false;

		/* ------------------------------------------------------------------------------------------
		 */
		if (navigator.appName.substr(0,9) == 'Microsoft')
			MSIE = true;
		else if (navigator.appName.substr(0,8) == 'Netscape')
			DOM2 = true;
		if (document.compatMode == 'CSS1Compat')
			CSS1 = true;

		/* ------------------------------------------------------------------------------------------
		 */
		function newElm(tag) {
			return document.createElement(tag);
		}

		function newTxt(content) {
			return document.createTextNode(content);
		}

		/* ------------------------------------------------------------------------------------------
		 */
		function getObj(id) {
			if (id == null)
				return document;
			if (document != null)
				return document.getElementById(id);
			if (window.document != null)
				return window.document.getElementById(id);
			if (this.document != null)
				return this.document.getElementById(id);
			return null;
		}

		function getFrm(id) {
			if (id == null)
				return window;
			if (window.frames != null)
				return window.frames[id];
			if (this.window.frames != null)
				return this.window.frames[id];
			return null;
		}

		function getElm(name) {
			var elms = document.getElementsByName(name);

			for (var e = 0; elms && (e < elms.length); e++)
				return elms.item(e);

			return null;
		}

		function getTag(name) {
			var elms = document.getElementsByTagName(name);

			for (var e = 0; elms && (e < elms.length); e++)
				return elms.item(e);

			return null;
		}

		/* ----------------------------------------------------------------------------------------
		 */
		function getElms(name) {
			return document.getElementsByName(name);
		}

		function getTags(name) {
			return document.getElementsByTagName(name);
		}

		/* ----------------------------------------------------------------------------------------
		 */
		function getEvt(event) {
			if (!event)
				return window.event;

			return event;
		}

		function getKey(event) {
			if ((typeof event         == 'undefined') ||
				(typeof event.keyCode == 'undefined'))
				return window.event.keyCode;

			return event.keyCode;
		}

		function getTE(event) {
			if (!event)
				return null;

			/* mouse-over from ... */
			if (event.target)
				return event.target;
			else if (event.srcElement)
				 return event.srcElement;

			return null;
		}

		function getFromTE(event) {
			if (!event)
				return null;

			/* mouse-over from ... */
			if (event.relatedTarget)
				return event.relatedTarget;
			else if (event.fromElement)
				 return event.fromElement;

			return null;
		}

		function getToTE(event) {
			if (!event)
				return null;

			/* mouse-out to ... */
			if (event.relatedTarget)
				return event.relatedTarget;
			else if (event.toElement)
				 return event.toElement;

			return null;
		}

		/* -----------------------------------------------------------
		 * convert a digit to 2-character numbers, signed or unsigned
		 */
		function d2num(num, signed) {
			num = Math.floor(num + 0.5);
			var sign = (signed == true ? (num < 0 ? '-' : '+') : '');
			num = Math.abs(num);
			if (num < 10)
				return sign + '0' + num;
			return sign + '' + num;
		}

		/* convert a number to .2-character digits, signed or unsigned */
		function f2num(num, signed) {
			var sign = (signed == true ? (num < 0 ? '-' : '+') : '');
			num = Math.abs(num);
			var nat = Math.floor(num);
			var rem = d2num((num - nat) * 100, false);

			return sign + '' + nat + (rem != 0 ? '.' + rem : '');
		}

		function f2float(num, signed) {
			var sign = (signed == true ? (num < 0 ? '-' : '+') : '');
			num = Math.abs(num);
			var nat = Math.floor(num);
			var rem = d2num((num - nat) * 100, false);

			return sign + '' + nat + '.' + rem;
		}

		function amount(bytes) {
			var units = ['bytes', 'KB', 'MB', 'GB', 'TB'];
			var unit = 0;

			while (bytes >= 10000) {
				bytes /= 1024;
				unit++;
			}

			return f2num(bytes, false) + ' ' + units[unit];
		}

		/* ------------------------------------------------------------------------------------------
		 */
		function clearSelect(field) {
			while (field.options.length > 0) {
				/* the way collections work */
				if (field.options.remove)
					field.options.remove(0);
				/* the way firefox works */
				else
					field.options[0] = null;
			}
		}

		function appendSelect(field, values) {
			var d = 0; for (val in values)
				field.options.add(new Option(values[val], d++, false, false));
		}

		function appendSelectNames(field, values) {
			for (var d = 0; d < (values.length >> 1); d++)
				field.options.add(new Option(values[(d << 1) + 1], values[(d << 1) + 0], false, false));
		}

		function appendSelectKeys(field, values) {
			for (var key in values)
				field.options.add(new Option(values[key], key, false, false));
		}

		function fillSelect(field, values) {
			clearSelect(field);
			appendSelect(field, values);
		}

		function fillSelectNames(field, values) {
			clearSelect(field);
			appendSelectNames(field, values);
		}

		function fillSelectKeys(field, values) {
			clearSelect(field);
			appendSelectKeys(field, values);
		}

		function selectValue(field, value) {
			for (var d = 0; d < field.options.length; d++)
				if (field.options.item(d).value == value) {
					field.value = value;
					field.selectedIndex = d;
					break;
				}
		}

		function selectText(field, text) {
			for (var d = 0; d < field.options.length; d++)
				if (field.options.item(d).text == text) {
					field.value = field.options.item(d).value;
					field.selectedIndex = d;
					break;
				}
		}

		function switchDisplay(dobj) {
			if (!dobj)
				return;

			if (dobj.style.display == 'none')
				dobj.style.display = 'block';
			else
				dobj.style.display = 'none';
		}

		/* ------------------------------------------------------------------------------------------
		 */
		function transImage(img, path) {
			if (MSIE == true) {
				img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + path + "');";
				img.src = "pics/blank.gif";
			}
			else
				img.src = path;
		}

		function checkWHStyle(img) {
			if ((img.style.left   != null) && (img.style.left  != '') &&
				(img.style.right  != null) && (img.style.right != '') &&
				(img.style.width  != null) && (img.style.width != '') &&
				(img.style.width.indexOf('%') != -1))
				if (MSIE == false)
					img.style.width = null;

			if ((img.style.top    != null) && (img.style.top    != '') &&
				(img.style.bottom != null) && (img.style.bottom != '') &&
				(img.style.height != null) && (img.style.height != '') &&
				(img.style.height.indexOf('%') != -1))
				if (MSIE == false)
					img.style.height = null;
		}

		function setAlpha(id, path) {
			var img = getObj(id);

			if (img != null)
				if (MSIE == true) {
					img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + path + "');";
					img.src = "pics/trans.gif";
				}
				else {
					checkWHStyle(img);
					img.src = path;
				}

			return img;
		}

		function setAlphaScale(id, path) {
			var img = getObj(id);

			if (img != null)
				if (MSIE == true) {
					img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + path + "', sizingMethod='scale');";
					img.src = "pics/trans.gif";
				}
				else {
					checkWHStyle(img);
					img.src = path;
				}

			return img;
		}

		/* ------------------------------------------------------------------------------------------
		 */
		function measureEventX(evt) {
			if (MSIE == true) {
				/* MICROSUCK events ONLY can be correct EXACTLY in the moment
				 * of the call!!!!
				 */
				if (document != null)
					if (document.body != null)
						return window.event.clientX + document.body.scrollLeft;

				return 0;
			}

			return evt.pageX;
		}

		function measureEventY(evt) {
			if (MSIE == true) {
				/* MICROSUCK events ONLY can be correct EXACTLY in the moment
				 * of the call!!!!
				 */
				if (document != null)
					if (document.body != null)
						return window.event.clientY + document.body.scrollTop;

				return 0;
			}

			return evt.pageY;
		}

		/* ------------------------------------------------------------------------------------------
		 */
		function measureFrameWidth(frmid) {
			var fobj = getFrm(frmid);
			var frmw;

			if (fobj != null) {
				if (MSIE == true) {
					if (fobj.document != null)
						if (fobj.document.body != null)
							frmw = fobj.document.body.scrollWidth;
				}
				else {
					/* first scroll completly down */
					fobj.scrollBy( 10000000, 0);

					/* measure the offset and add the height */
					frmw  = fobj.innerWidth - 0;
					frmw += fobj.pageXOffset;

					/* last scroll completly up */
					fobj.scrollBy(-10000000, 0);
				}
			}

			return frmw;
		}

		function measureFrameHeight(frmid) {
			var fobj = getFrm(frmid);
			var frmh;

			if (fobj != null) {
				if (MSIE == true) {
					if (fobj.document != null)
						if (fobj.document.body != null)
							frmh = fobj.document.body.scrollHeight;
				}
				else {
					/* first scroll completly down */
					fobj.scrollBy(0,  10000000);

					/* measure the offset and add the height */
					frmh  = fobj.innerHeight - 0;
					frmh += fobj.pageYOffset;

					/* last scroll completly up */
					fobj.scrollBy(0, -10000000);
				}
			}

			return frmh;
		}

		function offsetXFrame(frmid) {
			var fobj = getFrm(frmid);
			var frmo;

			if (fobj != null) {
				if (MSIE == true) {
					if (fobj.document != null)
						if (fobj.document.body != null)
							frmo = fobj.document.body.scrollLeft;
				}
				else
					frmo = fobj.pageXOffset;
			}

			return frmo;
		}

		function offsetYFrame(frmid) {
			var fobj = getFrm(frmid);
			var frmo;

			if (fobj != null) {
				if (MSIE == true) {
					if (fobj.document != null)
						if (fobj.document.body != null)
							frmo = fobj.document.body.scrollTop;
				}
				else
					frmo = fobj.pageYOffset;
			}

			return frmo;
		}

		/* ------------------------------------------------------------------------------------------
		 */
		function rethinkSize(frmid) {
			var cobj = getObj('content');
			var nobj = getObj('nav_left');
			var iWidth, iHeight;

			if ((cobj == null) ||
				(nobj == null))
				return;

			if (MSIE == true) {
				iWidth  = document.body.clientWidth ;
				iHeight = document.body.clientHeight; }
			else {
				iWidth  = window.innerWidth  - 2;
				iHeight = window.innerHeight - 2; }

			/*if (frmh <= iHeight) fobj.style.height = '100%';*/
			cobj.style.height = '0px';
			nobj.style.height = '0px';

			var crmh = measureFrameHeight('content');
			var nrmh = measureFrameHeight('nav_left');
			var frmh = Math.max(crmh, nrmh);

			/*if (frmh <= iHeight) fobj.style.height = '100%';*/
			if (!isNaN(frmh)) {
				cobj.style.height = frmh + 'px';
				nobj.style.height = frmh + 'px';
			}
		}

		/* ------------------------------------------------------------------------------------------
		 */
		var lWidth = 0, lHeight = 0;

		function rethinkPopUp(dWidth, dHeight, preserve) {
			var iWidth, iHeight;

			window.moveTo(50, 50);
//			window.resizeTo(dWidth, dHeight);

			if (MSIE == true) {
				iWidth  = document.body.clientWidth ;
				iHeight = document.body.clientHeight; }
			else {
				iWidth  = window.innerWidth;
				iHeight = window.innerHeight; }

//			window.resizeBy(dWidth - iWidth, dHeight - iHeight);
//
//			if (MSIE == true) {
//				iWidth  = document.body.clientWidth ;
//				iHeight = document.body.clientHeight; }
//			else {
//				iWidth  = window.innerWidth;
//				iHeight = window.innerHeight; }

			if (preserve) {
				var dAspect, iAspect;
				var pWidth, pHeight;

				dAspect = dWidth / dHeight;
				iAspect = iWidth / iHeight;

				pWidth  = iHeight * dAspect;
				pHeight = iWidth  / dAspect;

				if (iAspect > dAspect) {
					dWidth  = pWidth;
					dHeight = dWidth  / dAspect;
				}
				else
				if (dAspect > iAspect) {
					dHeight = pHeight;
					dWidth  = dHeight * dAspect;
				}
			}

			if (((dWidth  != iWidth ) || (dHeight != iHeight)) &&
				((lWidth  != iWidth ) && (lHeight != iHeight))) {
				lWidth  = iWidth;
				lHeight = iHeight;

				window.resizeBy(dWidth - iWidth, dHeight - iHeight);
//				window.resizeBy(dWidth - iWidth, dHeight - iHeight);

				setTimeout(function() {
					rethinkPopUp(dWidth, dHeight, preserve); }, 500);
			}
		}

		/* -----------------------------------------------------------
		 * get a query-variable from javascript
		 */
		function getQueryVariable(variable, uri) {
			var url  = (uri ? uri : window.location.href);

			/* split the url in location, get-query and position */
			var uris = url.split("?");
//			if (uris[1] != null)
//				uris = url.split("#");

			/* if we have a get-query */
			if (uris[1] != null) {
				var qvars = uris[1].split("&");

				/* loop through all existing vars */
				for (var i = 0; i < qvars.length; i++) {
					var pair = qvars[i].split("=");

					/* append if not be overwritten */
					if (pair[0] == variable)
						return pair[1];
				}
			}

			return null;
		}

		function getQueryInternal(uri) {
			var url  = (uri ? uri : window.location.href);

			/* split the url in location/get and internal-query */
			var uris = url.split("#");

			/* if we have a internal-query */
			return uris[1];
		}

		/* ------------------------------------------------------------------------------------------
		 */
		function placeQuery(url, vararray, inverse) {
			/* split the url in location and get-query */
			var uris =     url.split("?"); if (!uris[1]) uris[1] = '';
			var urir = uris[1].split("#"); if (!urir[1]) urir[1] = '';
			var vars = vararray;

			/* if we have a get-query */
			if (urir[0] != null) {
				var qvars = urir[0].split("&");

				/* loop through all existing vars */
				for (var i = 0; i < qvars.length; i++) {
					var pair = qvars[i].split("=");

					if (inverse) {
						/* quit if not be existant */
						if (vars[pair[0]] != null)
							vars[pair[0]] = pair[1];
					}
					else {
						/* append if not be overwritten */
						if (vars[pair[0]] == null)
							vars[pair[0]] = pair[1];
					}
				}
			}

			/* build new query string */
			var conc = '';
			for (var key in vars)
				if ((vars[key] != null) &&
					(vars[key] != 'null') &&
					(vars[key] != ''))
					conc += (conc == '' ? '?' : '&') + key + '=' + vars[key];

			if (urir[1])
				conc += '#' + urir[1];

			return conc;
		}

		function placeQueryInternal(url, position) {
			/* split the url in location and get-query */
			var uris = url.split("#");
			var urin = (uris[0] != null) ? uris[0] : '';

			/* build new query string */
			if ((position != null) &&
				(position != ''))
				urin += '#' + position;

			return urin;
		}

		/* ------------------------------------------------------------------------------------------
		 */
		function rewriteLocalURL(url) {
			var uri = url;

			/* identify Windows-Scheme */
			if ((uri.charAt(1) == ':') &&
				(uri.charAt(2) == '\\')) {
				uri = 'file:///' + uri.replace(/\\+/g, '/');
			}
			/* identify Linux-Scheme */
			else if (uri.charAt(0) == '/') {
				uri = 'file:///' + uri;
			}

			return uri;
		}

		function rewriteToBase(url) {
//			             N:\ Z\Z01-Dr-Zelaya\Z01-01-webhosting\Z01-01-contrato-webhosting.sdw
//			\\Bill\clientes\ Z\Z01-Dr-Zelaya\Z01-01-webhosting\Z01-01-contrato-webhosting.sdw
//			  /lan/clientes/ Z/Z01-Dr-Zelaya/Z01-01-webhosting/Z01-01-contrato-webhosting.sdw
			if (url != '') {
				/* convert drive-type */
				if ((url[1] == ':') &&
					(url[2] == '\\')) {
					url = url.substr(3, url.length - 3);
				}
				/* convert network-type */
				else
				if ((url[0] == '\\') &&
					(url[1] == '\\')) {
					url = url.replace(/\\\\Bill\\clientes\\+/g, '');
				}
				/* convert samba-type */
				else
				if ((url[0] == '/') &&
					(url[1] == 'l') &&
					(url[2] == 'a') &&
					(url[3] == 'n')) {
					url = url.replace(/\/lan\/clientes\/+/g, '');
				}

				/* make '/' */
				url = url.replace(/\\+/g, '/');

				/* strip filename */
				if ((pos = url.lastIndexOf('/')) != -1)
					url = url.substr(0, pos + 1);
			}

			return url;
		}

		/* ------------------------------------------------------------------------------------------
		 */
		function roundMoney(money) {
			m = new Number(money);

			m *= 100;
			m = Math.round(m);
			m /= 100;

			return m;
		}

		/* ------------------------------------------------------------------------------------------
		 * checks if a mail-adress
		 */
		function chkMail(mail) {
			return mail.match(/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/);
		}

		/* ------------------------------------------------------------------------------------------
		 * debugging
		 */
		function putDebug(topic, content) {
			if (content == '')
				return;

			var mess = getObj('mess'); if (!mess) {
				mess = newElm('div');
				mess.id = 'mess';
				mess.style.position = 'absolute';
				mess.style.zIndex = '10000';
				mess.style.top = '20px';
				mess.style.left = '20px';
			//	mess.style.right = '20px';
				mess.style.width = '0px';
				mess.style.bottom = '20px';
				mess.style.color = '#000000';
				mess.style.backgroundColor = '#E0E0E0';
				mess.style.overflow = 'hidden';
				mess.contents = new Array();
				mess.contents[''] = '';
			var indc = newElm('div');
				indc.style.position = 'absolute';
				indc.style.bottom = '40px';
				indc.style.left = '0px';
				indc.style.width = '20px';
				indc.style.height = '20px';
				indc.style.backgroundColor = 'red';
				indc.onclick = function() {
					var vis = (parseInt(mess.style.width) != 0);
					mess.style.width = (vis ? '0px' : '');
					mess.style.right = (vis ? '' : '20px');
				};
			var list = newElm('div');
				list.style.position = 'absolute';
				list.style.top = '40px';
				list.style.left = '20px';
				list.style.right = '20px';
				list.style.bottom = '20px';
				list.style.color = '#000000';
				list.style.backgroundColor = '#A0A0A0';
				list.style.border = '1px inset #C0C0C0';
				list.style.overflow = 'scroll';
				list.innerHTML = content;
			var selc = newElm('select');
				selc.style.width = '100%';
				selc.style.cursor = 'pointer';
				selc.onchange = function() {
					list.innerHTML = mess.contents[selc.options.item(selc.selectedIndex).text];
				};
			var body = getTag('body');
				mess.appendChild(selc);
				mess.appendChild(list);
				body.appendChild(indc);
				body.appendChild(mess); }

			mess.contents[topic] = content;
			mess.firstChild.options.add(new Option(topic, mess.firstChild.options.length, false, false));
		}
