﻿/* BFB: 28/9-2011, script that sets cookie that person wants to receive newsletter */
function saveNewsletterCookie(){
console.log('zoverzogoed');
}

/* BFB: 28/9-2011 script that redirects to mobile version based on screen size */
function chooseMobileVersion(){
  //if (document.location.href.indexOf('noresize')==-1 && document.location.href.indexOf('tester')>-1) {
  if (document.location.href.indexOf('noresize')==-1) {
     if (screen.width < 640){
	window.location = "http://m.charles.dk";
    }
  } 
}

/* BFB: 28/9-2011 script that reveals button to go to mobile version when full version is viewd on smartphones */
function createButtonToMobile(){
  if (screen.width < 640 && document.location.href.indexOf('button')>-1){
    if (document.location.href.indexOf('button')>-1){
	$elm('tilMobil').style.display = 'block';
    }
  }
}



function OpenWin(url,title,w,h)
{
var w = window.open("/" + url,title,"width=" + w + ",height=" + h + ",toolbars=false");
w = null;
}

function OpenProductWin(recID)
{
OpenWin("productdetails?recordid148=" + recID,"Produktdetaljer","530","320");
}

// 
// Functions for showing and hiding drop down boxes and iframes
// 
var styleID=null;
// only hide drop downs in IE
var hideDropDownFlag=(document.all ? true : false);

function setDropDownVisibility(visible, menuid, tagname, r) {
	if (!tagname) { tagname="SELECT"; }
    if (styleID && styleID!=menuid) {
		return false;
    }
	if (hideDropDownFlag) {
		if (!r) {
			if (document.body.getElementsByTagName) {
				var arr=document.body.getElementsByTagName(tagname);
				for (i=0; i<arr.length; i++) {
					arr[i].style.visibility=visible?"visible":"hidden";
				}
			}
		} else {						
					
			var coveredArea = r;
			if (document.body.getElementsByTagName) {
				var arr=document.body.getElementsByTagName(tagname);
				for (i=0; i<arr.length; i++) {
					var cmb = arr[i];
					var point = getPosPoint(cmb);
					var cArea = [point[0],point[1],cmb.clientWidth,cmb.clientHeight];										
					if (intersects(coveredArea, cArea)) {
						arr[i].style.visibility=visible?"visible":"hidden";
					}
				}
			}
			
		}
		
		styleID=visible ? null : menuid;
		return true;
	}
}

function intersects (r1, r2) {
	// Test the rects for overlap
	
	// get the radi of each rect			
	var width1 = parseInt(r1[2] / 2);
	var height1 = parseInt(r1[3] / 2);
	var width2 = parseInt(r2[2]/2);
	var height2 = parseInt(r2[3]/2);			
	
	// compute center of each rect
	var cx1 = r1[0] + width1;
	var cy1 = r1[1] + height1;
	var cx2 = r2[0] + width2;
	var cy2 = r2[1] + height2;
	
	// compute deltas
	var dx = Math.abs(cx2 - cx1);
	var dy = Math.abs(cy2 - cy1);
	
	// test if rects overlap
	if (dx<(width1+width2) && dy < (height1+height2)) return true;
	else return false;
}				


function getPosPoint (elm) {
	// GET THIS FROME SOMEWHERE ELSE !!!!
	// Gets the absolute position of the element as a point array [x,y]	
	if (!elm) return [-1,-1];
	var l = elm.offsetLeft;
	var t = elm.offsetTop;
	var tmp = elm.offsetParent;
	while (tmp != null && tmp != document.body) {
		l += tmp.offsetLeft;
		t += tmp.offsetTop;
		tmp = tmp.offsetParent;
	}
	if (!document.all) l -= 2;
	return [l, t];
}

// 
// Funktioner til at skjule og vise drop down felter, når JavaScript menuen
// er synlig
// 
function jsnavAfterShow(menuid) {	
	var frm=document.getElementById("editweb_page");
	var w=frm ? frm.contentWindow : null;
	if (jsmenu.MSIE && jsmenu.MacOS) {
		// hide iframes						
		setDropDownVisibility(false, menuid, (frm ? "IFRAME" : "SELECT"));
	} else if (hideDropDownFlag && w && w.setDropDownVisibility) {		
		// hide drop downs in the iframe "editweb_page"
		
		var o = document.getElementById(menuid);
		var r = null;
		if (o) {
			var p = getPosPoint(o);
			var p2 = getPosPoint(frm);
			p[0]=p[0]-p2[0];
			p[1]=p[1]-p2[1];
			var r = [p[0],p[1],o.clientWidth, o.clientHeight];
		}
		
		w.setDropDownVisibility(false, menuid, null, r);
	} else {		
		// hide drop downs in current window (all pages except EditWeb)
		var o = document.getElementById(menuid);
		var r = null;
		if (o) {
			var p = getPosPoint(o);
			var r = [p[0],p[1],o.clientWidth, o.clientHeight];
		}
		setDropDownVisibility(false, menuid,null,r);
	}
	
	var o = document.getElementById(menuid);
	var trigger = document.getElementById(menuid+"wrapper");
	if (o) {
		if (/Mozilla\/5\.0/.test(navigator.userAgent) || /Opera\/9/.test(navigator.userAgent)) o.style.left=parseInt(o.style.left)+5+"px";
		if (parseInt(o.style.borderTopWidth)==1) {				
			o.style.borderTopWidth="0px";
			var topE = document.createElement("IMG");
			topE.style.width = o.clientWidth-trigger.childNodes[0].offsetWidth+2 + "px";
			topE.style.height = "1px";
			topE.style.position="absolute";										
			topE.style.left = (trigger.childNodes[0].offsetWidth-2)+"px";
			if (Contigo) {
				topE.style.borderTop = "1px solid #D4D0C8";
			} else {
				topE.style.borderTop = "1px solid steelblue";
			}
			o.insertBefore(topE,o.firstChild);
		}				
	}
	
}

function jsnavBeforeHide(menuid) {
	var frm=document.getElementById("editweb_page");
	var w=frm ? frm.contentWindow : null;
	if (jsmenu.MSIE && jsmenu.MacOS) {
		// hide iframes
		setDropDownVisibility(true, menuid, (frm ? "IFRAME" : "SELECT"));
	} else if (hideDropDownFlag && w && w.setDropDownVisibility) {
		// show drop downs in the iframe "editweb_page"
		w.setDropDownVisibility(true, menuid);
	} else {
		setDropDownVisibility(true, menuid);
	}
}

function FixScrollable()
{
	if(Tangora.Browser.IE && Tangora.Browser.Version.indexOf("7.0")>-1)
	{
		var maincell = document.getElementById("maincell");
		maincell.innerHTML = maincell.innerHTML;
	}
}
