// DIV anzeigen/ausblenden
function toggle(objid) {
	if(document.getElementById(objid).style.display == "none") {
		document.getElementById(objid).style.display = "block";
	}
	else {
		document.getElementById(objid).style.display = "none";
	}
}

function show(objekt) {
	if(document.getElementById(objekt) != null) {
		document.getElementById(objekt).style.display = "block";
	}
}

function hide(objekt) {
	if(document.getElementById(objekt) != null) {
		document.getElementById(objekt).style.display = "none";
	}
}

var win= null;
function popup(url,w,h,scroll){
	//var winl = (screen.width-w)/2;
	//var wint = (screen.height-h)/2;
	var winl = 650;
	var wint = 300;
	
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars='+scroll+',';
	settings +='resizable=yes';
	
	win = window.open(url,"myPopup",settings);
	
	if (parseInt(navigator.appVersion) >= 4){
		win.window.focus();
	}
}


function sendform(frm) {
	document.getElementById(frm).submit();
}

function save(formName, submitbutton) {
	document.getElementById(submitbutton).disabled = true;	
	sendform(formName);
}

function delItem(mod, id, querystring)
{
	conf = confirm('Wirklich löschen?');
	
	if(conf == true) {
		location.href = querystring + "&action=delete&id=" + id;
		//alert(querystring + "&action=delete&id=" + id);
	}
}

function selPerpage(dest) {
	location.href = dest + document.getElementById('selPerpage').value;
}

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	} 
	
	return false;
	//alert('Query Variable ' + variable + ' not found');
}

function isFunction(a) {
     return typeof a == 'function';
}

function isUndefined(a) {
    return typeof a == 'undefined';
}

function isObject(a) {
    return (typeof a == 'object' && !!a) || isFunction(a);
}

function refreshFauna() {
	if (isObject(document.getElementById('ajax_subjects_tags'))) {
		readFile('ajax_subjects_tags.php?id=' + getQueryVariable("id"), 'ajax_subjects_tags');	
	} else if (isObject(document.getElementById('ajax_attached_files'))) {
		var params = "?item=" + getQueryVariable("p") + "&id=" + getQueryVariable("id");
		readFile('ajax_attached_files.php' + params, 'ajax_attached_files');	
	}
}


/** 
 * Ajax Start
 *
 */ 
function create_HTTP_con() {
	if(window.XMLHttpRequest) {
		HTTP_con = new XMLHttpRequest();
		return true;
	}
	else if(window.ActiveXObject) {
		HTTP_con = new ActiveXObject("Microsoft.XMLHTTP");
		return true;
	}
	else {
		return false;
	}
}

function readFile(path, target) {
	if(create_HTTP_con()) {
		HTTP_con.onreadystatechange = function() {
			if(HTTP_con.readyState == 4) {
				res = HTTP_con.responseText;
				document.getElementById(target).innerHTML = res;
			}
		}
		HTTP_con.open ('GET', path, true);
	}
	HTTP_con.send ('');
}

/** 
 * Ajax End
 *
 */ 