//
// We assume that, to be visibile, a certain element is either 'hidden' or 'block'
//
function switchVisible(id){
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		if(document.getElementById(id).style.display != 'block'){
		  document.getElementById(id).style.display = 'block';
		} else {
		  document.getElementById(id).style.display = 'none';
		}
	}
	else {
		if (document.layers) { // Netscape 4
			if(document.id.display != 'block'){
				document.id.display = 'block';
			} else {
				document.id.display = 'none'
			}
		}
		else { // IE 4
			if(document.all.id.style.display != 'block'){
			  document.all.id.style.display == 'block';
			} else {
			  document.all.id.style.display == 'none';
			}
		}
	}
}

function check_validity_date(){
	var van = new Date();
	van.setYear(document.agenda.CHECK_VAN_JAAR.options[document.agenda.CHECK_VAN_JAAR.selectedIndex].value);
	van.setMonth(document.agenda.CHECK_VAN_MAAND.options[document.agenda.CHECK_VAN_MAAND.selectedIndex].value);
	van.setDate(document.agenda.CHECK_VAN_DAG.options[document.agenda.CHECK_VAN_DAG.selectedIndex].value);
	
	var tot = new Date();
	tot.setYear(document.agenda.CHECK_TOT_JAAR.options[document.agenda.CHECK_TOT_JAAR.selectedIndex].value);
	tot.setMonth(document.agenda.CHECK_TOT_MAAND.options[document.agenda.CHECK_TOT_MAAND.selectedIndex].value);
	tot.setDate(document.agenda.CHECK_TOT_DAG.options[document.agenda.CHECK_TOT_DAG.selectedIndex].value);	
	
	
	var non_negative = false;	
	
	//check if we are not renting our location for a negative amount of time: 
	//ie: tot-date < van-date: 
	if(van.getTime() < tot.getTime()){
		//all is well.
		non_negative = true;
	} else {
		if(van.getTime() == tot.getTime()){
			//is the time different?
			v_uur = document.agenda.CHECK_VAN_UUR.options[document.agenda.CHECK_VAN_UUR.selectedIndex].value - 0;
			v_min = document.agenda.CHECK_VAN_MIN.options[document.agenda.CHECK_VAN_MIN.selectedIndex].value - 0;	
				
			t_uur = document.agenda.CHECK_TOT_UUR.options[document.agenda.CHECK_TOT_UUR.selectedIndex].value - 0;
			t_min = document.agenda.CHECK_TOT_MIN.options[document.agenda.CHECK_TOT_MIN.selectedIndex].value - 0;				
			
			if(v_uur < t_uur){
				non_negative = true;
			} else {
				if((v_uur == t_uur) && (v_min < t_min)){					
					non_negative = true;
				}
			}					
		} 
	}
	
	var realistic_timing = false;
	//check if we are not renting our location for an unacceptable (either to large or to small) amount of time: 
	//currently; 14 days is maximum	
	if(tot.getTime() - van.getTime() <= 14*24*60*60*1000)	
	{
		realistic_timing = true;
	} 
	
	if(!non_negative || !realistic_timing){
		alert("De door u ingevoerde data voldoen niet aan onze eisen. Dat kan komen doordat:\n-de einddatum kleiner is dan de begindatum\n-de activiteit te lang (> 14 dagen) duurt");
	}
	return non_negative && realistic_timing;
}

function updateImages(){
	document.getElementById('imgjs').src='img/vink.gif';
	if(xmlhttp_supported()){
		document.getElementById('imgxmlhttp').src='img/vink.gif';
	}
}

 function setUpdateTime2(){
	if(document.agenda) {
	   d = document.agenda;
	   if(d.CHECK_VAN_UUR) d.CHECK_VAN_UUR.onchange = updateTime2;
	   if(d.CHECK_VAN_UUR) d.CHECK_VAN_MIN.onchange = updateTime2;
	   if(d.CHECK_VAN_UUR) d.CHECK_VAN_DAG.onchange = updateTime2;
	   if(d.CHECK_VAN_UUR) d.CHECK_VAN_MAAND.onchange = updateTime2;
	   if(d.CHECK_VAN_UUR) d.CHECK_VAN_JAAR.onchange = updateTime2;	   
	   
	   if(d.CHECK_TOT_UUR) d.CHECK_TOT_UUR.onchange = updateTime2;
	   if(d.CHECK_TOT_UUR) d.CHECK_TOT_MIN.onchange = updateTime2;
	   if(d.CHECK_TOT_UUR) d.CHECK_TOT_DAG.onchange = updateTime2;
	   if(d.CHECK_TOT_UUR) d.CHECK_TOT_MAAND.onchange = updateTime2;
	   if(d.CHECK_TOT_UUR) d.CHECK_TOT_JAAR.onchange = updateTime2;
   }
   
   if(document.getElementById('hours')){
     days = document.getElementById('hours');
	 days.onchange = function changeValue(){
	   if(document.getElementById('days')){
	     document.getElementById('days').selectedIndex = 0;
	   }
	 }
   }
   
   if(document.getElementById('days')){
     days = document.getElementById('days');
	 days.onchange = function changeValue(){
	   if(document.getElementById('hours')){
	     document.getElementById('hours').selectedIndex = 0;
	   }
	 }
   }   
 }
 
function updateTime2(){
    d = document.agenda;
	
	//VAN-values
	v_uur = d.CHECK_VAN_UUR.options[d.CHECK_VAN_UUR.selectedIndex].value - 0;
	v_min = d.CHECK_VAN_MIN.options[d.CHECK_VAN_MIN.selectedIndex].value - 0;
	v_dag = d.CHECK_VAN_DAG.options[d.CHECK_VAN_DAG.selectedIndex].value - 0;
	v_mnd = d.CHECK_VAN_MAAND.options[d.CHECK_VAN_MAAND.selectedIndex].value - 0;
	v_yr  = d.CHECK_VAN_JAAR.options[d.CHECK_VAN_JAAR.selectedIndex].value - 0;
	
	//TOT-values
	t_uur = d.CHECK_TOT_UUR.options[d.CHECK_TOT_UUR.selectedIndex].value - 0;
	t_min = d.CHECK_TOT_MIN.options[d.CHECK_TOT_MIN.selectedIndex].value - 0;
	t_dag = d.CHECK_TOT_DAG.options[d.CHECK_TOT_DAG.selectedIndex].value - 0;
	t_mnd = d.CHECK_TOT_MAAND.options[d.CHECK_TOT_MAAND.selectedIndex].value - 0;
	t_yr  = d.CHECK_TOT_JAAR.options[d.CHECK_TOT_JAAR.selectedIndex].value - 0;
	
	van = new Date(v_yr, v_mnd, v_dag, v_uur, v_min, 0);
//	alert(v_yr + " " + v_mnd + " " + v_dag + " " + v_uur + " " + v_min + " " + 0 + " " + 0);
	//van.UTC(v_yr, v_mnd, v_dag, v_uur, v_min, 0, 0);
	
	tot = new Date(t_yr, t_mnd, t_dag, t_uur, t_min, 0);
	//tot.UTC(t_yr, t_mnd, t_dag, t_uur, t_min, 0, 0);
	
	if(tot.getTime() < van.getTime()){   	  
	  d.CHECK_TOT_UUR.selectedIndex = d.CHECK_VAN_UUR.selectedIndex;
	  d.CHECK_TOT_MIN.selectedIndex = d.CHECK_VAN_MIN.selectedIndex;
	  d.CHECK_TOT_DAG.selectedIndex = d.CHECK_VAN_DAG.selectedIndex;
	  d.CHECK_TOT_MAAND.selectedIndex = d.CHECK_VAN_MAAND.selectedIndex;
	  d.CHECK_TOT_JAAR.selectedIndex = d.CHECK_VAN_JAAR.selectedIndex;	
	}
}
