function preloadImages() {
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function swapImgRestore() {
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() {
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function goToURL() { //v3.0
  var i, args=goToURL.arguments; document.returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function dumb(vars) {
		window.location.href = vars;
}

function doLinkLeftFrame(link)
{
 parent.leftFrame.location.href=link;
}

function doLinkMainFrame(link)
{
 parent.mainFrame.location.href=link;
}

function doLinkHeader(link)
{
 parent.header.location.href=link;
}

function doLinkTreeStat(link)
{
 parent.treestat.location.href=link;
}




function reloadTreeStat(lang)
{
	parent.treestat.document.treestatform.submit();
}

function reloadTree() {
	parent.leftFrame.document.location.href='/chameleon/admin/webpage/navi.php';
}

function reloadTplTree() {
	parent.leftFrame.document.location.href='/chameleon/admin/template/navi.php';
	
}

function reloadLstTree() {
	parent.leftFrame.document.location.href='/chameleon/admin/table/navi.php';
	
}

function reloadPlstTree() {
	parent.leftFrame.document.location.href='/chameleon/admin/mediaplayer/navi.php';
	
}

function reloadBlogTree() {
	parent.leftFrame.document.location.href='/chameleon/admin/blog/navi.php';
	
}

function reloadGalTree() {
	parent.leftFrame.document.location.href='/chameleon/admin/gallery/navi.php';
	
}
function loadThisInLeftFrame(href) {
	parent.leftFrame.document.location.href=href;
}





var image_action = true
function openImageWindow() {
    wp_openDialog('../../editor/dialog_frame.php?window=image.php&return_function=insertImg', 'modal',730,466)
}
function insertImg(iurl, iwidth, iheight, ialign, ialt, iborder, imargin) {
    document.form1.image.value=iurl;
}

function openDocWindow() {
    wp_openDialog('../../editor/dialog_frame.php?window=document.php&return_function=insertDoc', 'modal',730,466)
}
function insertDoc(iHref,iTarget,iTitle) {
    document.form1.document.value=iHref;
}
function rockNroll(href) {
  win1 = window.open(href, "GalleryView", "width=420,height=370,left=100,top=200");
  win1.focus();
}



function getStat(id) {
	if (stat = parent.treestat.document.getElementById(id).value) {
		if (stat == 'off')
			document.getElementById(id).style.display = 'none';
		if (stat == 'on')
			document.getElementById(id).style.display = 'block';
	}
}


function treeklapper(id) {
	if (obj = document.getElementById(id)) {
		if(obj.style.display == 'none') {
			obj.style.display = 'block';
			if (btn = document.getElementById('btn_'+id)) {
				btn.src = '/chameleon/gui/standard/img/btn_minus9px.gif'
			}
			
			if (layer = parent.treestat.document.getElementById(id)) {
				layer.value = 'on';
			}
			if (hinzu = parent.treestat.document.getElementById('new_'+id)) {
				hinzu.value = 'on';
			}
		} else {
			obj.style.display = 'none';
			if (btn = document.getElementById('btn_'+id)) {
				btn.src = '/chameleon/gui/standard/img/btn_plus9px.gif'
			}

			if (layer = parent.treestat.document.getElementById(id)) {
				layer.value = 'off';
			}

			if (hinzu = parent.treestat.document.getElementById('new_'+id)) {
				hinzu.value = 'off';
			}
		}
	} else {
		
		if (obj = document.getElementById('new_'+id)) {
			if(obj.style.display == 'none') {
				obj.style.display = 'block';
				if (btn = document.getElementById('btn_'+id)) {
					btn.src = '/chameleon/gui/standard/img/btn_minus9px.gif'
				}
				if (hinzu = parent.treestat.document.getElementById('new_'+id)) {
					hinzu.value = 'on';
				}
			} else {
				obj.style.display = 'none';
				if (btn = document.getElementById('btn_'+id)) {
					btn.src = '/chameleon/gui/standard/img/btn_plus9px.gif'
				}
				if (hinzu = parent.treestat.document.getElementById('new_'+id)) {
					hinzu.value = 'off';
				}
			}
		}
	
	}
}
function changeVis(str) {
	obj1 = document.getElementById("help_"+str);
	obj2 = document.getElementById("more_"+str);
	obj3 = document.getElementById("clos_"+str);
	
	if(obj1.style.display == 'none') {
		obj1.style.display = 'block';
		obj2.style.display = 'none';
		obj3.style.display = 'block';
	} else {
		obj1.style.display = 'none';
		obj2.style.display = 'block';
		obj3.style.display = 'none';
	}
}

/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;

/**
 * enables highlight and marking of rows in data tables
 *
 */
function PMA_markRowsInit() {
    // for every table row ...
    var rows = document.getElementsByTagName('tr');
    for ( var i = 0; i < rows.length; i++ ) {
        // ... with the class 'odd' or 'even' ...
        if ( 'odd' != rows[i].className.substr(0,3) && 'even' != rows[i].className.substr(0,4) ) {
            continue;
        }
        // ... add event listeners ...
        // ... to highlight the row on mouseover ...
        if ( navigator.appName == 'Microsoft Internet Explorer' ) {
            // but only for IE, other browsers are handled by :hover in css
            rows[i].onmouseover = function() {
                this.className += ' hover';
            }
            rows[i].onmouseout = function() {
                this.className = this.className.replace( ' hover', '' );
            }
        }
        // Do not set click events if not wanted
        if (rows[i].className.search(/noclick/) != -1) {
            continue;
        }
        // ... and to mark the row on click ...
        rows[i].onmousedown = function() {
            var unique_id;
            var checkbox;

            checkbox = this.getElementsByTagName( 'input' )[0];
            if ( checkbox && checkbox.type == 'checkbox' ) {
                unique_id = checkbox.name + checkbox.value;
            } else if ( this.id.length > 0 ) {
                unique_id = this.id;
            } else {
                return;
            }

            if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                marked_row[unique_id] = true;
            } else {
                marked_row[unique_id] = false;
            }

            if ( marked_row[unique_id] ) {
                this.className += ' marked';
            } else {
                this.className = this.className.replace(' marked', '');
            }

            if ( checkbox && checkbox.disabled == false ) {
                checkbox.checked = marked_row[unique_id];
            }
        }

        // ... and disable label ...
        var labeltag = rows[i].getElementsByTagName('label')[0];
        if ( labeltag ) {
            labeltag.onclick = function() {
                return false;
            }
        }
        // .. and checkbox clicks
        var checkbox = rows[i].getElementsByTagName('input')[0];
        if ( checkbox ) {
            checkbox.onclick = function() {
                // opera does not recognize return false;
                this.checked = ! this.checked;
            }
        }
    }
}


function mark_rows(checkbox_id) {
    var checkbox = document.getElementById(checkbox_id);
	if (checkbox.checked == true) {
		markAllRows('tbl_'+checkbox_id )
	} else {
		unMarkAllRows('tbl_'+checkbox_id )
	}
}

function markAllRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            if ( checkbox.disabled == false ) {
                checkbox.checked = true;
				rows[i].className = ' marked';
                if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                    rows[i].className += ' marked';
                    marked_row[unique_id] = true;
                }
            }
        }
    }

    return true;
}

function unMarkAllRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            checkbox.checked = false;
				rows[i].className = ' odd';
            rows[i].className = rows[i].className.replace(' marked', '');
            marked_row[unique_id] = false;
        }
    }

    return true;
}

function check_cmssavebox(form) {
	if (form.getElementsByTagName('select')[0].value == '')
	return false;
	f = form.submit();
}


function blurlinks() {
	var e = document.getElementsByTagName('a');
	for (i = 0; i < e.length; i++) {
		e[i].onfocus = 	function() { this.blur(); }
	}
}

function chameleon_init() {
	blurlinks();
	PMA_markRowsInit();
}
window.onload = chameleon_init;

function switchNaviBG(id) {
	
	tbl = document.getElementById('tbl_navi');
	td = tbl.getElementsByTagName('td');
	for (i = 0; i < td.length; i++) {
		td[i].className = '';
	}

	document.getElementById('td_'+id).className = ' active';
}


function showSektion1 () {
	document.getElementById('sektionauswahl').src = '/chameleon/site/img/Sektionen/sektion1gr.jpg';
}
function showSektion2 () {
	document.getElementById('sektionauswahl').src = '/chameleon/site/img/Sektionen/sektion2gr.jpg';
}
function showSektion3 () {
	document.getElementById('sektionauswahl').src = '/chameleon/site/img/Sektionen/sektion3gr.jpg';
}
function showSektion4 () {
	document.getElementById('sektionauswahl').src = '/chameleon/site/img/Sektionen/sektion4gr.jpg';
}
	
