// Visa/dölj ett element
function toggleElement(elemId) {
	elem = document.getElementById(elemId);
	if(elem.style.display == 'none') {
		elem.style.display = '';
	}
	else {
		elem.style.display = 'none';
	}
}

// Växla vilken flik som visas - används av program, fakultet, ämne
function dispTab(tab, nrTabs) {
	var tabdiv;
	var i = 0;
	
	// Om flik 1, sätt utb.text till allmän text
	if(tab == 1 && document.getElementById('edu_nospec')) showEduText('nospec');
	
	for(i = 0; i < nrTabs; i++) {
		tablink = document.getElementById('tablink_'+i);
		tabdiv = document.getElementById('tab_'+i);
		if(i == tab) {
			tablink.className = 'tabCurrent';
			tablink.blur();
			tabdiv.style.display = '';
		}
		else {
			tablink.className = 'tabNormal';
			tabdiv.style.display = 'none';
		}
	}
	
}

// Göm div
function hidePopup(popid) {
	var poptext = document.getElementById(popid);
	if(poptext) poptext.style.visibility='hidden';
	//if(poptext) poptext.style.display='none';
}

// Lägg hjälptext i div och visa 
function showHelp(helpId) {
	var helpText = document.getElementById(helpId).innerHTML;
	document.getElementById('selma_help_text').innerHTML = helpText;
	document.getElementById('selma_help_box').style.visibility='visible';
	//document.getElementById('selma_help_box').style.display='';
}

// Ställer om vilken kolumn som ska sorteras och hur (fallande, stigande) i sökresultat för ModSelmaFriSokning
function sortList(col, order, stype) {
	document.selma_form.sort_id.value = col;
	document.selma_form.sort_ord.value = order;
	document.selma_form.sort_type.value = stype;
	document.selma_form.submit();
}

// Återställ avancerad sökning-formuläret till standardvärden
function resetForm() {
	document.selma_form.selma_fs_vad.selectedIndex = 0;
	toggleCheckboxes('selma_fs_hur[]', 0);
	document.selma_form.selma_fs_sprak.selectedIndex = 0;
	document.selma_form.selma_fs_termin.selectedIndex = 0;
	toggleCheckboxes('selma_fs_tid[]', 0);
	document.selma_form.selma_fs_takt.selectedIndex = 0;
	document.selma_form.selma_fs_fakultet.selectedIndex = 0;
	document.selma_form.sort_id.value = 'name';
	document.selma_form.sort_ord.value = 'asc';
	document.selma_form.sort_type.value = 'std';
}

function showEduText(txtId) {
	var eduText = document.getElementById('edu_'+txtId);
	if(eduText) document.getElementById('selma_edu_text').innerHTML = eduText.innerHTML;
}

function toggleCheckboxes(boxName, boxIndex) {
	var boxes = document.selma_form.elements[boxName];
	
	if (boxIndex == 0) {
		boxes[0].checked=true;
		
		for (i=1; i<boxes.length; i++) {
			boxes[i].checked=false;
		}
		
	}
	else {
		if(boxes[boxIndex].checked == false) {
			var hasChecked = false;
			for (i=1; i<boxes.length; i++) {
				if(boxes[i].checked) hasChecked = true;
			}
			if(!hasChecked) boxes[0].checked = true;
		}
		else {
			boxes[0].checked = false;
		}
	}
	
}

function openPrint(baseUrl, pParam) {
	var aH = screen.availHeight - 200;
	window.open(baseUrl+'modSelmaPrint.php?pparam='+pParam, 'sprint', 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,height='+aH+',left=200,width=800', false);
}
