
function CenterDiv(pDivIdStr,pWidth,pHeight)
{
	var lWidth= $(window).width() ;
	var lHeight = $(window).height();
	var lX = (lWidth-pWidth)/2;
	var lY = 100;//(lHeight-pHeight)/2;
//	alert("Centerdiv:"+pDivIdStr+":"+pWidth +","+lWidth+".");
	$(pDivIdStr).css({
		"z-index": 6,
		"position": "absolute",
		"left": parseInt(lX) + "px",
		"top":parseInt(lY) + "px",
		"width": pWidth+"px",
		"height": pHeight +"px"
	} );
}
function SetOverlayDiv(pPageContentStr)
{
	$('#OverlayContentDiv').html( pPageContentStr) ;
}
function DelaySetOverlayDiv(pPageContentStr)
{
	setTimeout("SetOverlayDiv( '"+pPageContentStr+"' );",1000);
	SetOverlayDiv( '<center><img src="Images/WWW/loader.gif" /></center>') ;
}
function ShowOverlayDiv( pURLStr, pCloseFunction, pWidth, pHeight)
{
	ShowOverlayTitleDiv( pURLStr, "", pCloseFunction, pWidth, pHeight)
}
function ShowOverlayTitleDiv( pURLStr, pTitleStr, pCloseFunction, pWidth, pHeight)
{
	var lButtonX = pWidth - 32 ;
	var lWidthExtended = parseInt(pWidth) + 8;
	var lHeightExtended = parseInt(pHeight)+52;
	CenterDiv("#OverlayContentDiv",lWidthExtended,lHeightExtended);
	lPageContentStr ='<div id="OverlayContentTitleDiv" style="width:'+lButtonX+'px;height:32px;position:absolute;left0px;top:0px;">'+pTitleStr+'</div><div style="width:32px;height:32px;position:absolute;left:'+lButtonX+'px;top:0px;"><img src="Images/WWW/fancy_close.png" onclick="JavaScript:'+pCloseFunction+'"></div><div id="ContentDiv" style="position:absolute;left:8px;top:32px;"><iframe marginheight="0" frameborder="1" id="" name="" src="'+pURLStr+'" width="'+pWidth+'px" height="'+pHeight+'px"></iframe></div>';
	DelaySetOverlayDiv(lPageContentStr);
//	SetOverlayDiv( "Testing..") ;
	$("#OverlayContentDiv").css (
	{
		"background-color": "white" ,
		"overflow": "hidden" ,
		"border-radius": "15px",
		"-moz-border-radius": "15px",
		"-webkit-border-radius": "15px",
		"box-shadow": "0 0 8px 5px #222",
		"-moz-box-shadow": "0 0 8px 5px #222",
		"-webkit-box-shadow": "0 0 8px 5px #222",
		"padding": "4px",
		"height:": lHeightExtended+"px",
		"width:": lWidthExtended+"px"
	});	
	$("#OverlayContentDiv").show( 'slow' );
	return "Ok";
}
function ShowShopTitleDiv( pURLStr, pTitleStr, pWidth, pHeight)
{
	return ShowOverlayTitleDiv( pURLStr,pTitleStr,"AbortShopDiv()", pWidth, pHeight);
}
function ShowShopDiv( pURLStr, pWidth, pHeight)
{
	return ShowOverlayDiv( pURLStr, "AbortShopDiv()", pWidth, pHeight);
}
function ShowShopCodeDiv( pPageContentStr)
{
	$("#OverlayContentDiv").html (pPageContentStr); 
	$("#OverlayContentDiv").show( 'slow' );
	return "Ok";
}
function CloseShopDiv( pStateStr, pMessageStr)
{
	lPageContentStr = '<font color="#ffffff">'+pMessageStr +'<input type="button" value="Back" onclick="JavaScript:HideShopDiv()" />';
	$("#OverlayContentDiv").html (lPageContentStr); 
	$("#OverlayContentDiv").show( );

	return "Ok";
}
function UpdateShopDiv( pStateStr , pMessageStr)
{
	SetOverlayDiv( pMessageStr ) ;
	return "Ok";	
}
function HideShopDiv()
{
	$("#OverlayContentDiv").html (""); 
	$("#OverlayContentDiv").hide('slow');
	return "Ok";
}
function AbortShopDiv()
{
	HideShopDiv();
	return "Ok";
}


function ShowScoutDiv( pURLStr,pWidth, pHeight)
{
	return ShowOverlayDiv( pURLStr,"HideScoutDiv()", pWidth, pHeight);
}
function HideScoutDiv()
{
	$("#OverlayContentDiv").html ( ""); 
	$("#OverlayContentDiv").hide( );
	return "Ok";
}

function SendToPrinter(pHTMLStr)
{
	var pwin=window.open('','PrintCode','width=100,height=100');
		pwin.document.open();
		pwin.document.write('<html><body onload="window.print()">'+pHTMLStr+'</body></html>');
		pwin.document.close();
	setTimeout(function(){pwin.close();},1000);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Popup windows, and popup blocker detection..
var lPopupWindow = null;
function OpenPopupWindow(pURLStr,pTitleStr,pWidth,pHeight,pFeaturesStr)
{
	var lWidth= $(window).width() ;
	var lHeight = $(window).height();
	var lWindowX = parseInt((lWidth-pWidth)/2);
	var lWindowY = parseInt((lHeight-pHeight)/2);
//	alert("OpenPopupWindow:"+lWindowX + ","+lWindowY);
	if (lWindowX < 0) lWindowX = 0;
	if (lWindowY < 0) lWindowY = 0;

	var lSettingsStr = 'height=' + pHeight + ',';
	lSettingsStr += 'width=' + pWidth + ',';
	lSettingsStr += 'top=' + lWindowY + ',';
	lSettingsStr += 'left=' + lWindowX + ',';
	lSettingsStr += pFeaturesStr;
//	alert("OpenPopupWindow:"+lSettingsStr);
	lPopupWindowCalled = false ;
	lPopupWindow = window.open(pURLStr,"",lSettingsStr);
//	lPopupWindow.window.focus();

	if ( lPopupWindow!=null)
	{
		return "Ok";
	}

	return "Err";
}
var lCheckPopupBlockedDone = false;
var lPopupAllowed = false ;
function CheckPopupBlocked() {
	lCheckPopupBlockedDone = false;
	lPopupAllowed = false ;	
 	setTimeout(function(){doCheckPopupBlocked(lPopupWindow);}, 3000);
}

function PopupWindowCheckIsDone()
{
	if(lCheckPopupBlockedDone)
	{
    return "true" ;
  }
  return "false";
}
function PopupWindowIsAllowed()
{
	if(lPopupAllowed)
	{
    return "true" ;
  }
  return "false";
}


function doCheckPopupBlocked(poppedWindow) {

    var result = false;
		var lReasonStr = "" ;
    try {
        if ( typeof poppedWindow == 'undefined') {
            // Safari with popup blocker... leaves the popup window handle undefined
            lReasonStr = " Safari with popup blocker... leaves the popup window handle undefined";
            result = true;
        }
        else if (poppedWindow && poppedWindow.closed) {
            // This happens if the user opens and closes the client window...
            // Confusing because the handle is still available, but it's in a "closed" state.
            // We're not saying that the window is not being blocked, we're just saying
            // that the window has been closed before the test could be run.
            result = false;
        }
        else if (poppedWindow && poppedWindow.outerWidth == 0) {
            // This is usually Chrome's doing. The outerWidth (and most other size/location info)
         // will be left at 0, EVEN THOUGH the contents of the popup will exist (including the
         // test function we check for next). The outerWidth starts as 0, so a sufficient delay
         // after attempting to pop is needed.
					lReasonStr = "This is usually Chrome's doing. ";

            result = true;
        }
        else if (poppedWindow && poppedWindow.LoadContent!='undefined') {
            // This is the actual test. The client window should be fine.
            result = false;
        }
        else if(poppedWindow && poppedWindow.outerWidth>100) {
            // This is the actual test. The client window should be fine.
            result = false;
        	}
        else {
            // Else we'll assume the window is not OK
						lReasonStr = " Else we'll assume the window is not OK";
            result = true;
        }

    } catch (err) {
        //if (console) {
        //    console.warn("Could not access popup window", err);
        //}
    }

    if(!result && poppedWindow.LoadContent!='undefined')
    {
//			poppedWindow.LoadContent();
    }

	lCheckPopupBlockedDone = true ;
	if (result == false)
	{
		lPopupAllowed = true ;
	}
	else
		alert("De pagina kan niet worden geopend in een nieuw venster. Het is waarschijnlijk dat uw browser 'Pop-up blokkering' aan heeft staan. Zet de blokkering voor deze site uit, zodat de pagina geopend kan worden."+lReasonStr+ ":"+poppedWindow.LoadContent);
}

function PopupWindowIsOpen()
{
  if (lPopupWindow!=null && !lPopupWindow.closed )
  {
    return "true" ;
  }
  return "false";

}

function PopupWindowIsClosed()
{
  if (!lPopupWindow || lPopupWindow==null || lPopupWindow.closed)
  {
    return "true" ;
  }
  return "false";
}

function ClosePopupWindow()
{
  if (!lPopupWindow || lPopupWindow==null || lPopupWindow.closed)
  {
    return "false" ;
  }
  lPopupWindow.close();
  lPopupWindow = null;
  return "true";
}

 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ExtractValueList(pParameterStr,pSeperator)
{
	return pParameterStr.split(pSeperator);
}

function ExtractParameterList(pParameterStr,pSeperator)
{
	var lParameters = pParameterStr.split(pSeperator);
	var lParameterArray = new Array();
	for (var lIndex=0; lIndex < lParameters.length; lIndex++) {
		var lPosition = lParameters[lIndex].indexOf('=');
		if (lPosition > 0) {
			var lKey = lParameters[lIndex].substring(0,lPosition);
			var lValue = lParameters[lIndex].substring(lPosition+1);
			lParameterArray[lKey] = lValue;
		}
	}
	return lParameterArray;
	
}
function ExtractParameter(pParameterArray,pKey, pExpectedValue)
{
	try
	{
		if(pParameterArray.hasOwnProperty(pKey))
		{
			return pParameterArray[pKey];
		}
	}
	catch(e)
	{
		return pExpectedValue;
	}
}
function ExtractFloatParameter(pParameterArray,pKey, pExpectedValue)
{
	try
	{
		var lString = ExtractParameter(pParameterArray,pKey, pExpectedValue);
		return parseFloat(lString);
	}
	catch(e)
	{
		return pExpectedValue;
	}
}
function ExtractIntParameter(pParameterArray,pKey, pExpectedValue)
{
	try
	{
		var lString = ExtractParameter(pParameterArray,pKey, pExpectedValue);
		return parseInt(lString);
	}
	catch(e)
	{
		return pExpectedValue;
	}
}

function GetParameters()
{
	var lQueryStr = window.location.search.substring(1);
	var lParameters = lQueryStr.split('&');

	for (var lIndex=0; lIndex < lParameters.length; lIndex++) {
		var lPosition = lParameters[lIndex].indexOf('=');

		if (lPosition > 0) {
			var lKey = lParameters[i].substring(0,lPosition);
			var lValue = lParameters[i].substring(lPosition+1);
			gUrlParameters[lKey] = lValue;
		}
	}
}

function GetParameter(pKey, pExpectedValue)
{
	if(gUrlParameters.hasOwnProperty(pKey))
	{
		return gUrlParameters[pKey];
	}
	return pExpectedValue;
}
function SetParameter(pKey, pValue)
{
		gUrlParameters[pKey] = pValue;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////


