/*
* Copyright 2006, mai-internet
* 24837 Schleswig
* Michael Mai, <mm@mai-internet.de>
* www.mai-internet.de
*/

function mi_confirm(meldung)
{
    return confirm(meldung);
} // end

function mi_popup(strURL, strName, strParameter) {
	objNewWindow= window.open(strURL, strName, strParameter);
}

function mi_select_checkboxes(strKey) {
	var toCheck = 'input['+strKey+']';
	alle = document.getElementsByTagName("input");
	for (var i = 0; i < alle.length; ++i) {	
		name = String(alle[i].getAttribute('name'));
		teil = name.substr(0, toCheck.length);
		type = alle[i].getAttribute('type');
		if (type == 'checkbox' && teil == toCheck) {
			/* alle[i].setAttribute('checked','checked'); */
			alle[i].checked = true;
		}
	}	
}

function mi_unselect_checkboxes(strKey) {
	var toCheck = 'input['+strKey+']';
	alle = document.getElementsByTagName("input");
	for (var i = 0; i < alle.length; ++i) {
		name = String(alle[i].getAttribute('name'));
		teil = name.substr(0, toCheck.length);
		type = alle[i].getAttribute('type');
		if (type == 'checkbox' && teil == toCheck) {
			// alle[i].removeAttribute('checked','');
			alle[i].checked = false;
		}
	}	
}

/*
function ALTswitch_tab(intTabreiter) {
	tabreiter = document.getElementById('mi_tabreiter' + intTabreiter);
	inhalt = document.getElementById('mi_tabreiter_content' + strIdContent);
	if (tabreiter != null && inhalt != null) {
		// alle_tabs = document.getElementsByName('mi_tabreiter');
		// for (var i = 0; i < alle_tabs.length; ++i) {
		for (var i = 0; i < anzahl_tabreiter; ++i) {
			alert(i);
			
		
			classname = alle_tabs[i].getAttribute('class');
			
			if (classname == 'tab_aktiv') {
				alle_tabs[i].setAttribute("class", "tab_inaktiv");
				alle_tabs[i].style.border = "1px solid #CCC";
				alle_tabs[i].style.color = "#AAA";
				alle_tabs[i].style.backgroundColor = "#EEE";
				
				// alert('get:' + alle_tabs[i].getAttribute('class'));
			}
			
		}
		alle_container = document.getElementsByName('tabcontainer');
		for (var i = 0; i < alle_container.length; ++i) {
			classname = alle_container[i].getAttribute('class');
			if (classname == 'show_content') {
				alle_container[i].setAttribute("class", "hide_content");
				// alert('get:' + alle_tabs[i].getAttribute('class'));
			}
		}
	
	}	
}
*/

function switch_tab(intTabreiter) {

	for (var i = 0; i < anzahl_tabreiter; ++i) {
		objTab = document.getElementById('mi_tabreiter'+i);
		objInhalt = document.getElementById('mi_tabreiter_content'+i);
		if (i == intTabreiter) {
			aktiviere_tab(objTab, objInhalt);			
		} else {
			deaktiviere_tab(objTab, objInhalt);
		}
	}
	
}

function aktiviere_tab(objTab, objInhalt) {
		if (objTab != null) {
			objTab.style.backgroundColor = "white";
			objTab.style.border = "1px solid #CCC";
			objTab.style.borderBottom = "1px solid white";
		}
		if (objInhalt != null) {
			objInhalt.style.visibility = "visible";
			objInhalt.style.display = "block";
		}				
}

function deaktiviere_tab(objTab, objInhalt) {
		if (objTab != null) {
			objTab.style.backgroundColor = "#EEE";
			objTab.style.border = "1px solid #CCC";			
		}
		if (objInhalt != null) {
			objInhalt.style.visibility = "hidden";
			objInhalt.style.display = "none";
		}	
}

/*
* Färbt eine angeklickte Tabellenzeile mit der Farbe
*/
objMem = null;
strMemFarbe = '';
function mi_zeilefaerben(objZeile, strNeueFarbe) {

/*
	for(i=0;i<arrMem.length;i++) {
		arrMem[i].style.backgroundColor = strMemFarbe;
	}
*/
	if(objMem != null) {
		objMem.style.backgroundColor = strMemFarbe;
	}

/*
	for(i=0;i<objZeile.childNodes.length;i++) {
		if (objZeile.childNodes[i]!= null && objZeile.childNodes[i].nodeName == 'TD') {			
			objZeile.childNodes[i].style.backgroundColor = farbe;
		}
	}
*/
	objMem = objZeile;
	strMemFarbe = objZeile.style.backgroundColor;
	objZeile.style.backgroundColor = strNeueFarbe;
	
}

/*
* Wenn das Datumsfeld für ein Jahr nur 2stellig eingeben wird, wird mit dem aktuellen Jahrtausend ergänzt
* Ich nehme hierbei mal an, dass meine Scripte das Jahr 2099 nicht überleben werden... 
*/
function mi_datumsfeld_ergaenze_jahr(objFeld) {
	if (objFeld != null) {
		jahr = objFeld.value;		
		if (jahr.length == 1) {
			jahr = '200' + jahr;
			
		}		
		if (jahr.length == 2) {
			jahr = '20' + jahr;
			
		}
		objFeld.value = jahr;
	}
}

function mi_datumsfeld_ergaenze_null(objFeld) {
	if (objFeld != null) {
		if (objFeld.value.length == 1) {
			objFeld.value = '0' + objFeld.value;
		}
	}
}

// Funktion die ein Element mit einer bestimten ID versteckt oder anzeigt
// boolShow = true: Element wird angezeigt, false sonst

function mi_show_element(strId, boolShow) {
	objElement = document.getElementById(strId);
	if (objElement != null) {
		if (boolShow) {
		    objElement.style.visibility = 'visible';
			objElement.style.display = 'block';			
		} else {
		    objElement.style.visibility = 'hidden';
			objElement.style.display = 'none';		
		}
	}
}

/**
 * Wie mi_show_element überprüft aber ob das Element
 * gerade an ist und schaltet es dann aus und umgekehrt
 */
function mi_switch(strId) {
	if (document.getElementById(strId).style.visibility == 'hidden') {
		mi_show_element(strId, true);
	} else {
		mi_show_element(strId, false);
	}
}


function mi_reset_textfield(strId) {
	objElement = document.getElementById(strId);
	if (objElement != null) {
		objElement.value = '';
	}
}

function mi_reset_calfields(strTag, strMonat, strJahr) {	
	mi_reset_textfield(strTag);
	mi_reset_textfield(strMonat);
	mi_reset_textfield(strJahr);
}

function mi_display_help(strId, objAnchor) {
	xajax_display_help(strId);
	var pos = Position.get(objAnchor);
	x = pos.left +100;
	y = pos.top - 30;
	if (y <= 0) y = 10;
	Position.set('DIVHelp',x, y);
	// window.setTimeout("xajax_display_help('"+strId+"')", 500);
	mi_show_element('DIVHelp', true);
}

function mi_display_entry(strId, objAnchor) {
	var pos = Position.get(objAnchor);
	x = pos.left +100;
	y = pos.top - 30;
	if (y <= 0) y = 10;
	Position.set('DIVEntry',x, y);
	mi_show_element('DIVEntry', true);
	xajax_display_entry(strId);
}

function mi_delete_entry(strId, objAnchor) {
	meldung = "Der Eintrag wird unwiderruflich gelöscht. Weiter?";
	if (!confirm(meldung)) {
		return false;
	} else {
		xajax_delete_entry(strId);
	}
}

function show_wuerfel(navid, index) {
	// alert(objAnchor);
	for (var i = 0; i < arrWuerfel.length; ++i) {
		hide_wuerfel(arrWuerfel[i], '');
	}
	objElement = document.getElementById('TD'+navid);
	if (objElement != null) {
		// objElement.style.backgroundImage="url(../img/frame/wuerfel.gif)";
		// 
		// objElement.style.backgroundRepeat="repeat-x";
		objElement.className = 'wuerfel';
		if (navid == '555507') {
			objElement.style.backgroundPosition="right 105px";
		}
	}
	mi_display_wuerfelrechts(index);
}
function hide_wuerfel(navid, aktiv) {
	objElement = document.getElementById('TD'+navid);
	if (objElement != null) {
		// objElement.style.backgroundImage="";
		// objElement.style.backgroundPosition="right 4px";
		// objElement.style.backgroundRepeat="repeat-x";
		objElement.className = '';
	}
	objElement = document.getElementById('TDWuerfelR');
	objElement.style.backgroundPosition="0px -100px";
}

function mi_display_wuerfelrechts(index) {
	if (index != 99) {
		index = index -1;
		startpos = 261;	
		abstand = 26;
		y = startpos + (abstand * index);		
	} else {
		// Startposition des Logos:
		y = 147;
	}
	objElement = document.getElementById('TDWuerfelR');
	objElement.style.backgroundPosition="10px "+y+"px";
}

