var activeTimeout = new Array();

function disappear(d_id) {
	if( activeTimeout[d_id] !== null ) {
		clearTimeout(activeTimeout);
	}
	activeTimeout[d_id] = setTimeout("closediv('"+d_id+"')",200);
}
function closediv(d_id){
	var object = document.getElementById(d_id);
	if(object.style.visibility){
		object.style.visibility="hidden";
	}
	else{
		object.style.display='none';
	}
}
function reappear(d_id) {
	if( activeTimeout[d_id] ) {
		clearTimeout( activeTimeout[d_id] );
		activeTimeout[d_id] = null;
	}
	var object = document.getElementById(d_id);
	
	if(object.style.visibility){
		object.style.visibility="visible";
	}
	else{
		object.style.display='block';
	}
}

function cms_popupwindowopen(url,name,width,height,pvpDir) {
	if(pvpDir && pvpDir !== ''){
		url = pvpDir + url;
	}
	if(url.indexOf('?') > 0) {
		tURL = url+'&REF=popup';
	}
	else {
		tURL = url+'?REF=popup';
	}
	var opener = window.open(tURL,name,'locationbar=no,menubar=no,status=no,width='+width+',height='+height+',resizable=yes,dependent=yes,scrollbars=yes').focus();
}
	
// fokus auf das erste inputfeld vom typ TEXT oder RADIO setzen
function setFocus(objectID) {
	if(objectID !== null) {
		$(objectID).focus();
	}
}

function $(i) {
	return document.getElementById(i);
}

// wenn im div mit der id QUESTIONDIVID der radiobutton mit dem value ANSWERVALUE gecheckt ist,
// dann blende das div mit der id SHOWDIVID ein
function showOn(questionDivId, answerValue, showDivId) {
	// check Inverse - TRUE or FALSE
	var checkChecked = true;
	if(answerValue < 0) {
		checkChecked = false;
		answerValue = answerValue*-1;
	}
	var elm = $(questionDivId);
	if (!elm) { return; }
	var display = 'none';
	var inputs = elm.getElementsByTagName('input');
	// ADD split for Array
	var answerValueArray = answerValue.toString().split(",");

	for (var i = 0; i < inputs.length; i++) {
		//if ((inputs[i].checked == checkChecked) && ((inputs[i].value == answerValue) || (answerValueArray.indexOf(inputs[i].value) > -1))) {
		if ((inputs[i].checked == checkChecked) && (inputs[i].value == answerValue || (ArrayIndexOf(answerValueArray, inputs[i].value) > -1))) {
			display = 'block';
			break;
		}
	}
	$(showDivId).style.display = display;
}
function ArrayIndexOf(Array, elt) {
	var len = Array.length;

	var from = 0;

	for (; from < len; from++) {
		if (parseInt(Array[from]) === parseInt(elt))
			return from;
	}
	return -1;
};

function spezial() {
	var elm1 = $('konventionellesElektroauto');
	var elm2 = $('ElektroautomitÖkostrom');
	var elm3 = $('andereTreibstoffe');
	if (elm1 && elm2 && elm3) {
		if (elm3.checked) {
			$('question_2_43').style.display = 'none';
		} else {
			$('question_2_43').style.display = 'block';
		}
	}
}

function blenden() {
	// wohnen 9
	//showOn('question_1_8', 26, 'question_1_9');
	// verkehr 1
	// ADD POLAK verkehr
	showOn('question_2_64', [228, 239], 'question_2_67');
	showOn('question_2_64', 239, 'question_2_68');
	showOn('question_2_76', -272, 'question_2_47');
	

	//showOn('question_2_49', 230, 'treibstoffe'); // subauswahl "andere treibstoffe" einblenden
	spezial(); // verbrauch ausblenden
	//showOn('question_2_64', 228, 'question_2_49');
	/*MOD 20071206 MONOVIC bei biodiesel verbrauch einblenden */
	var elm3 = $('andereTreibstoffe');
	if (elm3){
		if (elm3.checked) {
			showOn('treibstoffe', 225, 'question_2_43');
		}
	}

}

function hide_show(ereignis) {
	setTimeout ('blenden()', 100);
}

function initOnChange() {
	var elements = document.forms[0].elements;
	for (var j=0;j<elements.length;j++) {
		elm = elements[j];
		if (elm.type == 'radio' || elm.type == 'checkbox') {
			elm.onchange = hide_show;
			elm.onclick = hide_show;
		}
	}
	blenden();
}

function toLowerCaseReg () {

	var neu = document.REG.Login.value.toLowerCase();
	document.REG.Login.value = neu;
}


function cms_windowopen(url,name,width,height,pvpDir)
{
	if(pvpDir && pvpDir !== ''){
		var opener = window.open(pvpDir+'/administration'+url,name,'locationbar=no,menubar=no,status=no,width='+width+',height='+height+',resizable=yes,dependent=yes,scrollbars=yes').focus();
	}else{
		var opener = window.open('/administration'+url,name,'locationbar=no,menubar=no,status=no,width='+width+',height='+height+',resizable=yes,dependent=yes,scrollbars=yes').focus();
	}
}