// source: http://www.milov.nl
E = document.getElementById ? 1 : 0; // IE5, Mozilla
A = document.all ? 1 : 0;// IE4, IE5
L = document.layers ? 1 : 0; // NS4

var getById = (typeof document.getElementById != "undefined");		

function toggleDisplay(obj,display1,display2){

	if(!getById) return;
	
	obj = getRef(obj);
	
	if(obj.style.display == display1)
		obj.style.display = display2;
	else
		obj.style.display = display1;
		
	return false;
}

function getRef(obj){
	if(getById)
		return(typeof obj == "string") ? document.getElementById(obj) : obj;
}

function showDiv(id) {
	if (document.getElementById(id)) {
		var state = 0;
		if (document.getElementById(id).style.display == 'none'|document.getElementById(id).style.display == '') state = 1;
		document.getElementById(id).style.display = state ? 'block' : 'none';
	}
}

function getCookie(name) {
	var search = name + "="
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search) 
		if (offset != -1) { 
			offset += search.length 
			end = document.cookie.indexOf(";", offset) 
			if (end == -1) 
			end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
		} 
	}
}

function newWindow(url)
{
	var nieuw = window.open(url,"", 'height=595,width=400,toolbar=no,scrollbars=no,status=no,location=no,menubar=no,directories=no');
	return false;
}

function newPage(url)
{
	var nieuw = window.open(url,"", 'height=600,width=800,toolbar=no,scrollbars=yes,status=no,location=no,menubar=yes,directories=no');
	return false;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

	function puImage(imgName) {
		window.open('/popup.asp?'+imgName, '','resizable=1,height=200,width=200,top=300,left=300');
	}

function validateForm(formulier)
{
  var missing_fields = new Array()
  var total_missing = 0
  
  // Loop through all the form elements
  for (counter = 0; counter < formulier.length; counter++) {
    if (formulier[counter].className.indexOf("verplicht") != -1) {
      
      // Is it empty?
      if (its_empty(formulier[counter].value)) {
       
        // If so, add the field to the array of missing fields
        missing_fields[total_missing] = formulier[counter]
        total_missing++
      }
      // Wrong value?
      if (formulier[counter].value == "your name" || formulier[counter].value == "je naam" || formulier[counter].value == "tuo nomeie") {
       
        // If so, add the field to the array of missing fields
        missing_fields[total_missing] = formulier[counter]
        total_missing++
      }
      // Wrong value?
      if (formulier[counter].value == "artiest" || formulier[counter].value == "artist" || formulier[counter].value == "artista") {
       
        // If so, add the field to the array of missing fields
        missing_fields[total_missing] = formulier[counter]
        total_missing++
      }
      // Wrong value?
      if (formulier[counter].value == "titel" || formulier[counter].value == "title" || formulier[counter].value == "título") {
       
        // If so, add the field to the array of missing fields
        missing_fields[total_missing] = formulier[counter]
        total_missing++
      }
    }
  }

  // Were there any fields missing?
  if (total_missing > 0) {
  
    // Start the message
    var missing_message = "You're supposed to enter a valid value in the following field" +
               (total_missing == 1 ? ":" : "s:") +
               "\n______________________________\n\n"
    
    // Loop through the missing fields
    for (counter = 0; counter < missing_fields.length; counter++) {
      missing_message += missing_fields[counter].name.replace('_',' ') + "\n"
    }
  
    // Finish up and display the message
    missing_message += "\n______________________________\n\n" +
            "Please fill in these fields and then resubmit the form."
    alert(missing_message)
    
    // For emphasis, put the focus on the first missing field
    if(missing_fields[0].type!='hidden') missing_fields[0].focus();
  }
  else {
    // Otherwise, go ahead and submit
    formulier.submit();
 
  }
}
function its_empty(string_value) {

  // Check for the empty string and null
  if (string_value == "" || string_value == null) {
  
    // If either, it's empty so return true
    return true
  }
  
  // Otherwise, it's not empty so return false
  return false
}