/*
	korenbeurs.js
	v1.0 - 08/jul/2006 - Bob Kersten - Initial version.
	(C) Copyright 2006 Fellownet.
	All rights reserved.
*/

var popup_container;
var popup_iframe;
var popup_span;

var image_container;
var image_span;

function openReservations(notice_, url_) {
	popup_container = document.createElement('div');
	popup_container.setAttribute('id', 'div_container');
	popup_container.className = 'reservations';
	
	popup_span = document.createElement('span');
	popup_span.innerHTML = '<a href="javascript:closeReservations();">' + notice_ + '</a>';
	popup_container.appendChild(popup_span);

	popup_iframe = document.createElement('iframe');
	popup_iframe.setAttribute('src', url_);
	popup_iframe.setAttribute('frameborder', '0');
	popup_container.appendChild(popup_iframe);

	var body = document.getElementsByTagName('body').item(0);
	body.appendChild(popup_container);

	window.onscroll = window.onresize = function(e_) {
		var size = getWindowSize();
		popup_container.style.left = Math.ceil((size[0] / 2) - (600 / 2)) + 'px';
		popup_container.style.top = Math.ceil(getScrollHeight() + ((size[1] / 100) * 48) - (450 / 2)) + 'px';
	}
	window.onscroll();
}

function closeReservations() {
	var body = document.getElementsByTagName('body').item(0);
	body.removeChild(popup_container);	
}

var imageIsOpen = false;
function openImage(notice_, img_, width_, height_) {
	if (! imageIsOpen) {
		image_container = document.createElement('div');
		image_container.setAttribute('id', 'div_container');
		image_container.className = 'imagepopup';
		image_container.style.width = (width_ - 10) + 'px';
		image_container.style.height = (height_ - 10) + 'px';
	
		image_span = document.createElement('span');
		image_span.innerHTML = '<a href="javascript:closeImage();">' + notice_ + '</a>';
		image_container.appendChild(image_span);
	
		image_img = document.createElement('img');
		image_img.setAttribute('src', img_);
		image_container.appendChild(image_img);
	
		var body = document.getElementsByTagName('body').item(0);
		body.appendChild(image_container);
		imageIsOpen = true;
	
		window.onscroll = window.onresize = function(e_) {
			var size = getWindowSize();
			image_container.style.left = Math.ceil((size[0] / 2) - (width_ / 2)) + 'px';
			image_container.style.top = Math.ceil(getScrollHeight() + ((size[1] / 100) * 48) - (height_ / 2)) + 'px';
		}
		window.onscroll();
	}
}
			
function closeImage() {
	var body = document.getElementsByTagName('body').item(0);
	body.removeChild(image_container);
	imageIsOpen = false;
}

function getWindowSize() {
	var width = 0;
	var height = 0;
	if (typeof(window.innerWidth) == 'number') { /* probably non-IE */
		height = window.innerHeight;
		width = window.innerWidth;
	} else if (
		document.documentElement && (
			document.documentElement.clientWidth ||
			document.documentElement.clientHeight
		)
	) { /* probably IE 6+ in 'standards compliant mode' */
		height = document.documentElement.clientHeight;
		width = document.documentElement.clientWidth;
	} else if (
		document.body && (
			document.body.clientWidth ||
			document.body.clientHeight
		)
	) { /* probably IE 4 compatible */
		height = document.body.clientHeight;
		width = document.body.clientWidth;
	}
	return Array(width, height);
}

function getScrollHeight() {
	var height = 0;
	if (typeof(window.pageYOffset) == 'number') { /* Netscape compliant */
		height = window.pageYOffset;
	} else if (
		document.body && (
			document.body.scrollLeft ||
			document.body.scrollTop
		)
	) { /* DOM compliant */
		height = document.body.scrollTop;
	} else if (
		document.documentElement && (
			document.documentElement.scrollLeft ||
			document.documentElement.scrollTop
		)
	) { /* IE6 standards compliant mode */
		height = document.documentElement.scrollTop;
	}
	return height;
}


function sendContactForm() {
	Form.disable('contactform');
	var ajax = new Ajax.Request(
		$('contactform').getAttribute('action'), {
			method:'post',
			parameters:Form.serialize('contactform'),
			onSuccess: function(req_) {
				var parts = req_.responseText.split('|');
				if (parts.length > 1) Form.enable('contactform');
				alert(parts[0]);
				returnUser();
			}
		}
	);
	return false;
}

function sendMailingForm() {
	Form.disable('aanmeldform');
	var ajax = new Ajax.Request(
		$('aanmeldform').getAttribute('action'), {
			method:'post',
			parameters:Form.serialize('aanmeldform'),
			onSuccess: function(req_) {
				var parts = req_.responseText.split('|');
				if (parts.length > 1) Form.enable('aanmeldform');
				alert(parts[0]);
			}
		}
	);
	return false;
}


function returnUser() {
	window.location = "";
}
