function ConfirmGo()
{
	var agree = confirm("Weet je het zeker?");

	if (agree)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function DoSubmit(form_id)
{
	document.getElementById(form_id).submit();
}

function DoClear(field_id, new_name)
{
	var field = document.getElementById(field_id);
	var field_label = document.getElementById(field_id + '-label');

	field.name = new_name;
	field_label.style.visibility = 'hidden';
	field.focus();
}

function ArtikelSetFoto(foto_url)
{
	document.getElementById('grote_foto').src = './uploads/' + foto_url;
}

function pause(ms)
{
	var now = new Date();
	var exitTime = now.getTime() + ms;
	while (true)
	{
		now = new Date();
		if (now.getTime() > exitTime)
		{
			return;
		}
	}
}

function Refresh(ms)
{
	pause(ms);
	document.location = document.location;
}

function CheckSubmit(form_id, event)
{
	var form = document.getElementById(form_id);
	var keycode;

	if (window.event)
	{
		keycode = window.event.keyCode;
	}
	else if (event)
	{
		keycode = event.which;
	}

	if (keycode == 13)
	{
		form.submit();
	}
}

function VernieuwBevestig()
{
	setKortingscodeVernieuwen(document.getElementById('kortingscode').value);
}

function BestelAkkoord(betaalwijze)
{
	if (ConfirmGo())
	{
		setKortingscode(document.getElementById('kortingscode').value, betaalwijze);
	}
}

function OpenIcepay(order_id)
{
	if(window.open(base_url + 'icepay/index.php?order_id=' + order_id,'iDEAL','width=800,height=600,scrollbars=yes,toolbar=no,location=no,resizable=no'))
	{
	}
	else
	{
		//document.write('<p><strong>Uw pop-up blokker heeft de popup van iDEAL geblokkeerd. Klik <span class="link" onclick="OpenIdeal(' + order_id + ', \'' + betaalwijze + '\');">hier</span> om het venster te openen.</strong></p>');
	}
}

function PopUpVoorwaarden(pagina_id, taal_id)
{
	window.open(base_url + 'pages/cms/print.php?id=' + pagina_id + '&taal_id=' + taal_id ,'Print_pagina','width=800,height=600,scrollbars=yes,toolbar=no,location=no,resizable=no');
}

function addEvent(obj, eventType,fn, useCapture)
{
    if (obj.addEventListener)
    {
        obj.addEventListener(eventType, fn, useCapture);
        return true;
    }
    else
    {
        if (obj.attachEvent)
        {
            var r = obj.attachEvent("on"+eventType, fn);
            return r;
        }
    }
}

function NieuwsbriefAanmelden()
{
	var textbox = document.getElementById('nieuwsbrief_email');

	addNieuwsbrief(textbox.value);
	textbox.value = '';
}

function Link(url)
{
	document.location = base_url + url;
}

function signUp()
{
	startDate = new Date();
	url = 'http://www.affiliates.nl/aanmeldpopup.php?s_mer=907';
	tmpWin = window.open(url,startDate.getTime(),'toolbar=no,location=no,resizable=no,status=no,scrollbars=yes,menubar=no,width=400,height=350');
}

function popUpGroot(URL)
{
	URL = base_url + URL;
	day = new Date();
	id = day.getTime();
	popup = eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=660,left = 300,top = 20');");
}


function popUpMatentabel(URL)
{
	URL = base_url + URL;
	day = new Date();
	id = day.getTime();
	popup = eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=660,left = 300,top = 20');");
}

function matenTabel(id)
{
	popUpMatentabel('pages/categorie/matentabel.php?id=' + id);
}

function groteFoto(id, foto_id)
{
	popUpGroot('pages/categorie/foto.php?id=' + id + '&foto_id=' + foto_id);
}

addEvent(window, 'load', init_login);
function init_login()
{
	var username_field = document.getElementById('username_field');
	var password_field = document.getElementById('password_field');
	
	username_field.value = 'Email:';
	password_field.value = 'Password:';
	password_field.type = 'text';
	
	addEvent(username_field, 'focus', function() {
			if (password_field.value == 'Password:')
			{
				password_field.value = '';
				password_field.type = 'password';
			}
			if (username_field.value == 'Email:')
			{
				username_field.value = '';
			}
		});
	addEvent(password_field, 'focus', function() {
			if (password_field.value == 'Password:')
			{
				password_field.value = '';
				password_field.type = 'password';
			}
		});
	
	addEvent(username_field, 'blur', function() {
			if (username_field.value == '')
			{
				username_field.value = 'Email:';
			}
		});
	addEvent(password_field, 'blur', function() {
			if (password_field.value == '')
			{
				password_field.value = 'Password:';
				password_field.type = 'text';
			}
		});
}

function changePhoto(url, id, photoId)
{
	document.getElementById('fotoGroot').src = url;
	document.getElementById('fotoGroot').onclick = function() { groteFoto(id, photoId)};
}

var activeSize = null;
var iMaat = 0;
function showMaten()
{
	var matenUl = document.getElementById('maten');
	matenUl.style.display = 'block';
}

function chooseSize(id, obj)
{
	var matenUl = document.getElementById('maten');
	if (activeSize != null)
	{
		activeSize.className = 'link';
		activeSize.style.fontWeight = 'normal';
	}
	activeSize = obj;
	activeSize.className = '';
	activeSize.style.fontWeight = 'bold';
	iMaat = id;
}