/*Superfish v1.3.1  - jQuery menu widget Copyright (c) 2007 Joel Birch */
/* Custom settings used for delay and speed.  delay: 500, speed: 400*/

(function($){
    $.fn.superfish = function(o){
		var $sf = this,
			defaults = {
			hoverClass	: 'sfHover',
			pathClass	: 'overideThisToUse',
			delay		: 500,
			animation	: {opacity:'hide'},    
			speed		: 400    
		},
		over = function(){
				clearTimeout(this.sfTimer);
				clearTimeout($sf[0].sfTimer);
				$(this)
				.showSuperfishUl()
				.siblings()
				.hideSuperfishUl();
			},
		
		out = function(){
				var $$ = $(this);
				if ( !$$.is('.'+o.bcClass) ) {
					this.sfTimer=setTimeout(function(){
						$$.hideSuperfishUl();
						if (!$('.'+o.hoverClass,$sf).length) { 
							over.call($currents.hideSuperfishUl());
						}
					},o.delay);
				}		
			};
		
		$.fn.extend({
			hideSuperfishUl : function(){
				return this
					.removeClass(o.hoverClass)
					.find('ul:visible')
						.hide()
					.end();
			},
			showSuperfishUl : function(){
				return this
					.addClass(o.hoverClass)
					.find('>ul:hidden')
						.animate(o.animation,o.speed)
					.end();
			},
			applySuperfishHovers : function(){
				return this[($.fn.hoverIntent) ? 'hoverIntent' : 'hover'](over,out);
			}
		});
		o = $.extend({bcClass:'sfbreadcrumb'},defaults,o || {});
		var $currents = $('li:has(ul)',this).filter('.'+o.pathClass);
		if ($currents.length) {
			$currents.each(function(){
				$(this).removeClass(o.pathClass).addClass(o.hoverClass+' '+o.bcClass);
			});
		}
		var $sfHovAr=$('li:has(ul)',this)
			.applySuperfishHovers(over,out)
/* commented out .find('a').each(superfishFocusBlur) for performance - glowney & tguffee 6/08 */
/*			.find('a')
			.each(superfishFocusBlur)
*/			.end()
			.not('.'+o.bcClass)
				.hideSuperfishUl()
			.end();
		$(window).unload(function(){
			$sfHovAr.unbind('mouseover').unbind('mouseout');
		});
		return this.addClass('superfish').blur(function(){
			out.call(this);
		});
	};

function superfishFocusBlur(){
			var $a = $(this), $li = $a.parents('li');
			$a.focus(superfishOverCall).blur(superfishRemoveClass);
}

function superfishOverCall(){
			over.call($li);
			return false;
}
		
function superfishRemoveClass(){
			$li.removeClass(o.hoverClass);
}	


/* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * @name bgiframe
 * @type jQuery
 * @cat Plugins/bgiframe
 *
 * Version 2.1.1
 * Custom settings used for $.extend. top:'-1px',left:'0px',width:'180px' 
 */
//$.fn.bgIframe=$.fn.bgiframe=function(s){if($.browser.msie&&/6.0/.test(navigator.userAgent)){s=$.extend({top:'-1px',left:'0px',width:'180px',height:'auto',opacity:true,src:'javascript:false;'},s||{});var prop=function(n){return n&&n.constructor==Number?n+'px':n;},html='<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+'style="display:block;position:absolute;z-index:-1;'+(s.opacity!==false?'filter:Alpha(Opacity=\'0\');':'')+'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+'"/>';return this.each(function(){if($('> iframe.bgiframe',this).length==0)this.insertBefore(document.createElement(html),this.firstChild);});}return this;};


$.fn.bgIframe=$.fn.bgiframe=function(s){if($.browser.msie&&/6.0/.test(navigator.userAgent)){
		s=$.extend({
			top:'-1px',left:'0px',width:'180px',height:'auto',opacity:true,src:'javascript:false;'
		}
		,s||{});
		var prop=function(n){
			return n&&n.constructor==Number?n+'px':n;
		},
		html='';
		
		return this.each(function(){
		    if($('> iframe.bgiframe',this).length==0)this.insertBefore(document.createElement(html),this.firstChild);
	    });
}
return this;};

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
* Custom settings used for sensitivity setting. sensitivity:6
*/

$.fn.hoverIntent=function(f,g){
    var cfg={sensitivity:6,interval:100,timeout:0};
    cfg=$.extend(cfg,g?{over:f,out:g}:f);
    var cX,cY,pX,pY;
    var track=function(ev){cX=ev.pageX;cY=ev.pageY;};
    var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);
    if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);
    ob.hoverIntent_s=1;
    return cfg.over.apply(ob,[ev]);}
    else {pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};
    var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);
    ob.hoverIntent_s=0;
    return cfg.out.apply(ob,[ev]);};
    var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;
    while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}
    var ev=jQuery.extend({},e);
    var ob=this;
    if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}
    if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);
    if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}
    else{$(ob).unbind("mousemove",track);
    if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};
    return this.mouseover(handleHover).mouseout(handleHover);};

})(jQuery);

$(document).ready(function(){
	if (jQuery.browser.msie) {
		$("#topMenu")
		.superfish({
			animation : { opacity:"show",height:"show" }
		})
		.find(">li:has(ul)") 
			.mouseover(function(){
				$("ul", this).bgIframe({opacity:false});     
		})
		.find("a")
		.focus(function(){
			$("ul", $("#topMenu>li:has(ul)")).bgIframe({opacity:false});    						
		});
	} else {
		$("#topMenu")
		.superfish({
			animation : { opacity:"show",height:"show" }
		});
	}
});

/*styling <hr />*/
$(document).ready(function(){ $("hr").wrap("<div class='hr'></div>"); });

/* IBAN CHECK */
var imgNone = "/Design/images/blank.gif";
var imgAccept = "/Design/images/accept.gif";
var imgDeny = "/Design/images/deny.gif";


function Erase(){
	document.getElementById('acc1').value="";
	document.getElementById('acc2').value="";
	document.getElementById('acc3').value="";
	document.getElementById('ibannummer').value="";
	document.getElementById('imgValidation').src=imgNone;
	document.getElementById('acc1').focus();
}
function Next(objectId){
	var checkLength = "false";
	var object = document.getElementById(objectId);
	
	switch (objectId){
		case 'acc1' : if (object.value.length == 3) checkLength = "true"; break; 
		case 'acc2' : if (object.value.length == 7) checkLength = "true"; break;
		case 'acc3' : if (object.value.length == 2) checkLength = "true"; break;
	}
	
	if (checkLength == "true"){ toIBAN(); }
	if (checkLength == "true" && objectId != 'acc3'){
		if (objectId == 'acc1' ){ document.getElementById('acc2').focus(); }
		else { document.getElementById('acc3').focus(); }
	}
	else { document.getElementById(objectId).focus(); }
}
function Check97(){
	var checkdigit, checknumber, checkednumber;
	checknumber = document.getElementById('acc1').value.toString() + document.getElementById('acc2').value.toString();
	checkdigit = document.getElementById('acc3').value.toString();
	checkednumber = ((checknumber-1) % 97)+1;
	if(parseFloat(checkdigit) == parseFloat(checkednumber)){return checkdigit;}
	else{return "xx";}
}

function toIBAN(){
	var Check;
	Check = Check97();
	if (Check == "xx"){
		document.getElementById('imgValidation').src=imgDeny;
	}
	else {
		var IBANNummer;
		IBANNummer = Check.toString() + Check.toString() + "111400";
		IBANNummer = 98 - (parseFloat(IBANNummer) % 97);
		if (IBANNummer < 10 ){IBANNummer = "0" + IBANNummer.toString()}
		document.getElementById('imgValidation').src=imgAccept;
		document.getElementById('ibannummer').value = "BE"+IBANNummer+ " "+ document.getElementById('acc1').value + document.getElementById('acc2').value.substring(0,1) + " "+ document.getElementById('acc2').value.substring(1,5)+ " " + document.getElementById('acc2').value.substring(5,7)+ document.getElementById('acc3').value;
	}
}