// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {

		flashVer = -1;
	}
	return flashVer;
}

// If called with no parameters this function returns a floating point value
// which should be the version of the Flash Player or 0.0
// ex: Flash Player 7r14 returns 7.14
// If called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision){
 	var reqVer = parseFloat(reqMajorVer + "." + reqRevision);
   	// loop backwards through the versions until we find the newest version
	for(i=25;i>0;i--){
		if(isIE && isWin && !isOpera){
			versionStr = VBGetSwfVer(i);
		}
		else{
			versionStr = JSGetSwfVer(i);
		}
		if(versionStr == -1 ){
			return false;
		}
		else if (versionStr != 0){
			if(isIE && isWin && !isOpera){
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");
			}
			else{
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];

			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if((versionMajor > reqMajorVer) && (versionNum >= reqVer)) return true;
			else return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
		}
	}
	return (reqVer ? false : 0.0);
}

// Handle all the FSCommand messages in a Flash movie.
function mymovie_DoFSCommand(cmd, args) {
	var mymovieObj = isIE ? document.all.mymovie : document.mymovie;
	switch(cmd){
		case "popwin":
			popWindow(args);
			break;
		case "back":
			top.historyframe.history.go(parseInt("-"+args));
			break;
		default:
			break;
	}
}

function popWindow(args){
	var rt	= "hjaelp.htm";
	/*switch(args){
		case "-1": //	retningslinier
			rt	= "hjaelp.aspx?side=retningslinier";
			break;
		case "2": //	opslagstavle
			rt	= "hjaelp.aspx?side=opslagstavle"; //	"hjaelp_opslagstavle.htm"
			break;
		case "3": //	slægtstavle
			rt	= "hjaelp.aspx?side=stamtrae"; //	"hjaelp-stamtrae.htm"
			break;
		case "1": //	sudoku
			rt	= "hjaelp.aspx?side=sodoku"; //	"hjaelp_sudoku.htm"
			break;
	    case "4":// netværksgrupper
	        rt = "hjaelp.aspx?side=netvaerksgrupper";
	        break;
		default: //	sudoku
			rt	= args;
			if(rt=="undefined" || rt==3 || rt==4) rt	= "hjaelp.aspx?side=generelt"; //	"hjaelp.htm"
			break;
	}*/

	switch (args) {
	    case "-1": //	retningslinier
	        rt = "hjaelp.aspx?side=retningslinier";
	        break;
	    case "0": //	opslagstavle
	        rt = "hjaelp.aspx?side=opslagstavle"; //	"hjaelp_opslagstavle.htm"
	        break;
	    case "3": //	slægtstavle
	        rt = "hjaelp.aspx?side=stamtrae"; //	"hjaelp-stamtrae.htm"
	        break;
	    case "2": //	sudoku
	        rt = "hjaelp.aspx?side=sodoku"; //	"hjaelp_sudoku.htm"
	        break;
	    case "6": // netværksgrupper
	        rt = "hjaelp.aspx?side=netvaerksgrupper";
	        break;
	    default: //	sudoku
	        rt = args;
	        if (rt == "undefined" || rt == 3 || rt == 4) rt = "hjaelp.aspx?side=generelt"; //	"hjaelp.htm"
	        break;
	}

	var win	= window.open(rt,"win", "toolbar=0,titlebar=0,status=0,scrollbars=1,resizable=1,menubar=0,location=0,height=300,width=400");
	if(null==win){
		alert("Din browser skal tillade popupvinduer for at du kan bruge denne funktionalitet");
	}
	else{
		if(window.focus){
			win.focus();
		}
	}
}


function setSizes(w,h){
	var newW = w;
	var newH = h;

	var m	= getFlashMovieObject("mymovie");
	if(m!=null){
		if(isIE){
			m.width = newW;
			m.height = newH;
		}
		else{
			// * body er størrelsen af INDHOLDEt, ikke vinduet. IE tror fejlagtigt at body altid er samme størrelse som vinduet
			if(w == "100%") newW = document.body.clientWidth + "px";
			if(h == "100%") newH = document.body.clientHeight + "px";
			m.width = newW;
			m.height = newH;

		}
	}
}

function checkBrowser(){
	/*if (self.innerWidth){
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}else */if (document.documentElement && document.documentElement.clientWidth){
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}/*else if (document.body){
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}*/
	else return;
	extra_nw = isIE ? 0 : (frameHeight > top.minHeight ? 0 : 15)
	extra_nh = isIE ? 0 : (frameWidth > top.minWidth ? 0 : 15)

	nw = frameWidth > top.minWidth ? (frameWidth-extra_nw)+"px" : (top.minWidth-extra_nw) + "px";
	nh = frameHeight > top.minHeight ? (frameHeight - extra_nh)+"px" : (top.minHeight - extra_nh) + "px";

	setSizes(nw,nh);
}

function testMac(){
}

function getFlashMovieObject(movieName){
	var rt;
	if(window.document[movieName]!=null){
		rt	= window.document[movieName];
	}
	if(isIE==true){
		if(document.embeds!=null){
			var rt	= document.embeds[movieName];
			if(rt!=null) return rt;
			else{
				return document.getElementById(movieName);
			}
		}
		else return document.getElementById(movieName);
	}
	return document.getElementById(movieName);
}

function gotoHistory(qStr){
	var m = getFlashMovieObject("mymovie");
	/*	IE doesn't recognize SetVariable on the object returned from getFlashMovieObject() the first time
	*
	*/
	m.SetVariable("historyPosition", (null==qStr ? "" : qStr.toString()));
}

function setPage(dir){
	//check if Flash object exists
	var m = getFlashMovieObject("mymovie");
	if(null!=m){
		m.SetVariable("direction", (null==dir ? "" : dir.toString()));
	}
}

function getQString(){
	return location.search.length>0 ? location.search : null;
}

