
/**
 * 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 ( 'lk_table_bg' != rows[i].className.substr(0,11) ) {
            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;
            }
        }
    }
}


/**
 * marks all rows and selects its first checkbox inside the given element
 * the given element is usaly a table or a div containing the table or tables
 *
 * @param    container    DOM element
 */
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;
                if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                    rows[i].className += ' marked';
                    marked_row[unique_id] = true;
                }
            }
        }
    }

    return true;
}

/**
 * marks all rows and selects its first checkbox inside the given element
 * the given element is usaly a table or a div containing the table or tables
 *
 * @param    container    DOM element
 */
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 = rows[i].className.replace(' marked', '');
            marked_row[unique_id] = false;
        }
    }

    return true;
    
  
}

function SyncComboBoxValue(container_id, from_combo, to_combo_id)	{
		var to_combo = document.getElementById(to_combo_id);
		if (to_combo !== null) to_combo.value = from_combo.value;
	}  
	
function lk_showwaitingwindow()
	{
	var w;
	var h;

	h = lk_windowheight();
	w = lk_windowidth();
	
	w = w - 5;
	h = h - 5;
  if (document.all)            /* wenn Microsoft-Modell */
  {
    document.all.waitingbox.style.width=w + "px"; /* x verschieben */
    document.all.waitingbox.style.height=h + "px";  /* y verschieben */
    document.all.waitingbox.style.visibility="visible";  /* y verschieben */
  }
  else
  if (typeof(document.getElementById)=="function")
                               /* wenn Netscape 6.x */
  {
    document.getElementById("waitingbox").style.width = w + "px"; /* x verschieben */
    document.getElementById("waitingbox").style.height=h + "px";  /* y verschieben */
    document.getElementById("waitingbox").style.visibility="visible";
  }
  else
  if (document.waitingbox)       /* wenn Netscape 4.x */
  {
    document.waitingbox.width=w + "px";  /* x verschieben */
    document.waitingbox.height=h + "px";   /* y verschieben */
    document.waitingbox.visibility="visible";
  }
	
	
	}

function lk_windowwidth()
	{
		var w;
		
		
	  if (window.innerWidth) {
	    w = window.innerWidth;
	  } else if (document.body && document.body.offsetWidth) {
	    w = document.body.offsetWidth;
	  } else {
	    w = 0;
	  }
		return w;  
	
	}	
	
function lk_windowheight()
	{
		var h;
	  if (window.innerHeight) {
	    h = window.innerHeight;
	  } else if (document.body && document.body.offsetHeight) {
	    h = document.body.offsetHeight;
	  } else {
	    h = 0;
	  }
		return h;
	}

function lk_divresize(divid, w, h)
	{
	  if (document.all)            /* wenn Microsoft-Modell */
	  {
	    document.all[divid].style.width=w + "px"; /* x verschieben */
	    document.all[divid].style.height=h + "px";  /* y verschieben */
	  }
	  else
	  if (typeof(document.getElementById)=="function")
	                               /* wenn Netscape 6.x */
	  {
	    document.getElementById(divid).style.width = w + "px"; /* x verschieben */
	    document.getElementById(divid).style.height=h + "px";  /* y verschieben */
	  }
	  else
	  if (document[divid])       /* wenn Netscape 4.x */
	  {
	    document[divid].width=w + "px";  /* x verschieben */
	    document[divid].height=h + "px";  /* x verschieben */
	  }
		
	}	
	

	
function lk_check(cls, el){
	$$('.'+cls).each(function(e){
		e.checked = el.checked;
	});
}

function lk_mailtemplate_text_insertvar(selectid, txtid){
	sel = $(selectid);
	txt = $(txtid);
	
	textarea_insert(txt, '${' + sel.value + '}');
}

function lk_mailtemplate_html_insertvar(selectid, spaw){
	sel = $(selectid);
	
	spaw.insertHtmlAtSelection('${' + sel.value + '}');
}

function textarea_insert(input, insText) {
  input.focus();
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var range = document.selection.createRange();
    
    range.text = insText;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    
    range.moveStart('character', insText.length);      
    range.select();
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    input.value = input.value.substr(0, start) + insText + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    
    pos = start + insText.length;
    
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* für die übrigen Browser */
  else
  {
    input += insText;
  }
}


