// ----------------- footer
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function setFooter() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('contentContainer').offsetHeight;
			var footerElement = document.getElementById('footer');
			var footerHeight  = footerElement.offsetHeight;
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px';
			       //alert(footerElement.style.top);
			}
			else {
				footerElement.style.top = '0px';
			}
		}
	}
}

// ----- top breadcrumb menu
function organizeBreadcrumb() {
    var topContent = document.getElementById('topContentHolder');
    
    var divArray = topContent.getElementsByTagName("div");
    
    for (var i=0;i<divArray.length;i++) {
        if ((divArray[i].className=="breadcrumb-class")){ 
            var bcMenu = divArray[i];
            var bcNeededLength = document.getElementById('breadcrumb-length').innerHTML;
            var bcActualLength = stripHTML(bcMenu.innerHTML.replace(/^\s+|\s+$/g,"")).length;
            
            var bcPathArray = stripHTML(bcMenu.innerHTML).split("&nbsp;");
            var correction = 5 * (bcPathArray.length - 1)
            
            bcActualLength -= correction;
            
            if (bcActualLength > bcNeededLength)
            {                
                symbolsToCut = bcActualLength - bcNeededLength;
                
                var originalLastMenuItem = bcPathArray[bcPathArray.length - 1].replace(/^\s+|\s+$/g,"");
                var newLastMenuItem = originalLastMenuItem.substr(0,(originalLastMenuItem.length - symbolsToCut));
                
                bcMenu.innerHTML = bcMenu.innerHTML.replace(originalLastMenuItem, newLastMenuItem) + '...'; 
            }
        }
    }
}

function stripHTML(oldString) {

   var newString = "";
   var inTag = false;
   for(var i = 0; i < oldString.length; i++) {
   
        if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>') {
              if(oldString.charAt(i+1)=="<")
              {
              		//dont do anything
	}
	else
	{
		inTag = false;
		i++;
	}
        }
   
        if(!inTag) newString += oldString.charAt(i);

   }

   return newString;
}

window.onload = function() {
	setFooter();
}
window.onresize = function() {
	setFooter();
}

// ----------------- content boxes

function contentBoxItemMouseOver(obj){					
	if (obj.className != "selected"){		
		obj.firstChild.className = "withoutArrow";
	}				
}

function contentBoxItemMouseOut(obj){		
	if (obj.className != "selected"){		
		obj.firstChild.className = "withArrow";
	}			
}

ord=null; 
 function openorder(dibstype, ntl) 
 {if(ord==null || ord.closed) 
     ord=window.open('https://payment.architrade.com/order/type.pml?update=true&new=true&type='+dibstype+'&origin='+ntl,'DIBSBestilling','width=500,height=600,status=1,menubar=0,scrollbars=1,resizable=1'); 
   else 
     ord.location = 'https://payment.architrade.com/order/type.pml?update=true&new=true&type='+dibstype+'&origin='+ntl;
  ord.focus(); return false; 
}

function decryptCharcode(n,start,end,offset){n=n+offset;if(offset>0&&n>end){n=start+(n-end-1);}else if(offset<0&&n<start){n=end-(start-n-1);}
return String.fromCharCode(n);}
function decryptString(enc,offset){var dec="";var len=enc.length;for(var i=0;i<len;i++){var n=enc.charCodeAt(i);if(n>=0x2B&&n<=0x3A){dec+=decryptCharcode(n,0x2B,0x3A,offset);}else if(n>=0x40&&n<=0x5A){dec+=decryptCharcode(n,0x40,0x5A,offset);}else if(n>=0x61&&n<=0x7A){dec+=decryptCharcode(n,0x61,0x7A,offset);}else{dec+=enc.charAt(i);}}
return dec;}
function linkTo_UnCryptMailto(s){location.href=decryptString(s,-2);}
