// JavaScript Document

function submitEditedReport() {
	document.getElementById('editor1').EscapeUnicode = true;
	document.getElementById('xtext').value = document.getElementById('editor1').value;
	
	//Set selectedindex of team 2 and 3 to 0 if visibility = "none"
	if( $("scnd-team").style.display == "none") { $("team2").selectedIndex = 0; }
	
	if( $("thrd-team").style.display == "none") { $("team3").selectedIndex = 0; }

}

function submitCreateReport() {
	document.getElementById('editor1').EscapeUnicode = true;
	document.getElementById('xtext').value = document.getElementById('editor1').value;
	
	//Set selectedindex of team 2 and 3 to 0 if visibility = "none"
	if( $("scnd-team").style.display == "none") { $("team2").selectedIndex = 0; }
	
	if( $("thrd-team").style.display == "none") { $("team3").selectedIndex = 0; }

}




function myOnSubmitEventHandler() {
	document.getElementById('editor1').EscapeUnicode = true;
	document.getElementById('xtext').value = document.getElementById('editor1').value;
}
	

function onChangeRedirect(strTarget,obj) {
	eval(strTarget + ".location='" + obj.options[obj.selectedIndex].value+"'");
}


mainWindow = window.opener;

function UpdateParent(targetUrl) {
	if(typeof(mainWindow) == "object" && mainWindow != null){
		// Reference to parent-window.
		if(!mainWindow.closed){
			mainWindow.location = targetUrl;
			mainWindow.focus();
		} else {
			window.open(targetUrl);
		}
	} else {
		window.open(targetUrl);
	}
}

/* --------------------------------------------------------------------
 	populateselect()
 * --------------------------------------------------------------------
 * This function is to be called onload and populates the form according 
 * to the datasets.
 */

function populateselect(intId1,intId2,select1,select2,strUrl,strNoEntries,strHeader){
	/* Define Form elements (lesser typing)
	 * myForm is the form name, select1 and select 2 the selectboxes.
	 */
	sel1 = select1;
	sel2 = select2;
	strTargetUrl = strUrl;
	strNoEntryHeader = strNoEntries
	strEntryHeader = strHeader
	var blnFound = false;

	sel1.options.length = 0;
	sel1.options.length = datasets.length;
	for (i=0;i<datasets.length;i++){
		sel1.options[i].text = datasets[i][0];
		sel1.options[i].value = arrId[i][0];
		if(arrId[i][0] == intId1){
			blnFound = true;
			sel1.selectedIndex = i;
		} 
	}
	if(!blnFound){
		sel1.selectedIndex = 0;
	}
	
	if(intId2 != undefined){
		changeselect(intId2,sel1,sel2);
	} else {
		changeselect(0,sel1,sel2);
	}
}

/* --------------------------------------------------------------------
 	changeselect()
 * --------------------------------------------------------------------
 * This function changes the content of the second selectbox according 
 * to the data of the datasets and the selected option of the first.
 */

function changeselect(intId){
	/* Define Form elements (lesser typing)
	 * myForm is the form name, select1 and select 2 the selectboxes.
	 */
	var blnFound = false;

	var dataset=sel1.selectedIndex;
	sel2.options.length = 0;
	sel2.options.length = datasets[dataset].length-1;


	if(sel2.options.length == 0){
		var strNoEntries = new Option(strNoEntryHeader,"");
		sel2.options[0] = strNoEntries;
	} else {
		var strStartText = new Option(strEntryHeader,"");
		sel2.options[0] = strStartText;
	}
	
	for (i=1;i<(datasets[dataset].length);i++){
		objEntry = new Option(datasets[dataset][i],strTargetUrl + arrId[dataset][i]);
		sel2.options[i] = objEntry;
		if(arrId[dataset][i] == intId){
			blnFound = true;
			sel2.selectedIndex = i;
		} 
	}

	if(!blnFound){
		sel2.selectedIndex = 0;
	}
}

function SelChooseDate(target,obj){
	eval(target + ".location='" + obj.options[obj.selectedIndex].value + "'");
}

function validateSeekReport ( form ) {
	if((form.d.value == "-" || form.d.value == "") || (form.m.value == "-" || form.m.value == "") || (form.y.value == "-" || form.y.value == "")){
		alert("Du mangler at udfylde et af de tre felter.");
		return false;
	} else {
		return true;
	}
}




