/* 
------------------------------------------
	Flipbox written by CrappoMan
	simonpatterson@dsl.pipex.com
------------------------------------------
*/
function flipBox(who) {
	var tmp; 
	if (document.images['b_' + who].src.indexOf('_on') == -1) { 
		tmp = document.images['b_' + who].src.replace('_off', '_on');
		document.getElementById('box_' + who).style.display = 'none';
		document.images['b_' + who].src = tmp;
	} else { 
		tmp = document.images['b_' + who].src.replace('_on', '_off');
		document.getElementById('box_' + who).style.display = 'block';
		document.images['b_' + who].src = tmp;
	} 
}

function addText(elname, wrap1, wrap2) {
var formname = 'inputform';	
bbarea = document.forms[formname].elements[elname];
bbarea.focus();
   if (document.selection) {
	   var selText = bbarea.document.selection.createRange();
	   var numLenght = selText.text.length;
	   var selStart = selText.selectionStart;
	   var selEnd = selText.selectionEnd;
	   selText.text = wrap1 + selText.text + wrap2;
	   return false;
   } else if (bbarea.setSelectionRange) {
      var selStart = bbarea.selectionStart;
	  var selEnd = bbarea.selectionEnd;
	  var oldScrollTop = bbarea.scrollTop;
      bbarea.value = bbarea.value.substring(0, selStart) + wrap1 + bbarea.value.substring(selStart, selEnd) + wrap2 + bbarea.value.substring(selEnd);
      bbarea.setSelectionRange(selStart + wrap1.length, selEnd + wrap1.length);
	  bbarea.scrollTop = oldScrollTop;      
      bbarea.focus();
   } else {
	  var oldScrollTop = bbarea.scrollTop;
      bbarea.value += wrap1 + wrap2;
	  bbarea.scrollTop = oldScrollTop;      
      bbarea.focus();
	}
}

function insertText(elname, what, formname) {
	if (document.forms[formname].elements[elname].createTextRange) {
		document.forms[formname].elements[elname].focus();
		document.selection.createRange().duplicate().text = what;
	} else if ((typeof document.forms[formname].elements[elname].selectionStart) != 'undefined') { // for Mozilla
		var tarea = document.forms[formname].elements[elname];
		var selEnd = tarea.selectionEnd;
		var txtLen = tarea.value.length;
		var txtbefore = tarea.value.substring(0,selEnd);
		var txtafter =  tarea.value.substring(selEnd, txtLen);
		var oldScrollTop = tarea.scrollTop;
		tarea.value = txtbefore + what + txtafter;
		tarea.selectionStart = txtbefore.length + what.length;
		tarea.selectionEnd = txtbefore.length + what.length;
		tarea.scrollTop = oldScrollTop;
		tarea.focus();
	} else {
		document.forms[formname].elements[elname].value += what;
		document.forms[formname].elements[elname].focus();
	}
}

function show_hide(msg_id) {
	msg_id.style.display = msg_id.style.display == 'none' ? 'block' : 'none';
}

function openWin(URL,breit,hoch) {
big = window.open(URL, breit+"zoomed"+hoch, "width="+breit+",height="+hoch+",resizable=no,menubar=no,status=no,locationbar=no,dependent=yes,scrollbars=no,statusbar=no");
	big.focus(); 

}

function getposOffset(overlay, offsettype) {
var totaloffset = offsettype == 'left' ? overlay.offsetLeft : overlay.offsetTop;
var parentEl = overlay.offsetParent;
while (parentEl != null) {
totaloffset = offsettype == 'left' ? totaloffset + parentEl.offsetLeft : totaloffset + parentEl.offsetTop;
parentEl = parentEl.offsetParent;
}
return totaloffset;
}

function overlay(curobj, subobjstr, opt_position) {
if (document.getElementById) {
var subobj = document.getElementById(subobjstr);
subobj.style.display = subobj.style.display != 'block' ? 'block' : 'none';
var xpos = getposOffset(curobj, 'left') + ((typeof opt_position != 'undefined' && opt_position.indexOf('right') !=-1) ? -(subobj.offsetWidth - curobj.offsetWidth) : 0);
var ypos = getposOffset(curobj, 'top') + ((typeof opt_position != 'undefined' && opt_position.indexOf('bottom') !=-1) ? curobj.offsetHeight : 0);
subobj.style.left = xpos + 'px';
subobj.style.top = ypos + 'px';
return false;
} else { return true; }
}

function overlayclose(subobj) {
if (document.getElementById(subobj)!=null){
document.getElementById(subobj).style.display = 'none';
}
}