/*################################################################################
	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");


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

// 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
################################################################################*/

/*================================================================================
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; text-align:right" href="javascript:overlay.hide();">'+submiterror__close+'</a>';
	
	Alert({title:submiterror__title, content:str});
	overlay.opt.onclose = function(){
		if(els[0]) 
			els[0].focus();
	};
};
/*================================================================================
	initNaviElement()
================================================================================*/

/* Navigation*/
function initNaviElement(a)
{
	var cont = a.getNext();
	if(cont && cont.tagName == "DIV" && cont.className.toLowerCase().indexOf("navi") > -1 && cont.className.toLowerCase().indexOf("active") == -1)
	{
		cont.parentA		= a;
		a.subNode			= cont;
		//a.subNode.style.top	= a.offsetTop + "px";
		
		a.style.backgroundPosition = "140px 8px";
		
		a.addEvent('mouseenter',function(){
			this.subNode.style.display = "block";
			this.subNode.style.top	= this.offsetTop + "px";
			this.style.color = "#000000";
			this.style.backgroundImage = "url(/pix/navigation/hover.gif)";
		});
		a.addEvent('mouseleave',function(){
			this.subNode.style.top	= this.offsetTop + "px";
			this.subNode.style.display = "none";
			this.style.color = "#FFFFFF";
			this.style.backgroundImage = "url(/pix/navigation/passiv.gif)";
		});
		cont.addEvent('mouseenter',function(){
			this.style.display = "block";
			this.parentA.style.color = "#000000";
			this.parentA.style.backgroundImage = "url(/pix/navigation/hover.gif)";
		});
		cont.addEvent('mouseleave',function(){
			this.style.display = "none";
			this.parentA.style.color = "#FFFFFF";
			this.parentA.style.backgroundImage = "url(/pix/navigation/passiv.gif)";
		});
	}
}



/* Service Navigation*/
function initServiceNaviElement(a) {
	var subNavPos;
	var cont	= a.getNext();	
	var mainPosRight	= $('mainContainer').offsetLeft + 972;
	
	
	if(cont && cont.tagName == "DIV" && cont.className.toLowerCase().indexOf("navi") > -1) {
		cont.parentA	= a;
		a.subNode		= cont;
		
		a.onmouseover	= function() {
			
			this.subNode.style.display	= "block";
			this.style.color	= "#000000";
			
			
			
			if(navigator.appName == "Microsoft Internet Explorer") {
				this.subNode.style.left		= a.offsetLeft + 19 + "px";
				
				subNavPos	= a.offsetLeft + 100 + $('mainContainer').offsetLeft;
				
				if(subNavPos > mainPosRight) {
					this.subNode.style.left		= a.offsetLeft + (-(143-a.offsetWidth)) + "px";
				}
				
			} else {
				this.subNode.style.left		= a.offsetLeft + 5 + "px";
				
				subNavPos	= a.offsetLeft + 100 + $('mainContainer').offsetLeft;
				
				if(subNavPos > mainPosRight) {
					this.subNode.style.left		= a.offsetLeft + (-(155-a.offsetWidth)) + "px";
				}
				debug(this.subNode.offsetWidth);
				
			}
		};
		
		a.onmouseout	= function() {
			
			this.subNode.style.display	= "none";
			if(this.className.toLowerCase().indexOf("active") > -1) {
				this.style.color	= "#000000";
			} else {
				this.style.color	= "#ffffff";
			}			
		};
		
		cont.onmouseover	= function() {
			this.style.display	= "block";
			this.parentA.style.color	= "#000000";
		};
		
		cont.onmouseout	= function() {
			this.style.display	= "none";
			if(this.parentA.className.toLowerCase().indexOf("active") > -1) {
				this.parentA.style.color	= "#000000";
			} else {
				this.parentA.style.color	= "#ffffff";
			}
		};
		
		
	}
}


/*================================================================================
	initNavigation()
================================================================================*/


function initNavigation()
{
	var navi	= $('navigation');
	var childs	= navi.getElements('a');
	childs.each(function(node) { initNaviElement(node); });
	
	var subNavi = $('serviceNavigation');
	var subNaviChilds = subNavi.getElements('a');
	subNaviChilds.each(function(node) { initServiceNaviElement(node); });
	
	
}

window.addEvent("load",initNavigation);




/*================================================================================
	Div oeffnen
================================================================================*/

function openDiv(obj,cl) {
	if($(obj).style.display == "block") {
		$(obj).style.display='none';
	} else {
		$$('.'+cl).each(function(el){ el.style.display = "none";});
		$(obj).style.display='block';
	}
}


/*================================================================================
	Scroller
================================================================================*/

var scrollCont = null;
var cont = null;

function startScroll(bt,pos)
{
	//alert(id);
	bt.onmouseup = stopScroll;
	bt.onmouseout = stopScroll;
	cont = document.getElementById('scrollContent');
	scrollCont = setInterval("scroll" + pos + "()", 40);
	
}

function scrolldown() { cont.scrollTop += 11; }
function scrollup() { cont.scrollTop -= 11; }
function stopScroll() { clearInterval(scrollCont); }


/*================================================================================
	Banner
================================================================================*/

function bannerIncluded() {
	var container		= $('container');
	var bannerTop		= $('bannerTop');
	var bannerRight		= $('bannerRight');
	
	var positionCont	= container.offsetLeft;
	var positionR		= positionCont + container.offsetWidth;
	var positionT		= "";
	
	if(bannerTop && bannerRight) {
		positionT	= positionCont + (container.offsetWidth-bannerTop.offsetWidth);
		bannerTop.style.left	= positionT + bannerRight.offsetWidth + "px";
		container.style.marginTop	= bannerTop.offsetHeight + "px";
		
		bannerRight.style.marginTop	= 4 + "px";
		bannerRight.style.left	= positionR + "px";
		
		bannerRight.style.visibility	= "visible";
		bannerTop.style.visibility	= "visible";
		
	} else if(bannerTop) {	
		positionT	= positionCont + (container.offsetWidth-bannerTop.offsetWidth);
		bannerTop.style.left	= positionT-14 + "px";
		container.style.marginTop	= bannerTop.offsetHeight + "px";
		bannerTop.style.visibility	= "visible";
		
	} else if(bannerRight) {
		bannerRight.style.left	= positionR + "px";
		bannerRight.style.visibility	= "visible";
	}
}

window.addEvent("load",bannerIncluded);
window.addEvent("resize",bannerIncluded);



/*================================================================================
	Prompt
================================================================================*/



function setPrompt(id,id2,identifier) {
	var promptBox	= $(id);
	var promptBox2	= $(id2);
	
	if(identifier==1) {
		$('art').innerHTML	= "f&uuml;r 1 Jahr &agrave; CHF 85.00.";
	} else if(identifier==2) {
		$('art').innerHTML	= "GastroJournal f&uuml;r 24 Monate &agrave; CHF 199.00.";
	}
	
	promptBox.style.display	= "block";
	promptBox2.style.display	= "none";
	
}


function closePrompt(id) {
	var promptBox	= $(id);
	
	promptBox.style.display	= "none";
	if($('searchDiv')) {
		$('searchDiv').style.visibility = "visible";
	}
}


/*================================================================================
	Abo Order Processes: Helper Functions
================================================================================*/

function cmsAlert(title, content, close){
	Alert({
		title: title,
		content: '<p>'+content+'</p><a class="Right" style="display:block"'
	    				+' href="javascript:overlay.hide()">'
	    				+close+'</a>'
	});
}
/**
 * closes and opens prompts
 * @param close
 * @param open
 * @return
 */
function openPrompt(close, open) {
	close.setStyle('display', 'none');
	open.setStyle('display', 'block');
}

/**
 * turn "pages" eg. show and hide elements
 * Used for Gerantenverträge
 * @param from
 * @param to
 * @return
 */
function  togglePage(from,to){
	from.setStyle('display','none');
	to.setStyle('display','block');
}

/**
 * Limit chars that can be entered in a field
 * Used for Gerantenverträge
 * @param limitField
 * @param limitNum
 * @return
 */
function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}

/**
 * Check if the values of two passwords entered are the same 
 * @param pw
 * @param pw_rep
 * @return bool
 */
function checkPW(pw, pw_rep){
	if(pw == pw_rep)
		return true;
	else
		return false;
}




