function createDiv(divName, divHeight, divWidth) {
	var obj = document.getElementById(divName);
	if(obj!=null) {
		var objContent = document.getElementById(divName+"_content");
		objContent.innerHTML='<img src="loading.gif" alt="Loading" title="Loading">';
		obj.style="display:block; position:absolute; height:"+divHeight+"px; width:"+divWidth+"px; margin:-"+divHeight/2+"px 0px 0px -"+divWidth/2+"px; top: 50%; left: 50%; background-color: #f5f5f5; border: 1px dotted #000000;overflow:auto;";

	} else {
		var newDiv = document.createElement("DIV");
		newDiv.id=divName;
		newDiv.className=divName;
		newDiv.style="display:block; position:absolute; height:"+divHeight+"px; width:"+divWidth+"px; margin:-"+divHeight/2+"px 0px 0px -"+divWidth/2+"px; top: 50%; left: 50%; background-color: #f5f5f5; border: 1px dotted #000000;overflow:auto;";

		var divHead = document.createElement("DIV");
		divHead.id=divName+"_head";
		divHead.className=divName+"_head";
		divHead.style="text-align: right; padding: 2px; background-color: #dddddd;";
		divHead.innerHTML='<input type="button" class="button" value="X" onClick="closeDiv(\''+divName+'\');">';
		newDiv.appendChild(divHead);

		var divContent = document.createElement("DIV");
		divContent.id=divName+"_content";
		divContent.className=divName+"_content";
		divContent.innerHTML='<img src="loading.gif" alt="Loading" title="Loading">';
		newDiv.appendChild(divContent);

		document.body.appendChild(newDiv);
	}
}

function closeDiv(divId) {
	var obj = document.getElementById(divId);
	document.body.removeChild(obj);
}

function hideDiv(divId) {
  document.getElementById(divId).style.display = "none";
}

$(function() {
  $('.nyroModal').nyroModal();
});


var http = createRequestObject();

// Block auf-/zuklappen
function toggle(id, isShowImage){
  var id_header = id.concat("_header");

  if(document.getElementById(id).style.display != 'block') {
    document.getElementById(id).style.display = 'block';
    document.getElementById(id_header).className='div_header_open';
    if(isShowImage!=null && isShowImage) document.getElementById(id).innerHTML = '<img src="'+BASEDIR+'site/loading.gif" alt="Loading" title="Loading">';
  } else {
    document.getElementById(id).style.display = 'none';
    document.getElementById(id_header).className='div_header_closed';
  }
}

// Anzeigen eines PopUp mit nachladen von Daten
function show(id, action, isShowImage) {
  if(isShowImage!=null && isShowImage) {
    document.getElementById(id + "_content").innerHTML = '<img src="'+BASEDIR+'site/loading.gif" alt="Loading" title="Loading">'
    document.getElementById(id).style.display = "block";
	}
	sndReq(id + "_content", action);
}

// Schliessen des PopUp
function closeBlock(id) {
  document.getElementById(id).style.display = "none";
}

// --------------
// ---- AJAX ----
function createRequestObject() {
  var ro;
  var browser = navigator.appName;
  if(browser == "Microsoft Internet Explorer"){
    ro = new ActiveXObject("Microsoft.XMLHTTP");
  }else{
    ro = new XMLHttpRequest();
  }
  return ro;
}

function sndReq(id, action) {
  http.open('get', action);
	http.onreadystatechange = function() { handleResponse(id); };
  http.send(null);
}

function handleResponse(id) {
  if(http.readyState == 4){
	  document.getElementById(id).innerHTML = http.responseText;
  }
}
