var cTable = {
	
	RowOver : function (obj, classname) {
		
	    var theCells = null;
	
	    if (typeof(document.getElementsByTagName) != 'undefined') {
	        theCells = obj.getElementsByTagName('td');
	    } else if (typeof(obj.cells) != 'undefined') {
	        theCells = obj.cells;
	    } else {
	        return false;
	    }
	
	    var rowCellsCnt  = theCells.length;
	
	   	for (c = 0; c < rowCellsCnt; c++) {
	            theCells[c].className = classname;
	    }
	
	    return true;
		
	}
	
};

var cHTML = {
	
	bckg : null,
	active : null,
	w : 400,
	h : 90,
	opacity : 5,
	
	init : function() {
		
		c = cHTML.bckg = new cHTML.createElement('div', 'cHTMLbckg', 'absolute', 0, 0, 0, 0, API.maxZ);
		c.style.backgroundColor = 'black';
		if (!API.browser.ie5) c.style.cursor = 'progress';
		c.style.display = 'none';
		
		document.body.appendChild(c);
		API.setObjOpacity(c, cHTML.opacity);
		
		API.list.push('cHTML.resize'); // registrace resize funkce
		API.scrollList.push('cHTML.scroll'); // registrace scroll funkce
		
		cHTML.resize();
		
	},
	
	PageSets : function() {

		cHTML.show(50);
		cHTML.active = 'MsgBoxPageSets';
		bl = 40;
		bt = 20;
//		w = API.page.x2 - ((API.browser.ie && !API.browser.ie7)? 0 : 20) - (2 * bl);
//		h = API.page.y2 - 20 - (2 * bt);
		w = 940;
		h = Math.round(w / (API.page.x2 / API.page.y2));	
		o = new cHTML.createElement('div', cHTML.active, 'absolute', API.page.x50, API.scrollTop + API.page.y50, 1, 1, API.maxZ + 1);
		o  = API.stylize(o);
		o.style.overflowY = 'auto';
		o.style.MozBorderRadius = '5px';
		document.body.appendChild(o);
		new Animation.EaseIn(cHTML.active, API.page.x50 - (w / 2), API.scrollTop + (API.page.y50 - (h / 2)), w, h);
		o.innerHTML = '<p style="font-size: 10pt; padding-left: 10px; padding-top: 5px; font-weight: bold;"><span id="MsgBoxPageSetsTitleP">&nbsp;</span></p>';
		o.innerHTML += '<p id="MsgBoxPageSetsContent" style="padding: 5px 10px;">&nbsp;</p>';
		
		c = new cHTML.createElement('div', cHTML.active + '_close', 'absolute', w - 25, 0, 10, 10, API.maxZ + 1000);
		o.appendChild(c);
		c.innerHTML = '<a href="javascript:void(0);" onclick="cHTML.hide(true);">x</a>';

		API.getPhrase(28, 'MsgBoxPageSetsTitleP', 2);
		API.getAdminFunction('PageSets', 'MsgBoxPageSetsContent', 'user_role_id=' + APL_USER_ROLE_ID);
		
	},
	
	denyPage : function() {
		
		cHTML.show(50);
		cHTML.active = 'MsgBoxDenyPage';
		
		w = 470;
		h = 210;
		o = new cHTML.createElement('div', cHTML.active, 'absolute', API.page.x50, API.scrollTop + API.page.y50, 1, 1, API.maxZ + 1);
		o  = API.stylize(o);
		o.style.overflowY = 'auto';
		o.style.MozBorderRadius = '5px';
		document.body.appendChild(o);
		new Animation.EaseIn(cHTML.active, API.page.x50 - (w / 2), API.scrollTop + (API.page.y50 - (h / 2)), w, h);
		o.innerHTML = '<p><span id="MsgBoxDenyPageTitleP" style="font-size: 10pt; padding-left: 10px; padding-top: 10px; font-weight: bold;">&nbsp;</span><span> : ' + APL_PAGE + '</span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p>';
		o.innerHTML += '<p><a style="font-size: 9pt; padding-left: 15px;" href="#" onclick="API.throbber(\'MsgBoxDenyPageContent\');API.getAdminFunction(\'DenyPageId\', \'MsgBoxDenyPageContent\', \'user_role_id=' + APL_USER_ROLE_ID + '\');if ($(\'MsgBoxDenyPageTitleA2\').style.display != \'block\') {$(\'MsgBoxDenyPageTitleA1\').style.display = \'none\';$(\'MsgBoxDenyPageTitleA2\').style.display = \'block\'}" id="MsgBoxDenyPageTitleA1" onmouseover="API.showHelp();">&nbsp;</a>';
		o.innerHTML += '<a style="display:none; font-size: 9pt; padding-left: 15px;"  href="#" onclick="API.throbber(\'MsgBoxDenyPageContent\');API.getAdminFunction(\'DenyPage\', \'MsgBoxDenyPageContent\', \'user_role_id=' + APL_USER_ROLE_ID + '\');if ($(\'MsgBoxDenyPageTitleA2\').style.display == \'block\') {$(\'MsgBoxDenyPageTitleA1\').style.display = \'block\';$(\'MsgBoxDenyPageTitleA2\').style.display = \'none\'}" id="MsgBoxDenyPageTitleA2" onmouseover="API.showHelp();">&nbsp;</a></p>';
		o.innerHTML += '<p id="MsgBoxDenyPageContent" style="padding: 5px;">&nbsp;</p>';
		
		c = new cHTML.createElement('div', cHTML.active + '_close', 'absolute', w - 25, 0, 10, 10, API.maxZ + 1000);
		o.appendChild(c);
		c.innerHTML = '<a href="javascript:void(0);" onclick="cHTML.hide(true);">x</a>';

		API.getPhrase(24, 'MsgBoxDenyPageTitleP', 2);
		API.getPhrase(25, 'MsgBoxDenyPageTitleA1', 2);
		API.getPhrase(26, 'MsgBoxDenyPageTitleA2', 2);
		API.getAdminFunction('DenyPage', 'MsgBoxDenyPageContent', 'user_role_id=' + APL_USER_ROLE_ID);
		
	},
	
	denyElement : function (id, DOMid) {
		
		cHTML.show(50);
		cHTML.active = 'MsgBoxDenyElement';
		
		w = 470;
		h = 280;

		o = new cHTML.createElement('div', cHTML.active, 'absolute', API.page.x50, API.scrollTop + API.page.y50, 1, 1, API.maxZ + 1);
		o  = API.stylize(o);
		o.style.overflowY = 'auto';
		o.style.MozBorderRadius = '5px';
		document.body.appendChild(o);
		new Animation.EaseIn(cHTML.active, API.page.x50 - (w / 2), API.scrollTop + (API.page.y50 - (h / 2)), w, h);
		o.innerHTML = '<p><span id="MsgBoxDenyElementTitleP" style="font-size: 10pt; padding-left: 10px; padding-top: 10px; font-weight: bold;">&nbsp;</span></p>';
		o.innerHTML += '<p id="MsgBoxDenyElementContent" style="padding: 5px;">&nbsp;</p>';
		
		c = new cHTML.createElement('div', cHTML.active + '_close', 'absolute', w - 25, 0, 10, 10, API.maxZ + 1);
		o.appendChild(c);
		c.innerHTML = '<a href="javascript:void(0);" onclick="cHTML.hide(true);">x</a>';

		API.getPhrase(44, 'MsgBoxDenyElementTitleP', 2);
		API.getAdminFunction('DenyGroupElement', 'MsgBoxDenyElementContent', 'user_role_id=' + APL_USER_ROLE_ID + '&id=' + id);
		
//		setTimeout('cHTML.hide()', 10000);
		
	},
	
	EditElement : function (id, type) {
		
		if (type == 0) return;
		c = cHTML.bckg;
		
		if (!document.getElementById(id)) return;
		cHTML.show(50);
		cHTML.active = 'MsgBoxEditElement';
		if (document.getElementById('APIAdminControllerEditingP')) {
			$('APIAdminControllerEditingP').style.display = 'none';
		}
		
		APIAdmin.hideOnlyPrintElementsHighlight();
		
		switch (type) {

			case '#add#':
			
				w = 300;
				h = 90;
				o = new cHTML.createElement('div', cHTML.active, 'absolute', API.page.x50, API.scrollTop + API.page.y50, 1, 1, 10100);
				o  = API.stylize(o);
				o.style.MozBorderRadius = '5px';
				document.body.appendChild(o);
				new Animation.EaseIn(cHTML.active, API.page.x50 - (w / 2), API.scrollTop + (API.page.y50 - (h / 2)), w, h);
				o.innerHTML = '<p><span id="APIAdminAddTitleP" style="font-size: 10pt; padding-left: 10px; padding-top: 10px; font-weight: bold;">&nbsp;</span></p>';
				o.innerHTML += '<p id="APIAdminAddContent" style="padding: 5px;">&nbsp;</p>';

				c = new cHTML.createElement('div', cHTML.active + '_close', 'absolute', w - 18, 0, 10, 10, API.maxZ + 1);
				o.appendChild(c);
				c.innerHTML = '<a href="javascript:void(0);" onclick="cHTML.hide(true);if (document.getElementById(\'APIAdminControllerEditingP\')) {$(\'APIAdminControllerEditingP\').style.display = \'inline\';}">x</a>';

				API.getPhrase(11, 'APIAdminAddTitleP', 2);
				API.getAdminFunction('ChooseElementType', 'APIAdminAddContent', 'user_role_id=' + APL_USER_ROLE_ID + '&ElId=' + id);
				
			
			break;
			
			case 'base64':
				
				bl = 40;
				bt = 20 + API.scrollTop;
				w = API.page.x2 - ((API.browser.ie && !API.browser.ie7)? 0 : 20) - (2 * bl);
				h = API.page.y2 - 40;
				o = new cHTML.createElement('div', cHTML.active, 'absolute', API.page.x50, API.scrollTop + API.page.y50, 1, 1, 10100);
				o.innerHTML = '<form onsubmit="cHTML.PreviewElement(\'' + id + '\', \'' + type + '\');return false;"><textarea id="AdminEditElementTextArea" style="width: ' + w + 'px; height: ' + h + 'px;">' + $(id).innerHTML + '</textarea></form>';

				document.body.appendChild(o);
				new Animation.EaseIn(cHTML.active, bl, bt, w, h);
				
				//tinyMCE.addMCEControl($('AdminEditElementTextArea'), 'AdminEditElementTextArea');
				tinyMCE.execCommand("mceAddControl", true, 'AdminEditElementTextArea');
								
			break;
			
			case 'module':
			
				w = 400;
				h = 300;
				o = new cHTML.createElement('div', cHTML.active, 'absolute', API.page.x50, API.scrollTop + API.page.y50, 1, 1, 10100);
				o  = API.stylize(o);
				o.style.MozBorderRadius = '5px';
				document.body.appendChild(o);
				new Animation.EaseIn(cHTML.active, API.page.x50 - (w / 2), API.scrollTop + (API.page.y50 - (h / 2)), w, h);
				o.innerHTML = '<p><span id="APIAdminAddTitleModuleP" style="font-size: 10pt; padding-left: 10px; padding-top: 10px; font-weight: bold;">&nbsp;</span></p>';
				o.innerHTML += '<p id="APIAdminAddModuleContent" style="padding: 5px;">&nbsp;</p>';

				c = new cHTML.createElement('div', cHTML.active + '_close', 'absolute', w - 18, 0, 10, 10, API.maxZ + 1);
				o.appendChild(c);
				c.innerHTML = '<a href="javascript:void(0);" onclick="cHTML.hide(true);if (document.getElementById(\'APIAdminControllerEditingP\')) {$(\'APIAdminControllerEditingP\').style.display = \'inline\';}">x</a>';
				
				API.getPhrase(12, 'APIAdminAddTitleModuleP');
				API.getAdminFunction('ChooseModule', 'APIAdminAddModuleContent', 'user_role_id=' + APL_USER_ROLE_ID + '&ElId=' + id);
				
			
			break;
			
			case 'module_static':
			
				w = 400;
				h = 300;
				o = new cHTML.createElement('div', cHTML.active, 'absolute', API.page.x50, API.scrollTop + API.page.y50, 1, 1, 10100);
				o  = API.stylize(o);
				o.style.MozBorderRadius = '5px';
				document.body.appendChild(o);
				new Animation.EaseIn(cHTML.active, API.page.x50 - (w / 2), API.scrollTop + (API.page.y50 - (h / 2)), w, h);
				o.innerHTML = '<p><span id="APIAdminAddTitleModuleP" style="font-size: 10pt; padding-left: 10px; padding-top: 10px; font-weight: bold;">&nbsp;</span></p>';
				o.innerHTML += '<p id="APIAdminAddModuleContent" style="padding: 5px;">&nbsp;</p>';

				c = new cHTML.createElement('div', cHTML.active + '_close', 'absolute', w - 18, 0, 10, 10, API.maxZ + 1);
				o.appendChild(c);
				c.innerHTML = '<a href="javascript:void(0);" onclick="cHTML.hide(true);if (document.getElementById(\'APIAdminControllerEditingP\')) {$(\'APIAdminControllerEditingP\').style.display = \'inline\';}">x</a>';
				
				API.getPhrase(12, 'APIAdminAddTitleModuleP');
				API.getAdminFunction('ChooseModule', 'APIAdminAddModuleContent', 'user_role_id=' + APL_USER_ROLE_ID + '&ElId=' + id + '&module_layout=static');
				
			
			break;
			
			default:
				cHTML.hide();
			break;
			
		}
	},
	
	PreviewElement : function(id, type, callBack) {
		
		switch (type) {

			case 'base64':
			
				$(id).innerHTML = tinyMCE.getContent();
		
				tinyMCE.removeMCEControl(tinyMCE.getEditorId('AdminEditElementTextArea'));
				
			break;
			
			case 'module':
			
				API.LoadModule(callBack, id);
			
			break;
			
			default:
			
			break;
			
		}
		
		cHTML.hide(true);
		
		icons = getElementsByClassName('AdminIcon');
		
		if (icons.length > 0) for (i = 0; i < icons.length; i++) {
			
			icons[i].style.display = 'none';
			
			tmp = icons[i].id.substr(0, id.length);
			if (tmp == id) {
				icons[i].style.display = 'block';
			}
			
		}
		if (document.getElementById(id + 'AdminDelImg')) $(id + 'AdminDelImg').style.display = 'none';

		if (!callBack) {
			cHTML.preSaveElement(id, type);
		} else {
			cHTML.preSaveElement(id, type, callBack);
		}
		
	},
	
	preSaveElement : function (id, type, callBack) {

		w = 400;
		h = 50;
		c = new cHTML.createElement('div', 'preSaveBox', 'absolute', API.page.x50 - (w / 2), 0, w, h, API.maxZ);
		c.style.backgroundColor = 'Silver';
		c.style.border = '1px solid black';
		c.style.margin = c.style.padding = '0px';
		c.style.overflow = 'hidden';
		image = APL_ROOT + '/themes/images/flip_down.gif';
		
		document.body.appendChild(c);
		
		c.innerHTML = '<p id="preSaveBoxPhraseP" class="aCenter" style="margin: 5px;">&nbsp;</p>';
		
		API.getPhrase(21, 'preSaveBoxPhraseP');
		
		c.onmouseover = function () {
			c.style.height = 50 + 'px';
			c.style.background = 'Silver';
		};
		
		c.onmouseout = preSaveBoxTimer = function () {
			//c.style.height = '7px';
			//c.style.background = 'Silver url(' + image + ') no-repeat bottom center';
		};
		
		onclick = "API.removeElement('preSaveBox');cHTML.saveElement('" + id + "', '" + type + "');";

		butt = new cHTML.createElement('p', 'previewButtons', 'absolute', 0, 0, w, h, API.maxZ + 2);
		butt.innerHTML = '<img src="' + APL_ROOT + '/button/OK/2/"/ style="cursor: pointer" onclick="' + onclick + '"><img src="' + APL_ROOT + '/themes/images/empty.gif" width="20" height="1"/><img src="' + APL_ROOT + '/button/Storno/2/"/ style="cursor: pointer" onclick="cHTML.show();window.location.reload();">';
		butt.style.textAlign = 'center';
		butt.style.top = (h - ((API.browser.ie)?25:20)) + 'px';

		c.appendChild(butt);
		
		window.scrollTo(0,0);
		
		setTimeout('preSaveBoxTimer()', ADMIN_TIMEOUT);
		
	},
	
	saveElement : function (id, type) {
		
		re = /Element_/gi;
		ElementId = id.replace(re, '');
		
		data = $(id).innerHTML;
		
//		alert(id);
		
		switch (type) {

			case 'base64':
				
			break;
			
			case 'module':
			
			break;
			
			default:
			
			break;
			
		}

		url = APL_ROOT + '/saveElement/' + ElementId + '/';

		tmp = $(id).innerHTML;
		
		// fix kvuli onlyprint elementum (ktere jsou viditelne v administraci, ale maji se ulozit neviditelne)
		tmp = tmp.replace('<span class="onlyprint" style="display: block; position: relative; opacity: 1; overflow: auto">', '<span class="onlyprint">');
		tmp = tmp.replace('<span class=\"onlyprint\" style=\"display: block; position: relative; opacity: 1; overflow: auto;\">', '<span class="onlyprint">');
		tmp = tmp.replace('<span class="onlyprint" style="display: block;', '<span class="onlyprint" style="');
		tmp = tmp.replace('<span class=\"onlyprint\" style=\"display: block;', '<span class=\"onlyprint\" style=\"');
		
		$(id).innerHTML = '<form method="post" id="SaveDataForm" action="' + url + '" class="none"><input type="text" name="type" value="' + type + '"/><textarea name="data">' + tmp + '</textarea>';
		
//		pars = Form.Element.serialize('SaveDataTemp');
		
//		pars += '&type=' + type;
		
		API.appendComm(url);
		cHTML.show();
		
/*		var myAjax = new Ajax.Request(
						url, 
						{
							method: 'post',
							evalScripts : true,
							parameters: pars,
							asynchronous : true,
							onSuccess: cHTML.successElementSave
						});
		
		
		icons = getElementsByClassName('AdminIcon');
		
		if (icons.length > 0) for (i = 0; i < icons.length; i++) {
			
			icons[i].style.display = 'block';
			
		}
	*/	
		$('SaveDataForm').submit();
		
	},
	
	successElementSave: function () {
		API.removeElement('preSaveBox');
		API.appendComm(' - <b>ok</b><br/>');
		cHTML.MsgBoxInfo('<p class="aCenter" id="SuccesSaveBox">&nbsp;</p>', APL_ROOT + '/' + APL_PAGE + '/');
		API.getPhrase(22, 'SuccesSaveBox');
	},
	
	MsgBoxAlert : function (text, button, url, _eval) {
		
		c = cHTML.bckg;
		cHTML.active = 'MsgBoxAlert';
		cHTML.show();
		
		if (!text) text = 'no text';
		if (!button) button = 'OK';
		if (!url) {
			onclick = '';
		} else {
			onclick = 'window.location.replace(\'' + url + '\');';
		}
		
		if (!_eval) {} else {
			onclick = _eval;
		}
		
		o = new cHTML.createElement('div', cHTML.active, 'absolute', API.page.x50 - (cHTML.w / 2), API.scrollTop + API.page.y50 - (cHTML.h / 2), cHTML.w, cHTML.h, API.maxZ + 1);
		o.style.cursor = 'default';
		o.style.padding = '5px 10px';

		o.innerHTML = '<br/><p class="aCenter">' + text + '</p>';

		document.body.appendChild(o);
		
		butt = new cHTML.createElement('p', 'MsgBoxAlertButton', 'absolute', 0, 0, cHTML.w, cHTML.h, API.maxZ + 2);
		butt.innerHTML = '<img src="' + APL_ROOT + '/button/' + button + '/2/" style="cursor: pointer" onclick="cHTML.MsgBoxHide();' + onclick + '"/>';
		butt.style.textAlign = 'center';
		butt.style.top = (cHTML.h - ((API.browser.ie)?25:15)) + 'px';
		
		o.appendChild(butt);
		
		var scrollTop=$('MsgBoxAlert').offsetTop;
		
		if (API.browser.ie7) { 
			window.scrollTo(0,0);
		}
		
		if (API.browser.ie8) { 
			//alert('ie8 '+scrollTop);
			//if(scrollTop) window.scrollTo(0,(scrollTop-25));
		}
		
	},
	
	MsgBoxHide : function () {
		cHTML.hide(true);
		
	},

	MsgBoxInfo : function (text, url) {
		
		c = cHTML.bckg;
		cHTML.active = 'MsgBoxInfo';
		cHTML.show();
		
		if (!text) text = 'no text';
		if (!url) {
			url = APL_ROOT;
		}
		if (url == '') url = '/';
		o = new cHTML.createElement('div', cHTML.active, 'absolute', API.page.x50 - (cHTML.w / 2), API.scrollTop + API.page.y50 - (cHTML.h / 2), cHTML.w, cHTML.h, API.maxZ + 1);
		o.style.cursor = 'default';
		o.style.padding = '5px 10px';

		o.innerHTML = '<br/><p class="aCenter">' + text + '</p>';

		document.body.appendChild(o);
		
		MsgBoxInfoHide = function() {
			
			window.location.replace(url);
//			cHTML.show();
			
		};
		
		setTimeout('MsgBoxInfoHide()', ADMIN_TIMEOUT);
		
	},
	
	MsgBoxInfoTimeout : function (text, timeout) {
		
		c = cHTML.bckg;
//		cHTML.active = 'MsgBoxInfo';
//		cHTML.show();
		
		if (!text) text = 'no text';
		if (!timeout) {
			timeout = ADMIN_TIMEOUT;
		}

		o = new cHTML.createElement('div', 'MsgBoxInfo', 'absolute', API.page.x50 - (cHTML.w / 4), API.scrollTop + API.page.y50 - (cHTML.h / 4), cHTML.w /2 , cHTML.h / 2, API.maxZ + 1);
		o.style.cursor = 'default';
		o.style.padding = '5px 10px';

		o.innerHTML = '<br/><p class="aCenter">' + text + '</p>';

		document.body.appendChild(o);
		
		setTimeout(function() {API.removeElement('MsgBoxInfo')}, timeout);
		
	},
	
	msgBoxConfirm : function (text, url, button1, button2, _onclick, _nohide) {
		
		c = cHTML.bckg;
		latsA = cHTML.active;
		cHTML.active = 'msgBoxConfirm';
		cHTML.show();

		if (!button1) button1 = 'ANO';
		if (!button2) button2 = 'NE';
		
		box = new cHTML.createElement('div', cHTML.active, 'absolute', API.page.x50 - (cHTML.w / 2), API.scrollTop + API.page.y50 - (cHTML.h / 2), cHTML.w, cHTML.h, API.maxZ + 1);
		box.style.cursor = 'default';
		box.style.padding = '5px 10px';
		document.body.appendChild(box);
		box.innerHTML = '<br/><p class="aCenter">' + text + '</p>';

		if (!_onclick) {
			_onclick = "API.removeElement('" + cHTML.active + "');window.location.replace('" + url + "');";
		} else {
			if (!_nohide) {
				_onclick += "cHTML.hide(true);";
			} else {
				_onclick += "API.removeElement('" + cHTML.active + "');cHTML.active = '" + latsA + "';";
			}
		}
		
		if (!_nohide) {
			_onclick2 = "cHTML.hide(true);";
		} else {
			_onclick2 = "API.removeElement('" + cHTML.active + "');cHTML.active = '" + latsA + "';";
		}
		
		butt = new cHTML.createElement('p', 'msgBoxConfirmButton', 'absolute', 0, 0, cHTML.w, cHTML.h, API.maxZ + 2);
		butt.innerHTML = '<img src="' + APL_ROOT + '/button/' + button1 + '/2/" style="cursor: pointer" onclick="' + _onclick + '"/>';
		butt.innerHTML += '<img src="' + APL_ROOT + '/themes/images/empty.gif" width="20" height="0"/>';
		butt.innerHTML += '<img src="' + APL_ROOT + '/button/' + button2 + '/2/" style="cursor: pointer" onclick="' + _onclick2 + '"/>';
		butt.style.textAlign = 'center';
		butt.style.top = (cHTML.h - ((API.browser.ie)?25:15)) + 'px';

		box.appendChild(butt);
		
	},

	msgBoxPrompt : function (text, url, _default, _length, button1, button2) {
		
		c = cHTML.bckg;
		cHTML.active = 'msgBoxPrompt';
		cHTML.show();

		if (!button1) button1 = 'OK';
		if (!button2) button2 = 'Storno';
		if (!_length) _length = 5;
		if (!_default) _default = '';
		
		box = new cHTML.createElement('div', cHTML.active, 'absolute', API.page.x50 - (cHTML.w / 2), API.scrollTop + API.page.y50 - (cHTML.h / 2), cHTML.w, cHTML.h, API.maxZ + 1);
		box.style.cursor = 'default';
		box.style.padding = '5px 10px';
		document.body.appendChild(box);
		box.innerHTML = '<br/><p class="aCenter">' + text + '<br/><input type="text" id="PromptValue" size="' + _length + '" value="' + _default + '"/></p>';
		
		_onclick = "cHTML.msgBoxPromptSubmit('" + url + "/');";
		_onclick2 = "cHTML.hide(true);";
		
		butt = new cHTML.createElement('p', 'msgBoxPromptButton', 'absolute', 0, 0, cHTML.w, cHTML.h, API.maxZ + 2);
		butt.innerHTML = '<img src="' + APL_ROOT + '/button/' + button1 + '/2/" style="cursor: pointer" onclick="' + _onclick + '"/>';
		butt.innerHTML += '<img src="' + APL_ROOT + '/themes/images/empty.gif" width="20" height="0"/>';
		butt.innerHTML += '<img src="' + APL_ROOT + '/button/' + button2 + '/1/" style="cursor: pointer" onclick="' + _onclick2 + '"/>';
		butt.style.textAlign = 'center';
		butt.style.top = (cHTML.h - ((API.browser.ie)?25:15)) + 'px';

		box.appendChild(butt);		
		
		
	},
	
	msgBoxPromptSubmit : function (url) {

		window.location.replace(url + $('PromptValue').value + "/");
		
	},
	
	msgBox : function (text, buttons, evals) {

		if (!text) text = 'no text';
		
		c = cHTML.bckg;
		cHTML.active = 'msgBox';
		cHTML.show();
		
		box = new cHTML.createElement('div', cHTML.active, 'absolute', API.scrollTop + API.page.x50 - (cHTML.w / 2), API.scrollTop + API.page.y50 - (cHTML.h / 2), cHTML.w, cHTML.h, API.maxZ + 1);
		box.style.cursor = 'default';
		box.style.padding = '5px 10px';
		document.body.appendChild(box);
		box.innerHTML = '<br/><p class="aCenter">' + text + '</p>';

		butt = new cHTML.createElement('p', 'msgBoxPromptButton', 'absolute', 0, 0, cHTML.w, cHTML.h, API.maxZ + 2);
		butt.innerHTML = '';
		for (i = 0; i < buttons.length; i++) {
			butt.innerHTML += '<img src="' + APL_ROOT + '/button/' + buttons[i] + '/1/" style="cursor: pointer" onclick="' + evals[i] + ';"/>';
			if (i < (buttons.length - 1)) butt.innerHTML += '<img src="' + APL_ROOT + '/themes/images/empty.gif" width="20" height="0"/>';
		}

		butt.style.textAlign = 'center';
		butt.style.top = (cHTML.h - ((API.browser.ie)?25:15)) + 'px';
		
		box.appendChild(butt);

//		setTimeout('cHTML.hide();', 3 * ADMIN_TIMEOUT);
		
	},
	
	infoBox : function (text, buttons, evals, whoCall) {

		if (!text) text = 'no text';
		while((text.indexOf("&lt;")>0) || (text.indexOf("&gt;")>0)){
			text=text.replace("&lt;","<").replace("&gt;",">");
		}
		
		c = cHTML.bckg;
		cHTML.active = 'msgBox';
		cHTML.show();
		
		box = new cHTML.createElement('div', cHTML.active, 'absolute',  API.page.x50 - (cHTML.w / 2), API.scrollTop + API.page.y50 - (cHTML.h / 2), cHTML.w, 200, API.maxZ + 1);
		box.style.cursor = 'default';
		box.style.padding = '5px 10px';
		document.body.appendChild(box);
		box.innerHTML = '<br/>' + text + '<br/>';
		
		butt = new cHTML.createElement('p', 'msgBoxPromptButton', 'absolute', 0, 0, cHTML.w, cHTML.h, API.maxZ + 2);
		butt.innerHTML = '';
		for (i = 0; i < buttons.length; i++) {
			butt.innerHTML += '<img src="' + APL_ROOT + '/button/' + buttons[i] + '/1/" style="cursor: pointer" onclick="' + evals[i] + ';"/>';
			if (i < (buttons.length - 1)) butt.innerHTML += '<img src="' + APL_ROOT + '/themes/images/empty.gif" width="20" height="0"/>';
		}

		butt.style.textAlign = 'center';
		butt.style.top = 170 + 'px';
		box.appendChild(butt);

//		setTimeout('cHTML.hide();', 3 * ADMIN_TIMEOUT);
		if (API.browser.ie8) window.scrollTo(0,API.page.y50-cHTML.h);
		
	},
	
	printElement : function (element) {
		
		el = $(element);
		
		var win = window.open('', 'Win_' + element, 'screenX = ' + (API.page.x50 / 2) + ', screenY = ' + (API.page.y50 / 2) + ', width = 640, height = 640, innerWidth = ' + (API.page.x) + ', innerHeight = ' + (API.page.y) + ',resizable = 1, status = 0, toolbar = 0, titlebar = 0, menubar = ' + ((API.browser.ie)?'1':'0') + ', location = 0, scrollbars = 1, dependent = 1, alwaysRaised = 1'); 
		d = win.document;
		d.write('<head><title></title>');
		d.write('<link rel="stylesheet" type="text/css" href="' + APL_ROOT + '/themes/sob.css"/>');
//		d.write('<link rel="stylesheet" type="text/css" href="' + APL_ROOT + '/css/"/>');
		if (API.browser.ie) d.write('<link rel="stylesheet" type="text/css" href="' + APL_ROOT + '/themes/' + APL_THEME + '.user.print.ie.css"/>');
		d.write('<link rel="stylesheet" type="text/css" href="' + APL_ROOT + '/themes/' + APL_THEME + '.user.print.css"/>');
		d.write('<link rel="stylesheet" type="text/css" href="' + APL_ROOT + '/themes/' + APL_THEME + '.css"/>');
		if (API.CSSlist.length > 0) for (i = 0; i < API.CSSlist.length; i++) {
			d.write(API.CSSlist[i]);
		}
		d.write('<style type="text/css">.noprint {display: none;}</style>');
		d.write('</head>');
		d.write('<body>');
		tmp = el.innerHTML;
//		find = '<p class="aCenter noprint">'
//		end = tmp.substr(tmp.lastIndexOf(find) + find.length);
//		tmp = tmp.substr(0, tmp.lastIndexOf(find));
//		end = end.substr(end.indexOf('</p>') + 4);
		d.write(tmp);
		d.write('<script type="text/javascript">setTimeout(function(){window.print();window.close();}, 1000);</script>');
		d.write('</body>');
		d.close();
		
	},
	
	scroll : function() {
		
		c = cHTML.bckg;
		c.style.top = API.scrollTop + 0 + 'px';
		
	},
	
	resize : function() {
		
		c = cHTML.bckg;
		c.style.width = (API.page.x2 - ((API.browser.ie && !API.browser.ie7)? 0 : 20)) + 'px';
		c.style.height = API.page.y2 + 'px';
//		c.style.width = '100px';
//		c.style.height = '100px';
/*		if (cHTML.active != null) {
			$(cHTML.active).style.left = API.page.x50 - (cHTML.w / 2) + 'px';
			$(cHTML.active).style.top = API.page.y50 - (cHTML.h / 2) + 'px';
		}*/
		
		cHTML.scroll();
		
	},
	
	show : function(opacity) {
		if (!cHTML.bckg) {
			API.queue('cHTML.show();');
			return;
		}
		cHTML.bckg.style.display = 'block';
		if (!opacity) {
			void(0);
		} else {
			API.setObjOpacity(cHTML.bckg, opacity);
		}
		ar = $$('object');
		for (i = 0; i < ar.length; i++) {
			ar[i].style.visibility = 'hidden';
		};
	},
	
	hide : function(remove) {
		if (!cHTML.bckg) {
			API.queue('cHTML.hide();');
			return;
		}
		API.setObjOpacity(cHTML.bckg, cHTML.opacity);
		if (!remove) {
			new Animation.EaseOut(cHTML.active);
		} else {
			new Animation.EaseOut(cHTML.active, true);
			cHTML.active = null;
		}
		
		cHTML.bckg.style.display = 'none';
		API.showHelp();
		ar = $$('object');
		for (i = 0; i < ar.length; i++) {
			ar[i].style.visibility = 'visible';
		};
	},
	
	createElement : function(element, id, position, x, y, w, h, zindex, display) {

		API.removeElement(id);
		
		el = document.createElement(element);
		el.id = id;
		el.setAttribute('id', id);
		el.style.position = position;
		if (x < 0) {
			el.style.right = (0 - x) + 'px';	
		} else {
			el.style.left = x + 'px';
		}
		if (y < 0) {
			el.style.bottom = (0 - y) + 'px';	
		} else {
			el.style.top = y + 'px';
		}
		if (w == 0) {
			el.style.width = 'auto';
		} else {
			el.style.width = w + 'px';
		}
		if (h == 0) {
			el.style.height = 'auto';
		} else {
			el.style.height = h + 'px';
		}
		el.style.visibility = 'visible';
		el.style.display = 'block';
		if(display && display!='') el.style.display = display;
		el.style.zIndex = zindex;
		el.style.color = 'black';
		return el;
		
	}
	
};
