/******************************
* Intellinet Technologie GmbH *
* http://www.intellinet.de    *
******************************/

var EU_LAENDER = new Array("BE", "BG", "DK", "DE", "EE", "FI", "FR", "GR", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "AT", "PL", "PT", "SE", "SK", "SI", "ES", "CZ", "HU", "GB", "CY");

$(document).ready(function() {
	
	//Set a handler to all form elements
	
	$(":text,:radio,:checkbox,select").focus(
		function () {
			$(".modul_element_inaktiv_error").removeClass("red");
			$(".modul_element_inaktiv_error").removeClass("blue");
			$(".modul_element_inaktiv").removeClass("blue");
			if($(this).parent().parent().hasClass("modul_element_inaktiv_error")) {
				$(this).parent().parent().addClass("red");			
			} else {
				$(this).parent().parent().addClass("blue");
			}
		}
	);
	
	$(":text,:radio,:checkbox,select").keydown(
		function () {
			$(".modul_element_inaktiv_error").removeClass("red");
			$(".modul_element_inaktiv_error").removeClass("blue");
			$(".modul_element_inaktiv").removeClass("blue");
			if($(this).parent().parent().hasClass("modul_element_inaktiv_error")) {
				$(this).parent().parent().addClass("red");			
			} else {
				$(this).parent().parent().addClass("blue");
			}
		}
	);
	
	$(":text,:radio,:checkbox,select").blur(
		function () {
			$(".modul_element_inaktiv_error").removeClass("red");
			$(".modul_element_inaktiv_error").removeClass("blue");
			$(".modul_element_inaktiv").removeClass("blue");
		}
	);
	
	$(".modul_element_inaktiv").click(
		function () {
			$(".modul_element_inaktiv_error").removeClass("red");
			$(".modul_element_inaktiv_error").removeClass("blue");
			$(".modul_element_inaktiv").removeClass("blue");
			$(this).addClass("blue");
		}
	);
	
	$(".modul_element_inaktiv_error").click(
		function () {
			$(".modul_element_inaktiv_error").removeClass("red");
			$(".modul_element_inaktiv_error").removeClass("blue");
			$(".modul_element_inaktiv").removeClass("blue");
			$(this).addClass("red");
		}
	);
	
	/*Bind resize event and manage grey Layer */
	$(window).bind("resize", function(){ 
 		if($("#grey").css("visibility") == "visible") {
			screenWidth = document.body.offsetWidth;
			screenHeight = document.documentElement.scrollHeight
			$("#grey").css({visibility: 'visible', height: screenHeight, width: screenWidth}); 
 		}
	});
	
	/*Page Info Layer*/
	$("#hilfebutton").click(
		function () {
			screenWidth = document.body.offsetWidth;
			screenHeight = document.documentElement.scrollHeight;
			$("#grey").css({height: screenHeight, width: screenWidth});
			$("#grey").css({visibility: 'visible'});
			$("#page_layer").fadeIn(500);
		}
	);
	
});

/*Write Flash Control Element to avoid IE bug*/
function writeFlash() {
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="" width="557" height="110" id="eingabe" align="middle">');
		document.write('<param name="allowScriptAccess" value="sameDomain" />');
		document.write('<param name="movie" value="eingabe2m120.swf?conf=cnfg_eingabe120.xml&url=' + url + '&rlv=' + kreditbetrag + ',' + laufzeit + '" />');
		document.write('<param name="quality" value="high" />');
		document.write('<param name="wmode" value="transparent" />');
		document.write('<param name="bgcolor" value="#ffffff" />');
		document.write('<embed src="eingabe2m120.swf?conf=cnfg_eingabe120.xml&url=' + url + '&rlv=' + kreditbetrag + ',' + laufzeit + '" quality="high" wmode="transparent" bgcolor="#ffffff" width="557" height="110" name="eingabe" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="" />');
	document.write('</object>');
}

function popup(page,width,height) {
	var fenster;
	fenster = window.open(page,"Popup","width=" + width + ",height=" + height + ",top=50,left=50,toolbar=no,location=no,menubar=no,scrollbars=no,resizable=yes,status=no,resizeable=yes");
	if(fenster) fenster.focus();
}

function popup2(page,width,height) {
	var fenster2;
	fenster2 = window.open(page,"Popup2","width=" + width + ",height=" + height + ",top=80,left=80,toolbar=no,location=no,menubar=no,scrollbars=no,resizable=yes,status=no,resizeable=yes");
	if(fenster2) fenster2.focus();
}

function popupFenster(page,width,height) {
	var fenster;
	fenster = window.open(page,"Popup","width=" + width + ",height=" + height + ",top=50,left=50,toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=yes,status=no,resizeable=yes");
	if(fenster) fenster.focus();
}

/*Object Converter*/
function oc(a) {
  var o = {};
  for(var i=0;i<a.length;i++) {
    o[a[i]]='';
  }
  return o;
}

function showCancel() {
	screenWidth = document.body.offsetWidth;
	screenHeight = document.documentElement.scrollHeight;
	$("#grey").css({height: screenHeight, width: screenWidth});
	$("#grey").css({visibility: 'visible'});
	$("#info_layer_cancel").fadeIn(500);
}

function showWartenAngebot() {
	if(typ == 'B') {
		document.forms[0].submit();
	} else {
		screenWidth = document.body.offsetWidth;
		screenHeight = document.documentElement.scrollHeight;
		//posx = (screenWidth/2) - 295;
		//posx = 40; 
		//posy = 95; 
		$("#grey").css({height: screenHeight, width: screenWidth});
		$("#grey").css({visibility: 'visible'});
		$("#warten_angebot_layer").fadeIn(500);
		//Adjust layersize to new screenheight
		screenHeight = document.documentElement.scrollHeight;
		$("#grey").css({height: screenHeight});
		document.forms[0].submit();
	}
}

function showWartenAntrag() {
	if(typ == 'B') {
		document.forms[0].submit();
	} else {
		$("#antrag_layer").hide();
		screenWidth = document.body.offsetWidth;
		screenHeight = document.documentElement.scrollHeight;
		//posx = (screenWidth/2) - 295;
		//posx = 40; 
		//posy = 95; 
		$("#grey").css({height: screenHeight, width: screenWidth});
		$("#grey").css({visibility: 'visible'});
		$("#warten_antrag_layer").fadeIn(500);
		//Adjust layersize to new screenheight
		screenHeight = document.documentElement.scrollHeight;
		$("#grey").css({height: screenHeight});
		document.forms[0].submit();
	}
}

function showAngebot(url) {
	if(typ == 'B') {
		window.location.href = url;
	} else {
		screenWidth = document.body.offsetWidth;
		screenHeight = document.documentElement.scrollHeight;
		//posx = (screenWidth/2) - 295;
		//posx = 40; 
		//posy = 95;
		$("#grey").css({height: screenHeight, width: screenWidth});
		$("#grey").css({visibility: 'visible'});
		$("#angebot_layer").fadeIn(500);
		//Adjust layersize to new screenheight
		screenHeight = document.documentElement.scrollHeight;
		$("#grey").css({height: screenHeight});
		//Inhalt von url in Button übergeben...
		$("a[href*=/weiter]").click(function() {
			window.location.href = url;
	    	return false;
	    });
    }
}

function showAntrag() {
	if(typ == 'B') {
		document.forms[0].submit();
	} else {
		screenWidth = document.body.offsetWidth;
		screenHeight = document.documentElement.scrollHeight;
		//posx = (screenWidth/2) - 295;
		//posx = 40; 
		//posy = 95;
		$("#grey").css({height: screenHeight, width: screenWidth});
		$("#grey").css({visibility: 'visible'});
		$("#antrag_layer").fadeIn(500);
		//Adjust layersize to new screenheight
		screenHeight = document.documentElement.scrollHeight;
		$("#grey").css({height: screenHeight});
	}
}

function showHome() {
	if(typ == 'B') {
		location.href = '/start.do;jsessionid='+session+'?process=processKreditB';
	} else {
		screenWidth = document.body.offsetWidth;
		screenHeight = document.documentElement.scrollHeight;
		//posx = (screenWidth/2) - 295;
		//posx = 40; 
		//posy = 95;
		$("#grey").css({height: screenHeight, width: screenWidth});
		$("#grey").css({visibility: 'visible'});
		$("#home_layer").fadeIn(500);
		//Adjust layersize to new screenheight
		screenHeight = document.documentElement.scrollHeight;
		$("#grey").css({height: screenHeight});
	}
}

function hideCancel() {
	$("#info_layer_cancel").fadeOut(500,function(){
		$("#grey").css({visibility: 'hidden'});
	});
}

function hideFaq() {
	$("#faq_layer").fadeOut(500,function(){
		$("#grey").css({visibility: 'hidden'});
	});
}

function hideInfo() {
	$(".info_layer").fadeOut(500,function(){
		$("#grey").css({visibility: 'hidden'});
	});
}

function cancel(url) {
	$("#info_layer_cancel").fadeOut(500,function(){
		$("#grey").css({visibility: 'hidden'});
		window.location.href = url;
	});
}

function save() {
	document.forms[0].elements['save'].value = 'true';
	document.forms[0].submit();
}

function format(zahl) {
	var neu = '';
	zahl = '' + zahl;
	idx = zahl.length;
	while(idx > 0)    {
        if(idx - 3 > 0) {
	        neu = '.' + zahl.substring( idx - 3, idx) + neu;
		} else {
       		neu = zahl.substring(0, idx) + neu;
		}
       	idx -= 3;
   	}
	return neu;
}


