var currentid  = 0;
var siteurl    = "http://updo.nl/";

updateFields = function(id)
{
	tbody = $('uploadtbody');
	uploadbox = $('uploadbox-'+id);
	if(id % 2 == 1)classn = "td2"; else classn="";
	
	tr = new Element('tr',{id: 'uploadtr-'+id});
	td1 = new Element('td', {html: "<a href='#' onclick='removeField("+id+");'><img src='ico/cross.png' alt='verwijder uit lijst' /></a>", 'class': classn});
	td2 = new Element('td', {html: uploadbox.value, 'class': classn})
	td3 = new Element('td', {html: "<input type='checkbox' name='prive-"+id+"' class='privebox' />", 'class': classn, 'style': 'width:50px;'})
	td4 = new Element('td', {html: "<input type='checkbox' name='temp-"+id+"' class='tempbox' />", 'class': classn, 'style': 'width:50px;'})
	td5 = new Element('td', {html: "Root", 'class': classn, 'style': 'width:90px;'})
	
	tr.inject(tbody);
	td1.inject(tr);
	td2.inject(tr);
	td3.inject(tr);
	td4.inject(tr);
	td5.inject(tr);
	
	uploadbox.setStyle('display','none');
	
	currentid++;
	input = new Element('input',{type: 'file', name: 'upload-'+currentid, id: 'uploadbox-'+currentid, onchange: 'updateFields('+currentid+');'});
	input.inject($('uploadfields'));
	
	if($('uploadbox-maintable').getStyle('display') == 'none')
	{
		$('uploadbox-maintable').setStyle('display','block');
		$('upload-button').setStyle('display','block');
	}
}

removeField = function(id)
{
	if($chk('uploadtr-'+id))
	{
		$('uploadtr-'+id).destroy();
		$('uploadbox-'+id).destroy();
	}
}

setAllPrive = function(id)
{
	var value = id.checked;
	$$('.privebox').each(function(e)
	{
		e.set('checked',value);
	});
}

setAllTemp = function(id)
{
	var value = id.checked;
	$$('.tempbox').each(function(e)
	{
		e.set('checked',value);
	});
}

mapbrowser = function(type,id,element)
{
	if(element == -1)
	{
		newwindow = window.open(siteurl+'includes/selectmap-url.php?'+type+'='+id,'Map selecteren','height=200,width=150');
	}
	else
	{
		newwindow = window.open(siteurl+'includes/selectmap-ele.php?'+type+'='+id,'Map selecteren','height=200,width=150');
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

window.addEvent('domready',function(e)
{
	new Tips.Pointy($$('.tip'));
	
	$$('.wegonblur').each(function(e)
	{
		e.store('standaardtekst', e.value);
	});
	
	$$('.wegonblur').addEvents({'blur' : function(e)
	{
		if(this.value == "")
		{
			this.value = this.retrieve("standaardtekst");	
		}
	},'focus' :function(e)
	{
		if(this.value == this.retrieve("standaardtekst"))
		{
			this.value = "";
		}
	}});
});

