var ciSearchArray=new Array();

// JavaScript Document
function zoekci(queryZoekWoord, queryType, queryPaginaHuidig) {
	document.getElementById('ajax_queryzoekitem').value				=	queryZoekWoord
	document.getElementById('ajax_queryType').value					=	queryType
	document.getElementById('ajax_queryPaginaHuidig').value			=	queryPaginaHuidig

	// CHECKEN OF DROPBOXEN AANWEZIG ZIJN
	if (document.getElementById("CI_contentpaneel_footer") != null) {
		document.getElementById('CI_zoeken_paginanummer_top').value		=	queryPaginaHuidig
		document.getElementById('CI_zoeken_paginanummer_bottom').value	=	queryPaginaHuidig
	}
	if (isNaN(queryZoekWoord)) {
	document.getElementById('CI_zoeken_zoekitem').value			=	queryZoekWoord
	}
	ajaxPlaatsMarker()
	ajaxToonResultaat()
}

function zoekcifront(queryZoekWoord, queryType, ajax_queryExtraInstructie, queryPaginaHuidig) {
	urlToGo = "index.php?ajax_queryzoekitem=" + queryZoekWoord + "&ajax_querytype=" + queryType + "&ajax_queryPaginaHuidig=0&field=" + ajax_queryExtraInstructie + "&manual=true"
//	alert(urlToGo)
	document.location.href=urlToGo;
	//document.getElementById('ajax_queryzoekitem').value			=	queryZoekWoord
	//document.getElementById('ajax_queryType').value					=	queryType
	//document.getElementById('ajax_queryPaginaHuidig').value			=	queryPaginaHuidig
	//document.getElementById('CI_zoeken_paginanummer_top').value		=	queryPaginaHuidig
	//document.getElementById('CI_zoeken_paginanummer_bottom').value	=	queryPaginaHuidig
	//if (isNaN(queryZoekWoord)) {
	//document.getElementById('CI_zoeken_zoekitem').value			=	queryZoekWoord
	//}
}


// KOLOMMEN-STRUCTUUR INLEZEN
var colCount = 4;

if (colCount == 3) {
	// 3 kolommen
	var maxCaption = 42; 
	var captionWidth = 235;
	var thumbPaneelHeightEvent = 290;
	var thumbPaneelHeightFoto = 285;
	var thumbPaneelWidth = 255;
	var thumbAfbHeight = 220;
	

} else {
	 // 4 kolommen of anders
	var colCount = 4;
	var maxCaption = 27;
	var captionWidth = 165;
	var thumbPaneelHeightEvent = 245;
	var thumbPaneelHeightFoto = 237;
	var thumbPaneelWidth = 185;
	var thumbAfbHeight = 170;
}

function ajaxToonResultaat() {

		document.getElementById('dimPanelLayer').style.display = 'inline';
		queryZoekWoord			=	document.getElementById('ajax_queryzoekitem').value;
		queryTrefwoord	 		= 	document.getElementById('ajax_querytrefwoord').value;
		queryType				=	document.getElementById('ajax_queryType').value;
		queryPaginaHuidig 		= 	document.getElementById('ajax_queryPaginaHuidig').value;
		queryExtraInstructie	=	document.getElementById('ajax_queryExtraInstructie').value;
		queryPaginaAantalItems 	= 	36

		//alert('zoekitem=' + queryZoekWoord + '&action=' + queryType + '&page=' + queryPaginaHuidig + '&perpage=' + queryPaginaAantalItems + '&' + queryExtraInstructie)
		ajaxpack.postAjaxRequest('ci_ajax_dialogs.php', 'zoekitem=' + queryZoekWoord + '&trefwoord=' + queryTrefwoord + '&action=' + queryType + '&page=' + queryPaginaHuidig + '&perpage=' + queryPaginaAantalItems + '&field=' + queryExtraInstructie, 'txt')
		var myajaxnew=ajaxpack.ajaxobj
		myajaxnew.onreadystatechange = function() {
			
		if (myajaxnew.readyState == 4){ //if request of file completed
		if (myajaxnew.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			strBestandsnaamBron = myajaxnew.responseText
			//alert(myajaxnew.responseText)
			
			if ((queryType == 'get_fotooverzicht') || (queryType == 'get_eventoverzicht') || (queryType == 'get_lightboxoverzicht')) { 
				/////////////////////////////////////////////////////////////
				//
				// STRUCTUUR:
				// <#> foto-afscheiding
				// <|> veldafscheiding
				// Veld 1: `fotos`.`fotos_ID` 			// Foto ID
				// Veld 2: `fotos`.`fotos_date`			// Foto datum
				// Veld 3: `fotos`.`fotos_exclusive`	// Foto exclusief
				// Veld 4: `fotos`.`fotos_caption		// Foto bijschrift
				// Veld 5: `fotos`.`fotos_src`			// Foto thumbnail
				// Veld 6: `event`.`event_ID`			// Event id
				// Veld 7: `event`.`event_event`		// Event naam
				// Veld 8: `event`.`event_exclusive`	// Event exclusief
				// Veld 9: `event`.`event_location`		// Event locatie
				//
				/////////////////////////////////////////////////////////////
				var arrFoto = myajaxnew.responseText.split('<#>')
				document.getElementById("dimPanelLayer").style.display = "none";
				document.getElementById('CI_contentpaneel').innerHTML = '';
				
				// Uitlezen eigenschappen pagina
				var divPaginaEigenschappen = arrFoto[0].split("<|>");
				document.getElementById("CI_contentpaneel_header").innerHTML = '<strong>' + divPaginaEigenschappen[0] + '</strong>';
				document.getElementById('ajax_queryPaginaTotaal').value		=	divPaginaEigenschappen[1]
				document.getElementById('ajax_queryAantalTreffers').value		=	divPaginaEigenschappen[2]
				
				// TONEN PAGINANUMMERS
				ajaxToonPaginaNummering(divPaginaEigenschappen[1]);
				
				if (queryType != 'get_fotooverzicht') { // ALLES BEHALVE IMAGE-OVERZICHT
					// Plaatsen items
					for (var i = 1 ; i < arrFoto.length;i++) {
						var arrFotoDetails = arrFoto[i].split("<|>");
						arrFotoDetails[4] = arrFotoDetails[4].split('_')			.join(" "); 
						arrFotoDetails[5] = arrFotoDetails[5].split('_')			.join(" "); 
						var divThumbInhoud = document.getElementById('tmp_FotoThumbnail').innerHTML
						divThumbInhoud = divThumbInhoud.split('[PATH_THUMBNAIL]')		.join(arrFotoDetails[1] + '&col=' + colCount.toString()); 
						divThumbInhoud = divThumbInhoud.split('%5BPATH_THUMBNAIL%5D')	.join(arrFotoDetails[1] + '&col=' + colCount.toString()); 
						divThumbInhoud = divThumbInhoud.split('[THUMBNAIL_ID]')			.join(arrFotoDetails[1]); 
						divThumbInhoud = divThumbInhoud.split('[THUMBNAIL_HEIGHT]')		.join(thumbAfbHeight); 

						divThumbInhoud = divThumbInhoud.split('[FOTO_DATE]')			.join(arrFotoDetails[2]); 
						if (arrFotoDetails[4].length > maxCaption) {
							divThumbInhoud = divThumbInhoud.split('[CAPTIONSMALL]')		.join(arrFotoDetails[4].substr(0,35) + " (..)"); 
							divThumbInhoud = divThumbInhoud.split('[CUTOFF]')			.join("(..)");
						} else {
							divThumbInhoud = divThumbInhoud.split('[CUTOFF]')			.join("");
						}
	
						divThumbInhoud = divThumbInhoud.split('[CAPTIONSMALL]')			.join(arrFotoDetails[4]);
						divThumbInhoud = divThumbInhoud.split('[CAPTION]')				.join(arrFotoDetails[4]); 
						divThumbInhoud = divThumbInhoud.split('[EVENT_NAME]')			.join(arrFotoDetails[5]); 
						divThumbInhoud = divThumbInhoud.split('[EVENT_LOCATION]')		.join(arrFotoDetails[8]); 
						divThumbInhoud = divThumbInhoud.split('[FOTO_LOCATIEINQUERY]')	.join(arrFotoDetails[9]); 
						if(queryType == 'get_lightboxoverzicht' ) {
							urlDelete = "javascript:zoekci(" + queryZoekWoord + ", 'ajax_delfromlightbox', '&lightboxid=" + queryZoekWoord + "&photoid=" + arrFotoDetails[1] + "'); zoekci(" + queryZoekWoord + ", 'get_lightboxoverzicht', '')"
							divThumbInhoud = divThumbInhoud.split("[FOTO_LIGHTBOXACTION]")	.join("<a href=\"" + urlDelete + "\"><br><img src=\"images/site_art/icon_lightbox_small.png\" width=\"16\" height=\"10\" \ valign=\"absmiddle\" border=\"0\" style=\"margin-left:1px;margin-top:7px;\">&nbsp;Verwijder uit light-box</a>"); 
						} else {
							divThumbInhoud = divThumbInhoud.split('[FOTO_LIGHTBOXACTION]')	.join(""); 
						}
						// arrFotoDetails[3] FOTO EXCLUSIEF
						// arrFotoDetails[7] EVENT EXCLUSIEF
	 
						var divThumbnail = document.createElement('DIV');
						divThumbnail.innerHTML = divThumbInhoud;
						divThumbnail.id='CI_fotothumb';
						divThumbnail.className ='cbb-photo-thumb';
						divThumbnail.position ='absolute';
						divThumbnail.style.width = thumbPaneelWidth.toString() + "px";
						divThumbnail.style.height = thumbPaneelHeightFoto.toString() + "px";

						if (queryType == 'get_lightboxoverzicht') {
							divThumbnail.style.height = '250px';
						}
							
						document.getElementById("CI_contentpaneel").appendChild(divThumbnail);

						// BREEDTE CAPTION INSTELLEN
						document.getElementById("caption_" + arrFotoDetails[1].toString()).style.width=	captionWidth.toString() + "px";

	
						// Toevoegen Exclusive paneel
						if (arrFotoDetails[3] == '1') {
							document.getElementById("isExclusive_" + arrFotoDetails[1]).style.display = "inline";
						}
	
					}
				} else { // HET BETREFT EEN REGULIER FOTO-OVERZICHT, GROEPEREN IN EVENTS DUS
					//alert("image-overzicht")
					for (var i = 1 ; i < arrFoto.length;i++) {
						var arrEventDetails = arrFoto[i].split("<|>");
						arrEventDetails[4] = arrEventDetails[4].split('_')			.join(" "); 
						arrEventDetails[5] = arrEventDetails[5].split('_')			.join(" "); 
						arrEventDetails[6] = arrEventDetails[6].split('\"')			.join('')
						var divThumbInhoud = document.getElementById('tmp_EventThumbnail').innerHTML
						divThumbInhoud = divThumbInhoud.split('[PATH_THUMBNAIL]').join(arrEventDetails[1] + '&col=' + colCount.toString()); 
						divThumbInhoud = divThumbInhoud.split('%5BPATH_THUMBNAIL%5D').join(arrEventDetails[1] + '&col=' + colCount.toString()); 
						divThumbInhoud = divThumbInhoud.split('[THUMBNAIL_ID]')			.join(arrEventDetails[1]); 
						divThumbInhoud = divThumbInhoud.split('[THUMBNAIL_HEIGHT]').join(thumbAfbHeight); 
						divThumbInhoud = divThumbInhoud.split('[CAPTION_WIDTH]').join(captionWidth); 
						divThumbInhoud = divThumbInhoud.split('%5BCAPTION_WIDTH%5D').join(captionWidth); 

						divThumbInhoud = divThumbInhoud.split('[FOTO_DATE]')		.join(arrEventDetails[2]); 
						if (arrEventDetails[6].length > maxCaption) {
							divThumbInhoud = divThumbInhoud.split('[CAPTIONSMALL]')			.join(arrEventDetails[6]); 
							divThumbInhoud = divThumbInhoud.split('[CUTOFF]')		.join("(..)");
						} else {
							divThumbInhoud = divThumbInhoud.split('[CUTOFF]')		.join("");
						}
	
						divThumbInhoud = divThumbInhoud.split('[CAPTIONSMALL]')			.join(arrEventDetails[6]); 
						divThumbInhoud = divThumbInhoud.split('[CAPTION]')			.join(arrEventDetails[6]); 
						divThumbInhoud = divThumbInhoud.split('[EVENT_NAME]')		.join(arrEventDetails[6]); 
						divThumbInhoud = divThumbInhoud.split('[EVENT_LOCATION]')	.join(arrEventDetails[8]); 
						divThumbInhoud = divThumbInhoud.split('[FOTO_LOCATIEINQUERY]')	.join(arrEventDetails[9]); 
						var strLink = "index.php?ajax_querytype=get_eventoverzicht&ajax_queryzoekitem=" + arrEventDetails[5] + "&ajax_querytrefwoord=" + escape(document.getElementById('ajax_queryzoekitem').value);
						
						divThumbInhoud = divThumbInhoud.split('[LINK]')		.join(strLink); 
						divThumbInhoud = divThumbInhoud.split('%5BLINK%5D')		.join(strLink); 
					divThumbInhoud = divThumbInhoud.split('[FOTO_AANTAL]')		.join(""); 

						var divThumbnail = document.createElement('DIV');
						divThumbnail.innerHTML = divThumbInhoud;
						divThumbnail.id='CI_eventthumb';
						divThumbnail.className ='cbb-photo-thumb';
						divThumbnail.position ='absolute';
						divThumbnail.style.width = thumbPaneelWidth.toString() + "px";
						divThumbnail.style.height = thumbPaneelHeightEvent.toString() + "px";
	
						document.getElementById("CI_contentpaneel").appendChild(divThumbnail);
						
						// BREEDTE CAPTION INSTELLEN
						document.getElementById("caption_" + arrEventDetails[1].toString()).style.width	= captionWidth.toString() + "px";
	
						// Toevoegen Exclusive paneel
//						if (arrEventDetails[3] == '1') {
//							document.getElementById("isExclusive_" + arrEventDetails[1]).style.display = "inline";
//						}
	
					}

				}
				
				// Mededeling bij geen treffers
				if (queryType != 'get_lightboxoverzicht') {
					if (divPaginaEigenschappen[2] == 0) {
						ajaxPopup('dialog_noresults', '');
					} 
				}

				// Vormgeving toevoegen
				//cbb.init('-photo-thumb')
				showSIFR()

			} else if ((queryType == 'get_eventoverzichtrecent') || (queryType == 'get_eventoverzichtcatagory') || (queryType == 'get_eventspecialcoverage')) {
				//////////////////////////////////////////////////////////////////////
				//
				// STRUCTUUR:
				// <#> foto-afscheiding
				// <|> veldafscheiding
				// Veld 1: var				 					// Foto ID
				// Veld 2: var									// Foto datum
				// Veld 3: var									// Foto exclusief
				// Veld 4: var									// Foto bijschrift
				// Veld 5: var									// Foto thumbnail
				// Veld 6: `event`.`event_event`				// Event naam
				// Veld 7: `event`.`event_exclusive`			// Event exclusief
				// Veld 8: `event`.`event_location`				// Event locatie
				// Veld 9: `photographers`.`photographers_naam`	// Event fotograaf
				// Veld 10: `event`.`event_ID`					// Event ID
				// Veld 11: var									// Aantal foto's
				//
				//////////////////////////////////////////////////////////////////////
				
				var arrEvent = myajaxnew.responseText.split('<#>')
				document.getElementById("dimPanelLayer").style.display = "none";
				document.getElementById('CI_contentpaneel').innerHTML = '';
				
				// Uitlezen eigenschappen pagina
				var divPaginaEigenschappen = arrEvent[0].split("<|>");

				// CHECKEN OF DROPBOXEN AANWEZIG ZIJN
				if (document.getElementById("CI_contentpaneel_footer") != null) {
					document.getElementById("CI_contentpaneel_header").innerHTML = '<strong>' + divPaginaEigenschappen[0] + '</strong>';
					document.getElementById('ajax_queryPaginaTotaal').value		=	divPaginaEigenschappen[1]
					document.getElementById('ajax_queryAantalTreffers').value		=	divPaginaEigenschappen[2]


				// TONEN PAGINANUMMERS
				ajaxToonPaginaNummering(divPaginaEigenschappen[1]);
				}

				// Plaatsen items
				for (var i = 1 ; i < arrEvent.length;i++) {
					var arrEventDetails = arrEvent[i].split("<|>");
					arrEventDetails[5] = arrEventDetails[5].split('_')			.join(" "); 

					var divThumbInhoud = document.getElementById('tmp_EventThumbnail').innerHTML;
					divThumbInhoud = divThumbInhoud.split('[PATH_THUMBNAIL]').join(arrEventDetails[1]); 
					divThumbInhoud = divThumbInhoud.split('%5BPATH_THUMBNAIL%5D').join(arrEventDetails[1]); 
					divThumbInhoud = divThumbInhoud.split('[FOTO_ID]')			.join(arrEventDetails[1]); 
					divThumbInhoud = divThumbInhoud.split('[FOTO_DATE]')		.join(arrEventDetails[2]); 
					if (arrEventDetails[5].length > maxCaption) {
						divThumbInhoud = divThumbInhoud.split('[CAPTION]')		.join(arrEventDetails[5].substr(0,35)); 
						divThumbInhoud = divThumbInhoud.split('[CUTOFF]')		.join("(..)");

					} else {
						divThumbInhoud = divThumbInhoud.split('[CUTOFF]')		.join("");
					}
					divThumbInhoud = divThumbInhoud.split('[CAPTION]')		.join(arrEventDetails[5]); 
					divThumbInhoud = divThumbInhoud.split('[EVENT_NAME]')		.join(arrEventDetails[5]); 
					divThumbInhoud = divThumbInhoud.split('[EVENT_LOCATION]')	.join(arrEventDetails[7]); 
					divThumbInhoud = divThumbInhoud.split('[EVENT_ID]')			.join(arrEventDetails[9]); 
					
					if (arrEventDetails[11] == 1) {
					//var strLink = "javascript:zoekci('" + arrEventDetails[9] + "', 'get_eventspecialcoverage', 0);";
					var strLink = "index.php?ajax_querytype=get_eventspecialcoverage&ajax_queryzoekitem=" + arrEventDetails[9] + "";

					} else {
//					var strLink = "javascript:zoekci('" + arrEventDetails[9] + "', 'get_eventoverzicht', 0);";
					var strLink = "index.php?ajax_querytype=get_eventoverzicht&ajax_queryzoekitem=" + arrEventDetails[9] + "";
					}
					
					divThumbInhoud = divThumbInhoud.split('[LINK]')		.join(strLink); 
					divThumbInhoud = divThumbInhoud.split('%5BLINK%5D')		.join(strLink); 
					divThumbInhoud = divThumbInhoud.split('[FOTO_AANTAL]')		.join(arrEventDetails[10]); 

					var divThumbnail = document.createElement('DIV');
					divThumbnail.innerHTML =divThumbInhoud;
					divThumbnail.id='CI_eventthumb';
					divThumbnail.className ='cbb-photo-thumb';

					document.getElementById("CI_contentpaneel").appendChild(divThumbnail);

					// Toevoegen Exclusive paneel
					if (arrEventDetails[6] == '1') {
						document.getElementById("isExclusive_" + arrEventDetails[9]).style.display = "inline";
					} else {
						// Alleen als een event niet exclusive is en wel Special Coverage 'special' tonen
						if (arrEventDetails[11] == 1) {
						document.getElementById("isSpecialEvent_" + arrEventDetails[9]).style.display = "inline";
						}
					}
	
				}

				// Mededeling bij geen treffers
				if (divPaginaEigenschappen[2] == 0) {
					ajaxPopup('dialog_noresults', '');
				}
				
				// Vormgeving toevoegen
				// cbb.init('-photo-thumb')
				showSIFR()

			} else if (queryType == 'ajax_dellightbox') {
				window.location.reload(true);

			} else { // einde if-clause queryType
				document.getElementById("dimPanelLayer").style.display = "none";
//window.location.reload(true);	
			}
		}
		}
	}
}

function ajaxBewaarZoekopdracht() {
	var zoekOpdracht = ""
	for(i=0; i < document.formZoekCI.elements.length; i++)	{
		zoekOpdracht = zoekOpdracht + document.formZoekCI.elements[i].name + "<|>" + document.formZoekCI.elements[i].value + "<#>";
	}
	return zoekOpdracht
}

function ajaxLaadZoekopdracht(strData) {
	var arrFormFields = strData.split("<#>");
	for(i=0; i < arrFormFields.length; i++) {
		var arrFormDetails = arrFormFields[i].split("<|>");
			if (arrFormDetails[0].length > 0) {
			document.formZoekCI[arrFormDetails[0]].value = arrFormDetails[1]
//			alert(arrFormDetails[0] + "|" + arrFormDetails[1])
			}
	}
}

function ajaxPlaatsMarker() {
	// AJAX-BACK BUTTON ACTIVEREN DOOR OPSLAAN HUIDIGE ZOEKOPDRACHT
	var backButtonHash=Math.floor(Math.random()*1000000000)

	// I-FRAME METHODE ALLEEN VOOR IE GEBRUIKERS
	if (document.all) {
		document.getElementById("ci_ajax_backiframe").src = "ci_ajax_backiframe.php?summary=" + backButtonHash;
	}
	
	// HASH-METHODE VOOR ALLE BROWSERS
	document.location.hash = backButtonHash;
	ciSearchArray[backButtonHash] = ajaxBewaarZoekopdracht()
	recentHash = "#" + backButtonHash;
}

function ajaxSaveQueryToSession() {
	divWrapperHistory = document.getElementById("wrapperSearchHistory")
	divItemsHistory = document.getElementById("itemsSearchHistory")
	if (divItemsHistory) {
		// Vlak opschonen
		if (divWrapperHistory) {
			divWrapperHistory.style.display = "block";
		}
		divItemsHistory.innerHTML = "";
	}
		ajaxpack.postAjaxRequest('ci_ajax_dialogs.php', 'action=save_searchhistory&keyword=' + document.getElementById("ajax_queryzoekitem").value + '&search=' + escape(ajaxBewaarZoekopdracht()), 'txt')
		var myajaxnew=ajaxpack.ajaxobj
	if (divItemsHistory) {
		myajaxnew.onreadystatechange = function() {
			
		if (myajaxnew.readyState == 4){ //if request of file completed
		if (myajaxnew.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			 if (myajaxnew.responseText.length > 0) {
				arrayHistoryItems = myajaxnew.responseText.split("<#>")
					for (var i = 0 ; i < arrayHistoryItems.length-1;i++) {
						arrayItem = arrayHistoryItems[i].split("|");
						var divHistoryItem = document.createElement('DIV');
						divHistoryItem.innerHTML = "terug naar > <a href=\"javascript:ajaxGetQueryFromSession(" + arrayItem[0] + ");\">" + arrayItem[1] + "</a>";
			//			divHistoryItem.id='CI_fotothumb';
			//			divHistoryItem.className ='cbb-photo-thumb';
			//			divHistoryItem.position ='absolute';
						divItemsHistory.appendChild(divHistoryItem);
					}
			 } else {
				divWrapperHistory.style.display = "none";
			 }
		}
		}
		}
	} // Bestaat de DIV; zijn we niet op de voorpagina?
}

function ajaxGetQueryFromSession(intID) {
	ajaxpack.getAjaxRequest('ci_ajax_dialogs.php', 'action=get_searchhistory&id=' + escape(intID), 'txt')
	var myajaxnew=ajaxpack.ajaxobj
	myajaxnew.onreadystatechange = function() {
		
	if (myajaxnew.readyState == 4){ //if request of file completed
	if (myajaxnew.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
//		alert(myajaxnew.responseText)
		ajaxLaadZoekopdracht(myajaxnew.responseText)
		ajaxPlaatsMarker()
		ajaxToonResultaat()
	}
	}
	}
	
}
function ajaxToonPaginaNummering(inputAantalPaginas) {
		queryPaginaHuidig 		= 	document.getElementById('ajax_queryPaginaHuidig').value;
		queryPaginaAantalItems 	= 	36
		
		// Vullen paginanummer combo
		var selectPaginaNummer_top = document.getElementById('CI_zoeken_paginanummer_top');
		var selectPaginaNummer_bottom = document.getElementById('CI_zoeken_paginanummer_bottom');
		selectPaginaNummer_top.options.length = 0; // Eerst leegmaken
		selectPaginaNummer_bottom.options.length = 0; // Eerst leegmaken

		for (var i = 0 ; i < inputAantalPaginas;i++) {
			selectPaginaNummer_top.options[i] = new Option(i+1,i*queryPaginaAantalItems);
			selectPaginaNummer_bottom.options[i] = new Option(i+1,i*queryPaginaAantalItems); // Eerst leegmaken
		}

		// Weergeven huidige pagina en totaal aantal pagina's
		intAantalPaginas = Math.round(inputAantalPaginas);
		var intVerschil	= (inputAantalPaginas - intAantalPaginas)

		if (intVerschil > 0) {
			intAantalPaginas = intAantalPaginas + 1;
		}
		
		selectPaginaNummer_top.value		=	document.getElementById('ajax_queryPaginaHuidig').value
		selectPaginaNummer_bottom.value		=	document.getElementById('ajax_queryPaginaHuidig').value
		document.getElementById('ci_weergave_totaalpaginas_bottom').innerHTML = intAantalPaginas;
		document.getElementById('ci_weergave_totaalpaginas_top').innerHTML = intAantalPaginas;
}

function ajaxToonPrevNextPreview(intCuritem, boolGoBack) {
		queryZoekWoord			=	document.getElementById('ajax_queryzoekitem').value;
		queryTrefWoord			=	document.getElementById('ajax_querytrefwoord').value;
		queryType				=	document.getElementById('ajax_queryType').value;
		if (document.getElementById('ajax_queryExtraInstructie').value.length > 0) {
		queryExtraInstructie	=	"&" + document.getElementById('ajax_queryExtraInstructie').value;
		}

		if(boolGoBack == true) {
			queryPaginaHuidig 		= 	intCuritem - 1 // Ga één item terug
			if (queryPaginaHuidig == -1) {
				queryPaginaHuidig = (document.getElementById('ajax_queryAantalTreffers').value -1)
			}

		} else {
			queryPaginaHuidig 		= 	intCuritem + 1 // Ga één item vooruit
			if (queryPaginaHuidig > (document.getElementById('ajax_queryAantalTreffers').value -1)) {
				queryPaginaHuidig = 0			
			}
		}
		queryPaginaAantalItems 	= 	1

		ajaxpack.postAjaxRequest('ci_ajax_dialogs.php', 'zoekitem=' + queryZoekWoord + '&trefwoord=' + queryTrefWoord + '&action=' + queryType + '&page=' + queryPaginaHuidig + '&perpage=' + queryPaginaAantalItems + queryExtraInstructie, 'txt')
		var myajaxnew=ajaxpack.ajaxobj
		myajaxnew.onreadystatechange = function() {
			
		if (myajaxnew.readyState == 4){ //if request of file completed
		if (myajaxnew.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			// alert(myajaxnew.responseText)
			var arrFoto = myajaxnew.responseText.split('<#>')
			var arrFotoDetails = arrFoto[1].split('<|>')
			// Tonen van de foto
			ajaxPopup('dialog_fotodetail', '&id=' + arrFotoDetails[1] + '&qloc='+queryPaginaHuidig);
		}
		}
		}
}

function ajaxToonPrevNextPage(boolGoBack) {
		queryPaginaAantalItems 	= 	36
		intHuidigePagina 	= parseInt(document.getElementById('ajax_queryPaginaHuidig').value)
		intAantalTreffers 	= parseInt(document.getElementById('ajax_queryAantalTreffers').value)
		intPaginaTotaal 	= parseInt(document.getElementById('ajax_queryPaginaTotaal').value)

		if (boolGoBack ==  true) {
			intNieuwePagina = intHuidigePagina - queryPaginaAantalItems;
			if (intNieuwePagina < 0) {
				intNieuwePagina = (intPaginaTotaal * queryPaginaAantalItems)
			}
		} else {
			intNieuwePagina = intHuidigePagina + queryPaginaAantalItems;
			if (intNieuwePagina > intAantalTreffers) {
				intNieuwePagina = 0
			}
		}
		// alert(intNieuwePagina);
		document.getElementById('ajax_queryPaginaHuidig').value = intNieuwePagina;
		ajaxPlaatsMarker();
		ajaxToonResultaat();
}

function ajaxLightboxActies(intIDLightbox, intIDFoto, strAction, qloc) {
	
	queryType =	"ajax_" + strAction + "lightbox";
	queryArgumenten = ""
	if (strAction == "add") {
	queryArgumenten = "&lightboxname=" + escape(intIDLightbox);
	}
	// alert(queryArgumenten)
	
		ajaxpack.postAjaxRequest('ci_ajax_dialogs.php', "action=" + queryType + '&lightboxid=' + intIDLightbox + '&photoid=' + intIDFoto + queryArgumenten, 'txt')
		var myajaxnew=ajaxpack.ajaxobj
		myajaxnew.onreadystatechange = function() {
			
		if (myajaxnew.readyState == 4){ //if request of file completed
		if (myajaxnew.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			if (strAction == "addto") {
				alert("Photo added to lightbox")
				
			} else if (strAction == "add") {
				alert("Lightbox added")
				
				if (qloc != 100000) { // Herkent toevoegen van Lightbox in sidebar
				ajaxPopup('dialog_fotodetail', '&id=' + intIDFoto + '&qloc=' + qloc);
				} else {
				window.location.reload(true);	

				}

			} else if (strAction == "del") {
				alert("Lightbox deleted")
				ajaxPopup('dialog_fotodetail', '&id=' + intIDFoto + '&qloc=' + qloc);
				
			} else if (strAction == "delfrom") {
				alert("Photo deleted from lightbox")
				ajaxClosePopup();			
			}
		}
	}
	}
}

function replaceAll( str, replacements ) {
    for ( i = 0; i < replacements.length; i++ ) {
        var idx = str.indexOf( replacements[i][0] );

        while ( idx > -1 ) {
            str = str.replace( replacements[i][0], replacements[i][1] ); 
            idx = str.indexOf( replacements[i][0] );
        }

    }
    return str;
}

function formVolgendVeld(e, nextfield, formname) { 

var keycode;
if (window.event) {
	keycode = window.event.keyCode;
} else if (e) {
	keycode = e.keyCode; 
} else {
	return false;
}

if (keycode == 13) {  //enter key pressed
	if (nextfield == "done"){ 
		if (formname=="smalllogin") {
			ajaxLogin(document.getElementById('small_login_user').value, document.getElementById('small_login_pass').value); return false;
		} else if (formname=="normallogin") {
			ajaxLogin(document.getElementById('login_user').value, document.getElementById('login_pass').value); return false;
		}
		return false;
//		alert()
//		document.getElementById(formname).submit()
	} else { //  we're not done yet, send focus to next box
		eval("document.getElementById('" + nextfield + "').focus()");
		return false;
	}
}
}
// document.onkeypress = onKeyPress; 

function ajaxPopup(action, argumenten) {

	if(argumenten != undefined) {
		var strArgumenten = argumenten
	} else {
		var strArgumenten = ''
	}

// GEBRUIKER INLOGGEN
// && = AND
// || = OR
	ajaxpack.getAjaxRequest('ci_ajax_dialogs.php', 'action=' + action + strArgumenten, 'txt')
	var myajax=ajaxpack.ajaxobj
	myajax.onreadystatechange = function() {

		if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			// alert(myajax.responseText)

			document.getElementById("Panel_Dialogs").innerHTML = myajax.responseText;
			// alert(myajax.responseText);
			document.getElementById("background_Dialogs").style.display = 'inline'
			document.getElementById("Panel_Dialogs").style.visibility = 'hidden'
			document.getElementById("Panel_Dialogs").style.display = 'inline'

			// document.getElementById("background_Dialogs").style.display = 'none'

			// JUIST POSITIONEREN VAN DIALOOGVENSTER
			var Opera = window.opera ? true : false;
			var CanvasBreedte	= 786
			var centerLeft		= 0
			var centerTop		= 0
			//var menuObject = document.getElementById("Dialog_Paneel")
			// var BasisWaarde = document.getElementById("Dialog_Paneel").style.width

			var centerLeft = getScrollX() + (getWinWidth() / 2) - (document.getElementById('Dialog_Paneel').clientWidth / 2);
			var centerTop =	getScrollY() + (getWinHeight() / 2) - (document.getElementById('Dialog_Paneel').clientHeight / 2);
			
			if (centerLeft < 0) { centerLeft = 0 }
			if (centerTop < 0) { centerTop = 0 }
			
//			centerTop = centerTop + 200
			// Aanpassen van eigenschappen van betreffende DIV.
//			document.getElementById(menuNaam).style.visibility = 'visible';
//			document.getElementById(menuNaam).style.left = (MargeLinks + BasisWaarde) + 'px';
			document.getElementById("Dialog_Paneel").style.left = (centerLeft) + 'px';
			document.getElementById("Dialog_Paneel").style.top = (centerTop) + 'px';
			document.getElementById("Panel_Dialogs").style.visibility = 'visible'

			// FIX voor IE6 waardoor onderliggende formulier elementen niet doorslaan
			document.getElementById("background_Frame_Dialogs").style.left = (centerLeft) + 'px';
			document.getElementById("background_Frame_Dialogs").style.top = (centerTop) + 'px';
			document.getElementById("background_Frame_Dialogs").style.width = (document.getElementById('Dialog_Paneel').clientWidth+2) + 'px';
			document.getElementById("background_Frame_Dialogs").style.height = (document.getElementById('Dialog_Paneel').clientHeight+2) + 'px';
			document.getElementById("background_Frame_Dialogs").style.display = 'inline'
			
			if ((action == "dialog_fotodetail") && (document.getElementById('ajax_currentLightbox').value).length > 0){
			document.getElementById('ci_lightbox').value = document.getElementById('ajax_currentLightbox').value;
			}

			
		} else if (myajax.status==500) {
			ajaxClosePopup		  
		}
		} 
	}
}

// returns height of window
function getWinHeight() {
	var winHt = 0;
	if (window.innerHeight) winHt = window.innerHeight-18;
	else if (document.documentElement && document.documentElement.clientHeight) 
		winHt = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight) 
		winHt = document.body.clientHeight;
	return winHt;
}	

// returns height of window
function getWinWidth() {
	var winWd = 0;
	if (window.innerWidth) winWd = window.innerWidth-18;
	else if (document.documentElement && document.documentElement.clientWidth) 
		winWd = document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth) 
		winWd = document.body.clientWidth;
	return winWd;
}

// returns amount of vertical scroll
function getScrollY() {
	var sy = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		sy = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		sy = document.body.scrollTop; 
	else if (window.pageYOffset)
		sy = window.pageYOffset;
	else if (window.scrollY)
		sy = window.scrollY;
	return sy;
}

// returns amount of vertical scroll
function getScrollX() {
	var sx = 0;
	if (document.documentElement && document.documentElement.scrollLeft)
		sx = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft) 
		sx = document.body.scrollLeft; 
	else if (window.pageXOffset)
		sx = window.pageXOffset;
	else if (window.scrollX)
		sx = window.scrollX;
	return sx;
}

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 var 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 eraseCookie(name) {
	createCookie(name,"",-1);
}

function ajaxClosePopup() {
	document.getElementById("Panel_Dialogs").innerHTML = '';
	document.getElementById("background_Dialogs").style.display = 'none'
	document.getElementById("Panel_Dialogs").style.display = 'none'
	document.getElementById("background_Frame_Dialogs").style.display = 'none'

}

function ajaxLogin(UserName, Password) {
	
// GEBRUIKER INLOGGEN
// && = AND
// || = OR

//alert('action=ajax_login&user=' + UserName + '&pass=' + Password)
if (UserName.length > 0 && Password.length > 0) {
	ajaxpack.postAjaxRequest('ci_ajax_dialogs.php', 'action=ajax_login&username=' + UserName + '&password=' + Password, 'txt')
	var myajax=ajaxpack.ajaxobj
	myajax.onreadystatechange = function() {

		if (myajax.readyState == 4){ //if request of file completed
			// alert(myajax.responseText)
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			//alert(myajax.responseText)
			if (myajax.responseText == "[OK]") {
				window.location.reload(true);
			} else if (myajax.responseText == "[ERROR]") {
				alert('The username and password you entered are incorrect. Please check your input and try again. If you are a new client please register using the button \'subscribe as client\'')
				// ajaxClosePopup()
			}
		}
		} 
	}
	
} else {
	alert('De gebruikersnaam en wachtwoord die u heeft gebruikt zijn onjuist. Controleer uw invoer en probeer nogmaals in te loggen. Indien u een nieuwe professionele client bent, registreer dan via de knop \'registreren als client\'.')
}
}

function ajaxLogOut() {
	ajaxpack.postAjaxRequest('ci_ajax_dialogs.php', 'action=ajax_logout', 'txt')
	var myajax=ajaxpack.ajaxobj
	myajax.onreadystatechange = function() {

		if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			window.location.reload(true);
		}
		} 
	}

}

function ajaxPassForget(Emailadres) {
		ajaxpack.postAjaxRequest('ci_ajax_dialogs.php', 'action=dialog_passforgetsave&email=' + Emailadres, 'txt')

	var myajax=ajaxpack.ajaxobj
	myajax.onreadystatechange = function() {

		if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			if(myajax.responseText == "[OK]") {
			alert("We hebben uw wachtwoord succesvol verzonden aan " + Emailadres)
			ajaxClosePopup()
			} else {
			alert("Er is helaas geen account aanwezig voor het opgegeven e-mailadres. (" + Emailadres + "). Controleer uw invoer en probeer het opnieuw.")
			}
		}
		} 
	}

}


function ajaxRegister() {
	var queryRegister = ""
	for(i=0; i<document.getElementById('form_Register').elements.length; i++)
	{
	if (document.form_Register.elements[i].name == "Nieuwsbrief") {
		//	alert(document.form_Register.elements[i].checked)
		//	Gaat om een checkbox, andere behandeling
		queryRegister = queryRegister + "&"+ escape(document.form_Register.elements[i].name) + "=" + escape(document.form_Register.elements[i].checked)
	} else {
		queryRegister = queryRegister + "&"+ escape(document.form_Register.elements[i].name) + "=" + escape(document.form_Register.elements[i].value)
	}
		document.form_Register.elements[i].style.borderColor = "";
		document.form_Register.elements[i].style.borderLeftWidth = "";
	}
//	alert(queryRegister)

	ajaxpack.postAjaxRequest('ci_ajax_dialogs.php', 'action=dialog_registersave' + queryRegister, 'txt')
	var myajax=ajaxpack.ajaxobj
	myajax.onreadystatechange = function() {

		if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			 //alert(myajax.responseText)
			// WAT ER MOET GEBEUREN: CHECK ÓF ERROR. ZO JA: TONEN IN INNERHTML, ZO NEE: ACTIE NA REGISTRATIE UITVOEREN
			if (myajax.responseText == "[OK]") {
				alert("Thank you for registering with CyberImage!\n\nYour request is now being checked and within 24 hours, after approval, you receive an activation mail from us.\n\nIn case you need to order/download photos urgently please contact us at info@cyberimage.nl or call +31 6 50595340 or +31 6 54705986.\n\nThank you!\nCyberImage Team")
				window.location.reload(true);
			} else {
				var arrFoutResponse = myajax.responseText.split("<#>");
				alert(arrFoutResponse[0])
				if (arrFoutResponse[1].length > 0) {
					var arrFoutFields = arrFoutResponse[1].split("<|>");
					for (i=0; i<arrFoutFields.length-1; i++) {
					document.form_Register.elements[arrFoutFields[i]].style.borderLeftWidth 	= "3px";
					document.form_Register.elements[arrFoutFields[i]].style.borderColor 	= "#F00";
					// alert(arrFoutFields[i])
					}
				}
				document.getElementById('Panel_Fout').innerHTML = "Please correct your details and press 'register as client' again."// 
				//ajaxClosePopup()			
				}
		}
		} 
	}
}

function nieuwsWissel(intID) {
	if (document.getElementById('nieuws_body_' + intID).style.display =='inline') {
		document.getElementById('nieuws_body_' + intID).style.display ='none'
		document.getElementById('nieuws_teaser_' + intID).style.display ='inline'
	} else {
		document.getElementById('nieuws_body_' + intID).style.display ='inline'
		document.getElementById('nieuws_teaser_' + intID).style.display ='none'
	}
} 

function downloadWissel(licenseOK) {
	if (licenseOK == true) {
		document.getElementById('downloadcondOK').style.display = 'inline'
		document.getElementById('downloadcondNOTOK').style.display = 'none'
	} else {
		document.getElementById('downloadcondOK').style.display = 'none'
		document.getElementById('downloadcondNOTOK').style.display = 'inline'
	}
}

function lightboxWissel(keuze) {
	document.getElementById('ajax_currentLightbox').value = keuze;
	
	if (keuze > 0) {
		document.getElementById('preview_Lightbox_ADD').style.display = 'inline'
		document.getElementById('preview_Lightbox_NEW').style.display = 'none'
	} else {
		document.getElementById('preview_Lightbox_ADD').style.display = 'none'
		document.getElementById('preview_Lightbox_NEW').style.display = 'inline'
	}
}