window.addEvent('domready', function() {
    rijRollOverEvents();
    hoofdstukKlapUit();
    kopRijRollOverEvents();
    subRijRollOverEvents();
    wijzigZoekformEvent();
    zoekResultatenEvents();
    icoonEuroGroenEvents();
    icoonVerwijderenEvents();
    icoonToevoegenEvents();
    vergelijkingOpslaanEvent();
    vergelijkingPrintenEvent();
    vensterPrintenEvent();
    vensterSluitenEvent();
    icoonPrinterEvents();
    icoonTellFriendEvents();
    faqLinks();
    keepalive();
});

function keepalive() {
    var heavyImage = new Image();
    var randomnumber = Math.floor(Math.random() * 9999999999)
    heavyImage.src = "/layouts/KeepAlive.aspx?random=" + randomnumber;
    setTimeout(keepalive, 300000);
}

function rijRollOverEvents() {
	rijen = $$('table.overzichtTabel tr.rij');
	
	rijen.each(function(rij) {
		rij.addEvent('mouseover', function() {
			rij.className = 'rij rij_mo';	
		});
		
		rij.addEvent('mouseout', function() {
			rij.className = 'rij';	
		});
	});
}

function kopRijRollOverEvents() {
	koprijen = $$('table.overzichtTabel tr.kopRij');
	
	koprijen.each(function(koprij) {
		koprij.addEvent('mouseover', function() {
			koprij.className = 'kopRij kopRij_mo';	
		});
		
		koprij.addEvent('mouseout', function() {
			koprij.className = 'kopRij';	
		});
	});
}

function subRijRollOverEvents() {
	subrijen = $$('table.overzichtTabel tr.subRij');
	
	subrijen.each(function(subrij) {
		subrij.addEvent('mouseover', function() {
			subrij.className = 'subRij subRij_mo';	
		});
		
		subrij.addEvent('mouseout', function() {
			subrij.className = 'subRij';	
		});
	});
}

function wijzigZoekformEvent() {
	if ($('wijzigZoekform')) {
		$('wijzigZoekform').addEvent('change', function() {
			wijzigZoekform();
		});
	}
}

function zoekResultatenEvents() {
	if ($('klapper_samenvattingen')) {
		$('klapper_samenvattingen').addEvent('click', function() {
			toggleResultaten('samenvattingen');
		});
	}
	if ($('klapper_nieuwsberichten')) {
		$('klapper_nieuwsberichten').addEvent('click', function() {
			toggleResultaten('nieuwsberichten');
		});
	}
	if ($('klapper_overzichten-en-indices')) {
		$('klapper_overzichten-en-indices').addEvent('click', function() {
			toggleResultaten('overzichten-en-indices');
		});
	}
	if ($('klapper_cao-overzicht')) {
		$('klapper_cao-overzicht').addEvent('click', function() {
			toggleResultaten('cao-overzicht');
		});
	}
	if ($('klapper_redactioneel-commentaar')) {
		$('klapper_redactioneel-commentaar').addEvent('click', function() {
			toggleResultaten('redactioneel-commentaar');
		});
	}
	if ($('klapper_marketing-paginas')) {
		$('klapper_marketing-paginas').addEvent('click', function() {
			toggleResultaten('marketing-paginas');
		});
	}
	if ($('klapper_generieke-paginas')) {
		$('klapper_generieke-paginas').addEvent('click', function() {
			toggleResultaten('generieke-paginas');
		});
	}
	if ($('klapper_oris')) {
		$('klapper_oris').addEvent('click', function() {
			toggleResultaten('oris');
		});
	}
	if ($('klapper_faqs')) {
		$('klapper_faqs').addEvent('click', function() {
			toggleResultaten('faqs');
		});
	}
	if ($('klapper_links')) {
		$('klapper_links').addEvent('click', function() {
			toggleResultaten('links');
		});
	}

}



function faqLinks() {
	if ($('cat_marketing-paginas')) {
		$('cat_marketing-paginas').addEvent('click', function() {
			toggleResultaten('marketing-paginas');
		});
	}
	
	if ($('cat_links')) {
		$('cat_links').addEvent('click', function() {
			toggleResultaten('links');
		});
	}

}


function icoonEuroGroenEvents() {
	euroIconen = $$('.icoonEuroGroen','.icoonEuroGroenCaoWeb');
	
	euroIconen.each(function(euroIcoon) {
		//euroIcoon.addEvent('click', function() {
		//	alert('popup functie komt hier');
//			toonPopup();	
		//});
		euroIcoon.addEvent('mouseover', function() {
			euroIcoon.src = '/siteimg/icoon_euro_groen12_actief.gif';	
		});
		euroIcoon.addEvent('mouseout', function() {
			euroIcoon.src = '/siteimg/icoon_euro_groen12.gif';	
		});
	});
}



function icoonVerwijderenEvents() {
	verwijderIconen = $$('.icoonVerwijderen');
	
	verwijderIconen.each(function(verwijderIcoon) {
		//verwijderIcoon.addEvent('click', function() {
		//	alert('verwijderCAO functie komt hier');
//			verwijderCAO();	
		//});
		verwijderIcoon.addEvent('mouseover', function() {
			verwijderIcoon.src = '/siteimg/icoon_verwijderen_actief.gif';	
		});
		verwijderIcoon.addEvent('mouseout', function() {
			verwijderIcoon.src = '/siteimg/icoon_verwijderen.gif';	
		});
	});
}

function icoonToevoegenEvents() {
	toevoegIconen = $$('.icoonToevoegen');
	
	toevoegIconen.each(function(toevoegIcoon) {
		//toevoegIcoon.addEvent('click', function() {
		//	alert('toevoegCAO functie komt hier');
//			toevoegCAO();	
		//});
		toevoegIcoon.addEvent('mouseover', function() {
			toevoegIcoon.src = '/siteimg/icoon_toevoegen_actief.gif';	
		});
		toevoegIcoon.addEvent('mouseout', function() {
			toevoegIcoon.src = '/siteimg/icoon_toevoegen.gif';	
		});
	});
}

function icoonPrinterEvents() {
	Printer = $$('.icoonPrinter');
	
	Printer.each(function(PrintersIcon) {
		//PrintersIcon.addEvent('click', function() {
		//	alert('printer popup verschijnt');
//			toevoegCAO();	
		//});
		PrintersIcon.addEvent('mouseover', function() {
			PrintersIcon.src = '/siteimg/icoon_printer_actief.gif';	
			
		});
		PrintersIcon.addEvent('mouseout', function() {
			PrintersIcon.src = '/siteimg/icoon_printer.gif';	
		});
	});
}

function icoonTellFriendEvents() {
	TellFriend = $$('.tellFriend');
	TellFriend.each(function(tellFriendIcon) {
		//tellFriendIcon.addEvent('click', function() {
		//	alert('Tellafriend systeem komt hier');
//			toevoegCAO();	
		//});
		tellFriendIcon.addEvent('mouseover', function() {
			tellFriendIcon.src = '/siteimg/icoon_tellfriend_actief.gif';	
			
		});
		tellFriendIcon.addEvent('mouseout', function() {
			tellFriendIcon.src = '/siteimg/icoon_tellfriend.gif';	
		});
	});
}


function vergelijkingOpslaanEvent() {
	if ($('vergelijkingOpslaan')) {
		$('vergelijkingOpslaan').addEvent('click', function() {
			alert('opslaan van vergelijking functie komt hier');
//			opslaanVergelijking();
		});
	}
}

function vergelijkingPrintenEvent() {
	if ($('vergelijkingPrinten')) {
		$('vergelijkingPrinten').addEvent('click', function() {
			window.print();
		});
	}
}


function vensterSluitenEvent() {
	if ($('vensterSluiten')) {
		$('vensterSluiten').addEvent('click', function() {
			window.close();
		});
	}
}

function vensterPrintenEvent() {
	if ($('vensterPrinten')) {
		$('vensterPrinten').addEvent('click', function() {
			window.print();
		});
	}
}



function wijzigZoekform() {
	if (document.forms['zoekForm'].elements['zoekWijze'].tagName == "SELECT") {
		if (document.forms['zoekForm'].elements['zoekWijze'].value == 'uitgebreid') {
			document.getElementById('zoekDiv').className = 'uitgebreidZoeken';
			document.getElementById('uitgebreidZoekCriteria').style.display = 'block';
			document.getElementById('buttonSnelZoeken').style.display = 'none';
		}
		else {
			document.getElementById('zoekDiv').className = 'snelZoeken';
			document.getElementById('uitgebreidZoekCriteria').style.display = 'none';
			document.getElementById('buttonSnelZoeken').style.display = 'block';
		}
	}
	else if (document.forms['zoekForm'].elements['zoekWijze'][0].type == "radio") {
		if (document.forms['zoekForm'].elements['zoekWijze'].length > 1) {
			for (i=0; i < document.forms['zoekForm'].elements['zoekWijze'].length; i++) {
				if (document.forms['zoekForm'].elements['zoekWijze'][i].checked) {
					if (document.forms['zoekForm'].elements['zoekWijze'][i].value == 'uitgebreid') {
						document.getElementById('zoekDiv').className = 'uitgebreidZoeken';
						document.getElementById('uitgebreidZoekCriteria').style.display = 'block';
						document.getElementById('buttonSnelZoeken').style.display = 'none';
					}
					else {
						document.getElementById('zoekDiv').className = 'snelZoeken';
						document.getElementById('uitgebreidZoekCriteria').style.display = 'none';
						document.getElementById('buttonSnelZoeken').style.display = 'block';
					}
				}
			}
		}
		else if (document.forms['zoekForm'].elements['zoekWijze'].length == 1) {
			if (document.forms['zoekForm'].elements['zoekWijze'][0].checked) {
				if (document.forms['zoekForm'].elements['zoekWijze'][0].value == 'uitgebreid') {
					document.getElementById('zoekDiv').className = 'uitgebreidZoeken';
					document.getElementById('uitgebreidZoekCriteria').style.display = 'block';
					document.getElementById('buttonSnelZoeken').style.display = 'none';
				}
				else {
					document.getElementById('zoekDiv').className = 'snelZoeken';
					document.getElementById('uitgebreidZoekCriteria').style.display = 'none';
					document.getElementById('buttonSnelZoeken').style.display = 'block';
				}
			}
		}
	}
}



//function verwijderCAO(caoId) {
	//if(confirm("Weet u zeker dat u deze CAO uit Mijn CAO's wilt verwijderen?")) alert ('caoId = ' + caoId);
//}

//function toevoegCAO(caoId) {
	//alert (caoId);
//}



var popupTeller = 0;

// Eerste versie popup-venster
function toonPopup(id) {
	window.open ('popup.html?id='+id, 'Popup_'+popupTeller, 'width=650px, height=397px');
	popupTeller++;
}

// Alternatief / andere uitvoering
function toonPopupAlternatief(id) {
	window.open ('popup_alternatief.html?id='+id, 'Popup_alternatief_'+popupTeller, 'width=650px, height=314px');
	popupTeller++;
}


/*
function toggleNavigatie(hoofdstuk) {
	if ($('nav_hs' + hoofdstuk).style.display == 'none') {
		$('nav_hs' + hoofdstuk).style.display = 'block';
		$('toggle_hs' + hoofdstuk).className = 'toonNavigatie';
	}
	else if ($('nav_hs' + hoofdstuk).style.display == 'block') {
		$('nav_hs' + hoofdstuk).style.display = 'none';
		$('toggle_hs' + hoofdstuk).className = 'verbergNavigatie';
	}
}
*/


function hoofdstukKlapUit () {
$$('.toonNavigatie').each(function(item, index) {
						
            item.addEvent('click', function() {
              $$('.navigatie').each(function(item2) {
              item2.style.display = 'none';
              
					});
               	$$('.navigatie')[index].style.display = 'block';
                $$('.toonNavigatie').each(function(item2) {
              	item2.style.display = 'block';
              	
					});
					$$('.toonNavigatie')[index].style.display = 'none';
       }); 
});

$$('.verbergNavigatie').each(function(item, index) {
			 item.addEvent('click', function() {
           	 
           	 $$('.navigatie')[index].style.display = 'none';
           	  $$('.toonNavigatie')[index].style.display = 'block';
       }); 
});
}



function toggleResultaten(cat) {
	if ($('result_' + cat).className == 'zichtbaar') {
		$('result_' + cat).className = 'verborgen';
		$('klapper_' + cat).src = '/siteimg/klapUit.gif';
	}
	else if ($('result_' + cat).className == 'verborgen') {
		$('result_' + cat).className = 'zichtbaar';
		$('klapper_' + cat).src = '/siteimg/klapIn.gif';
	}
}

function toggleResultatenViaLinks(catLink) {

	if ($('cat_' + catLink).className == 'zichtbaar') {
		$('cat_' + catLink).className = 'verborgen';
		$('klapper_' + catLink).src = '/siteimg/klapUit.gif';
	}
	else if ($('cat_' + catLink).className == 'verborgen') {
		$('cat_' + catLink).className = 'zichtbaar';
		$('klapper_' + catLink).src = '/siteimg/klapIn.gif';
	}
}




/*
function ruler() {
	rijen = $$('table.overzichtTabel tr.rij');
	
	rijen.each(function(element) {
		element.onmouseover = function() {
			element.className = 'rij rij_mo';	
		}
		
		element.onmouseout = function() {
			element.className = 'rij';	
		}
		
	});
	
	subrijen = $$('table.overzichtTabel tr.subRij');
	
	subrijen.each(function(element) {
		element.onmouseover = function() {
			element.className = 'subRij subRij_mo';	
		}
		
		element.onmouseout = function() {
			element.className = 'subRij';	
		}
		
	});
	
	koprijen = $$('table.overzichtTabel tr.kopRij');
	
	koprijen.each(function(element) {
		element.onmouseover = function() {
			element.className = 'kopRij kopRij_mo';	
		}
		
		element.onmouseout = function() {
			element.className = 'kopRij';	
		}
		
	});
		
		
}
*/


