/*################################################################################
	D E B U G
################################################################################*/







var debugModus = 0	; // Debugmodus EIN = 1 || AUS = 0

function debug(txt)
{
	if(!debugModus || typeof(console) != "object") { return; }
	else { console.log(txt); }
}
debug("debugModus = true");

/*################################################################################
Alert - Helper Function
################################################################################*/
function cmsAlert(title, content, close){
	Alert({
		title: title,
		content: '<p>'+content+'</p><a style="display:block"'
	    				+' href="javascript:overlay.hide()">'
	    				+close+'</a>'
	});
}

/*================================================================================
onSubmitError()
================================================================================*/
validator.onSubmitError = function(els){

	var str = '<b>'+submiterror__message+'</b><br />';
	els.each(function(el){
		str += '- '+el.title || el.label.innerHTML.stripTags();
		str += '<br />';
	});
	
	str += '<a style="display:block;" href="javascript:overlay.hide();">'+submiterror__close+'</a>';
	
	Alert({title:submiterror__title, content:str});
	overlay.opt.onclose = function(){
		if(els[0]) 
			els[0].focus();
	};
};

/*################################################################################
	$$$
################################################################################*/

// get Elements by Name

function $$$(obj)
{
	var obj = document.getElementsByName(obj);
	obj = (obj.length==1)?obj[0]:obj;
	return obj;
}


/*################################################################################
	F U N C T I O N S
################################################################################*/

function faq(trigger) {
	$$('.QandA').each(function(el){
		el.getNext('div[class=faq]').setStyle('display','none');
	});
	trigger.getNext('div[class=faq]').setStyle('display','block');
}

function initInfoBoxes()
{
	info = $$('.info');
	info.each(function(el)
	{
		el.content = el.getNext('div');
		el.box = $('infoBox');
		el.boxContent = $('infoBoxContent');
		el.iframe = $('infoBox_iFrame');
		el.addEvent('mouseover',function(e)
		{
			this.boxContent.innerHTML = this.content.innerHTML;
			this.box.style.left = e.page.x - 278 + "px";
			this.box.style.display = "block";
			var boxHeight = this.box.offsetHeight;
			this.box.style.top = e.page.y - boxHeight + "px";
			this.iframe.style.top = this.box.offsetTop + "px";
			this.iframe.style.left = this.box.offsetLeft + "px";
			this.iframe.style.height = this.box.offsetHeight + "px";
			this.iframe.style.width = this.box.offsetWidth + "px";
			this.iframe.style.display = "block";
			this.iframe.setOpacity(0.001);
			
		});
		el.addEvent('mouseout',function(e)
		{
			this.box.style.display = "none";
			this.boxContent.innerHTML = "";
			this.iframe.style.display = "none";
		});
	});
}
window.addEvent('domready',initInfoBoxes);



/* Nationalitäten Abfrage */

function checkNation() {
	var land = document.forms["schritt2"].nation.value;
	if(land != "Schweiz" && land != "") {
		$("nationalitaet").style.display = "block";	
	} else {
		$("nationalitaet").style.display = "none";	
	}
}

function checkEmployment() {
	var art = document.forms["schritt3"].anstellung;
	if(art.selectedIndex == 1) {
		$("AnstDiv").style.display = "block";	
	} else {
		$("AnstDiv").style.display = "none";	
	}
}

function changeStep(next) {
	var activeLayer 	= "step" + activePage;
	var nextLayer 		= "step" + next;
	$(activeLayer).style.display = "none";
	$(nextLayer).style.display = "block";
	activePage = next;
}

/* Kredit antrag */

function kreditAntrag(produkt) {
	if(produkt == "classic") {
		$('classicBild').style.display = "none";
		$('classicBildLink').style.display = "none";
		$('classicText').style.display = "block";
		$('classicTextLink').style.display = "block";
		$('dispoBild').style.display = "block";
		$('dispoBildLink').style.display = "block";
		$('dispoText').style.display = "none";
		$('dispoTextLink').style.display = "none";
	}
	
	if(produkt == "dispo") {
		$('dispoBild').style.display = "none";
		$('dispoBildLink').style.display = "none";
		$('dispoText').style.display = "block";
		$('dispoTextLink').style.display = "block";
		$('classicBild').style.display = "block";
		$('classicBildLink').style.display = "block";
		$('classicText').style.display = "none";
		$('classicTextLink').style.display = "none";
	}
}

/* Antrag senden */

function bildSwitch() {
	if($('fadeOut').style.display == "block") {
		$('fadeOut').style.display = "none";
		$('fadeIn').style.display = "block";
	} else {
		$('fadeOut').style.display = "block";
		$('fadeIn').style.display = "none";	
	}
}

/* LabelSwitch beim kleinen Rechner */

function wunschkredit() {
	$("rechnerLabel").innerHTML = "Wunschkredit in CHF";
}

function wunschrate() {
	$("rechnerLabel").innerHTML = "Wunschrate in CHF";
}

function budget() {
	$("einfuehrung").innerHTML 	= 'Gem&auml;ss Ihren Angaben hat unser System folgenden Kreditrahmen errechnet:';
	$("summe").innerHTML 		= '13&rsquo;600.00<span class="waehrung"> CHF<br />(inkl. Zinsen)</span>';
	$("erklaerung").innerHTML 	= 'Es handelt sich um einen Richtgr&ouml;sse. Eine detaillierte Pr&uuml;fung Ihres Haushaltsbudgets wird im Antragsprozess durchgef&uuml;hrt.';
	
}

/* Ratenrechner füllen */

function fillIn() {
	$("rateVon").innerHTML 		= "478.50";
	$("rateBis").innerHTML 		= "492.50";
	$("zinsVon").innerHTML 		= "1059.60";
	$("zinsBis").innerHTML 		= "1376.75";
	$("absichernVon").innerHTML 	= "17.70";
	$("absichernBis").innerHTML 	= "18.15";
}

/* CHF in die FormularFelder setzen */
function setCHF(inp)
{
	inp.onblur = function()
	{
		if(this.value == "") { this.value = "CHF"; }
	}
	inp.onfucus = function() {
		if(this.value == "CHF") { this.value = ""; }
	}
	inp.onfucus();
}

/* Show'n'Hide */

function showDiv(layer) {
	$(layer).style.display = "block";	
}

function hideDiv(layer) {
	$(layer).style.display = "none";	
}


/*#################################################################
	Text Scroller
###################################################################*/	

var scrollCont	= null;
var cont 		= null;
	
function startScroll(bt,id, pos)
{
	bt.onmouseup = stopScroll;
	bt.onmouseout = stopScroll;
	cont = document.getElementById(id);
	scrollCont = setInterval("scroll" + pos + "()", 60);
}
function scrolldown() { cont.scrollTop += 11; }
function scrollup() { cont.scrollTop -= 11; }
function stopScroll() { clearInterval(scrollCont); }



/*===================================================================
	containerHeight
===================================================================*/	

function setContainerHeight() {
	var height = 0;
	var ct = $$('.inhalt');
	ct.each(function(el){
		if(el.getSize().y > height) height = el.getSize().y;
	});
	if(ct.length > 1) {
		ct.each(function(el) {
		el.style.height = height +"px"; 
		});
	}
	
	var dropzone = $$('.dropzone');
	dropzone.each(function(dz){
		dz.style.position = "relative";				   
	});
	//return true;	
}

window.addEvent("load", setContainerHeight);
