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 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;
}