     


var activeElement;
var changeContent;
var reloadAfter;
var MaxYScroll;

function disableEventPropagation(evt) {
  if (evt) {
   if (typeof evt.stopPropagation == 'function') {
      evt.stopPropagation()
    } else {
      evt.cancelBubble=true;
    }
  }
}

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function setLightboxElements() {
  document.write('<div id="lightbox_close"><a href="javascript:hideLightbox();">schliessen</a></div>');
  document.write('<div id="lightbox_light"><iframe id="lightbox_iframe" src="" border="0" frameborder="0"></iframe></div>');
  document.write('<div id="lightbox_fade"></div>');
}

function setContentElements() {
  document.write('<div id="contentmask_top"></div>');
  document.write('<div id="contentmask_left"></div>');
  document.write('<div id="contentmask_right"></div>');
  document.write('<div id="contentmask_bottom"></div>');
  document.write('<div id="contentmask_toolbox"><nobr><a href="javascript:subcontent_add();"><img src="/cmscontent/icons/toolbox_add.gif" border="0" /></a>&nbsp;<span id="contentmask_toolbox_settings"><a href="javascript:subcontent_edit();"><img src="/cmscontent/icons/toolbox_setting.gif" border="0" /></a>&nbsp;<a href="javascript:subcontent_moveup();"><img src="/cmscontent/icons/toolbox_up.gif" border="0" /></a>&nbsp;<a href="javascript:subcontent_movedown();"><img src="/cmscontent/icons/toolbox_down.gif" border="0" /></a>&nbsp;<a href="javascript:subcontent_remove();"><img src="/cmscontent/icons/toolbox_remove.gif" border="0" /></a></span></nobr></div>');
  
  var allPageTags=document.getElementsByTagName("*"); 
  for (i=0; i<allPageTags.length; i++) { 
    if(allPageTags[i].id.match(/^content_/)) {
      document.getElementById(allPageTags[i].id).onmouseover = function(evt) {  (evt) ? outlineElement(this,evt) : outlineElement(this,event) };
      document.getElementById(allPageTags[i].id).onclick = function(evt) {  (evt) ? showToolbox(this,evt) : showToolbox(this,event) };
    }
  }
}

function outlineElement (obj,evt) {
	disableEventPropagation(evt);
	
	if (activeElement == null) {
  	var curleft = curtop = 0;      	
  	var curwidth = obj.offsetWidth-2;
    var curheight = obj.offsetHeight-2;
  	
    if (obj.offsetParent) {
      do {
  			curleft += obj.offsetLeft;
  			curtop += obj.offsetTop;
      } while (obj = obj.offsetParent); 
    }
              
    cmt = document.getElementById('contentmask_top');
    cmt.style.display = "block";
    cmt.style.left   = curleft + "px";
    cmt.style.top 	 = curtop + "px";
    cmt.style.width  = (curwidth + 2) + "px";
 
    cmt = document.getElementById('contentmask_left');
    cmt.style.display = "block";
    cmt.style.left   = curleft + "px";
    cmt.style.top 	 = curtop + "px";
    cmt.style.width  = "0px";
    cmt.style.height = curheight + "px";

    cmt = document.getElementById('contentmask_right');
    cmt.style.display = "block";
    cmt.style.left   = curleft + curwidth + "px";
    cmt.style.top 	 = curtop + "px";
    cmt.style.width  = "0px";
    cmt.style.height = curheight + "px";
      
    cmt = document.getElementById('contentmask_bottom');
    cmt.style.display = "block";
    cmt.style.left   = curleft + "px";
    cmt.style.top 	 = curtop + curheight + "px";
    cmt.style.width  = (curwidth + 2) + "px";       
  }  
}

function showToolbox (obj,evt) {
	disableEventPropagation(evt);
	
	if (activeElement == null) {
	  activeElement = obj.id;
	  
  	var curleft = curtop = 0;      	
  	var curwidth = obj.offsetWidth-2;
    var curheight = obj.offsetHeight-2;
  	
    if (obj.offsetParent) {
      do {
  			curleft += obj.offsetLeft;
  			curtop += obj.offsetTop;
      } while (obj = obj.offsetParent); 
    }
              
    cmt = document.getElementById('contentmask_toolbox');
    cmt.style.display = "block";
    cmt.style.left   = (curleft + curwidth - 101) + "px";
    cmt.style.top 	 = (curtop - 23) + "px";  
    
    if (activeElement.match(/\.\d{6}$/) == null) {
      document.getElementById('contentmask_toolbox_settings').style.display = "none";
    } else {
      document.getElementById('contentmask_toolbox_settings').style.display = "inline";
    }          
  } else {
    if (activeElement == obj.id) {
      activeElement = null;
    
      cmt = document.getElementById('contentmask_toolbox');
      cmt.style.display = "none";
    }
  }
}

function getPageScroll(){
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


function getPageSize(){
  var xScroll, yScroll;
  
  if (window.innerHeight && window.scrollMaxY) {	
  	xScroll = document.body.scrollWidth;
  	yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
  	xScroll = document.body.scrollWidth;
  	yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
  	xScroll = document.body.offsetWidth;
  	yScroll = document.body.offsetHeight;
  }
  
  var windowWidth, windowHeight;
  if (self.innerHeight) {	// all except Explorer
  	windowWidth = self.innerWidth;
  	windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
  	windowWidth = document.documentElement.clientWidth;
  	windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
  	windowWidth = document.body.clientWidth;
  	windowHeight = document.body.clientHeight;
  }	
  
  // for small pages with total height less then height of the viewport
  if(yScroll < windowHeight){
  	pageHeight = windowHeight;
  } else { 
  	pageHeight = yScroll;
  }
  
  // for small pages with total width less then width of the viewport
  if(xScroll < windowWidth){	
  	pageWidth = windowWidth;
  } else {
  	pageWidth = xScroll;
  }
  
  
  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
  return arrayPageSize;
}


function StopScroll(){
  var arrayPageScroll = getPageScroll();
  if (arrayPageScroll[1] != MaxYScroll){ window.scroll(0,MaxYScroll); }
}      


function showLightbox (iframeurl,contentid,reloadafter) {
  changeContent = contentid;
  reloadAfter = reloadafter
  
  var arrayPageSize = getPageSize();
  var arrayPageScroll = getPageScroll();
  	
  document.getElementById('lightbox_fade').style.height = (arrayPageSize[1] + 'px');
  document.getElementById('lightbox_light').style.height = ((arrayPageSize[3] - 40) + 'px');
  document.getElementById('lightbox_light').style.top = ((arrayPageScroll[1] + 20) + 'px');
  document.getElementById('lightbox_close').style.top = ((arrayPageScroll[1] + 20) + 'px');
  
  document.getElementById('lightbox_light').style.display='block';
  document.getElementById('lightbox_fade').style.display='block';
  document.getElementById('lightbox_close').style.display='block';
  document.getElementById('lightbox_iframe').src=iframeurl;
  
  MaxYScroll = arrayPageScroll[1];
  window.onscroll=StopScroll;
}



function hideLightbox () {
  document.getElementById('lightbox_light').style.display='none';
  document.getElementById('lightbox_fade').style.display='none';
  document.getElementById('lightbox_close').style.display='none';
  document.getElementById('lightbox_iframe').src='';
  if (changeContent) {
    changeContent = null;
  }
  if (reloadAfter) {
    reloadAfter = null;
    window.location.href = window.location.href;
  }
  
  window.onscroll='';
}

function subcontent_moveup () {
  if (activeElement != null) {
    window.location.href = baseurl + '&moveup=' + activeElement.split('_')[1];
  }
}

function subcontent_movedown () {
  if (activeElement != null) {
    window.location.href = baseurl + '&movedown=' + activeElement.split('_')[1];
  }
}

function subcontent_remove () {
  if (activeElement != null) {
    window.location.href = baseurl + '&remove=' + activeElement.split('_')[1];
  }
}

function subcontent_edit () {
  if (activeElement != null) {
    showLightbox (settingsurl + '?param_dynamic_dbsubcontentsettings_editor=' + activeElement.split('_')[1], null, 1);
  }
}

function subcontent_add () {
  if (activeElement != null) {
    showLightbox (settingsurl + '?param_dynamic_dbsubcontentsettings_create=' + activeElement.split('_')[1], null, 1);
  }
}  

function selectcontent(contentid) 
{
  if (changeContent != null) {
    document.getElementById(changeContent).value = contentid;
  }
 // document.getElementById(changecontent+'_preview').innerHTML ='definiert';
}


