
//-- get object
function getObj(obj) {
    if      (document.getElementById)   return document.getElementById(obj);
    else if (document.all)              return document.all[obj];
    else if (document.layers)           return document.layers[obj];
    else return;
}

//-- display aan/uit
function toggleVisibility(obj) {
    getObj(obj).style.display = (getObj(obj).style.display == "inline") ? "none" : "inline";
}

//-- menu in/uitklappen
function toggleMenu(obj) {

    nextSib = obj.parentNode.nextSibling;
    
    if (nextSib.nodeType == 3) {
        nextSib = nextSib.nextSibling;
    }
    
    if (nextSib.style.display == 'block') {
        nextSib.style.display = 'none';
    } else {
        nextSib.style.display = 'block'
    }
}
        
//-- linkje outline in IE fixen
if (document.all) document.onmousedown = function() {
    for (i in document.links) {
        document.links[i].onfocus = document.links[i].blur;
    }
}

//-- record verwijderen
function deleteRecord(recordid, recordtitle, deletionpage) {
    if (confirm('Klik op OK om het record met de naam "' + recordtitle + '" te verwijderen, en op Annuleren/Cancel om terug te gaan naar het overzicht.')) {
        window.location.href = deletionpage + '?id=' + recordid + '&name=' + escape(recordtitle);
    }
}

function deleteRecord1(recordid, recordtitle, deletionpage, extra) {
    if (confirm('Klik op OK om het record met de naam "' + recordtitle + '" te verwijderen, en op Annuleren/Cancel om terug te gaan naar het overzicht.')) {
        window.location.href = deletionpage + '?id=' + recordid + '&name=' + escape(recordtitle) + '&mid=' + extra;
    }
}

//-- uit frame breken
function breakOutOfFrame() {
    if (self != top) top.location.href = self.location.href;
}

//-- file input tonen / verbergen
function toggleFileInput(mode) {
    document.getElementById('hidefile').style.display = mode;
}

function toggleProductMenu(b) {
    var a = document.getElementsByTagName('dd');
    
    for (var i = 0; i < a.length; i++) {
        if (a.item(i).className == 'sub') {
            a.item(i).style.display = (b) ? 'block' : 'none';
        }
    }
}

function linkOver(id){
var href = document.getElementById('link'+id);	
if (href){ href.className = 'link_over';}}

function linkOut(id) {	
var href = document.getElementById('link'+id);
if (href){ href.className = '';}}

function checkMasterInput(id, val) {	
	var vragen = document.getElementsByName(id);
	if (vragen.length != 0) {
		for(var i=0; i<=vragen.length-1; i++) {
			if (vragen[i].value == val) {
				vragen[i].checked = true;
			}			
		}
	}	
}

function selectMasterInput(id, val) {	
	var vragen = document.getElementById(id);
	if (vragen.options.length != 0) {
		for(var i=0; i<=vragen.options.length-1; i++) {
			if (vragen.options[i].value == val) {
				vragen.options[i].selected = true;
			}			
		}
	}	
}

function openAnswer(value, i) 
{
	if (document.getElementById('answer_row_'+i)) 
	{
		if (value == 'empty_row' || value == 'title')
		{
			document.getElementById('answer_options_row_'+i).style.display = 'none';
			document.getElementById('answer_question_row_'+i).style.display = 'none';
			document.getElementById('mandatory_row_'+i).style.display = 'none';
		}	
		else if (value == 'email' || value == 'attachment')
		{
			document.getElementById('answer_options_row_'+i).style.display = 'none';
			document.getElementById('answer_question_row_'+i).style.display = 'none';
			document.getElementById('mandatory_row_'+i).style.display = 'block';
		}	
		else if (value == 'radio' || value == 'checkbox' || value == 'select') 
		{
			document.getElementById('answer_options_row_'+i).style.display = 'block';
			document.getElementById('answer_question_row_'+i).style.display = 'block';
			document.getElementById('mandatory_row_'+i).style.display = 'block';			
		} 
		else {
			document.getElementById('answer_options_row_'+i).style.display = 'none';
			document.getElementById('answer_question_row_'+i).style.display = 'block';
			document.getElementById('mandatory_row_'+i).style.display = 'block';
		}
	}
}

function browserCheck() 
{
	var strAgent = navigator.userAgent.toLowerCase(); 
	var strBrowser = "";
	
	if (strAgent.indexOf("opera 5")!=-1)
	{
	strBrowser = "Opera 5.x";
	}
	else if (strAgent.indexOf("opera")!=-1)
	{
	strBrowser = "Opera";
	}
	else if (strAgent.indexOf("msie 7.0")!=-1)
	{
	strBrowser = "Internet Explorer 7.x";
	}
	else if (strAgent.indexOf("msie 6.0")!=-1)
	{
	strBrowser = "Internet Explorer 6.x";
	}
	else if (strAgent.indexOf("msie 5.5")!=-1)
	{
	strBrowser = "Internet Explorer 5.5";
	}
	else if (strAgent.indexOf("msie 5.0")!=-1)
	{
	strBrowser = "Internet Explorer 5.0";
	}
	else if (strAgent.indexOf("msie 4")!=-1)
	{
	strBrowser = "Internet Explorer 4";
	}
	else if (strAgent.indexOf("netscape/7")!=-1)
	{
	strBrowser = "Netscape 7.x";
	}
	else if (strAgent.indexOf("netscape6")!=-1)
	{
	strBrowser = "Netscape 6.x";
	}
	else if (strAgent.indexOf("mozilla/4")!=-1)
	{
	strBrowser = "Netscape 4.x";
	}
	else if (strAgent.indexOf("mozilla")!=-1)
	{
	strBrowser = "Mozilla";
	}
	else
	{
	strBrowser = "onbekende";
	}
	return strBrowser;
}

function moreQuestions()
{		
	document.formulier.veldtoevoegen.disabled = true;

	var i = document.formulier.questions.value;
	    i++;
	
	var mycurrent_row_0  = document.getElementById("questionTable").insertRow(-1);
	var mycurrent_row_1  = document.getElementById("questionTable").insertRow(-1);
	var mycurrent_row_2  = document.getElementById("questionTable").insertRow(-1);
	mycurrent_row_2.setAttribute("id", "answer_question_row_"+i);
	var mycurrent_row_3  = document.getElementById("questionTable").insertRow(-1);
	mycurrent_row_3.setAttribute("id", "answer_options_row_"+i);
	var mycurrent_row_4  = document.getElementById("questionTable").insertRow(-1);
	mycurrent_row_4.setAttribute("id", "mandatory_row_"+i);
	var mycurrent_row_5  = document.getElementById("questionTable").insertRow(-1);
   
	mycurrent_cell_1_1 = document.createElement("td");
	mycurrent_cell_1_2 = document.createElement("td");
	mycurrent_cell_1 = document.createElement("td");
    mycurrent_cell_2 = document.createElement("td");
	mycurrent_cell_2.setAttribute("colSpan","2");
	
	mycurrent_cell_3_1 = document.createElement("td");
	mycurrent_cell_3_2 = document.createElement("td");
	mycurrent_cell_3 = document.createElement("td");
	mycurrent_cell_3.setAttribute("width","30");
	mycurrent_cell_4 = document.createElement("td");
	mycurrent_cell_4.setAttribute("width","150");
	mycurrent_cell_5 = document.createElement("td");
	mycurrent_cell_5.setAttribute("width","390");
	
	mycurrent_cell_6_1 = document.createElement("td");
	mycurrent_cell_6_2 = document.createElement("td");
	mycurrent_cell_6 = document.createElement("td");
    mycurrent_cell_7 = document.createElement("td");
	mycurrent_cell_7.setAttribute("colSpan","2");
	
	mycurrent_cell_8_1 = document.createElement("td");
	mycurrent_cell_8_2 = document.createElement("td");
	mycurrent_cell_8 = document.createElement("td");
    mycurrent_cell_9 = document.createElement("td");
	mycurrent_cell_9.setAttribute("colSpan","2");
	
	mycurrent_cell_10_1 = document.createElement("td");
	mycurrent_cell_10_2 = document.createElement("td");
	mycurrent_cell_10 = document.createElement("td");
    mycurrent_cell_11 = document.createElement("td");
	mycurrent_cell_11.setAttribute("colSpan","2");
	
	mycurrent_cell_12_1 = document.createElement("td");
	mycurrent_cell_12_2 = document.createElement("td");
	mycurrent_cell_12 = document.createElement("td");
	mycurrent_cell_12.setAttribute("colSpan","3");
	
	browser = browserCheck();
		
	if (browser == 'Mozilla' || browser == 'onbekend')
	{
		input_question = document.createElement('input');
		input_question.setAttribute('type', 'text');
		input_question.setAttribute('name', 'question_'+i);
		input_question.setAttribute('class', 'input');
	
		input_type = document.createElement('select');
		input_type.setAttribute('name', 'type_'+i);
		input_type.setAttribute('class', 'select');
		input_type.setAttribute('onchange', 'openAnswer(this.value, '+i+');'); 
		
		option = document.createElement('option');
        option.text = '';
		option.value = '';
        input_type.appendChild(option);
		
		option = document.createElement('option');
        option.text = 'Lege regel (tussenruimte in formulier)';
		option.value = 'empty_row';
        input_type.appendChild(option);
		
		option = document.createElement('option');
        option.text = 'Titel (dik gebdrukte tekst)';
		option.value = 'title';
        input_type.appendChild(option);
		
		option = document.createElement('option');
        option.text = 'Radiobutton (enkele optie)';
		option.value = 'radio';
        input_type.appendChild(option);
		
		option = document.createElement('option');
        option.text = 'Checkbox (meerdere opties)';
		option.value = 'checkbox';
        input_type.appendChild(option);
		
		option = document.createElement('option');
        option.text = 'Selectie (enkele optie)';
		option.value = 'select';
        input_type.appendChild(option);
		
		option = document.createElement('option');
        option.text = 'Text (enkele regel)';
		option.value = 'text';
        input_type.appendChild(option);
		
		option = document.createElement('option');
        option.text = 'E-mailadres';
		option.value = 'email';
        input_type.appendChild(option);
		
		option = document.createElement('option');
        option.text = 'Textarea (meerdere regels)';
		option.value = 'textarea';
        input_type.appendChild(option);
		
		option = document.createElement('option');
        option.text = 'Bijlage';
		option.value = 'attachment';
        input_type.appendChild(option);
		
		input_answer = document.createElement('textarea');
		input_answer.setAttribute('name', 'answer_'+i);
		input_answer.setAttribute('rows', '4');
		input_answer.setAttribute('style', 'width:510px;');
		input_answer.setAttribute('class', 'input');	
		
		input_mandatory	= document.createElement('input');
		input_mandatory.setAttribute('type', 'checkbox');
		input_mandatory.setAttribute('name', 'mandatory_'+i);
	} 
	else {
		input_question = document.createElement('<input name="question_'+i+'" type="text" class="input">');		
		input_type = document.createElement('<select name="type_'+i+'" class="select" onChange="openAnswer(this.value, '+i+')">');		
		input_type.options[0] = new Option('','');
		input_type.options[1] = new Option('Lege regel (tussenruimte in formulier)', 'empty_row');
		input_type.options[2] = new Option('Titel (dik gedrukte tekst)', 'title');
		input_type.options[3] = new Option('Radiobutton (enkele optie)','radio');
		input_type.options[4] = new Option('Checkbox (meerdere opties)','checkbox');
		input_type.options[5] = new Option('Selectie (enkele optie)','select');
		input_type.options[6] = new Option('Text (enkele regel)','text');
		input_type.options[7] = new Option('E-mailadres','email');
		input_type.options[8] = new Option('Textarea (meerdere regels)','textarea');
		input_type.options[9] = new Option('Bijlage','attachment');
		input_answer = document.createElement('<textarea name="answer_'+i+'" rows="4" style="width:520px;" class="input"></textarea>');
		input_mandatory = document.createElement('<input name="mandatory_'+i+'" type="checkbox" value="1">');	
	}
	
	mycurrent_cell_1.innerHTML = i+'.';
	mycurrent_cell_2.appendChild(input_question); 
	mycurrent_row_0.appendChild(mycurrent_cell_1_1);
	mycurrent_row_0.appendChild(mycurrent_cell_1_2);
	mycurrent_row_0.appendChild(mycurrent_cell_1);
	mycurrent_row_0.appendChild(mycurrent_cell_2);
	
	mycurrent_cell_3.innerHTML = '';
	mycurrent_cell_4.innerHTML = 'Antwoorden in de vorm van: ';
	mycurrent_cell_5.appendChild(input_type); 
	mycurrent_row_1.appendChild(mycurrent_cell_3_1);
	mycurrent_row_1.appendChild(mycurrent_cell_3_2);
	mycurrent_row_1.appendChild(mycurrent_cell_3);
	mycurrent_row_1.appendChild(mycurrent_cell_4);
	mycurrent_row_1.appendChild(mycurrent_cell_5);
	
	mycurrent_cell_6.innerHTML = '';
	mycurrent_cell_7.appendChild(input_answer);
	mycurrent_row_2.appendChild(mycurrent_cell_6_1);
	mycurrent_row_2.appendChild(mycurrent_cell_6_2);
	mycurrent_row_2.appendChild(mycurrent_cell_6);
	mycurrent_row_2.appendChild(mycurrent_cell_7);
	
	mycurrent_cell_8.innerHTML = '';
	mycurrent_cell_9.innerHTML += 'Voor checkbox, radiobuttons en selectie, elke regel is een antwoord.<br>Voor \'anders, nl:\', voeg een plus-teken toe (+) (alleen voor checkbox en radiobuttons).';
	mycurrent_row_3.appendChild(mycurrent_cell_8_1);
	mycurrent_row_3.appendChild(mycurrent_cell_8_2);
	mycurrent_row_3.appendChild(mycurrent_cell_8);
	mycurrent_row_3.appendChild(mycurrent_cell_9);
 
 	mycurrent_cell_10.innerHTML = '';
	mycurrent_cell_11.appendChild(input_mandatory);
	mycurrent_cell_11.innerHTML += 'Verplicht in te vullen';
	mycurrent_row_4.appendChild(mycurrent_cell_10_1);
	mycurrent_row_4.appendChild(mycurrent_cell_10_2);
	mycurrent_row_4.appendChild(mycurrent_cell_10);
 	mycurrent_row_4.appendChild(mycurrent_cell_11);
 
	mycurrent_cell_12.innerHTML = '';
	mycurrent_row_5.appendChild(mycurrent_cell_12_1);
	mycurrent_row_5.appendChild(mycurrent_cell_12_2);
	mycurrent_row_5.appendChild(mycurrent_cell_12);
	
	document.formulier.questions.value = i;
	document.formulier.veldtoevoegen.disabled = false;
} 
