	var http = false;
	var alertbox = false;
	var inwork=false;
function Switcher(radiobox)
{
  for (i=1; i < radiobox.length + 1; i++) {
  ES = document.getElementById("ES" + i);
    if (ES.checked == true) {
      document.getElementById(ES.value + "[value]").innerHTML=document.getElementById(ES.value).value;
    }else{
      if(document.getElementById(ES.value))
      value_input = document.getElementById(ES.value).value;
      else
      value_input = document.getElementById(ES.value + "[value]").innerHTML;
      document.getElementById(ES.value + "[value]").innerHTML='<input id="'+ES.value+'" name="ErgebnisInput" class="currency" type="text" onkeyup="format(this.value,this.id)" value="'+ value_input +'" />';
    }
  }
}


function entry_load(action,id,field,addit) {
	if(id == "selects")id=selects;
    if(action=='delete' && !confirm('Wollen Sie den Eintrag wirklich l�schen?')) return false;
	sendRequest('?', 'do='+action+'&id='+id, field, addit);
}

function entry_load_strategies(action,id,isin,field,addit) {		
	if(action == 'save_asset'){
		branche_id=document.getElementById('select_assets_'+id).value;
		min_gewichtung=document.getElementById('min_gewichtung_'+id).value;
		max_gewichtung=document.getElementById('max_gewichtung_'+id).value;
		inwork=false;
	}else{
		branche_id="";
		min_gewichtung="";
		max_gewichtung="";
	}
	
	if(action == 'save_fonds'){
		if(document.getElementById('select_fonds_'+id)) isin=document.getElementById('select_fonds_'+id).value;
		gewichtung=document.getElementById('gewichtung_'+id).value;
		fonds_id=document.getElementById('editfonds_'+id).value;
		inwork=false;
	}else{
		gewichtung="";
		fonds_id="";
	}
	
	if(action == 'get_fondslist'){
		branche_id=document.getElementById('assets_'+id).value;
		inwork=false;
	}
	
	if(action == 'get_gewichtungslist'){
		branche_id=document.getElementById('assets_'+id).value;
		inwork=false;
	}
	
	if(action == 'save_strategy'){
		title=document.getElementById('title_'+id).value;
		text=document.getElementById('text_'+id).value;
		inwork=false;
	}else{
		title="";
		text="";
	}

	if (inwork) {
		alert('Bitte speichern Sie zu erst Ihre offenen Änderungen.');
		return false;
	}

    sendRequest('?', 'do='+action+'&id='+id+'&isin='+isin+'&gewichtung='+gewichtung+'&branche_id='+branche_id+'&fonds_id='+fonds_id+'&min_gewichtung='+min_gewichtung+'&max_gewichtung='+max_gewichtung+'&title='+title+'&text='+text, field, addit);
}

function GetCalendar(month,field,query) {
	sendRequest('ajaxrequest.php', 'do=calendar&month=' + month + '&query=' + query, field,0);
}

function SetIP(fieldid)
{
	sendRequest('http://www.opal-consulting.com/getip.php', '', fieldid, 'form');
}



function format(number,div){
	var number = new String(number); 
	number = str_replace('.', '', number);
	number = str_replace(',', '.', number);	if(number.split('.')[1] < 100 || (number.search(/\./) != -1 && number.split('.')[1] == false)) return false;
	sendRequest('?', 'do=format&math='+number, div, 'form');
	math_investment(document.einmalzahlung.ErgebnisInput);
}

function math_investment(inputbox){
	if(inputbox.length>3)return false;
	if(document.getElementById('Vari[Anlagebetrag]')) var Anlagebetrag= str_replace('.', '', document.getElementById('Vari[Anlagebetrag]').value); else result='Vari[Anlagebetrag][value]';
	if(document.getElementById('Vari[Zinssatz]')) var Zinssatz 	= str_replace('.', '', document.getElementById('Vari[Zinssatz]').value); else result='Vari[Zinssatz][value]';
	if(document.getElementById('Vari[Anlagedauer]')) var Anlagedauer = str_replace('.', '', document.getElementById('Vari[Anlagedauer]').value); else result='Vari[Anlagedauer][value]';
	if(document.getElementById('Vari[Endbetrag]')) var Endbetrag 	= str_replace('.', '', document.getElementById('Vari[Endbetrag]').value); else result='Vari[Endbetrag][value]';

	sendRequest('?', 'do=einmalzahlung&Anlagebetrag='+Anlagebetrag+'&Zinssatz='+Zinssatz+'&Anlagedauer='+Anlagedauer+'&Endbetrag='+Endbetrag, result);
}

/* TEST BEGINN */
function new_entry(where,what,id,add,reload) {
    sendRequest('?', 'do='+what+'&id='+id, where, add);
    if(reload > 0) window.setTimeout("location.reload()", 500);
    if(reload == -1) window.setTimeout("StartDragDrop()", 500);
}

function edit_entry(where,what,id) {
    if(document.getElementById('group_id') && id <= 0) var id = document.getElementById('group_id').value;	
    sendRequest('?', 'do='+what+'&id='+id, where);
}

function save_entry(where,what,id,sid,reload) {
	if(document.getElementById('date'+id)) var date = encodeURIComponent(document.getElementById('date'+id).value);
    if(document.getElementById('law_id'+id)) var law_id = encodeURIComponent(document.getElementById('law_id'+id).value);
    if(document.getElementById('title'+id)) var title = encodeURIComponent(document.getElementById('title'+id).value);
    if(document.getElementById('text'+id)) var text = encodeURIComponent(document.getElementById('text'+id).value);
    if(document.getElementById('verantstalter'+id)) var veranstalter = encodeURIComponent(document.getElementById('veranstalter'+id).value);
    if(document.getElementById('ort'+id)) var ort = encodeURIComponent(document.getElementById('ort'+id).value);
    if(document.getElementById('kategorie'+id)) var kategorie = encodeURIComponent(document.getElementById('kategorie'+id).value);
    if(document.getElementById('date_start'+id)) var date_start = encodeURIComponent(document.getElementById('date_start'+id).value);
    if(document.getElementById('date_end'+id)) var date_end = encodeURIComponent(document.getElementById('date_end'+id).value);
    sendRequest('?', 'do='+what+'&date='+date+'&law_id='+law_id+'&title='+title+'&text='+text+'&veranstalter='+veranstalter+'&ort='+ort+'&kategorie='+kategorie+'&date_start='+date_start+'&date_end='+date_end+'&id='+id+'&sid='+sid+'&uploads='+uploads, where);
	if(reload > 0) window.setTimeout("location.reload()", 500);
}

function delete_entry(where,what,id,reload) {
    if(document.getElementById('group_id') && id <= 0) var id = document.getElementById('group_id').value;
    if(confirm('Wollen Sie den Eintrag wirklich l�schen?')){
    	sendRequest('?', 'do='+what+'&id='+id, where);
		if(reload > 0) window.setTimeout("location.reload()", 500);
    }
}

function unvisible_entry(where,what,id) {
    if(document.getElementById('group_id') && id <= 0) var id = document.getElementById('group_id').value;
    sendRequest('?', 'do='+what+'&id='+id, where);
}


function upload_file(sid,allowed,path,newname) {
    sendRequest('upload.php', 'do=uploader&uploads='+uploads+'&sid='+sid+'&allowed='+allowed+'&path='+path+'&newname='+newname, 'uploader');
}

function access_file(what,id,file,access) {
    if(!access || confirm('Wollen Sie die Datei "'+file+'" wirklich f�r jeden Benutzer einsehbar machen?')){
        sendRequest('?', 'do='+what+'&oldfile='+file+'&access='+access+'&id='+id, 'file_'+file);
    }
}

function delete_file(what,id,file,access) {
    if(confirm('Wollen Sie die Datei "'+file+'" wirklich l�schen?')){
        sendRequest('?', 'do='+what+'&oldfile='+file+'&access='+access+'&id='+id, 'file_'+file);
    }
}
/* TEST END */

function search_network() {
    infos = new Object();
    counter = 0;
    
	for(var i = 1; i <= maxquestions;)
	{
		data = new Object();
		if(document.getElementById('selection'+i) && 
		   document.getElementById('answers'+i)){
			data['question'] = encodeURIComponent(document.getElementById('selection'+i).value);
			data['answer'] = encodeURIComponent(document.getElementById('answers'+i).value);
			infos[counter] = data;
			counter++;
		}
	i++;
	}
    sendRequest('?', 'infos='+JSON.stringify(infos), 'search_box');
}

function delete_network(e){
	if(document.getElementById('field'+e)) {
		document.getElementById('field'+e).innerHTML="";
		questions[e]['selected']=false;
		makeselect();
	}
}

function uploadFile(sid,allowed) {
    sendRequest('upload.php', 'do=uploader&uploads='+uploads+'&sid='+sid+'&allowed='+allowed, 'uploader');
}

function newPartnerCat() {
    sendRequest('?', 'do=new_cat', 'catlist', 2);
    window.setTimeout("location.reload()", 500);
}

function editPartnerCat(cat_id) {
    sendRequest('?', 'do=edit_cat&cat_id='+cat_id, 'c_title_'+cat_id);
}

function savePartnerCat(cat_id) {
    var title = encodeURIComponent(document.getElementById('title').value);
    sendRequest('?', 'do=save_cat&title='+title+'&cat_id='+cat_id, 'c_title_'+cat_id);
}

function deletePartnerCat(cat_id) {
    if(confirm('Wollen Sie den Eintrag wirklich l�schen?')){
        sendRequest('?', 'do=delete_cat&cat_id='+cat_id, 'c_title_'+cat_id);
    }
}

function newPartnerCatIn() {
    sendRequest('?', 'do=new', 'partnerlist[0]', 2);
    window.setTimeout("location.reload()", 500);
}

function editPartnerCatIn(p_id) {
    sendRequest('?', 'do=edit&p_id='+p_id, 'p_'+p_id);
}

function savePartnerCatIn(p_id,sid) {
    var title = encodeURIComponent(document.getElementById('title').value);
    var url = encodeURIComponent(document.getElementById('url').value);
    sendRequest('?', 'do=save&title='+title+'&url='+url+'&p_id='+p_id+'&sid='+sid+'&uploads='+uploads, 'p_'+p_id);
	window.setTimeout("location.reload()", 500);
}

function deletePartnerCatIn(p_id) {
    if(confirm('Wollen Sie den Eintrag wirklich l�schen?')){
        sendRequest('?', 'do=delete&p_id='+p_id, 'p_'+p_id);
        window.setTimeout("location.reload()", 500);
    }
}

function saveAwCatIn(cat_in_id,sid) {
    var title = encodeURIComponent(document.getElementById('title'+cat_in_id).value);
    var text  = encodeURIComponent(document.getElementById('text'+cat_in_id).value);
    sendRequest('?', 'do=save&title='+title+'&text='+text+'&cat_in_id='+cat_in_id+'&sid='+sid+'&uploads='+uploads, 'cat_info'+cat_in_id);
}

function accessFileAw(id,file,access) {
    if(!access || confirm('Wollen Sie die Datei "'+file+'" wirklich f�r jeden Benutzer einsehbar machen?')){
        sendRequest('?', 'do=accessFile_info&oldfile='+file+'&access='+access+'&id='+id, 'file_'+file);
    }
}

function deleteFileAw(id,file,access) {
    if(confirm('Wollen Sie die Datei "'+file+'" wirklich l�schen?')){
        sendRequest('?', 'do=delete_info&oldfile='+file+'&access='+access+'&id='+id, 'file_'+file);
    }
}

function accessFileAwCatIn(cat_in_id,file,access) {
    if(!access || confirm('Wollen Sie die Datei "'+file+'" wirklich f�r jeden Benutzer einsehbar machen?')){
        sendRequest('?', 'do=accessFile&oldfile='+file+'&access='+access+'&cat_in_id='+cat_in_id, 'file_'+file);
    }
}

function deleteFileAwCatIn(cat_in_id,file,access) {
    if(confirm('Wollen Sie die Datei "'+file+'" wirklich l�schen?')){
        sendRequest('?', 'do=delete&oldfile='+file+'&access='+access+'&cat_in_id='+cat_in_id, 'file_'+file);
    }
}

function editLexCatIn(cat_in_id) {
    sendRequest('?', 'do=edit&cat_in_id='+cat_in_id, 'lexikon_entry'+cat_in_id);
}
function saveLexCatIn(cat_in_id,sid) {
    var title = encodeURIComponent(document.getElementById('title'+cat_in_id).value);
    var text  = encodeURIComponent(document.getElementById('text'+cat_in_id).value);
    sendRequest('?', 'do=save&title='+title+'&text='+text+'&cat_in_id='+cat_in_id+'&sid='+sid+'&uploads='+uploads, 'lexikon_entry'+cat_in_id);
}
function newLexCatIn(cat_id) {
    sendRequest('?', 'do=new&cat_id='+cat_id,'lex_content',2);
}

function deleteLexCatIn(cat_in_id) {
    if(confirm('Wollen Sie den Eintrag wirklich l�schen?')){
        sendRequest('?', 'do=delete&cat_in_id='+cat_in_id, 'lexikon_entry'+cat_in_id);
    }
}

function checkZip(plzbox,ortbox_id) {
	if(inputbox.value.length == 5) {
		sendRequest('/ajaxrequest.php', 'do=zipcode&zipcode=' + inputbox.value, ortbox_id);
	}
}


queue = new Array();
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
xmlHttp=getHTTPObject();
function sendRequest(file, queryString, div, ifadd) {
	if(xmlHttp) {
		/* Request Daten in die Warteschlange setzen, falls der vorherige noch nicht abgeschlossen ist */
		if(xmlHttp.readyState == 1 || xmlHttp.readyState == 2 || xmlHttp.readyState == 3) {
			if(alertbox){
				alert(alertbox); exit;
			}
			queueLength = queue.length;
			queue[queueLength] = new Array();
			queue[queueLength][0] = file;
			queue[queueLength][1] = queryString;
			queue[queueLength][2] = div;
			if(!ifadd) { document.getElementById(div).innerHTML = 'Bitte warten...'; } //Optionaler Infotext
		} else {
			if(queryString == "") {
				xmlHttp.open('GET', file, true);
			} else {
				xmlHttp.open('POST', file, true);
				xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				xmlHttp.send(queryString);
			}
			/*
				xmlHttp.open('FILE', file, true);
				xmlHttp.setRequestHeader('Content-Type', 'multipart/form-data');
				xmlHttp.send(queryString);
			*/
			if(!div) return false;
			xmlHttp.onreadystatechange = function () {
				if(xmlHttp.readyState == 2) {
					if(!ifadd) document.getElementById(div).innerHTML = 'Lade Inhalt...';
				}
				if(xmlHttp.readyState == 4) {
					if(xmlHttp.status == 200) {
						if(ifadd){
							if(ifadd=="before")
								document.getElementById(div).innerHTML = xmlHttp.responseText + document.getElementById(div).innerHTML;
							else if(ifadd == "form")
								document.getElementById(div).value = xmlHttp.responseText;
							else
								document.getElementById(div).innerHTML = document.getElementById(div).innerHTML + xmlHttp.responseText;
						}
						else
							document.getElementById(div).innerHTML = xmlHttp.responseText;
					} else if(xmlHttp.status == 404) {
						document.getElementById(div).innerHTML = 'Die Datei wurde nicht gefunden!';
					}
					/* Warteschlange abarbeiten */
					queueLength = queue.length;
					if(queueLength != 0) {
						sendRequest(queue[0][0], queue[0][1], queue[0][2]);
						queue.shift(); //Erstes Element entfernen, den Rest eine Position nach vorne r�cken
					}
				}
		   };
		  if(queryString == "") {
				xmlHttp.send(null);
		  }
		}
	}
}

