// common functions

function toggleObject(whichLayer) {
	if (document.getElementById) {
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = (style2.display == "block" ? "none" : "block");
	} else if (document.all) {
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display =(style2.display == "block" ? "none" : "block");
	} else if (document.layers) {
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = (style2.display == "block" ? "none" : "block");
	}
}

// bb code

function getSelectionInfo(selection) {
	var text = window.document.viesti_form.viesti_teksti;

	if (selection == 'start') {
		var returnvalue = text.value.substr(0, text.selectionStart);
	}
	if (selection == 'selection') {
		var returnvalue = text.value.substr(text.selectionStart, text.selectionEnd - text.selectionStart);
	}
	if (selection == 'end') {
		var returnvalue = text.value.substr(text.selectionEnd, 5000);
	}

	return returnvalue;
}

function tag(tagadd, tagclose) {
	var post = window.document.viesti_form.viesti_teksti;
	post.value = getSelectionInfo('start') + tagadd + getSelectionInfo('selection') + tagclose + getSelectionInfo('end');
}

// frontpage

function validateVote(selectionId) {

	var selectBox1 = document.forms['aanestys_form'].aanestys_kappale_1;
	var selectBox2 = document.forms['aanestys_form'].aanestys_kappale_2;
	var selectBox3 = document.forms['aanestys_form'].aanestys_kappale_3;
	var box1Count = selectBox1.options.length;	
	var box2Count = selectBox2.options.length;	
	var box3Count = selectBox3.options.length;	
	
	if (selectionId == 1) {
					
		for (i = 0; i <= box2Count; i++) {
			if (selectBox2.options[i].value == selectBox1.options[selectBox1.selectedIndex].value) selectBox2.options[i] = null;
		}							

	}
	if (selectionId == 2) {

		for (i = 0; i <= box3Count; i++) {
			if (selectBox3.options[i].value == selectBox2.options[selectBox2.selectedIndex].value) selectBox3.options[i] = null;
		}									

	}
	if (selectionId == 3) {
			
		for (i = 0; i <= box1Count; i++) {
			if (selectBox1.options[i].value == selectBox3.options[selectBox3.selectedIndex].value) selectBox1.options[i] = null;
		}		

	}									
}