/* rest.js */

deleteArticle = function(articleId) {
	if (articleId > 0 && confirm('Wollen Sie den Artikel wirklich entfernen?')) {
		window.location.href = 'article.do?action=delete&id=' + articleId;
	}
};

loadEntries = function(chapterId, currentPage, entryId, del) {
	if (chapterId > 0) {
		load('entries.do?chapterId=' + chapterId + '&currentPage=' + currentPage + '&entryId=' + entryId + '&del=' + del, 'entryPH');
	} else {
		Element.update($(entryPH), "");
	}
};

loadChapter = function(chapterId, currentPage, ph) {
	load('article/x.html?chapterId=' + chapterId + '&currentPage=' + currentPage, "obernase");
};

m_xx = function(id, action) { load('_chapter.do?action=' + action + '&id=' + id, 'contentPH'); };

m_li		= function(id) { m_xx(id, 'left'); };
m_re		= function(id) { m_xx(id, 'right'); };
m_ho		= function(id) { m_xx(id, 'up'); };
m_ru		= function(id) { m_xx(id, 'down'); };
m_toggle	= function(id) { m_xx(id, 'toggle'); };
m_add		= function(id) { m_xx(id, 'add'); };
m_del		= function(id) { m_xx(id, 'del'); };
m_edit		= function(id) { m_xx(id, 'edit'); };

function med_upload(id) {
	var w = window.open('uploadMedicament.do?action=edit&id=' + id, 'upload', 'width=640,height=400,left=160,top=200');
	w.focus();
}
			
/* Tooltip */
function showThumb(id, e) {

	var thumb = $('thumb' + id);
	var tt = $('tooltip');

	if (thumb && tt) {
		tt.innerHTML = thumb.innerHTML;

		if (document.all) {

			// IE: Scrolling mit einrechnen
			var x,y;
			if (document.documentElement && document.documentElement.scrollTop)
					// Explorer 6 Strict
				{
					x = document.documentElement.scrollLeft;
					y = document.documentElement.scrollTop;
				}
				else if (document.body) // all other Explorers
				{
					x = document.body.scrollLeft;
					y = document.body.scrollTop;
				}
			tt.style.left = event.clientX + 20 + x;
			tt.style.top = event.clientY - 160 + y;
		} else {
			try {
				event=e;
				tt.style.left= event.pageX + 20 + "px";
				tt.style.top = event.pageY - 160 + "px";
			} catch(e) {
			}
		}
		tt.style.visibility = "visible";
	}
}

function hideThumb()
{
	var tt = $('tooltip');
	if (tt) {
		tt.style.visibility = "hidden";
	}
}

var currentTimeout;

function simpleQuickSearch(searchValue) {
	clearTimeout( currentTimeout );
	if (searchValue.strip().length > 2) { // erst ab mind. 3 Zeichen suchen
		currentTimeout = setTimeout( 'doSQS()', 1000 );
	} else {
		var ph = $('ajax-searchbox');
		if (ph) {
			Element.hide('ajax-searchbox');
		}
	}
}

function doSQS() {
	saveForm('/bipi/_globalSearch.html', 'search', 'ajax-searchbox');
	var ph = $('ajax-searchbox');
	if (ph) {
		Element.show('ajax-searchbox');
	}
}

/////////////////////
///  Tim

/*
function doLogin() {

	var pars = Form.serialize('loginForm');
	new Ajax.Updater( 'ph_content2', '/bipi/_login.html', { method: 'post', parameters: pars, onSuccess: function(transport) {
		new Ajax.Updater( 'header', '/bipi/_header.html', { method: 'get'});
		new Ajax.Updater( 'subnav', '/bipi/_left.html', { method: 'get'});
	}});
	return false;
}
*/

function dr_e_handle(key, val) {
	$(key).value=val;
	saveForm('_entriesFree.html', 'myForm', 'meds-overview-wrapper', true);
	return false;
}