base2.DOM.bind(document);

function F_AddLoadEvent(F_Win) {
  var O_OldOnload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = F_Win;
  } else {
    window.onload = function() {
      if (O_OldOnload) {
        O_OldOnload();
      }
      F_Win();
    }
  }
}

var V_AutolinkRemind = 0;

function F_AutoLinkOver(){
	O_Img = this.matchSingle("img");
	S_Imgsrc = O_Img.src;
	A_ImgsrcSub = new Array();
	A_ImgsrcSub[0] = S_Imgsrc.substr(0,S_Imgsrc.length - 5);
	A_ImgsrcSub[1] = S_Imgsrc.substr(S_Imgsrc.length - 5, 1);
	A_ImgsrcSub[2] = S_Imgsrc.substr(S_Imgsrc.length - 4, 4);
	if(A_ImgsrcSub[1] == "p"){
		V_AutolinkRemind = 1;
		S_Imgsrc = A_ImgsrcSub[0]+"a"+A_ImgsrcSub[2];
		O_Img.setAttribute('src', S_Imgsrc);
	}
}

function F_AutoLinkOut(){
	O_Img = this.matchSingle("img");
	S_Imgsrc = O_Img.src;
	A_ImgsrcSub = new Array();
	A_ImgsrcSub[0] = S_Imgsrc.substr(0,S_Imgsrc.length - 5);
	A_ImgsrcSub[1] = S_Imgsrc.substr(S_Imgsrc.length - 5, 1);
	A_ImgsrcSub[2] = S_Imgsrc.substr(S_Imgsrc.length - 4, 4);
	if(V_AutolinkRemind == 1){
		V_AutolinkRemind = 0;
		S_Imgsrc = A_ImgsrcSub[0]+"p"+A_ImgsrcSub[2];
		O_Img.setAttribute('src', S_Imgsrc);
	}
}

function F_AutoLinkInit(){
	var A_AutoLinks = document.matchAll("a.autolink");
	for(i=0;i<A_AutoLinks.length;i++){
		var O_AutoLink = A_AutoLinks.item(i);
		O_AutoLink.i = i;
		O_AutoLink.addEventListener("mouseover", F_AutoLinkOver, false);
		O_AutoLink.addEventListener("mouseout", F_AutoLinkOut, false);
	}
}

// added to window.onload
F_AddLoadEvent(F_AutoLinkInit);


// folgender Aufruf stand in body.onload, dann funzt allerdings der autolink nicht mehr
// Und mittlerweile wird die Serverzeit benutzt, deswegen wirds nix mit diesem Intervall
// window.setInterval('zeitausgabe()',1000);
// ersatz:

function setTimer() {
	if(document.getElementById('timer') != null) {
		
		now_ts = Math.round(time_b.getTime() / 1000);
		
		ende = new Date(time_b.getFullYear(), time_b.getMonth(), (time_b.getDate() + 1), 0, 0, 0)
		ende_ts = Math.round(ende.getTime() / 1000);
		
		diff = ende_ts - now_ts;
		
		if(diff > 3600) {
			h = Math.floor(diff / 3600);
			diff -= (h * 3600);
			h = h < 10 ? '0'+h : h;
		} else {
			h = '00';
		}
		
		if(diff > 60) {
			m = Math.floor(diff / 60);
			diff -= (m * 60);
			m = m < 10 ? '0'+m : m;
		} else {
			m = '00';
		}
		
		diff = diff < 10 ? '0'+diff : diff;
		
		output = h + ':' + m + '<span style="font-size:14px;color:#FFF;">:' + diff + '</span>';
		
		time_b.setSeconds(time_b.getSeconds() + 1);
		
		document.getElementById('timer').innerHTML = output;
	}
	
	setTimeout("setTimer()", 1000);
}


function commentarySwitch(answer_id) {
	c = document.getElementById('commentaryPost');
	
	document.getElementById('answer_id').value = answer_id;
	
	if(answer_id != 0) {
		//document.getElementById('comm_headline').disabled = true;
		//document.getElementById('comm_headline').value = 'no headline pendejo';
	} else {
		//document.getElementById('comm_headline').disabled = false;
	}
	
	if(c.style.display == 'none') {
		c.style.display = 'block';
	} else {
		c.style.display = 'none';
	}
}

function hover(id) {
	var folder = "pics/buttons/";
	var source = document.getElementById(id).src; 
	
	if(source.substr(source.length - 6, 6) == '_p.gif') {
		document.getElementById(id).src = folder + id + '_a.gif'; 
	} else {
		document.getElementById(id).src = folder + id + '_p.gif'; 
	}
}

function reloadWK1() {
	amount = document.getElementById('menge').value;
	window.location.href = 'index.php?page=wk1&amount=' + amount;
}

function setBirthday(trigger) {
	b = document.getElementById('birthday');
	
	if(trigger == 'focus') {
		if(b.value == 'TT.MM.JJJJ') {
			b.value = '';
		}
	} else {
		if(b.value == '') {
			b.value = 'TT.MM.JJJJ';
		}
	}
}

function sendPassword() {
	f = window.open('pages/sendpass.php', "popup", "height=220,width=460,top=300,left=300");
}

function retroQuestion(id) {
	f = window.open('pages/retroquestion.php?id='+id, "popup", "height=640,width=500,top=200,left=200");
}

/* 
function search(evt) {
	evt = (evt) ? evt : ((event) ? event : null);

	if (evt) {
		alert(evt.keyCode);
		
		if (evt.charCode) {
			alert(evt.charCode);
		}
		showTarget(evt);
	}
}*/


function disableFields(kabool) {
	color = kabool ? '#FAFAF7' : '#FFFFFF';
	
	document.getElementById("bank_owner").disabled = kabool;
	document.getElementById("bank_institute").disabled = kabool;
	document.getElementById("bank_blz").disabled = kabool;
	document.getElementById("bank_ktonr").disabled = kabool;
	
	document.getElementById("bank_owner").style.backgroundColor = color;
	document.getElementById("bank_institute").style.backgroundColor = color;
	document.getElementById("bank_blz").style.backgroundColor = color;
	document.getElementById("bank_ktonr").style.backgroundColor = color;
}

function openShipping() {
	window.open('index.php?page=agb&anchor=versandkosten', "Versandkosten", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=400,width=600,top=200,left=200");
}

function openAGB() {
	window.open('index.php?page=agb', "AGB", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=600,width=930,top=200,left=200");
}

function openPrivacypolicy() {
	window.open('index.php?page=datenschutz', "Datenschutz", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=600,width=930,top=200,left=200");
}




/*
function zeitausgabe() {
	if(document.getElementById('timer') != null) {
		a = new Date();
		b = new Date();
		now_ts = Math.round(b.getTime() / 1000);
		/* Da wir nun wieder auf 00:00 Uhr umschalten...
		if(a.getHours() < 7) {
			ende = new Date(b.getFullYear(), b.getMonth(), b.getDate(), 7, 0, 0)
			ende_ts = Math.round(ende.getTime() / 1000);
		} else {
			ende = new Date(b.getFullYear(), b.getMonth(), (b.getDate() + 1), 7, 0, 0)
			ende_ts = Math.round(ende.getTime() / 1000);
		}
		*//*
		ende = new Date(b.getFullYear(), b.getMonth(), (b.getDate() + 1), 0, 0, 0)
		ende_ts = Math.round(ende.getTime() / 1000);
		diff = ende_ts - now_ts;
		if(diff > 3600) {
			h = Math.floor(diff / 3600);
			diff -= (h * 3600);
			h = h < 10 ? '0'+h : h;
		} else {
			h = '00';
		}
		
		if(diff > 60) {
			m = Math.floor(diff / 60);
			diff -= (m * 60);
			m = m < 10 ? '0'+m : m;
		} else {
			m = '00';
		}
		
		diff = diff < 10 ? '0'+diff : diff;
		output = h + ':' + m + '<span style="font-size:14px;color:#FFF;">:' + diff + '</span>';
		document.getElementById('timer').innerHTML = output;
	}
}*/