var vpospics = null;

function openpopup(in_strUrl, in_intWidth, in_intHeight, in_openfullsize){
	if (vpospics != null) {
	   if (!vpospics.closed) vpospics.close();
	   vpospics=null;
	}

//	vpospics=window.open(in_strUrl,"","width=" + in_intWidth + ",height=" + in_intHeight + ",toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,left=" + (screen.width - in_intWidth)/2 + ",top=" + ((screen.height - in_intHeight)/2));

	vpospics=window.open(in_strUrl,"","width=" + in_intWidth + ",height=" + in_intHeight + ",toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,left=" + (screen.width - in_intWidth)/2 + ",top=" + ((screen.height - in_intHeight)/2));
}


function openfixedpopup(in_strUrl, in_intWidth, in_intHeight, in_openfullsize){
	if (vpospics != null) {
	   if (!vpospics.closed) vpospics.close();
	   vpospics=null;
	}

//	vpospics=window.open(in_strUrl,"","width=" + in_intWidth + ",height=" + in_intHeight + ",toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,left=" + (screen.width - in_intWidth)/2 + ",top=" + ((screen.height - in_intHeight)/2));

	vpospics=window.open(in_strUrl,"","width=" + in_intWidth + ",height=" + in_intHeight + ",toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,left=" + (screen.width - in_intWidth)/2 + ",top=" + ((screen.height - in_intHeight)/2));
}


function openmidlerpopup(in_strUrl, in_intWidth, in_intHeight, in_openfullsize){
	if (vpospics != null) {
	   if (!vpospics.closed) vpospics.close();
	   vpospics=null;
	}

	vpospics=window.open(in_strUrl,"","width=" + in_intWidth + ",height=" + in_intHeight + ",toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,left=" + (screen.width - in_intWidth)/2 + ",top=" + ((screen.height - in_intHeight)/2));

//	vpospics=window.open(in_strUrl,"","width=" + in_intWidth + ",height=" + in_intHeight + ",toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,left=" + (screen.width - in_intWidth)/2 + ",top=" + ((screen.height - in_intHeight)/2));
}

function openpopupfullscreen(in_strUrl){
	if (vpospics != null) {
	   if (!vpospics.closed) vpospics.close();
	   vpospics=null;
	}

//	vpospics=window.open(in_strUrl,"","width=" + in_intWidth + ",height=" + in_intHeight + ",toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,left=" + (screen.width - in_intWidth)/2 + ",top=" + ((screen.height - in_intHeight)/2));

	vpospics=window.open(in_strUrl,"","type=fullWindow,fullscreen,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0");
}

function openbookpopup(in_strUrl, in_intWidth, in_intHeight, in_openfullsize){
	if (vpospics != null) {
	   if (!vpospics.closed) vpospics.close();
	   vpospics=null;
	}

	vpospics=window.open(in_strUrl,"","width=" + in_intWidth + ",height=" + in_intHeight + ",toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,left=0,top=0");
}


function openvhdpopup(in_strUrl){
	if (vpospics != null) {
	   if (!vpospics.closed) vpospics.close();
	   vpospics=null;
	}

//	vpospics=window.open(in_strUrl,"","width=800,height=300,toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,left=" + (screen.width - 600)/2 + ",top=" + ((screen.height - 400)/2));
	vpospics=window.open(in_strUrl,"","width=600,height=400,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0resizable=1,left=" + (screen.width - 500)/2 + ",top=" + ((screen.height - 400)/2));
}
function openfullscreenapp(in_strUrl) {
	if (vpospics != null) {
	   if (!vpospics.closed) vpospics.close();
	   vpospics=null;
	}
	var in_intWidth = screen.width-6;
	var in_intHeight = screen.availHeight;
	vpospics=window.open(in_strUrl,"","width=" + in_intWidth + ",height=" + in_intHeight + ",toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,left=1,top=1");
}

function removeQueryStringItem (in_url, in_name) {
	var strReturn = in_url.substring(0, in_url.indexOf("?"));
	var qs = in_url.substring(strReturn.length+1,in_url.length);
	
	var ar_QueryStrings = qs.split("&");


	var blnQuestionMark = false;
	for (var i = 0; i < ar_QueryStrings.length; i++) {
		var tmp = ar_QueryStrings[i].substring(0, ar_QueryStrings[i].indexOf("="));
		if (tmp != in_name) {
			if (blnQuestionMark)
				strReturn = strReturn + "&" + ar_QueryStrings[i];
			else {
				strReturn = strReturn + "?" + ar_QueryStrings[i];
				blnQuestionMark = true;
			}
		}
	}

	return strReturn;
}
function isINT(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
	         IsNumber = false;
         }
      }
   return IsNumber;
   
}

function remove_color_hash(in_str)
{
	if (in_str.charAt(0) == "#")
	{
		return in_str.substring(1,in_str.length);
	}
	else
	{
		if(in_str.toLowerCase() == 'ingen')
		{
			return "ffffff";
		}
		else
		{
			return in_str;
		}
	}
}

function getTextBGColor(in_bgColor)
{
	var red;
	var green; 
	var blue; 
	var bgfarve;

	bgfarve  = remove_color_hash(in_bgColor);

	red = bgfarve.substring(0, 2);
	green = bgfarve.substring(2, 2);
	blue = bgfarve.substring(4, 2);

	if (red <= 68 && green <= 68 && blue <= 68)
	{
		return "ffffff";
	}
	else
	{
		return "000000";
	}
}

function urlDecode(in_string){
	var tempstr
	var rg = /\+/g;

	tempstr = unescape(in_string);
	tempstr = tempstr.replace(rg, " ")

	return tempstr.replace(rg, " ");
}


//Denne funktion laver et CPR nummer check
function check_cpr(in_cprnr)
{
	var blnRet;
	blnRet = false;

	if (in_cprnr == "" || in_cprnr.length < 10)
	{	
		blnRet = false;
	}
	else
	{
		var ar_tal, i, sum, rest, kontroltal;
		var ar_cpr = new Array(9);
		ar_tal = new Array(4, 3, 2, 7, 6, 5, 4, 3, 2);

		for (i=0; i<in_cprnr.length; i++)
		{
			ar_cpr[i] = parseInt(in_cprnr.charAt(i));
		}
		
		sum = 0;

		for (i=0; i < 9; i++)
		{
			sum += (parseInt(ar_cpr[i]) * parseInt(ar_tal[i]));
		}

		rest = sum % 11;
		kontroltal = 11 - rest;

		if (rest == 0)
		{
			kontroltal = 0;
		}

		blnRet = false;

		if (kontroltal == 10)
		{
			blnRet = false;
		}
		
		if (parseInt(kontroltal) == parseInt(ar_cpr[9]))
		{
			blnRet = true;
		}
	}

	return blnRet;
}


//Denne funktion laver tekst om fra ( stringToJavaEncode ) så den kan skrives i javascript
function stringToJavaDecode(in_tmpStr){
	
	var tmpStr = urlDecode(in_tmpStr);
	var rg = /__THISISALINEBREAKE_HVAL_/g;
	tmpStr = tmpStr.replace(rg, "<br />");
	rg = /__THISISAPLUSTAG__1__HVAL_/g;
	tmpStr = tmpStr.replace(rg, "+");
	return tmpStr;
}

//Denne funktion laver tekst om fra ( stringToJavaEncode ) så den kan skrives i javascript
function stringToJavaTextareaDecode(in_tmpStr){
	
	var tmpStr = urlDecode(in_tmpStr);
	var rg = /__THISISALINEBREAKE_HVAL_/g;
	tmpStr = tmpStr.replace(rg, "\n");
	rg = /__THISISAPLUSTAG__1__HVAL_/g;
	tmpStr = tmpStr.replace(rg, "+");
	return tmpStr;
}

//Til at udskrive bl.a. flash uden "Click to activate"
function WriteEmbeddedFlash(fileid, checksum, width, name){
	if (checksum.length > 0)
	{
		document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"  WIDTH="' + width + '" id="flashthingy' + name + '" ALIGN=""><PARAM NAME=movie VALUE="http://hval.dk/modules/vhd/showfile/showfile.aspx?id=' + fileid + '&cs=' + checksum + '"><PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF><EMBED src="http://hval.dk/modules/vhd/showfile/showfile.aspx?id=' + fileid + '&cs=' + checksum + '" quality=high bgcolor=#FFFFFF  WIDTH="' + width + '" NAME="flashthingy' + name + '" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>');
	}
	else
	{
		document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"  WIDTH="' + width + '" id="flashthingy' + name + '" ALIGN=""><PARAM NAME=movie VALUE="http://hval.dk/modules/vhd/showfile/showfile.aspx?id=' + fileid + '&cs=' + checksum + '"><PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF><EMBED src="http://hval.dk/modules/vhd/showfile/showfile.aspx?id=' + fileid + '&cs=' + checksum + '" quality=high bgcolor=#FFFFFF  WIDTH="' + width + '" NAME="flashthingy' + name + '" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>');
	}
}

// defaultEmptyOK er standard falsk.
var defaultEmptyOK = false;
function isPositiveInteger(s) {
    var secondArg = defaultEmptyOK;

    if (isPositiveInteger.arguments.length > 1)
        secondArg = isPositiveInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a positive, not negative, number

    return (isSignedInteger(s, secondArg)
			 && ((isEmpty(s) && secondArg) || (parseInt(s) > 0)));
}

// isSignedInteger (STRING s [, BOOLEAN emptyOK])
// see comments of function isInteger.
//
// EXAMPLE FUNCTION CALL:          RESULT:
// isSignedInteger ("5")           true 
// isSignedInteger ("")            defaultEmptyOK
// isSignedInteger ("-5")          true
// isSignedInteger ("+5")          true
// isSignedInteger ("", false)     false
// isSignedInteger ("", true)      true

function isSignedInteger(s) {
    if (isEmpty(s))
        if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
    else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ((s.charAt(0) == "-") || (s.charAt(0) == "+"))
            startPos = 1;
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

// isInteger (STRING s [, BOOLEAN emptyOK])
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true 
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

function isInteger(s) {
    var i;

    if (isEmpty(s))
        if (isInteger.arguments.length == 1) return defaultEmptyOK;
    else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

// Returns true if character c is a digit 
// (0 .. 9).

function isDigit(c) {
    return ((c >= "0") && (c <= "9"))
}

// Check whether string s is empty.

function isEmpty(s) {
    return ((s == null) || (s.length == 0))
}
