function openLogin() {
	if($('sites')) {
		Element.show("sites");
		if (typeof(Effect) == "object") {
			Effect.Queues.get('login').invoke('cancel');
			new Effect.Opacity('sites', {
							duration: 0.3,
							transition: Effect.Transitions.linear,
							to: 1.0,
							queue: { position: 'end', scope: 'login' }
			});
		}
	}
}

function closeLogin() {
	if($('sites')) {
		if (typeof(Effect) == "object") {
			Effect.Queues.get('login').invoke('cancel');
			new Effect.Opacity('sites', {
								duration: 1.5,
								transition: Effect.Transitions.linear,
								to: 0.0,
								afterFinish: function() {Element.hide("sites")},
								queue: { position: 'end', scope: 'login' }
						}
			);
		}
		else {
			Element.hide("sites");
		}
	}
}

function openCountries() {
	Element.show("countrylist");
	if (typeof(Effect) == "object") {
		Effect.Queues.get('countries').invoke('cancel');
		new Effect.Opacity('countrylist', {
							duration: 0.3,
							transition: Effect.Transitions.linear,
							to: 1.0,
							queue: { position: 'end', scope: 'countries' }
		});
	}
}

function closeCountries() {
	if (typeof(Effect) == "object") {
		Effect.Queues.get('countries').invoke('cancel');
		new Effect.Opacity('countrylist', {
							duration: 1.5,
							transition: Effect.Transitions.linear,
							to: 0.0,
							queue: { position: 'end', scope: 'countries' },
							afterFinish: function() {Element.hide("countrylist")}
		});
	}
	else {
		Element.hide("countrylist");
	}
}

Event.observe(window, "load", function() 	{
							Event.observe("countries", "mouseover", openCountries, false);
							if (typeof(Effect) == "object") {
								Event.observe("countries", "mouseout", closeCountries, false);
								new Effect.Opacity('countrylist', { to: 0.0 });
							}
							else {
								Event.observe("countries", "click", closeCountries, false);
							}

							Event.observe("login", "mouseover", openLogin, false);
							if (typeof(Effect) == "object") {
								if($('sites')) {
									new Effect.Opacity("sites", { to: 0.0 });
								} 
								Event.observe("login", "mouseout", closeLogin, false);
							}
							else {
								Event.observe("login", "click", closeLogin, false);
							}

						}, false);



Event.observe(window, "load", function()	{
							var frms = document.getElementsByClassName("emarkform");
							for (i = 0; i < frms.length; i++) {
								var mandatory = frms[i].getAttribute("mandatory");
								if (mandatory.length) {
									Event.observe(frms[i], "submit", function(e) {
										if (!EmarkForm.validate(Event.element(e))) {
											Event.stop(e);
										}
									}, false);
								}
							}
}, false);

Event.observe(window, "load", function()	{
							var intrumMap = new EmarkMap(52.091873870318295, 4.284453392028809);
							if (intrumMap.valid) {
								intrumMap.setAddress("<div style='font-size:12px'>Intrum Justitia Nederland B.V.,<br>Johan de Wittlaan 3<br>2517 JR Den Haag<br>Nederland<br>Tel: +31-(0)70-452 7000.</div>");
							}
}, false);



 
function EmarkMap (x, y) {
	if(typeof GBrowserIsCompatible == "undefined" ) {
		this.valid = false;
		return false;
	}
	if (!$('map')) {
		this.valid = false;
		return false;
	}
	else if (!GBrowserIsCompatible()) {
		this.valid = false;
		return false;
	}
	else {
		this.valid = true;
	}
	this.map = new GMap2($('map'));
	this.map.addControl(new GSmallMapControl());
	this.map.addControl(new GMapTypeControl());
	this.point = new GPoint(y,x);
	this.map.setCenter(new GLatLng(x, y), 14);
	this.marker = new GMarker(this.point);
	this.map.addOverlay(this.marker);
	//GEvent.bind(this.map, "click", this, this.onClick);
}

EmarkMap.prototype.onClick = function(overlay, point) {
	$('dbg').innerHTML += "click: " + point.x + "," + point.y + "<br>";
}

EmarkMap.prototype.setAddress = function(str) {
	this.marker.openInfoWindowHtml(str);
}

var EmarkForm = {
	validate : function(frm) {
		var frm = $(frm);
		var mandatory = frm.getAttribute("mandatory").split(",");
		mandatory.each(function (id) {
			Element.removeClassName(id + 'Label', 'error');
		});

		Form.getElements(frm).each( function(input) {
			var type = input.type.toLowerCase();
			if (type == "checkbox" || type == "radio") {
				if (input.checked) {
					mandatory = mandatory.reject(function(val) {
						return val == input.name;
					});
				}
			}
			else if (type == "textarea" || type == "text") {
				if (input.value.length) {
					mandatory = mandatory.reject(function(val) {
						return val == input.id;
					});
				}
			}
		});

		if (mandatory.length) {
			mandatory.each( function(id) {
				new Effect.Highlight(id + "Label", {
					queue: 'end',
					duration: 0.5,
					afterFinish: function() { Element.addClassName(id + 'Label', 'error') }
				});
			});
			return false;
		}
		else {
			return true;
		}
	}
};

