function updateFile(elemID) {
  $(elemID+'x').value = $(elemID).value;
  if ($(elemID).value != '') {
    $(elemID+'btn').style['display'] = 'inline';
  }
}

function clearFile(elemID) {
  $(elemID).value = '';
  $(elemID+'x').value = '';
  $(elemID+'btn').style['display'] = 'none';
}

function deleteContact(imgElm) {
  m = imgElm.parentNode.parentNode;
  tblElm = m.parentNode;
  m.parentNode.removeChild ( m );  
  reSetRows ( tblElm );
}

function addContact(rowElm) {
  rowElm.parentNode.appendChild ( rowElm.cloneNode ( true ) );
  rowElm.onclick = function () { };  
  reSetRows ( rowElm.parentNode );  
  rowElm.getElementsByTagName ( 'img' ) [ 0 ].style [ 'display' ] = 'inline';
}

// Function to reSet the row colors
function reSetRows ( tblElm ) {
  trs = tblElm.getElementsByTagName('tr');
  b = 'row0';
  for (a = 0; a < trs.length; a++)
    trs[a].className = (b = b == 'row0' ? 'row1' : 'row0');
}

// Function for updating function
function changeFunctionField ( elem ) {
  var inpElems = elem.parentNode.getElementsByTagName('input');
  var hiddenField = '';
  for (var i = 0; i < inpElems.length; i++) {
    hiddenField = inpElems[i];
    if (hiddenField.type == 'hidden') {
      break;
    }
  }
  if (elem.type == 'text') {
    hiddenField.value = elem.value;
  } else { // HANDLE SELECTBOX
    
    // If vwb is --other-Holder-- then show textfield
    if (elem.value == '--other-Holder--') {
      for (var i = 0; i < inpElems.length; i++) {
        textField = inpElems[i];
        if (textField.type == 'text') {
          break;
        }
      }
      // Show textfield
      textField.style['display'] = 'inline';
      // Hide select
      elem.style.display = 'none';
      hiddenField.value = '';
    } else  {
      if (elem.options[0].value == '' && elem.options[0].text == 'Selecteer') {
        elem.options [ 0 ] = null;
      }      
      // Just set the value
      hiddenField.value = elem.value;
    }
  }
  return false;
}

function showEmailForm(show) {
  if (show) {
    $('emailFormContainer').fade('in');
    $('tintScreen').fade(0.8);
  } else {
    $('emailFormContainer').fade('out');
    $('tintScreen').fade('out');
  }
  
}

function showPostAddress(show) {
  if (show) {
    $('postAddressForm').setStyle('display', '');
    $('postAddressForm').fade('in');    
    
  } else {
    $('postAddressForm').fade('out');
    (function(){ $('postAddressForm').setStyle('display', 'none'); }).delay(500);
  }  
}


window.addEvent('domready', function() {

  $each($$('input.file'), function(elem) {
    elem.setOpacity(0);
    elem.parentNode.style['display'] = 'block';
  });
  
  $each($$('div.file'), function(div) {
    div.style['display'] = 'block';
  });
  
  $each($$('.hide'), function(elem) {
    elem.fade('hide').removeClass('hide');
  });
  
  $each($$('.hide-registration'), function (elem) {
	 elem.setStyle('display', 'none') ;
  });
  
  $each($$('.addRegistration'), function(tr) {
	 tr.setStyle('display', '');
	 if (!tr.getElement('a')) {
		 return;
	 }
	 tr.getElement('a').addEvent('click', function (e) {
		 e.stop();
		 var idParts = this.id.split('_');
		 if ($('activity_'+idParts[1]+'_'+idParts[2])) { 
			 $('activity_'+idParts[1]+'_'+idParts[2]).setStyle('display', ''); 
			 this.getParent().getParent().destroy(); 
		 }
		 return false;
	 })
  });

});

window.addEvent('domready',function() {
  /* settings */
  var showDuration = 3500;
  var container = $('slideshow-container');
  var images = container.getElements('img');
  var currentIndex = 0;
  var interval;
  /* opacity and fade */
  images.each(function(img,i){ 
    if(i > 0) {
      img.set('opacity',0);
    }
  });
  /* worker */
  var show = function() {
    images[currentIndex].fade('out');
    images[currentIndex = currentIndex < images.length - 1 ? currentIndex+1 : 0].fade('in');
  };
  /* start once the page is finished loading */
  window.addEvent('load',function(){
    interval = show.periodical(showDuration);
  });
});
