var xmlHttp
var resultfield;
var field;

function showResult(str, resultID, table, type)
{	
	resultfield = "results_" + resultID;
	inputfield = resultID + "_field";
	typeid = type;

	
	document.getElementById(inputfield).setAttribute("autocomplete","off");
	
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	var url="/../acp/lib/getcontent.php"
	url=url+"?q=" + str + "&table=" + table + "&valuefield=" + inputfield + "&formfield=" + resultID + "&resultbox=" + resultfield  + "&type=" + typeid


	
	if ( str.length == 0 )
	{ 
		document.getElementById(inputfield).style.backgroundImage = "url(./images/icons/selectbox_arrow.gif)";
		document.getElementById(resultfield).style.display = "none";
	
	}else{
		
		xmlHttp.onreadystatechange=stateChanged
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}
} 

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById(resultfield).innerHTML = xmlHttp.responseText;
		document.getElementById(resultfield).style.display = "block";		
		
		document.getElementById(inputfield).style.backgroundImage = "url(./images/icons/selectbox_arrow.gif)";
	
	}else if( xmlHttp.readyState==4 ){
		document.getElementById(resultfield).style.display = "none";		
	}

}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		 // Internet Explorer
		 try
		 {
		 	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		 }
		 catch (e)
		 {
		 	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		 }
	}
	
	return xmlHttp
}


function dbcheck(str, field, table)
{	
	showfield = "results_" + field;

	document.getElementById(field).setAttribute("autocomplete","off");
	
	if (str.length==0)
	{ 
		 document.getElementById(showfield).style.display = "none";
		 return
	}

	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 

	var url="/../acp/lib/getcontent.php"
	url=url+"?q=" + str + "&table=" + table + "&field=" + field + "&type=5"
	
	xmlHttp.onreadystatechange=stateUpdated
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
} 

function stateUpdated() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById(showfield).innerHTML = xmlHttp.responseText;
		document.getElementById(showfield).style.display = "block";		
	}

}

 /*if( $_GET['type'] == 'add_location_user' )
 {
	$add_user = $Core->db->Execute( "INSERT INTO fcms_user (tou, ctr_id, username, name, email, password, usergroup, parentuserID, user_registered, status) VALUES (1, ".$_GET['ctr_id'].", '".strtolower($_GET['club']."-".$_GET['city'])."', '".$_GET['club']."-".$_GET['city']."', '".$_GET['email']."',  '".md5($new_pw)."', 4, ".$_GET['parentuserid'].",  ".$time.", 1)" );
 	*/

function addUser(type, username, ctr_id, email, parentuserid, relID)
{	
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 

	document.getElementById("addlocationuser").style.display = "none";
	document.getElementById("ajaxuseradd").style.display = "block";
	document.getElementById("ajaxuseradd").innerHTML = '<img src=\'images/addload.gif\' />';
		
	var url="/../acp/lib/setcontent.php";
	url=url+"?username=" + username +  "&ctr_id=" + ctr_id +  "&email=" + email +  "&parentuserid=" + parentuserid +  "&relatedID=" + relID + "&type=" + type;

	xmlHttp.onreadystatechange=useradded;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 


function useradded() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("ajaxuseradd").style.display = "block";		
		document.getElementById("addlocationuser").style.display = "none";		
	}
	
	if ( xmlHttp.responseText == 1 )
	{
		document.getElementById("ajaxuseradd").innerHTML = "<strong>Benutzer wurde bereits angelegt und hat bereits per E-Mail Zugangsdaten erhalten.</strong>";
				
	}
	else if ( xmlHttp.responseText == 2 )
	{
		document.getElementById("ajaxuseradd").innerHTML = "<strong>Der Benutzer wurde erfolgreich angelegt. Zugangsdaten wurden an Ihne via E-Mail gesendet!</strong>";
	}

}

/*
var contentSearchReq = false;
var t = null;
var contentSearchLast = "";
	
function requestData( queryfield, boxname, table )
{
	this.boxname = boxname;
	this.queryfield = queryfield;
	this.table = table;
}



var isIE = false;
// on !IE we only have to initialize it once
if (window.XMLHttpRequest) {
	contentSearchReq = new XMLHttpRequest();
}

function contentSearchInit() {
	
	if (navigator.userAgent.indexOf("Safari") > 0) 
	{
		document.getElementById(queryfield).addEventListener("keydown",contentSearchKeyPress,false);
	} 
	else if (navigator.product == "Gecko") 
	{	
		document.getElementById(queryfield).addEventListener("keypress",contentSearchKeyPress,false);
		document.getElementById(queryfield).addEventListener("blur",contentSearchHideDelayed,false);	
	} 
	else 
	{
		document.getElementById(queryfield).attachEvent('onkeydown',contentSearchKeyPress);
		isIE = true;
	}
	
	document.getElementById(queryfield).setAttribute("autocomplete","off");

}

function contentSearchHideDelayed() {
	window.setTimeout("contentSearchHide()",400);
}
	
function contentSearchHide() {
	return false;
}

function contentSearchKeyPress(event) {

	if (event.keyCode == 40 )
	//KEY DOWN
	{
		highlight = document.getElementById("LSHighlight");
		if (!highlight) {
			highlight = document.getElementById(boxname).firstChild.firstChild;
		} else {
			highlight.removeAttribute("id");
			highlight = highlight.nextSibling;
		}
		if (highlight) {
			highlight.setAttribute("id","LSHighlight");
		} 
		if (!isIE) { event.preventDefault(); }
	} 
	//KEY UP
	else if (event.keyCode == 38 ) {
		highlight = document.getElementById("LSHighlight");
		if (!highlight) {
			highlight = document.getElementById("LSResult").firstChild.firstChild.lastChild;
		} 
		else {
			highlight.removeAttribute("id");
			highlight = highlight.previousSibling;
		}
		if (highlight) {
				highlight.setAttribute("id","LSHighlight");
		}
		if (!isIE) { event.preventDefault(); }
	} 
	//ESC
	else if (event.keyCode == 27) {
		highlight = document.getElementById("LSHighlight");
		if (highlight) {
			highlight.removeAttribute("id");
		}
		document.getElementById(boxname).style.display = "none";
	} 
	//BACKSPACE - required for IE
	else if (event.keyCode == 8 && isIE) {
		contentSearchStart();
	}
	
	//RETURN
	else if (event.keyCode == 13 ) {
		return contentSearchSubmit();
	}
	
	
}
function contentSearchStart() {
	
	if (t) {
		window.clearTimeout(t);
	}
	t = window.setTimeout("contentSearchDoSearch()",200);
}

function contentSearchDoSearch() {

	if (typeof contentSearchRoot == "undefined") {
		contentSearchRoot = "";
	}
	if (typeof contentSearchRootSubDir == "undefined") {
		contentSearchRootSubDir = "";
	}
	if (typeof contentSearchParams == "undefined") {
		contentSearchParams2 = "";
	} else {
		contentSearchParams2 = "&" + contentSearchParams;
	}
	if (contentSearchLast != document.getElementById(queryfield).value) {
	if (contentSearchReq && contentSearchReq.readyState < 4) {
		contentSearchReq.abort();
	}
	if ( document.getElementById(queryfield).value == "") {
		contentSearchHide();
		contentSearchLast = "";
		return false;
	}
	if (window.XMLHttpRequest) {
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		contentSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
//alert(document.getElementById(queryfield).value);
	contentSearchReq.onreadystatechange = contentSearchProcessReqChange;
	contentSearchReq.open("GET", "./lib/getcontent.php?q=" + document.getElementById(queryfield).value + "&target=" + document.getElementById("fieldname").value + "&table=" + table + contentSearchParams2);
	contentSearchLast = document.getElementById(queryfield).value;
	contentSearchReq.send(null);
	
	}
}

function contentSearchProcessReqChange() {

	if (contentSearchReq.readyState == 4) {
		var  res = document.getElementById(boxname);
		res.style.display = "block";		
		res.innerHTML = contentSearchReq.responseText;
		 
	}
}

function contentSearchSubmit() {
	var highlight = document.getElementById("LSHighlight");
	if (highlight && highlight.firstChild) {
		window.location =highlight.firstChild.nextSibling.getAttribute("href");
		return false;
	} 
	else {
		return true;
	}
}*/