var IsFormSubmitted = false;
function CheckFormSubmitted() {
	if(IsFormSubmitted) {
		alert('The Server is already working for your request, please be patient...');
		return false;
	}
	else {
		IsFormSubmitted = true;
		return true;
	}
}

var shopSubmitted = false;
function shopSubmit(target) {
	if(shopSubmitted) {
		alert('The Server is already working for your request, please be patient...');
	}
	else {
		shopSubmitted = true;
		target.submit();
	}
	return false;
}

function ButtonNavigateToUrl(url) {
	if(CheckFormSubmitted()) {
		window.location.href = url;
	}
}

function calcMenuSize() {
	// Menu Left
	var addActive = 25;
	var addInactive = 37;
	$("#rl2010_menubar .menuLeft li").each(function(){
		$(this).css(
			"width",
			$(this).find(".bg").innerWidth(true) + ($(this).hasClass("active") ? addActive : addInactive)
		);
	});
}




var tabDirection = true;
var tabInterval;

$(document).ready(function() {

	/* Loginbox */
	$('#nav_inner #rl2010_menubar ul.menuRight li.login .button').click(function(){
		var parent = $(this).parents('#rl2010_menubar .login.isLoggedOut');
		if(parent.hasClass('active')) {
			parent.removeClass('active');
		}
		else {
			parent.addClass('active');
		}
	});
	
	/* Language selection */
	$(".LanguageSelect").hover(
		function() {$('.LanguageSelectSelectBox').attr('style', 'visibility:visible;');},
		function() {$('.LanguageSelectSelectBox').attr('style', 'visibility:hidden;');}
	);
	
	
	/* Tabbox */
	$(".contentHeader .tab").click(function(){
		$(".contentHeader .tab").removeClass("active");
		$(".tabBox .tabContent").removeClass("active");
		
		$(this).addClass("active");
		$(".tabBox").find("#"+$(this).attr("id")).addClass("active");
	});
	$(".tabBoxControl .tabCtrl").click(function(){
		clearInterval(tabInterval);
		tabSetActive($(this).attr("id"));
	});
	$(".tabBoxControl .goLeft").click(function(){
		clearInterval(tabInterval);
		tabMoveLeft();
	});
	$(".tabBoxControl .goRight").click(function(){
		clearInterval(tabInterval);
		tabMoveRight();
	});
});

	function tabMoveLeft() {
		if($(".tabBoxControl .tabCtrl.active").prev().length > 0) {
			tabSetActive($(".tabBoxControl .tabCtrl.active").prev().attr("id"))
		}
		else {
			tabSetActive($(".tabBoxControl .tabCtrl:last").attr("id"));
		}
	}
	function tabMoveRight() {
		if($(".tabBoxControl .tabCtrl.active").next().length > 0) {
			tabSetActive($(".tabBoxControl .tabCtrl.active").next().attr("id"));
		}
		else {
			tabSetActive($(".tabBoxControl .tabCtrl").attr("id"));
		}
	}
	
	function tabSetActive(id, instant) {
		// Buttons
		$(".tabBox .tabBoxControl .tabCtrl.active").removeClass("active");
		$(".tabBox .tabBoxControl").find("#"+id).addClass("active");
		
		// Tabs
		// ------------------------------------------------------------
		if(instant) {
			$(".tabBox .tabBoxContent").stop().css("right", $(".tabBox .tabBoxControl .tabCtrl.active").prevAll().length * 980);
		}
		else {
			$(".tabBox .tabBoxContent").stop().animate(
				{ right: ($(".tabBox .tabBoxControl .tabCtrl.active").prevAll().length * 980) },
				650
			);
		}
	}
	
	
	function tabAutoRotate() {
		if(tabDirection) {
			if($(".tabBoxControl .tabCtrl.active").next().length > 0) {
				tabMoveRight();
			}
			else {
				tabMoveLeft();
				tabDirection = false;
			}
		}
		else {
			if($(".tabBoxControl .tabCtrl.active").prev().length > 0) {
				tabMoveLeft();
			}
			else {
				tabMoveRight();
				tabDirection = true;
			}
		}
	}
	
	
	
$(document).ready(function() {
	// Trigger once at startup -> activate tab (if needed)
	if($(".tabBox .tabContent.active").length > 0) {
		tabSetActive($(".tabBox .tabContent.active").attr("id"), true);
	}
	
	
	/* Variable Box */
	$(".varBox.closeable .varBoxHead .trigger, .varBox.closeable .varBoxHead .link").click(function(){
		var parent = $(this).parents(".varBox.closeable");
		var item = parent.find(".varBoxContent");
		if(item.is(":visible")) {
		    item.hide();
			parent.addClass("closed").removeClass("open");
		}else{
		    item.show();
			parent.addClass("open").removeClass("closed");
		}
		if($(this).find(".hide").length>0){
			$(this).find("a.button").toggleClass("hide");
		}
	});
	
	
	/* Tooltips Orange InfoIcon */
	$(".infoIconFrame_orange").each(function(){
		$(this).mouseover(function(e){
			$(this).children(".hide").hide();
			var positionX=e.layerX-40;
			var positionY=e.layerY+22;
			$(this).children(".hide").children(".tooltipFrame_orange").css({
				left:positionX,
				top:positionY
			});
			$(this).children(".hide").show();
		}).mouseout(function(e){ 
			$(this).children(".hide").hide();
		});
	});	
	
	/* ContextMenu */
	$(".cTextMenu .linkLft").click(function(){
		var menu = $(this).parents(".cTextMenu");
		if(menu.hasClass("open")) {
			menu.removeClass("open");
			menu.addClass("close");
			$(document).unbind("mousedown", contextMenuOpenedOnclick);
		}
		else {
			$(".cTextMenu").removeClass("open");
			$(".cTextMenu").addClass("close");
			menu.removeClass("close");
			menu.addClass("open");
			$(document).bind("mousedown", contextMenuOpenedOnclick);
			/* Context Menu IE7 fix */
			if($.browser.msie){
				$(this).parents(".cTextMenu").find(".inner .bc").width($(this).parents(".cTextMenu").find("ul.submenu").innerWidth());
				$(this).parents(".cTextMenu").find(".inner .tc").width($(this).parents(".cTextMenu").find("ul.submenu").innerWidth());
			}					
		}
	});	
	
	$(".cTextMenu .submenu a").click(function(){
		var menu = $(this).parents(".cTextMenu");
		if(menu.hasClass("open")) {
			menu.removeClass("open");
			menu.addClass("close");
			$(document).unbind("mousedown", contextMenuOpenedOnclick);
		}
	});

	var contextMenuOpenedOnclick = function (e) {
		var target = e.target ? e.target : event.srcElement;
		if($(target).parents(".cTextMenu").length > 0) {
			return;
		}
		$(".cTextMenu").removeClass("open");
		$(".cTextMenu").addClass("close");
		$(document).unbind("mousedown", contextMenuOpenedOnclick);
		if($("body").find(".cTextMenu").hasClass("open")==false){
			if($(target).parents(".servicebox.active").length==0){
				hideServiceBox();
			}
			if($(target).parents(".servicebox").length==1){
				showServiceBox($(target).parents(".servicebox"));
			}
			if($(target).hasClass("servicebox")==true){
				showServiceBox($(target));
			}
		}
	};
	
	/* Tooltips Red InfoIcon */
	$(".infoIconFrame_red").each(function(){
		$(this)
			.mouseover(function(e){
			  $(this).children(".hide").hide();
		      var positionX=e.layerX-40;
		      var positionY=e.layerY+20;
		      $(this).children(".hide").children(".tooltipFrame_red").css({
		          left:positionX,
		          top:positionY
		      });
		      $(this).children(".hide").show();
	     })
	     .mouseout(function(e){ 
	    	 $(this).children(".hide").hide();
	     });
	});	
	
	$('div.cta_orange').each(function(){
		$(this).mouseout(function() {     
			$('div.cta_orange_left', this).css('backgroundPosition','0 0'),
			$('div.cta_orange_middle', this).css('backgroundPosition','0 0'),
			$('div.cta_orange_right', this).css('backgroundPosition','-11px 0')
		}).mouseover(function() {
			$('div.cta_orange_left', this).css('backgroundPosition','-38px 0'),
			$('div.cta_orange_middle', this).css('backgroundPosition','0 -50px'),
			$('div.cta_orange_right', this).css('backgroundPosition','-49px 0')
		}).click(function() {
			$('div.cta_orange_left', this).css('backgroundPosition','-76px 0'),
			$('div.cta_orange_middle', this).css('backgroundPosition','0 -100px'),
			$('div.cta_orange_right', this).css('backgroundPosition','-87px 0')
		}).mousedown(function() {
			$('div.cta_orange_left', this).css('backgroundPosition','-76px 0'),
			$('div.cta_orange_middle', this).css('backgroundPosition','0 -100px'),
			$('div.cta_orange_right', this).css('backgroundPosition','-87px 0')
		});
	});
	$('div.cta_grey').each(function(){
		$(this).mouseout(function() {     
			$('div.cta_grey_left', this).css('backgroundPosition','0 -50px'),
			$('div.cta_grey_middle', this).css('backgroundPosition','0 -150px'),
			$('div.cta_grey_right', this).css('backgroundPosition','-27px -50px')
		}).mouseover(function() {
			$('div.cta_grey_left', this).css('backgroundPosition','-38px -50px'),
			$('div.cta_grey_middle', this).css('backgroundPosition','0 -200px'),
			$('div.cta_grey_right', this).css('backgroundPosition','-65px -50px')
		}).click(function() {
			$('div.cta_grey_left', this).css('backgroundPosition','-76px -50px'),
			$('div.cta_grey_middle', this).css('backgroundPosition','0 -250px'),
			$('div.cta_grey_right', this).css('backgroundPosition','-103px -50px')
		}).mousedown(function() {
			$('div.cta_grey_left', this).css('backgroundPosition','-76px -50px'),
			$('div.cta_grey_middle', this).css('backgroundPosition','0 -250px'),
			$('div.cta_grey_right', this).css('backgroundPosition','-103px -50px')
		});
	});
	
	
	
	/* HoverBox Tooltip */
	$(".hoverBox .icon").live(
		"mouseover mouseout",
		function(event){
			if (event.type == 'mouseover') {
				$(this).parent(".hoverBox").find(".hoverWrap .hoverInfo").show();
			} else {
				$(this).parent(".hoverBox").find(".hoverWrap .hoverInfo").hide();
			}
		}
	);
	
		
	$(".servicebox").hover(
		function(){
			if($("#cc_servicebox").find(".cTextMenu").hasClass("open")==false){
				showServiceBox($(this));
			}
		},
		function(){
			if($("#cc_servicebox").find(".cTextMenu").hasClass("open")==false){
				hideServiceBox();
			}
		}
	);
		
	$(".link_type_2 .button").hover(
		function(){
			$(this).parent("div").removeClass("link_type_2");		
		},
		function(){
			$(this).parent("div").addClass("link_type_2");		
		}	
	);
	
	$(".link_type_8 .button").hover(
			function(){
				$(this).parent("div").removeClass("link_type_8");		
			},
			function(){
				$(this).parent("div").addClass("link_type_8");		
			}	
		);
	
	$(".foldingTitle a").click(function(){
		var childrenArrow=$(this).find(".arrow");
		if(childrenArrow.hasClass("arrowDown")==false){
			childrenArrow.addClass("arrowDown");
			childrenArrow.parents("tbody").find(".hidden").show();
		}else{
			childrenArrow.removeClass("arrowDown");
			childrenArrow.parents("tbody").find(".hidden").hide();
		}
	});	
	
	/*Simple Context Menu*/
	if($(".cTextMenu.simple").length>0){
		$(".cTextMenu.simple").each(function(index,item) {
			var maxLength = 0;
			$(item).find(".submenu a").each(function(i,child) {
				if($(child).text().length>maxLength){maxLength=$(child).text().length};			
			});
			maxLength = maxLength*3.5+130;
			$(item).find(".linkCenter").css("width",Math.ceil(maxLength)+"px");
		});
	}
});


showCustomer = function(type, delay) {
	
	if(delay == '') delay = '150';
	
	switch(type) {
		case 'new':
			$('#orderProcess_Login_customerExisting3').hide();
			$('#orderProcess_Login_customerExisting2').hide();
			$('#orderProcess_Login_customerExisting1').hide();
			$('#orderProcess_Login_choose').hide();
			$('#orderProcess_Login_welcomeExisting').hide();
			$('#orderProcess_Login_welcomeNew').show();
			break;
		case 'existing':
			$('#orderProcess_Login_customerNew').hide();
			$('#orderProcess_Login_welcomeNew').hide();
			$('#orderProcess_Login_choose').hide();
			$('#orderProcess_Login_customerExisting1').fadeIn(delay);
			$('#orderProcess_Login_customerExisting2').fadeIn(delay);
			$('#orderProcess_Login_customerExisting3').fadeIn(delay);
			$('#orderProcess_Login_welcomeExisting').show();
			break;
		case 'error':
			$('#loginHeaderInfoText').hide();
			$('#loginHeader').addClass('orderProcess_BalkenObenRed');
			$('#loginHeaderErrorText').show();
			$('#input_email_error').show();
			$('#input_email_error_icon').show();
			$('#input_password_error').show();
			$('#input_password_error_icon').show();
			$('#input_password_error_space').hide();
			break;
	}	
}

function showServiceBox(box) {
	if($("#cc_servicebox").find(".cTextMenu ").hasClass("open")==false){
		hideServiceBox();
		$(box).css("background-color","#f5f5f5");
		$(box).find(".hidden").show();
		$(box).addClass("active");
	}
}

function hideServiceBox() {
	$(".servicebox").css("background-color","#FFFFFF");
	$(".servicebox").find(".hidden").hide();
	$(".servicebox").removeClass("active");
}
