var insideLayer = false;
var cur_answer = null;

function navover(obj, margin) {

	if (margin) obj.firstChild.style.marginLeft = margin + 'px';

	/*var mw = obj.parentNode.offsetWidth;
	var ow = obj.offsetWidth;
	var om = ((obj.offsetWidth + obj.offsetLeft) - mw) * -1;
	if (om < 0) obj.firstChild.style.marginLeft = om + 'px';*/
	obj.className = 'over';
}

function navout(obj) {
	obj.className = '';
}

function showtip(id) {
	document.getElementById('tooltip_'+id).style.display = 'block';
}

function hidetip(id) {
	document.getElementById('tooltip_'+id).style.display = 'none';
}

function tou(show) {
	if (document.getElementById('voorwaarden'))
		document.getElementById('voorwaarden').style.display = (show ? 'block' : 'none');
}

function saveClick(arc_id) {

	xmlHttp.get('/action.php?mode=saveclick&arc_id='+arc_id);

}

function closeAllLayers() {

	if (insideLayer) return;

}

function focusField(obj) {
	if (typeof(obj) != 'undefined' && obj && (obj.value == 'mobiele telefoonnummer' || obj.value == 'wachtwoord')) obj.value = '';
}

function more(id) {

	var m = document.getElementById(id + '_more');
	var l = document.getElementById(id + '_less');

	if (m && l) {
		m.style.display = 'block';
		l.style.display = 'none';
	}

}

function less(id) {

	var m = document.getElementById(id + '_more');
	var l = document.getElementById(id + '_less');

	if (m && l) {
		m.style.display = 'none';
		l.style.display = 'block';
	}

}

function submitOnEnter(frm, btn) {

	if (typeof(event) != 'undefined') {
		if (navigator.appName == "Netscape") {
			var code = event.which;
		} else {
			var code = event.keyCode;
		}

		alt = event.altKey;
	}

	if (code == 13) {
		submitForm(frm, btn)
	}

	return false;
}

function click_chk_archive(chk, frm) {

	if (chk.checked) {
		if (typeof(frm.elements['usr_email']) != 'undefined') {
			i3a_screen_att_set_mandatory('usr_email', true);
			if (frm.elements['usr_email'].value.length < 1) {
				alert('U dient een e-mailadres in te vullen');
				frm.elements['usr_email'].focus();
			}
		} else if (typeof(frm.elements['usr_email_pending']) != 'undefined') {
			i3a_screen_att_set_mandatory('usr_email_pending', true);
			if (frm.elements['usr_email_pending'].value.length < 1) {
				alert('U dient een e-mailadres in te vullen');
				frm.elements['usr_email_pending'].focus();
			}
		}

	} else {
		if (typeof(frm.elements['usr_email']) != 'undefined') {

			i3a_screen_att_set_mandatory('usr_email', false);

		} else if (typeof(frm.elements['usr_email_pending']) != 'undefined') {

			i3a_screen_att_set_mandatory('usr_email_pending', false);
		}

	}

}

function i3a_screen_att_set_mandatory(att_code, state) {
	var tbl = document.getElementById(att_code+'_ctrl_maincontainer');
	tbl.rows[0].cells[1].innerHTML = state ? '<span class="ctrl_mandatory" id="'+att_code+'_mandatory">&nbsp;*</span>' : '';
}

function checkProfileForm() {

	var frm = document.forms['frm_profile'];

	if ((frm.elements['usr_password_new'].value.length > 0 && frm.elements['usr_password_new'].value.length < 5) || (frm.elements['usr_password_new_repeat'].value.length > 0 && frm.elements['usr_password_new_repeat'].value.length < 5)) {
		alert('Het wachtwoord moet minimaal 5 karakters lang zijn.');
		return false;
	}

	if (!checkEmail(frm)) return false;

	if (!checkPlukYouURL()) return false;

	if (compareFields('usr_password_new','usr_password_new_repeat'))
		if (autoCheckForm(frm)) return true;

	return false;

}

function checkEmail(frm) {

	if (typeof(frm.elements['usr_archivemode']) != 'undefined' && Number(frm.elements['usr_archivemode'].value) > 0 && frm.elements['usr_email'].value.length == 0) {
		alert('Indien je van sms naar e-mail gebruik wil maken is het noodzakelijk om je e-mailadres in te vullen');
		return false;
	}

	return true;

}

function checkSignupForm() {

	var frm = document.forms['frm_signup'];
	/*if ((frm.elements['usr_password'].value.length > 0 && frm.elements['usr_password'].value.length < 5) || (frm.elements['usr_password_repeat'].value.length > 0 && frm.elements['usr_password_repeat'].value.length < 5)) {
		alert('Het wachtwoord moet minimaal 5 karakters lang zijn.');
		return false;
	}

	if (compareFields('usr_password','usr_password_repeat'))*/
		if (autoCheckForm(frm)) return true;

	return false;

}

function checkAgreed(frm) {

	if (frm.elements['license_agree'].value != '') return true;

	alert('U dient akkoord te gaan met de algemene voorwaarden.');
	return false;

}

function checkMobile(frm) {

	if (frm.elements['usr_phone_mobile'].value.length != 8) {
		alert('Ongeldig mobiel telefoonnummer');
		return false;
	}

	return true;

}

function checkPlukYouURL() {

	var pyu = document.getElementById('usr_plukyouurl');
	if (pyu && !pyu.value) {

		var rdo_a = document.getElementById('rdo_pyu_a');
		var rdo_b = document.getElementById('rdo_pyu_b');
		var rdo_c = document.getElementById('rdo_pyu_c');

		if ((rdo_a && rdo_a.checked) || (rdo_b && rdo_b.checked) || (rdo_c && rdo_c.checked)) {
			alert('Indien je je plukYou nickname naar een url wilt laten doorlinken is het noodzakelijk om een url in te voeren');
			return false;
		}

	}

	return true;

}

// Called onload
function initialize() {

	// Make	sure to properly update the page height before loading the flash movie;
	// putting the flash movie inside the html would prevent the onload event from being
	// triggered as long as the movie has not been completely loaded which takes a long time
	updateHeight();

	var il;
	if ((il = document.getElementById('usr_password'))) il.focus();

}

function showFlashMain(src) {
	document.getElementById('intropic').style.display = 'none';
	document.getElementById('flashintro').style.display = 'block';
	//createFlashMovie('flashintro', '/flash/' + src, 448, 262);
	createFlashMovie('flashintro', '/flash/' + src, 448, 270);
}

// load flash movie using javascript to avoid needing to activate the control in order to communicate with it
// due to a patent conflict between Microsoft and EOLAS. Hooray.
function createFlashMovie(container, src, width, height) {

	var il = document.getElementById(container);
	if (il) {

		if (il.firstChild) il.removeChild(il.firstChild);

		var fle = document.createElement('EMBED');
		fle.setAttribute('quality', 'high');
		fle.setAttribute('wmode', 'transparent');
		fle.setAttribute('allowScriptAccess', 'sameDomain');
		fle.setAttribute('pluginspage', 'http://www.macromedia.com/go/getflashplayer');
		fle.type = 'application/x-shockwave-flash';
		fle.src = src;
		fle.width = width;
		fle.height = height;
		il.appendChild(fle);

	}

}

function updateHeight() {

	var framework = document.getElementById('framework');
	var mc = document.getElementById('main_container');
	var d0 = document.getElementById('dots_v_0');
	var d1 = document.getElementById('dots_v_1');
	var d2 = document.getElementById('dots_v_2');
	var dr = document.getElementById('dots_v_right');

	if (framework && mc) {

		var mh = (framework.offsetHeight - mc.offsetTop - 28) + 'px';
		if (d0) d0.style.height = mh;
		if (d1) d1.style.height = mh;
		if (d2) d2.style.height = mh;
		if (dr) dr.style.height = mh;

	}

}

function faq_toggleanswer(id) {

	var elm = 'faq_answer' + id;

	if (typeof(cur_answer) != 'undefined' && cur_answer && cur_answer.id != elm) {
		cur_answer.style.display = '';
	}

	cur_answer = document.getElementById(elm);

	if (typeof(cur_answer) != 'undefined' && cur_answer) {
		cur_answer.style.display = (cur_answer.style.display == 'block' ? 'none' : 'block');
	}

}

function open_image(url, plukcode) {

	window.open('/index.php?p=tdyp0207&code=image&popup=1&image='+url+(plukcode ? '&plukcode='+plukcode : ''), '_blank', 'width=100,height=100,location=no,menubar=no,toolbar=no,status=no,statusbar=no,rezisable=no,scrollbars=no');

}

// Automatically scales the window to fit the contents
function autoSizeWindow() {

	var wo = document.getElementById('window_contents');
	//var s_offset = new javascriptKit.compat.scrollOffset();

	var width = wo.offsetWidth;
	var height = wo.offsetHeight + 20;
	//var width = s_offset.width;
	//var height = s_offset.height;

	window.moveTo(screen.width / 2 - width / 2, screen.height / 2 - height / 2);
	window.resizeTo(width, height);

}

function playSound(src) {

	var snd = document.createElement('BGSOUND');
	snd.loop = false;
	snd.src = src;

}

function show_info(id) {
	close_info();
	document.getElementById(id).style.display = 'block';
}

function close_info() {
	document.getElementById('info_password').style.display = 'none';
	document.getElementById('info_signup').style.display = 'none';
}

function showSignup(frm) {
	document.getElementById('s').value = 'aanmelden';
	//frm.action = (document.body.className == 'extern' ? '?s=aanmelden' : '/plukpagina/aanmelden/');
	frm.submit();
}