var at_StandardSpalten = new Array(), at_lastTRclass, at_click = new Array(), at_zusatz_parameter = '', at_lastParameters, enable_click = false;;

function at_TRmouseover(objekt, TID) {
	if (at_click[TID]['at_last_mo_obj'] != '' && at_click[TID]['at_last_mo_obj'] != at_click[TID]['at_old_tr']) {
		at_click[TID]['at_last_mo_obj'].style.backgroundColor = at_click[TID]['at_lastTRbgcolor'];
		at_click[TID]['at_last_mo_obj'].style.color = '#454545';
		at_click[TID]['at_lastTRbgcolor'] = '';
		at_click[TID]['at_last_mo_obj'] = '';
	}

	if (objekt != at_click[TID]['at_old_tr']) {
		at_click[TID]['at_lastTRbgcolor'] = objekt.style.backgroundColor;
		at_click[TID]['at_last_mo_obj'] = objekt;
		//objekt.style.backgroundColor = '#76a2e0';
		//objekt.style.color = '#FFFFFF';
	}
/*
	document.getElementById('txt').innerHTML = objekt;
	var tooltip = document.getElementById('at_' + TID + '_tooltip'), yPos_TT;
	if (tooltip) {
		tooltip.style.display = 'block';

		yPos_TT = yPos - 247;
		if (TOPBAR != '1') yPos_TT = yPos_TT - 76;
		if (yPos_TT > 300) yPos_TT = yPos_TT - (tooltip.offsetHeight + 30);
		tooltip.style.top = (yPos_TT +30) + 'px';
	}
	*/
}

function at_TRmouseout(objekt, TID) {
	if (objekt != at_click[TID]['at_old_tr']) {
	//	objekt.style.backgroundColor = at_click[TID]['at_lastTRbgcolor'];
	//	objekt.style.color = '#454545';
		at_click[TID]['at_lastTRbgcolor'] = '';
		at_click[TID]['at_last_mo_obj'] = '';
	}
//	return "";
}

function at_ClickEntry(TID, tr_el, SrcTableID) {
	at_TRmouseout(tr_el, TID)
	if (at_click[TID]['at_old_tr'] != '') {
		at_click[TID]['at_old_tr'].style.backgroundColor = at_click[TID]['at_old_tr_bgColor'];
		at_click[TID]['at_old_tr'].style.color = '#454545';
	}
	if (tr_el != at_click[TID]['at_old_tr']) {
		enable_click = true;
		at_click[TID]['at_old_SrcTableID'] = SrcTableID;
		at_click[TID]['at_old_tr'] = tr_el;
		at_click[TID]['at_old_tr_bgColor'] = tr_el.style.backgroundColor;
		at_click[TID]['at_old_tr'].style.backgroundColor = '#3d80df';
		at_click[TID]['at_old_tr'].style.color = '#FFFFFF';
	} else {
		enable_click = false;
		at_click[TID]['at_old_SrcTableID'] = '';
		at_click[TID]['at_old_tr'] = '';
	}
}

function at(TID, key, parameters) {
//alert(parameters);
	at_lastParameters = parameters;
    var xhr = http(), params = AJAXBURL+"rootpath_parent="+rootpath+at_zusatz_parameter+"&qid="+qid+"&TID="+TID+"&key="+key+'&vw='+vw+"&"+parameters;
    xhr.open("POST", rootpath + "includes/at/ajax.php", true);
    xhr.onreadystatechange = function() {
  	  if (xhr.readyState == 4) {
	   	var rueckgabe = xhr.responseText;
//alert(rueckgabe);
		at_jscode(rueckgabe);
		document.getElementById('at_div_'+TID).innerHTML = rueckgabe;
		if (document.getElementById('loadingbox')) document.getElementById('loadingbox').style.display = 'none';
//		if (vw > 1 && key == 'chgbox') at_Click
	}
    }
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //alert(params);
    xhr.send(params);
	if (document.getElementById('loadingbox')) document.getElementById('loadingbox').style.display = 'block';
    else alert('no loadingbox')
}

function at_jscode(rueckgabe) {
	var c = rueckgabe.split('<script type='), jscode = '';
	if (c.length > 1) {
		lastcount =  c[1].indexOf('</script');
		jscode = c[1].substring(18,lastcount);
		eval(jscode);
	}
}

function at_chgbox(TID, type, absolut_positioniertes_parent) {
	var frm = 'frmChgBox_' + TID, el;
	if (type == 'standard') {
		for (var index = 0; index < document.forms[frm].elements.length; index++) {
			if (in_array(document.forms[frm].elements[index].value, at_StandardSpalten[TID])) document.forms[frm].elements[index].checked = true;
			else document.forms[frm].elements[index].checked = false;
		}
		CheckChgBox(TID, true, true);
	} else if (type == 'all_on') {
		for (var index = 0; index < document.forms[frm].elements.length; index++) {
			document.forms[frm].elements[index].checked = true;
		}
		CheckChgBox(TID, true, true);
	} else if (type == 'all_off') {
		for (var index = 0; index < document.forms[frm].elements.length; index++) {
			document.forms[frm].elements[index].checked = false;
		}
		CheckChgBox(TID, false, true);
	} else if (type == 'ok' && CheckChgBox(TID, true, false) == true) {
		var neueSpalten = new Array();
		for (var index = 0; index < document.forms[frm].elements.length; index++) {
			el = document.forms[frm].elements[index];
			if (el.checked == true) neueSpalten.push(el.value);
		}
		at(TID, 'chgbox', at_lastParameters + '&cols='+neueSpalten);
	} else if (type == 'reset') {
		document.forms[frm].reset();
		CheckChgBox(TID, true, true);
	} else if (type == 'set_pos') {
        if (absolut_positioniertes_parent != '') {
            // bei absolut positionierte Parents darf nicht yPos dazuaddiert werden!
            // yPos gibt die Position des Mauszeigers an
            // stattessen wird ein anderer Wert aus der at/data/X.inc.php verwendet
            var newYPos = absolut_positioniertes_parent;
        } else {
            var newYPos = yPos + 15;
    		newYPos = newYPos - 250;
    		if (TOPBAR != '1' && TOPBAR != 1) newYPos = newYPos + 75;
        }

		document.getElementById('at_' + TID + '_chgbox').style.top = newYPos + 'px';
	}
}

function CheckChgBox(TID, checken, veraenderung) {
	var frm = 'frmChgBox_' + TID, ok = false;
	if (checken == true) {
		// Ueberprueft ob noch minimum ein Feld aktiv ist
		for (var index = 0; index < document.forms[frm].elements.length; index++) {
			if (document.forms[frm].elements[index].checked == true) {
				ok = true;
				break;
			}
		}
	}

	if (ok == false && veraenderung == true) {
		// Setze den Button inaktiv
		document.getElementById('btn'+TID+'_chgbox_ok_inner').className = "btn_center colour15 fsize_md";
		document.getElementById('btn'+TID+'_chgbox_ok_outer').style.cursor = 'default';
	} else if (ok == true && veraenderung == true) {
		// Setze den Button aktiv
		document.getElementById('btn'+TID+'_chgbox_ok_inner').className = "btn_center colour10 fsize_md";
		document.getElementById('btn'+TID+'_chgbox_ok_outer').style.cursor = 'pointer';
	}

	return ok;
}

function in_array(wert, array1) {
	var im_array = false;
	for (var index in array1) {
		if (wert == array1[index]) im_array = true;
	}
	return im_array;
}
