function onInit()
{
	if (window.g_message != undefined && g_message != "")
	{
		window.alert(g_message);
	}
	
	var highlight = _GET("highlight");
	if (highlight)
	{
		x = document.getElementById("content") == undefined ? undefined : document.getElementById("content");
		highlightText(highlight, "highlighted", x);
	}
}

function checkRegistration(form, msg)
{
	var usernameField = document.getElementById('username');
	var passwordField = document.getElementById('password');
	var password2Field = document.getElementById('password2');
	var emailField = document.getElementById('email');
	
	document.getElementById("username_label").className = "";
	document.getElementById("password_label").className = "";
	document.getElementById("password2_label").className = "";
	document.getElementById("email_label").className = "";
	document.getElementById("usertype_label").className = "";	
	
	var noErrors = true;
	
	if (usernameField.value == "")
	{
		noErrors = false;
		document.getElementById("username_label").className = "failed";
	}
	if (passwordField.value == "" || password2Field.value == "" || passwordField.value != password2Field.value)
	{
		noErrors = false;
		document.getElementById("password_label").className = "failed";
		document.getElementById("password2_label").className = "failed";
	}
	var regX = new RegExp(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/);
	if (!regX.test(emailField.value))
	{
		noErrors = false;
		document.getElementById("email_label").className = "failed";
	}
	
	var checked = false;
	for (var i = 0; i < form.usertype.length; i++)
	{
		if (form.usertype[i].checked)
		{
			checked = true;
		}
	}
	if (!checked)
	{
		noErrors = false;
		document.getElementById("usertype_label").className = "failed";
	}
	
	if (!noErrors)
		window.alert(msg);
	
	return noErrors;
}


function emptyForm(formId)
{
	f = document.getElementById(formId);
	for (x in f.elements)
	{
		if (f.elements[x] != null)
		{
			if (f.elements[x].type == 'text' || f.elements[x].type == 'textarea')
				f.elements[x].value = '';
		}
	}
}

function onLoadForm(widget)
{
	widget.addEventListener("submitted", function()
	{
		widget.showStatistics();
	});
}

function checkPasswordForm(form, msg)
{
	if (form.username.value == "")
	{
		window.alert(msg);
		return false;
	}
}

function checkLogin(form, msgNoUser, msgNoPw)
{
	if (form.username.value == "")
	{
		window.alert(msgNoUser);
		return false;
	}
	else if (form.password.value == "")
	{
		window.alert(msgNoPw);
		return false;
	}
}

function createIcon() {
	var icon = new GIcon(null, 'arrow.png');
	icon.shadow = 'http://www.google.com/mapfiles/shadow50.png';
	icon.iconSize = new GSize(20, 34);
	icon.shadowSize = new GSize(37, 34);
	icon.iconAnchor = new GPoint(9, 34);
	icon.infoWindowAnchor = new GPoint(9, 2);
	icon.infoShadowAnchor = new GPoint(18, 25);
	return icon;
} 

function onLoadProfielMap(widget)
{
	var marker = '';
	if (coord != '')
	{
		var icon = createIcon();
		var array = coord.split(';');
		marker = new GMarker(new GLatLng(array[0], array[1]), {
			title: "Lokatie",
			icon: icon ? icon : G_DEFAULT_ICON,
			clickable: false,
			draggable: false
		});
		widget.gmap.addOverlay(marker);
	}
	
	GEvent.addListener(widget.gmap, "click", function(overlay, latlng) {
		widget.gmap.removeOverlay(marker);
		
		document.getElementById("location").value = latlng.lat()+";"+latlng.lng();
		document.getElementById("lat").value = latlng.lat();
		document.getElementById("long").value = latlng.lng();
			
		var icon = createIcon();
		var array = coord.split(';');
		marker = new GMarker(new GLatLng(latlng.lat(), latlng.lng()), {
			title: "Lokatie",
			icon: icon ? icon : G_DEFAULT_ICON,
			clickable: false,
			draggable: false
		});
		widget.gmap.addOverlay(marker);
	});
	
	widget.gmap.addControl(new GLargeMapControl());
}

function onLoadGooglemap(widget)
{
	if(window.objects != undefined)
	{
		var icon = createIcon();
		for(var i=0; i<objects.length; i++) {
			var object = objects[i];
			if(object['active'] != 1 && skipInactives) {
				continue;
			}
			var array = object['location'].split(';');
			var marker = new GMarker(new GLatLng(array[0], array[1]), {
				title: object['title'],
				icon: icon ? icon : G_DEFAULT_ICON,
				clickable: true,
				draggable: false
			});
			object['marker'] = marker;
			marker.bindInfoWindowHtml(object['content']);
			widget.gmap.addOverlay(marker);
			if(object['active'] == 1) {
				marker.openInfoWindowHtml(object['content']);
			}
		}
	}
	
	GEvent.addListener(widget.gmap, "infowindowopen", function()
	{
		var infoWindow = widget.gmap.getInfoWindow();
		var tmppoint = widget.gmap.fromLatLngToContainerPixel(infoWindow.getPoint());
		tmppoint.y -= 60;
		widget.gmap.panTo(widget.gmap.fromContainerPixelToLatLng(tmppoint));
	});

	widget.gmap.addControl(new GMapTypeControl());
	widget.gmap.setUIToDefault();
}

function onShowResidence(id) {
	for(var i=0; i<objects.length; i++) {
		var object = objects[i];
		if(id == object['id']) {
			object['marker'].openInfoWindowHtml(object['content']);
		}
	}
	return false;
}
