

graphicContext = null;

var windowObjectReference;
var strWindowFeatures = "resizable,,scrollbars,width=500,height=600";
var strWindowFeatures2 = "toolbar=0,scrollbars=0,location=1,statusbar=0,menubar=0,resizable=0,width=300,height=450";
var strWindowFeatures3 = "menubar=0,location=0,resizable=yes,scrollbars=yes,status=0,width=500,height=700";

function setGraphicContext (context) {
	if(context != null && context.indexOf(".xsd") == -1)
	{
		window.parent.frames[1].graphicContext = context+".xsd";
		graphicContext = context+".xsd";
		}
	else
	{
		window.parent.frames[1].graphicContext = context;
		graphicContext = context;}
}

function getGraphicContext () {
	return graphicContext;
}


/* ------------------------------------------------------------------------------------------------
-	Function showHideBlock
-
- Show or hide a block
------------------------------------------------------------------------------------------------ */
function showHideBlock(blockId) {
	if(window.document.getElementById(blockId).style.display == "none") {
		window.document.getElementById(blockId).style.display = "block";
	}
	else {
		window.document.getElementById(blockId).style.display = "none";
	}
}

/* ------------------------------------------------------------------------------------------------
-	Function showHideBlock2
-
- Show or hide a block
------------------------------------------------------------------------------------------------ */
function showHideBlock2(blockId) {
	var imgId = 'img_'+blockId;
	var windUrl = window.parent.frames[2].location.pathname;
	
	if(window.document.getElementById(blockId).style.display == "none") {
		window.document.getElementById(blockId).style.display = "block";
		window.document.getElementById(imgId).src = "../img/bluearrow_down.png";
		window.open(windUrl+"#"+blockId, "content");
	}
	else {
		window.document.getElementById(blockId).style.display = "none";
		window[imgId].src = "../img/bluearrow_left.png";
	}
}

/* ------------------------------------------------------------------------------------------------
-	Function showHideBlock3
-
- Show or hide a block
------------------------------------------------------------------------------------------------ */
function showHideBlock3(blockId, schemaContext) {
	var imgId = 'img_'+blockId;
	var windUrl = window.parent.frames[2].location.pathname;
	
	if(window.document.getElementById(blockId).style.display == "none") {
		window.document.getElementById(blockId).style.display = "block";
		window.document.getElementById(imgId).src = "../img/bluearrow_down.png";
		window.open(windUrl+"#"+blockId, "content");
	}
	else {
		window.document.getElementById(blockId).style.display = "none";
		window[imgId].src = "../img/bluearrow_left.png";
	}
	
	setGraphicContext(schemaContext);
}

function toggle_visibility(id) {
    var e = document.getElementById(id);
    e.style.display = ((e.style.display != 'block') ? 'block' : 'none');
}

/* ------------------------------------------------------------------------------------------------
-	Function moveTo
-
- 
------------------------------------------------------------------------------------------------ */
function moveTo(blockId) {
	var windUrl = window.parent.frames[2].location.pathname;
	window.open(windUrl+"#"+blockId, "content");
}

/* ------------------------------------------------------------------------------------------------
-	Function launchDD
-
- Open data dictionary
------------------------------------------------------------------------------------------------ */
function launchDD(type) {
	if(type == "schema") {
		window.open("../toc/tocSchema.xml", "toc");
		window.open("../toc/tocSchemaOpen.xml", "content");
	}
	if(type == "elem") {
		window.open("../toc/tocElem.xml", "toc");
		window.open("../toc/tocElemOpen.xml", "content");
	}
	if(type == "att") {
		window.open("../toc/tocAtt.xml", "toc");
		window.open("../toc/tocAttOpen.xml", "content");
	}
}

function reLaunchDD(type) {
	if(type == "schema") {
		/*window.open("../toc/tocSchema.xml", "toc");*/
		window.open("../toc/tocSchemaOpen.xml", "content");
	}
	if(type == "elem") {
		/*window.open("../toc/tocElem.xml", "toc");*/
		window.open("../toc/tocElemOpen.xml", "content");
	}
	if(type == "att") {
		/*window.open("../toc/tocAtt.xml", "toc");*/
		window.open("../toc/tocAttOpen.xml", "content");
	}
}
/* ------------------------------------------------------------------------------------------------
-	Function returnToList
-
- 
------------------------------------------------------------------------------------------------ */
function returnToList(type) {
	if(type == "elem") {
		window.open("../toc/tocElemOpen.xml", "content");
	}
	else {
		window.open("../toc/tocAttOpen.xml", "content");
	}
}

/* ------------------------------------------------------------------------------------------------
-	Function openDD
-
- Open data dictionary
------------------------------------------------------------------------------------------------ */
function openDD(targetId) {
	//window.open("./dd.xml#"+targetId, "content");
	//window.parent["content"][targetId].style.display = "block";	
	
	window.open(targetId+".xml", "content");
}

/* ------------------------------------------------------------------------------------------------
-	Function load
-
- Loading of data dictionary
------------------------------------------------------------------------------------------------ */
function load() {
	waitF.close();	
}


/* ------------------------------------------------------------------------------------------------
-	Function home
-
- Loading of home frame
------------------------------------------------------------------------------------------------ */
function home() {
	window.open("./toc.html", "toc");
	window.open("./frontpage.html", "content");
}


/* ------------------------------------------------------------------------------------------------
-
-
- generic function as firefox does not support showModalDialog any more
------------------------------------------------------------------------------------------------ */
/*function popup(URL) {
w = window.open(URL, "", strWindowFeatures);
}*/

// Template Script für PopUps
// 
// Quelle: https://www.stichpunkt.de/beitrag/popup.html
// 
// Beispielhaftes HTML im Hauptdokument
// <a href="html-or.jpg" onclick="return popup(this,123,456)" title="..."
// or
// <a href="html-or.jpg" onclick="return popup(this)" title="..."


var pop = null;

function popdown() {
  if (pop && !pop.closed) pop.close();
}

function popup(obj,w,h) {
  var url = (obj.getAttribute) ? obj.getAttribute('href') : obj.href;
  if (!url) return true;
  w = (w) ? w += 20 : 150;  // 150px*150px is the default size
  h = (h) ? h += 25 : 150;
 var left = ( screen.width - w ) / 2;
 var top = ( screen.height - h ) / 2;
  var args = 'width=' + w + ',height=' + h + ',top='+ top + ', left=' + left + ',resizable,location="no",location="no"' ;
  popdown();
  pop = window.open(url,'',args);
  return (pop) ? false : true;
}

/**
 * Pop up an external window center of the page (works with dual monitor setup's)
 *
 * @constructor
 * 
 * modified the example from https://anil.io/blog/javascript/javascript-popup-vertical-horizontal-center-dual-screen/
 */
function PopupCenter(obj, title, w, h) {
  var url = (obj.getAttribute) ? obj.getAttribute('href') : obj.href;
  if (!url) return true;
    // Fixes dual-screen position                         Most browsers      Firefox
    var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left;
    var dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top;

    var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
    var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;

    var left = ((width / 2) - (w / 2)) + dualScreenLeft;
    var top = ((height / 2) - (h / 2)) + dualScreenTop;

    var args =  'width=' + w + ', height=' + h + ', top=' + top + ', left=' + left + 'resizable="yes",location="no",toolbar="no"' ;
    popdown();
    pop = window.open(url,title,args);
    // Puts focus on the new Window
    if (window.focus) {
        if(pop) {
            pop.focus();
        } else {
            $('<div class="has-error"><p class="help-block">Pop Up blocked. Please disable your pop up blocker.</p></div>').insertBefore('.refNo');
        }
    }
    return (pop) ? false : true;
}

window.onunload = popdown;
window.onfocus = popdown;
