// JavaScript Document

// Bookmark the page
// Compatible: IE, FF
function add_bookmark(url, title) {
	title = "Fitplein.nl - "+title;
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url, ""); // FF
	} else if (document.all) {
		window.external.AddFavorite(url, title); // IE
	} else if (window.opera && window.print) {
		return true; // Opera
	}
}

// Send email to a friend
// Compatible: IE
function mail_to_friend() {
	mail_str = "mailto:?subject=Artikel van fitplein.nl";
	mail_str += "&body=Een vriend/vriendin raadt je aan om dit artikel op fitplein.nl te lezen: "+location.href;
	location.href = mail_str;
}

// Update the number of stored articles
// Compatible: IE, FF
function update_stored_articles() {
	// Check for processing
	if (!processing) {
		ajaxRequest('/artikel/article_tools.php?type=get_stored_articles', 'update_stored_articles');
		return;
	}
	// Ready to go
	time_out(100); // Small delay to be sure everything is done
	if (xmlRequest.readyState == 4) {
		document.getElementById('tools').getElementsByTagName('a')[4].innerHTML = "Bewaarde artikelen ("+xmlRequest.responseText+")";
		
		processing = false;
	}
}

// Show popin when an user wants to see article, but is not logged in
// Compatible: IE
function show_register_popin()
{
	var w, h;
	
    if (window.innerHeight && window.scrollMaxY) {// Firefox         
		h = window.innerHeight + window.scrollMaxY;         
		w = window.innerWidth + window.scrollMaxX;     
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac         
		h = document.body.scrollHeight;         
		w = document.body.scrollWidth;     
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari         
		h = document.body.offsetHeight;         
		w = document.body.offsetWidth;       
	} 
	
	var div = document.createElement("div");
	var s = div.style;
	s.position = "absolute";
	s.left = 0;
	s.top = 0;
	s.width = w+"px";
	s.height = h+"px";
	s.background = "#000";
	s.filter = "alpha(opacity=50)";
	s.opacity = 0.5;
	s.MozOpacity = 0.5;
	div.id = "darken";
	
	document.getElementsByTagName("body")[0].appendChild(div);
	
	div = document.createElement("div");
	s = div.style;
	s.position = "fixed";
	s.left = "50%";
	s.top = "50%";
	s.border = "1px dashed white";
	s.width = "300px";
	s.height = "auto";
	s.background = "#cde84d";
	div.id = "popup";
	
	document.getElementsByTagName("body")[0].appendChild(div);	
	document.getElementById("popup").innerHTML = '<h1>Registreren</h1>'+
	'<p>Voor deze functie moet u ingelogd zijn!</p><a style="display:block;margin-top:5px;color:#004080;" href="/login.php">Inloggen</a>'+
	'<a style="display:block;margin-top:5px;color:#004080;" href="/account_create.php">Registreren</a>'+
	'<a style="display:block;margin-top:5px;color:#004080;" href="javascript:;" onclick="closePopup()">Close</a>';
}