var LOCAL = (document.location.host == "127.0.0.1");

if(LOCAL)
	var baseURL = document.location.protocol + "//" + document.location.hostname + "/cttc/public/content/";
else
	var baseURL = document.location.protocol + "//" + document.location.hostname + "/public/content/";


function choseDate(control, day, month, year)
{
	if(String(month).length == 1) {
		month = String("0" + month);
	}
	if(String(day).length == 1) {
		day = String("0" + day);
	}
	window.document.forms[0].elements[control + "_d"].value	=	day;
	window.document.forms[0].elements[control + "_m"].value	=	month;
	window.document.forms[0].elements[control + "_y"].value	=	year;
}

function checkbox_enable(name)
{
	document.actionform.elements[name].checked = 1;
}



function confirmDelete()
{
	if(confirm('Sind sie sicher, das Sie diesen Eintrag entfernen möchten ?')) return true;
	return false;
}

function confirmSendApplication()
{
	if(confirm('Sind Sie sicher, dass Sie diese Bewerbung absenden wollen?')) return true;
	return false;
}



function hideShowElement(elem, show)
{
	if(show == 1)
		elem.style.display = "block";
	else
		elem.style.display = "none";
	//alert(elem+" - "+show+"-"+elem.style.display);
	return true;
}

var geklickt = false;

function openNewsletter()
{
	var fbreite=453;
	var fhoehe=400;
	var aussehen="toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,titlebar=no,width="+fbreite+",height="+fhoehe;
	newWindow = window.open("http://ea.ce-intern.com/_s.php?&fid=2433&fpw=fdd85804ee5513979cbde1acdd4763b0&mode=submit","",aussehen);
	newWindow.focus();
	return false; // damit formular nicht abgeschickt wird
}

function popup(url)
{
	var fbreite=800;
	var fhoehe=600;
	var aussehen="toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,titlebar=no,width="+fbreite+",height="+fhoehe;
	newWindow = window.open(url,"",aussehen);
	newWindow.focus();
	return false; // damit formular nicht abgeschickt wird
}


function chkAll(chkArray)
{
	for(i=0; i<chkArray.length; i++) chkArray[i].checked = true;
	return true;
}


var rowCache 	= new Array();
var parentRows = new Array();

function showHide()
{
	for(var i=0; i<parentRows.length; i++)
	{
		// index suchen
		if(parentRows[i] == this.id && rowCache[i]) {
			// gefunden

			for(var e=0; e<rowCache[i].length; e++)
			{
				// alle childrens zu / aufklappen
				hideShowElementById(rowCache[i][e]);
			}
			break;
		}
	}
}

function hideShowElementById(id)
{
	var elem = document.getElementById(id);
	if(elem.style.display == "none")
		elem.style.display = "";
	else
		elem.style.display = "none";
	return true;
}

function dynamicRepeater(baseElemID, parentRepeater, childRepeater, onloadCollapse)
{
	//hideShowElement(elem, show);
	var baseElem 	= document.getElementById(baseElemID);
	if(baseElem.childNodes[0].nodeType != 1 && baseElem.childNodes[1].nodeType == 1)
		baseElem = baseElem.childNodes[1];
	else
		baseElem = baseElem.childNodes[0];

	if(baseElem)
	{
		var i = -1;
		var curr;

		//alert(baseElem.nodeName);
		for (k in baseElem.childNodes)
		{
			if(baseElem.childNodes[k].nodeType != 1) continue;
			curr = baseElem.childNodes[k];
			
			if((curr.id.substr(0, childRepeater.length) != childRepeater) && (curr.id.substr(0, parentRepeater.length) == parentRepeater)) {
				i++;
				rowCache[i] = new Array();
				parentRows[i] = curr.id;
				curr.onclick = showHide;
				continue;
			}
			rowCache[i].push(curr.id);
			if(onloadCollapse) {
				hideShowElementById(curr.id);
			}
		}
	}

	document.write('<br><a href="javascript:;" onClick="showAll();">Alle Details anzeigen</a>');

}

function showAll()
{
	for(var i=0; i<parentRows.length; i++)
	{
		for(var e=0; e<rowCache[i].length; e++)
		{
			document.getElementById(rowCache[i][e]).style.display = "";
		}
	}
}


function openCalender(controlName)
{
	f1 = window.open(baseURL+'datepicker.php?control='+controlName, 'datepicker', 'width=180, height=170, location=no, menubar=no, resizable=yes, scrollbars=no, status=yes, toolbar=no');
	f1.focus();
}