var aantal_huidig = 0;

var startList = function() 
{
	if (document.all&&document.getElementById) 
	{
		navRoot = document.getElementById("navigatie");
		for (i=0; i<navRoot.childNodes.length; i++) 
		{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() 
				{
					this.className+=" over";
				}
				node.onmouseout=function() 
				{
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
/*
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
*/


function externalLinks() 
{
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) 
  {
    var anchor = anchors[i];
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") 
    {
      anchor.target = "_blank";
    }
  }
}

function loadpage(page) 
{
  parent.location = page;
}

function executeit() 
{
  startList();
  externalLinks();
}

function switchProperty(id)
{
  document.getElementById('switch_property_form').submit();
}

function CountImages() {
	document.forms[1].elements["is_there_hoofdafbeelding"].value = 'false';

	for(var i=0; i<document.forms[1].elements.length; i++) {
		if(document.forms[1].elements[i].id.indexOf('foto_') === 0) {
			highest_value = parseInt(document.forms[1].elements[i].id.substr(5,document.forms[1].elements[i].id.length));
		}
	}

	if(highest_value > 4) {
		aantal = highest_value;
	} else {
		aantal = 4;
	}
	
	if(aantal >= aantal_huidig) {
		aantal_huidig = aantal;
	} else {
		aantal_huidig = aantal_huidig + 1;
	}

	document.forms[1].elements["amount_images"].value = aantal_huidig;
}

function AddPictureFormElement() {
	for(var i=0; i<document.forms[1].elements.length; i++) {
		if(document.forms[1].elements[i].id.indexOf('foto_') === 0) {
			var highest_value = parseInt(document.forms[1].elements[i].id.substr(5,document.forms[1].elements[i].id.length));
		}
	}
	

	//uit gezet om voor andere doeleinden te gebruiken
	/*if(highest_value > 4) {
		aantal = highest_value;
	} else {
		aantal = 4;
	}
	aantal = highest_value;
	
	if(aantal >= aantal_huidig) {
		aantal_huidig = aantal + 1;
	} else {
		aantal_huidig = aantal_huidig + 1;
	}
	*/
	aantal_huidig = parseInt(document.getElementById("amount_images").value);
	
	html = '';
	html += '<fieldset class="fl"><b>Afbeelding ' + aantal_huidig + '</b><br />';
	html += '<label class="addlabel">Afbeelding toevoegen:</label>';
	html += '<input type="file" name="foto_' + aantal_huidig + '" id="foto_' + aantal_huidig + '" />'
	html += '<input type="text" onclick="javascript:MakeInputEmpty('+ aantal_huidig +');" id="image_caption_' + aantal_huidig + '" name="image_caption_' + aantal_huidig + '" value="voeg tekst toe.." /></fieldset><br /><br />';

	bla = document.getElementById('extra_afbeeldingen');
	bla.innerHTML += html;
	amount_images = aantal_huidig + 1;
	document.getElementById("amount_images").value = amount_images;
}

function AddMainPictureFormElement() {
	for(var i=0; i<document.forms[1].elements.length; i++) {
		if(document.forms[1].elements[i].id.indexOf('foto_') === 0) {
			highest_value = parseInt(document.forms[1].elements[i].id.substr(5,document.forms[1].elements[i].id.length));
		}
	}

	html = '';
	html += '<fieldset class="fl"><b>Hoofdafbeelding</b><br />';
	html += '<label class="addlabel">Hoofdafbeelding toevoegen:</label>';
	html += '<input type="file" name="hoofd_afbeelding" id="hoofd_afbeelding" /></fieldset><br /><br />';

	bla = document.getElementById('hoofd_afbeelding');
	bla.innerHTML += html;

	document.getElementById('hoofdafbeelding_button').style.visibility = 'hidden';
}

function AddFileFormElement() {
	
	aantal = parseInt(document.getElementById('counter').value);
	
	if(aantal >= aantal_huidig) {
		aantal_huidig = aantal + 1;
	} else {
		aantal_huidig = aantal_huidig + 1;
	}

	html = '';
	html += '<fieldset class="fl"><b>Bestand ' + aantal_huidig + '</b><br />';
	html += '<label class="addlabel">bestand toevoegen:</label>';
	html += '<input type="file" name="file_' + aantal_huidig + '" id="file_' + aantal_huidig + '" />'
	html += '<input type="text" onclick="javascript:MakeNameInputEmpty('+ aantal_huidig +');" id="name_' + aantal_huidig + '" name="name_' + aantal_huidig + '" value="voeg naam toe.." /></fieldset><br /><br />';

	bla = document.getElementById('extra_afbeeldingen');
	bla.innerHTML += html;
	document.forms[1].elements["amount_images"].value = aantal_huidig;
}

function MakeInputEmpty(id) {
	if(document.getElementById("image_caption_" + id).value == 'voeg tekst toe..' || document.getElementById("image_caption_" + id).value == '') {
		document.getElementById("image_caption_" + id).value = '';
	}
}

function MakeNameInputEmpty(id) {
	if(document.getElementById("name_" + id).value == 'voeg naam toe..' || document.getElementById("name_" + id).value == '') {
		document.getElementById("name_" + id).value = '';
	}
}

window.onload=executeit;
