var punt;
var quote;
var key = 0;
function initQuote(){
	getQuote();
	quote = setInterval("clearOneSec()",11000);
}
function getQuote(){
	var aantal = quotes.length;
	
	
	//aantal;
	if(key >= aantal){
		key = 0;
	}
	var box = document.getElementById('quoteBox');
	//alert(box);
	//alert(key);
	box.innerHTML = quotes[key];
	//clearInterval(punt);
	//punt = setInterval("addDot()",1000);
	key ++;
}
function addDot(){
	//alert("sec");
	//var box = document.getElementById('quoteBox');
	//box.innerHTML = box.innerHTML + ".";
}
function clearOneSec(){
	var box = document.getElementById('quoteBox');
	box.innerHTML = "";
	window.setTimeout("getQuote()", 1000);
}
function getScreenDimensions()
{
	var ret = new Object();
	
	if(document.layers||(document.getElementById&&!document.all))
	{ 
	   ret.availWidth=window.innerWidth;
	   ret.availHeight=window.innerHeight;
	   ret.scrollLeft = window.pageXOffset;
	   ret.scrollTop = window.pageYOffset;
	}
	else if(document.all && document.documentElement)
	{
	   ret.availWidth=document.documentElement.clientWidth;
	   ret.availHeight=document.documentElement.clientHeight;
	   ret.scrollLeft = document.documentElement.scrollLeft;
	   ret.scrollTop = document.documentElement.scrollTop;
	}
	else if (document.all)
	{
		ret.availWidth=document.body.clientWidth;
		ret.availHeight=document.body.clientHeight;
		ret.scrollLeft = document.body.scrollLeft;
		ret.scrollTop = document.body.scrollTop;	
	}
	
	return ret;
}
function getTotalHeight()
{
	var totalHeight;
	if(document.layers||(document.getElementById&&!document.all))
	{ 
	   availHeight=window.innerHeight;
	   scrollTop = window.pageYOffset;
	}
	else if(document.all)
	{
	   availHeight=document.body.clientHeight;
	   scrollTop = document.body.scrollTop;
	}

	totalHeight = availHeight + scrollTop;
	return (totalHeight < document.body.scrollHeight ? document.body.scrollHeight : totalHeight);
}

function placeAtCenter(div)
{
	// place div in center of screen
	var dim = getScreenDimensions();
	var x = Math.floor(dim.scrollLeft + (dim.availWidth - div.offsetWidth)/2);
	var y = Math.floor(dim.scrollTop + (dim.availHeight - div.offsetHeight)/2);
	div.style.top = y + "px";
	div.style.left = x + "px";
}

function openPic(url,id){
	
	var pic = document.getElementById("pic");
	var div = document.getElementById("picPopup");
	var bg = document.getElementById("picBg");
	//var next = document.getElementById("next");
	//var prev = document.getElementById("prev");
	
	//var url = "cms_file.php?fromDB="+id+"&maxWidth=600&maxHeight=600";
	pic.onload = function()
	{
		placeAtCenter(div);
	}
	div.style.display = "";
	pic.src = url;
	//alert(url);
	bg.style.display = "";
	bg.style.height = getTotalHeight() + "px";
	pic.onload = function()
	{
		placeAtCenter(div);
	}
	return false;
}
function closePic(){
	var pic = document.getElementById("pic");
	var div = document.getElementById("picPopup");
	var bg = document.getElementById("picBg");
	
	url = "images/loading.jpg";
	
	div.style.display = "none";
	pic.src = url;
	//alert(url);
	bg.style.display = "none";
}

function onSearchLink(){
	
	var pu = document.getElementById('popUpLinks');
	pu.style.display = "";
	placeAtCenter(pu);
	return false;	
}
function onSearchPic(){
	
	var pu = document.getElementById('popUpPics');
	pu.style.display = "";
	placeAtCenter(pu);
	return false;	
}

function closePopUp(pop){
	//alert(pop);
	
	var pu = document.getElementById(pop);
	//alert(pu);
	pu.style.display = "none";
	
	return false;		
}
function closePopUpIframe(pop){
	//alert(pop);
	
	var pu = parent.document.getElementById(pop);
	//alert(pu);
	pu.style.display = "none";
	
	return false;		
}
function onCopyUrl(url){
	 if( window.clipboardData && clipboardData.setData )
	{
		clipboardData.setData("Text", url);
		closePopUp('popUpLinks');
		alert("Link gekopieerd");
		
	}
	else
	{
		closePopUp('popUpLinks');
		prompt("Dit is de link naar de pagina: \n\ndruk op Ctrl+c om de link te kopiëren \n",url);
	}
	return false;	
}
function onPicClicked(url){
	 if( window.clipboardData && clipboardData.setData )
	{
		clipboardData.setData("Text", url);
		closePopUpIframe('popUpPics');
		alert("Link gekopieerd");
		
	}
	else
	{
		closePopUpIframe('popUpPics');
		prompt("Dit is de link naar de pagina: \n\ndruk op Ctrl+c om de link te kopiëren \n",url);
	}
	return false;
}
function onAddPic(url,id){
	parent.document.getElementById("imgSpace").innerHTML += "<div class='img'><img src='"+url+"'></div>";
	if(parent.document.getElementById("imgInput").value != "")
		parent.document.getElementById("imgInput").value += ","+id;
	else
		parent.document.getElementById("imgInput").value = id;
	closePopUpIframe('popUpPics');
	alert("Plaatje #"+ id+ "  toegevoegd"); 
	return false;
}
function deletePic(elem,id){
	if(confirm("Weet u zeker dat u dit plaatje wilt verwijderen?")){
		var now = document.getElementById("imgInput").value;
		//alert(now);
		var strReplaceAll = now;
		var replacement = id+",";
		var intIndexOfMatch = strReplaceAll.indexOf( replacement );
		while (intIndexOfMatch != -1){
			strReplaceAll = strReplaceAll.replace( replacement, "" )
			intIndexOfMatch = strReplaceAll.indexOf( replacement );
		}
		//var strReplaceAll = now;
		replacement = id;
		var intIndexOfMatch = strReplaceAll.indexOf( replacement );
		while (intIndexOfMatch != -1){
			strReplaceAll = strReplaceAll.replace( replacement, "" )
			intIndexOfMatch = strReplaceAll.indexOf( replacement );
		}
		//alert( strReplaceAll );
		//now.replace( id, " ");
		//alert(now);
		if(strReplaceAll.substr(strReplaceAll.length-1) == ","){
			now = strReplaceAll.substr(0,strReplaceAll.length-1);
		}else{
			now = strReplaceAll;
		}
		//alert(now);
		document.getElementById("imgInput").value = now;
		elem.style.display = "none";
	}
	return false;
}
function onDelete(id){
	var go = confirm("Weet u zeker dat u dit plaatje wilt verwijderen? \n");
	if(go){
		document.location = "pics_admin.php?delete=" + id;
		return true;
	}else{
		return false;
	}
}
function rollOver(elem){
	elem.style.backgroundColor = "#272727";	
}
function rollOut(elem){
	elem.style.backgroundColor = "#212121";
}
function clickAuto(id){
	document.location = "index.php?id="+id;	
}
function checkPic(elem){
	if(elem.width > 104){
		elem.style.height = '100%';
		elem.style.width = '107';
	}
}
