/**
*	Set events
**/
$(document).ready(function()
{
	// Link homeuserbox to profile page if profname is set
	$('.homeuserbox').each(function()
	{
		var prof_name = this.getAttribute('profname');
		if (prof_name)
		{
			$(this).click(function()
			{
				window.location = '/profile/view/' + prof_name;
			});
			$(this).mouseover(function()
			{
				$(this).css('cursor', 'pointer');
			});

			// Strip teaser title
			$(this).removeAttr('title');
		}
		else
		{
			// Pretend it's a link
			$(this).mouseover(function()
			{
				$(this).css('cursor', 'pointer');
			});

			// Add tooltip, normal
			$(this).Tooltip({
				showURL: false,
				left: -100,
				delay: 250,
				extraClass: 'tooltip',
				track: true,
				showonclick: true
			});

		}
	});

	// Set confirm on main menu item "register"
	$('#link_register').click(function()
	{
		if (confirm('Je bent nu ingelogd. Je wordt automatisch uitgelogd tijdens de aanmelding. Wil je verder gaan?'))
		{
			window.location = '/registration';
		}
		else
		{
			return false;
		}
	});

	// Set up Highslide, if present
	if (window.hs)
	{
		hs.graphicsDir = '/js/lib/highslide/graphics/';
		hs.showCredits = false;
		hs.preloadImages(5);
	}

});

// ----------------------------------------------

/**
*	$$
*
*	Returns an object reference
*	for the given object id
**/
function $$(obj_id)
{
	return document.getElementById(obj_id);
}

// ----------------------------------------------

/**
*	Add in_array function to array
**/
Array.prototype.hasValue = function(value)
{
	var len = this.length;
	for (var x = 0; x <= len; x++)
	{
		if (this[x] == value)
		{
			return true;
		}
	}
	return false;
}

// ----------------------------------------------

function GetWindowSize(dim)
{
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}

	return (dim == 'width' ? x : y);
}

// ----------------------------------------------

/**
*	GetSelVal
*
*	Returns the value of the selected option
*	of the given select (object id).
**/
function GetSelVal(sel_id)
{
	if ($$(sel_id).selectedIndex != null)		// index could be 0
	{
		return $$(sel_id).options[$$(sel_id).selectedIndex].value;
	}
	return '';
}

// ----------------------------------------------

/**
*	ConfirmStopReg
*
*	Asks for confirmation to stop registration.
**/
function ConfirmStop(text)
{
	var msg = 'Weet je zeker dat je wilt stoppen met ' + text + '?';
	if (confirm(msg))
	{
		if (text == 'de aanmelding')
		{
			window.location = '/home';
		}
		else
		{
			window.location = '/account/view';
		}
	}
}

function unsetRadios(elem){
	if (elem.value) {
		$('.radios input:radio').attr('checked',false);
		$('.radios').hide();
	}else{
		$('.radios').show();
	}
}


function CheckActionCodeTermsOK() {
	if($("#promocodecond_ok:checked").length == 1){
		return true;
	}
	alert("Je moet akkoord gaan met de actievoorwaarden");
	return false;

}