// initialize page
$(document).ready(function () {
setupCollapsableItems();
replaceHeaders();
showHideForm();
});



// JavaScript Document
function switch_class(elem,c1,c2){
	if(elem.className == c1){
		elem.className = c2;
	} else {
		elem.className =c1;
	}
	
}

// JavaScript Document
function show_hide(elem){
	if (document.getElementById(elem).style.display == 'none'){
		document.getElementById(elem).style.display = 'block';
	}	else {
		document.getElementById(elem).style.display = 'none';
	}
}

//showHideForm
function showHideForm() {
	if ($("#age").attr("checked") == true) {
		$("#formChecked").show();
		$("#ageYounger").hide();
	} else {
		$("#formChecked").hide();
		$("#ageYounger").show();
	}
}

// javascript popup maken
function doPopUp(url, name, w, h, scrollbars){
	var doPopUpX = (screen.width/2)-(w/2);
	var doPopUpY = (screen.height/2)-(h/2);
	var pos = "left="+doPopUpX+",top="+doPopUpY;
	doPopUpWindow = window.open(url,name,"scrollbars=" + scrollbars + ",width=" + w + ",height=" + h + ","+pos);
}

// fireCommand
function fireCommand(formname, command, commandId) {
	eval('document.'+formname+'.fldCommand.value=command');
	eval('document.'+formname+'.fldCommandId.value=commandId');
	eval('document.'+formname+'.submit()');
}

function promptCommand(formname, command, commandId, message) {
	returnvalue = prompt(message,'');
	if (returnvalue != null) {
		eval('document.'+formname+'.fldCommand.value=command');
		eval('document.'+formname+'.fldCommandId.value=commandId');
		eval('document.'+formname+'.fldPrompt.value=returnvalue');
		eval('document.'+formname+'.submit()');
	}
}

// confirmCommand
function confirmCommand(formname, command, commandId, message) {
	if (confirm(message)) {
		eval('document.'+formname+'.fldCommand.value=command');
		eval('document.'+formname+'.fldCommandId.value=commandId');
		eval('document.'+formname+'.submit()');
	}
}

// setup collapsable items
function setupCollapsableItems(){
// hide by defaulr
$(".collapsable").each(function(i) {
if (!$(this).hasClass("opened")){
$(this).find(":nth-child(2)").hide();
}
});

$(".collapsable").find(":first").click(function(){
var content = $(this).parent().find(":nth-child(2)");
var container = $(this).parent();

if (content.css("display") == "block"){
container.removeClass("opened");
container.addClass("closed");
content.hide();
} else {
container.removeClass("closed");
container.addClass("opened");
content.show();
}
});
}


