var totalX = 0;
var totalY = 0;

var leftX = 0;
var leftY = 0;

var rightX = 0;
var rightY = 0;


function fixLayout(n, from, to, depth) {
	
	if(n.className) {
		var classname = n.className;
		var classPart = classname.substr(0,3);
	} else {
		classPart = '';
	}
	
	if(classPart == 'box'){
		
		kindOfBox = '';
		boxAutoHeightFix = false;
		
		if(classname.indexOf('boxLeftCol') != -1) {
			kindOfBox = 'left';
			
		}else if(classname.indexOf('boxRightCol') != -1) {
			kindOfBox = 'right';
			
		}else if(classname.indexOf('boxTwoCol') != -1) {
			kindOfBox = 'two';
		}
		
		// check if height has to be fixed
		if(classname.indexOf('boxAutoHeightFix') != -1) {
			boxAutoHeightFix = true;
		}
		
		boxId = '#' + n.id;
		
		
		if(boxAutoHeightFix == true) {
			//alert(Math.ceil($(boxId).height()/45));
			
			factor = (Math.ceil($(boxId).height()/45)*45)-10;
			
			$(boxId).css( {height:factor+"px"} );
		}
		
		
		//alert(kindOfBox);
		if(kindOfBox == 'left') {
			leftX = $(boxId).position().left;
			$(boxId).css( {position:"absolute", top:leftY+"px", left:leftX+"px"} );
			leftY += $(boxId).height()+10;
		}
		else if(kindOfBox == 'right') {
			rightX = $(boxId).position().left;
			$(boxId).css( {position:"absolute", top:rightY+"px", left:rightX+"px"} );
			rightY += $(boxId).height()+10;
		}
		else if(kindOfBox == 'two') {
			if(leftY >= rightY) {
				totalY = leftY;
			} else if (rightY > leftY) {
				totalY = rightY;
			} else {
				
			}
			
			totalX = $(boxId).position().left;
			$(boxId).css( {position:"absolute", top:totalY+"px", left:totalX+"px"} );
			totalY += $(boxId).height()+10;
			
			leftY = totalY;
			rightY = totalY;
		}
		
		
	}
	var kids = n.childNodes;
	for(var i = 0; i < kids.length; i++){
		
		if(depth == 1) {
			fixLayout(kids[i], from, to, depth+1);
		}
	}
}



function filterArticles(url) {	
	location.href = url;
}


function changeSeriesArticle(url) {	
	location.href = url;
}


function checkCartArticleDelete_de() {
	var message=confirm("Wollen Sie den Artikel wirklich aus Ihrem Warenkorb entfernen?");
	return message;
}
function checkCartArticleDelete_en() {
	var message=confirm("Do you really want to remove this article from your cart?");
	return message;
}



var d_firstname	= '';
var d_lastname 	= '';
var d_company 	= '';
var d_street	= '';
var d_zip 		= '';
var d_city 		= '';
var d_country 	= '';

function checkDeliveryAddress(form) {
	
	if(form.d_address_identical.checked == true) {
		
		//document.getElementById('deliveryaddress').style.display = 'none';
		
		d_firstname	= form.d_firstname.value;
		d_lastname 	= form.d_lastname.value;
		d_company 	= form.d_company.value;
		d_street	= form.d_street.value;
		d_zip 		= form.d_zip.value;
		d_city 		= form.d_city.value;
		d_country 	= form.d_country.value;
		
		form.d_firstname.value	= form.firstname.value;
		form.d_lastname.value 	= form.lastname.value;
		form.d_company.value 	= form.company.value;
		form.d_street.value	 	= form.street.value;
		form.d_zip.value 		= form.zip.value;
		form.d_city.value 		= form.city.value;
		form.d_country.value 	= form.country.value;		
		
	} else {
		//document.getElementById('deliveryaddress').style.display = 'inline';
		
		// get saved values
		form.d_firstname.value	= d_firstname;
		form.d_lastname.value 	= d_lastname;
		form.d_company.value 	= d_company;
		form.d_street.value	 	= d_street;
		form.d_zip.value 		= d_zip;
		form.d_city.value 		= d_city;
		form.d_country.value 	= d_country;
	}
	
}



function openPopUp(url) {
    
    var sheight = 600;
    var swidth = 400;
    var stop = ((screen.availHeight)/2 -sheight/2);
    var sleft = ((screen.width)-swidth)-20;

    spopupWindow = window.open(url, "popup", "resizable=no,location=yes,scrollbars=yes,width="+swidth+",height="+sheight+",left="+sleft+",top="+stop);
    spopupWindow.focus();
}
