function closeModalDialog(){
	Dialog.closeInfo();
} 

function openModalDialog(urlToLoad, title, width, height){
	Dialog.info({url: urlToLoad}, {className: "spread", id: "modalPanel", title: title, width:width, height: height, closable: true, destroyOnClose: true});
}	

function addNewContactGoOn(transport){
	alert(transport.responseText);
	form=window.parent.document.getElementById("conferenceForm");
	form.elements["newContactId"].value="${actionBean.user.username}";
	alert("${actionBean.user.username}");
	form.elements["newContactToParticipants"].click();
	window.parent.closeModalDialog();
}

function newStandard(){
	window.parent.location.href = "Conferences.action?newConferenceStandard";
	if(window.parent.document.dialog != null){
		window.parent.document.dialog.destroy();
	}
}

function newStandard01803(){
	window.parent.location.href = "Conferences.action?newConferenceStandard01803";
	if(window.parent.document.dialog != null){
		window.parent.document.dialog.destroy();
	}
}

function newSimultan(){
	window.parent.location.href = "Conferences.action?newConferenceSimultan";
	if(window.parent.document.dialog != null){
		window.parent.document.dialog.destroy();
	}
}

function newVerhandlung(){
	window.parent.location.href = "Conferences.action?newConferenceVerhandlung";
	if(window.parent.document.dialog != null){
		window.parent.document.dialog.destroy();
	}
}

//Script zum Anlegen einer neuen Pin-Conference und weiterleitung zur Bearbeitung der Conference
function newPin(){
	window.parent.location.href ="Conferences.action?newConferencePin";
	if(window.parent.document.dialog != null){
		window.parent.document.dialog.destroy();
	}
}

function openConfirmDialog(form,event,infoField,okText,cancelText){
	var info = "<h1>" + $(infoField).value +"<h1>";
	okText = $(okText).value;
	cancelText = $(cancelText).value;
	Dialog.confirm(info,
			{
				title: "Info",
				okLabel: okText,
				cancelLabel: cancelText,
				className: "dialogSpread",
				width: 500,
				onCancel: function(win){return false;},
				onOk: function(win){
					form.action = form.action+"?"+event;
					form.submit();
				}
			});
}

function openConfirmDialogAGB(form,event,confId,infoField,planAgbText,okText,cancelText, warnText){
	var acceptAgbString="<input type='checkbox' id='agbcb' name='agbcb' value='accept'> <a href='impressum.jsp' target='blank'>"+$(planAgbText).value+"</a></input>";
	var info = "<div style='text-align:left'><h1>" + $(infoField).value +"</h1></div>"+"<div style='text-align: left; padding-left: 1em; padding-top: 5px;'>"+acceptAgbString+"</div><div id='acceptwarndiv' style='display: none; color: red; text-align: left' name='acceptwarndiv'>"+$(warnText).value+"</div>";
	okText = $(okText).value;
	cancelText = $(cancelText).value;
	Dialog.confirm(info,
			{
				title: "Info",
				okLabel: okText,
				cancelLabel: cancelText,
				className: "dialogSpread",
				width: 500,
				onCancel: function(win){return false;},
				onOk: function(win){
					if($("agbcb").checked){
						form.action = form.action+"?"+event+"&conferenceId=" + confId;
						form.submit();
					}else{
						$("acceptwarndiv").show();
					}		
				}
			});
}

/**
 * A confirm dialog, which will execute a function
 * @param func, must be instance of Function
 * @param messageText, dialog text
 * @param okText, label text of ok button
 * @param cancelText, label text of cancel button
 * @return
 */
function openConfirmDialogFunctionCall(func,messageText,okText,cancelText){
	var info = "<h1>" + messageText +"<h1>";
	Dialog.confirm(info,
			{
				title: "Mitteilung",
				okLabel: okText,
				cancelLabel: cancelText,
				className: "dialogSpread",
				width: 410,
				height: 190,
				onCancel: function(win){return false;},
				onOk: function(win){
					if(func instanceof Function){
						func();
						return true;
					}else{
						alert("func is not instance of Function!");
					}
				}
			});
}

function openInfoDialog(form,event,infoField,okText,cancel){
	var info = "<h1>" + $(infoField).value +"<h1>";
	okText = $(okText).value;
	buttonClass = "ok_button";
	if(cancel){
		buttonClass = "cancel_button";
	}
	Dialog.alert(info, 
			{	
				title: "Info",
				className: "dialogSpread",
				buttonClass: buttonClass,
				width:370, 
				height:230, 
				okLabel: okText, 
				ok:function(win) {return true;}
			}
	);
}

/**
 * Aktualisiert die Status-Anzeige und die damit verbundene Button view
 * bei einer laufenden Konferenz.
 * @param response
 * @return void
 */
function refreshParticipantStatus(response){
	var entrys = response.responseXML.getElementsByTagName("entry");
	for(var i=0; i < entrys.length; i++){
		var participantId = entrys[i].childNodes[0].firstChild.nodeValue;
		var status = entrys[i].childNodes[1].firstChild.nodeValue;
		$("status" + participantId).update(status);
		var muted = entrys[i].childNodes[2].firstChild.nodeValue;
		var participantType = entrys[i].childNodes[3].firstChild.nodeValue;
		var cabin="-";
		var currentCabin="-";
		
		if(status=="ONLINE"){
			//For all conference elements
			$("status" + participantId).style.color='#0F0';
			
			//For participant and interpreter elements
			if(participantType == "PARTICIPANT" || participantType == "INTERPRETER"){
				if(muted == 'true'){
					$("muteParticipant" + participantId).hide();
					$("unmuteParticipant" + participantId).show();
				}else{
					$("muteParticipant" + participantId).show();
					$("unmuteParticipant" + participantId).hide();
				}
				$("kickParticipant" + participantId).show();
				$("dialoutParticipant" + participantId).hide();
				
				//For participant elements only
				if(participantType == "PARTICIPANT"){
					/*
					 * Only, if participant is not binded to main cabine only,
					 * he can change to speaker cabin.
					 */
					var cabinEntry = entrys[i].childNodes[4].firstChild.nodeValue;
					if(cabinEntry=="MAIN"){
						$("cabinFieldChange"+participantId).hide();
					}else{
						$("cabinFieldChange"+participantId).show();
					}
					/*
					 * Set his current cabin
					 */
					var currentCabinEntry = entrys[i].childNodes[5].firstChild.nodeValue;
					if(currentCabinEntry=="MAIN"){
						currentCabin="Hauptkabine";
					}else{
						currentCabin=currentCabinEntry;
					}
					$("currentCabin"+participantId).update(currentCabin);
					$("currentCabinField"+participantId).show();
				}
			}
		}else{
			//For all conference elements
			$("status" + participantId).style.color='#F00';
			
			//For participant and interpreter elements
			if(participantType == "PARTICIPANT" || participantType == "INTERPRETER"){
				$("muteParticipant" + participantId).hide();
				$("unmuteParticipant" + participantId).hide();
				$("kickParticipant" + participantId).hide();
				$("dialoutParticipant"+participantId).show();
				
				//For participant elements only
				if(participantType == "PARTICIPANT"){
					$("currentCabinField"+participantId).hide();
				}
			}
		}
	}
	executerFunctionRunning=0;
}

function resetField(field){
	if(field.value == "dd.mm.yyyy" || field.value == "hh:mm")
		field.value = "";
}
	
	/*
	ajax-aufruf zum hinzufuegen (eines neuen kontakts), daraufhin hinzuf�gen des neues Kontaktes in 
	die Teilnehmerliste
	*/
 	function invokeAndAddBoxEntry(form, event, container) {
             if (!form.onsubmit) { form.onsubmit = function() { return false } };
             var params = Form.serialize(form, {submit:event});
             var selectedParam;
             //wenn verfuegbar: zum hinzufuegen gewaehlte gruppe
             var boxStr = "groupsList";
             var box =$(boxStr);
             for(var i=0; i<box.options.length; i++){
             	if(box.options[i].selected){
             		selectedParam="allUsersForGroup="+box.options[i].value+"&";
             		break;
             	}
             }
             new Ajax.Request(form.action, {method:'post', parameters: selectedParam+params, onComplete: addBoxEntryFromRequest});
   	}    	
	   
	   	
   	
   	
   	function addBoxEntryFromRequest(originalRequest) {
   		var rootXML = originalRequest.responseXML.getElementsByTagName('root').item(0);
   		for(var i=0; i<rootXML.getElementsByTagName('contact').length; i++){
   			var contactXML = rootXML.getElementsByTagName('contact').item(i);
   			var id = contactXML.getElementsByTagName('id');
   			var name = contactXML.getElementsByTagName('name');
   			addBoxEntry('participantsList', id[0].firstChild.nodeValue, name[0].firstChild.nodeValue);
   			removeEntry('contactsList',  id[0].firstChild.nodeValue);
  		} 	
   		sortBox('participantsList');
   		sortBox('contactsList');
  	}		
  	
  	function sortBox(boxStr){
		var box = $(boxStr);
		var arrBox = new Array();
		for(var i=0; i<box.options.length; i++){
			arrBox[i]=box.options[i];
		}
		arrBox.sort();
     	box.length = 0;
     	for( var c=0; c<arrBox.length; c++) {
           box[c] = arrBox[c];
     	}
  	}
   	
   	function addBoxEntry(boxStr, value, text) {
		 var box = $(boxStr);
	     //pruefen, ob eintrag schon vorhanden ist
	     var available=false;
		 for(var i=0; i<box.options.length; i++){
	     	if(box.options[i].value==value){
	     		available=true;
	     	}
	     }
	     //wenn noch nicht vorhanden: hinzufuegen
	     if(!available){
	     	var no = new Option();
	     	no.value = value;
	     	no.text = text;
	     	box[box.options.length]=no;
		 }
	}
	
	function removeEntry(boxStr, removeValue){
		var box = $(boxStr);
		var arrBox = new Array();
		var minus=0;
		for(var i=0; i<box.options.length; i++){
			if(box.options[i].value!=removeValue){
				arrBox[i-minus]=box.options[i];
			}else{
				minus++;
			}
		}
		arrBox.sort();
     	box.length = 0;
     	for( var c=0; c<arrBox.length; c++) {
           box[c] = arrBox[c];
     	}	
	}
/*
function insertTranslator(){
	var translator = $("translator");
	var newRow = document.createElement("tr");
	var cellCount = translator.getElementsByTagName("th").length;
	//alert(cellCount);
	var cells = new Array();
	for (var i=0; i<cellCount; i++){
		cells[i] = document.createElement("td");
		newRow.appendChild(cells[i]);
	}
	var text = $("translators").firstChild.cloneNode(true);
	cells[0].appendChild(text);
	text = document.createTextNode(translator.childNodes.length-1);
	cells[1].appendChild(text);
	var defaultLanguage = $("conference.language");
	var translatorLanguage = defaultLanguage.cloneNode(true);
	var option = translatorLanguage.options[defaultLanguage.selectedIndex];
	translatorLanguage.removeChild(option);
	cells[2].appendChild(translatorLanguage);
	
	var button = document.createElement("input");
	button.setAttribute("type","button");
	button.setAttribute("value","X");
	button.setAttribute("style","width:30px;");
	var onClickStr = "removeRow(this.parentNode.parentNode)";
	button.setAttribute("onClick",onClickStr);
	cells[3].appendChild(button);
	
	/*button = document.createElement("input");
	button.setAttribute("type","button");
	button.setAttribute("value",$("saveConference").value);
	button.setAttribute("style","width:100px;");
	onClickStr = "insertThisTranslator(this.parentNode.parentNode)";
	button.setAttribute("onClick",onClickStr);
	cells[4].appendChild(button);
	
	translator.appendChild(newRow);
	$("conference.language").disabled = true;
	translatorLanguage.disabled = false;
	var url = "";
	new Ajax.Request(url,{method:'post'});
}
*/
/*function insertThisTranslator(row){
	var cells = row.childNodes;
	var cell = cells[2];
	var oldContent = cell.firstChild; 
	var textData = oldContent.value;
	var newContent = document.createTextNode(textData);
	cell.replaceChild(newContent,oldContent);
	cell = row.lastChild;
	var changeButton = cell.firstChild;
	changeButton.setAttribute("style","width:30px;");
	changeButton.setAttribute("value","( )");
	var onClickStr = "changeTranslator(this.parentNode.parentNode)";
	changeButton.setAttribute("onClick",onClickStr);
	cell = cell.previousSibling;
	var removeButton = cell.firstChild;
	onClickStr = "removeTranslator(this.parentNode.parentNode)";
	removeButton.setAttribute("onClick",onClickStr);
	var allTranslators = $("allTranslators");
	var allTranslatorsStr = allTranslators.value;
	allTranslatorsStr = allTranslatorsStr + cells[1].firstChild.nodeValue + "," + textData + ";";
	allTranslators.value = allTranslatorsStr;
}

function removeTranslator(row){
	var parent = row.parentNode;
	parent.removeChild(row);
	var rows = parent.childNodes;
	var allTranslatorsStr = "";
	var j;
	for(var i=2; i<rows.length; i++){
		j = i - 1;
		rows[i].childNodes[1].innerHTML = j;
		allTranslatorsStr = allTranslatorsStr + j + "," + rows[i].childNodes[2].innerHTML + ";";
	}
	$("allTranslators").value = allTranslatorsStr;
	checkTranslators($("conference.language"));
}*/
/*
function removeRow(row){
	var parent = row.parentNode;
	parent.removeChild(row);
	var rows = parent.childNodes;
	for(var i=1; i<rows.length; i++)
		rows[i].childNodes[1].innerHTML = i-1;
	checkTranslators($("conference.language"));
}*/

/*function changeTranslator(row){
	var cell = row.childNodes[2];
	var defaultLanguage = $("conference.language");
	var translatorLanguage = defaultLanguage.cloneNode(true);
	translatorLanguage.disabled = false;
	var option = translatorLanguage.options[defaultLanguage.selectedIndex];
	translatorLanguage.removeChild(option);
	var oldContent = cell.firstChild; 
	var textData = oldContent.nodeValue;
	var options = translatorLanguage.childNodes;
	for(var i=0; i<options.length; i++){
		if(options[i].value == textData)
			options[i].selected = true;
	}
	cell.replaceChild(translatorLanguage,oldContent);
	cell = row.lastChild;
	var insertButton = cell.firstChild;
	insertButton.setAttribute("style","width:100px;");
	insertButton.setAttribute("value",$("saveConference").value);
	var onClickStr = "insertThisTranslator(this.parentNode.parentNode)";
	insertButton.setAttribute("onClick",onClickStr);
}*/

function checkTranslators(select){
	var isExist = $("translator").getElementsByTagName("select");
	//alert(isExist.length + "   " + $("allTranslators").value);
	//if(isExist.length > 0 || $("allTranslators").value != ""){
	if(isExist.length > 0){
		select.disabled = true;
//		return true;
	}
	else{
		select.disabled = false;
//		return false;
	}
}

/**
 * Change the cabin of a participant via ajax request. The change is defined by toggle of server state.
 * @param partId, participant id, which should change cabin.
 * @return void
 */
function changeCabin(partId, confId){
	$("cabinFieldChange" + partId).hide();
	var params="changeCabinOnline=true&participantIdForChangeCabine="+partId+"&conferenceId=" + confId;
	new Ajax.Request("Conferences.action", {method:'post', parameters: params});
}

function checkLanguage(){
	var languageWarning = document.getElementById("languageWarning");
	var addCabinButton = document.getElementById("addCabinButton");
	if(!languageWarning){
		return false;
	}
	if(document.getElementById('language').value==""){
		languageWarning.style.visibility='visible';
		addCabinButton.disabled=true;
	}
	else {
		languageWarning.style.visibility='hidden';
		addCabinButton.disabled=false;
	}
}

