﻿function $(id) {
	return document.getElementById(id);
}

function openWindow(url, id, width, height) {
	var left = (screen.availWidth - width) / 2;
	var top = (screen.availHeight - height) / 2;

//	window.open(url, id, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width='+width+',height='+height+',left='+left+',top='+top);
	window.open(url, id, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width='+width+',height='+height+',left='+left);
}

// dd-MM-yyyy ?
function IsValidDate(value) {
//	var exp = /(((0[1-9]|[12][0-9]|3[01])([-./])(0[13578]|10|12)([-./])(\d{4}))|(([0][1-9]|[12][0-9]|30)([-./])(0[469]|11)([-./])(\d{4}))|((0[1-9]|1[0-9]|2[0-8])([-./])(02)([-./])(\d{4}))|((29)(\.|-|\/)(02)([-./])([02468][048]00))|((29)([-./])(02)([-./])([13579][26]00))|((29)([-./])(02)([-./])([0-9][0-9][0][48]))|((29)([-./])(02)([-./])([0-9][0-9][2468][048]))|((29)([-./])(02)([-./])([0-9][0-9][13579][26])))/;
	var exp = /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/
	var re = new RegExp(exp);
	return value.match(re);
}

// 00:00 - 23:59
function IsValidTime(value) {
	var exp = /([0-1][0-9]|2[0-3]):[0-5][0-9]/;
	var re = new RegExp(exp);
	return value.match(re);
}

function IsValidEmail(value) {
	var res = false;
	try {
		var exp = '^[A-Za-z0-9](([_\\.\\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\\.\\-]?[a-zA-Z0-9]+)*)\\.([A-Za-z]{2,})$';
		var re = new RegExp(exp);

		res = ((value.length > 0) && (value.match(re).length > 0));
	} catch (ex) {res = false;}
	return res;
}

function ValidateEmail(sender, e) {
	e.IsValid = (IsValidEmail(e.Value) != '');
}

function ValidateSex(sender, e) {
	e.IsValid = (e.Value != '-');
}

function refreshAds() {
	var d = new Date();
	setIFrame('iframe_skyscraper', '/Banner.aspx?item=skyscraper&d=' + d);
	setIFrame('iframe_recommended', '/Banner.aspx?item=recommended&d=' + d);
}

function setIFrame(id, url) {
	if (el = document.getElementById(id)) {
		//el.src = url;
		el.src = el.src;
	}
}

function addFavorite(url, title, text) {
	if (typeof(text) == "undefined" || text == "") {
		text = "Druk op Ctrl+D om de website toe te voegen aan je favorieten!";
	}
	
	/* Firefox */
	if (window.sidebar) {
		/* sucks, since it creates a bookmark that by default opens in the sidebar! */
		/* window.sidebar.addPanel(title, url, ""); */
		alert(text);
	/* Opera */
	} else if(window.opera && window.print) {
		var el = document.createElement('a');
		el.setAttribute('href', url);
		el.setAttribute('title', title);
		el.setAttribute('rel', 'sidebar');
		el.click();
	/* Internet Explorer */
	} else if(window.external) {
		window.external.AddFavorite(url, title);
	} else {
		alert(text);
	}
}

function setLinkable(ie6) {
	var divs = document.getElementsByTagName('DIV');
	var l = divs.length;
	for(i = 0; i < l; i++) {
		if (divs[i].className.match('linkable')) {
			divs[i].style.cursor = "pointer";
			if (ie6) {
				divs[i].onmouseover = addStyle;
				divs[i].onmouseout = removeStyle;
			} else {
				//alert('non-ie6!');
			}
		}
	}
}

function addStyle() {
	if (!this.className.match('block_hover')) {
		this.className += ' block_hover';
	}
}

function removeStyle() {
	if (this.className.match('block_hover')) {
		this.className = remove(this.className, 'block_hover');
	}
}

/* 
**  Remove all occurrences of a token in a string
**    s  string to be processed
**    t  token to be removed
**  returns new string
*/
function remove(s, t) {
	i = s.indexOf(t);
	r = "";
	if (i == -1) return s;
	r += s.substring(0,i) + remove(s.substring(i + t.length), t);
	return r;
}

function showFortuneFriends() {
	toggleElement('block_text', false);
	toggleElement('block_friends', true, true);
}

function toggleElement(id, visible, showinline) {
	if (el = document.getElementById(id)) {
		if (visible) {
			if (showinline) {
				el.style.display = 'inline';
			} else {
				el.style.display = 'block';
			}
		} else {
			el.style.display = 'none';
		}
	}
}

function injectFlashMovie(id, url, width, height) {
	if (el = document.getElementById(id)) {
		el.innerHTML = "<embed width=\"" + width + "\" height=\"" + height + "\" type=\"application/x-shockwave-flash\" src=\"" + url + "\">";
	}
}

function headerSearchSubmit(e) {
	var characterCode = -1;			//literal character code will be stored in this variable
	if (e && e.which) {				//if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which;	//character code is contained in NN4's which property
	} else {
		try {
			e = event;
			characterCode = e.keyCode;	//character code is contained in IE's keyCode property
		} catch (exception) {
		}
	}
	if (characterCode == 13) {		//if generated character code is equal to ascii 13 (if enter key)
		WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$SearchButton", "", false, "", "/Search.aspx", false, true));
		return false;
	}
	return true;
}

function ShowLegend(hash) {
	var w = window.open("/Embed/Legend.aspx#" + hash, "legend_dialog", "height=250, width=480, left=5, top=5", true);
}

function ShowVoorwaarden(cat) {
	var w = window.open("/Embed/Voorwaarden.aspx?Category=" + cat, "av_dialog", "height=580, width=580", true);
}

function openEgg(eggNumber) {
	var w = window.open("/Embed/EasterEgg.aspx?egg=" + eggNumber, "egg_dialog", "height=470, width=560", true);
	if (w.focus) {
		w.focus();
	}
}

function diceCheckForm(language) {
	if (!(elfn = document.getElementById('ctl00_ContentPlaceHolder_OracleDice_FirstName'))) return;
	if (!(elln = document.getElementById('ctl00_ContentPlaceHolder_OracleDice_LastName'))) return;
	if (!(ele = document.getElementById('ctl00_ContentPlaceHolder_OracleDice_Email'))) return;
	elbd = document.getElementById('ctl00_ContentPlaceHolder_OracleDice_BirthDay');
	elbm = document.getElementById('ctl00_ContentPlaceHolder_OracleDice_BirthMonth');
	elby = document.getElementById('ctl00_ContentPlaceHolder_OracleDice_BirthYear');

	if (language == "en") {
		invalid_name = "Please specify your name!";
		invalid_email = "Please specify a valid email address!";
		invalid_birthdate = "Please specify a valid birth date!";
		invalid_sex = "Please specify your sex!";
	} else {
		invalid_name = "Geef je volledige naam op!";
		invalid_email = "Je hebt geen geldig e-mailadres ingevuld!";
		invalid_birthdate = "Je hebt geen geldige geboortedatum ingevuld!";
		invalid_sex = "Je hebt geen geslacht ingevuld!";
	}

	if (elfn.value.length < 2) {
		alert(invalid_name);
		elfn.focus();
		return;
	}
	if (elln.value.length < 2) {
		alert(invalid_name);
		elln.focus();
		return;
	}
	if (!IsValidEmail(ele.value)) {
		alert(invalid_email);
		ele.focus();
		return;
	}
	if (!IsValidDate(elbd.value + "-" + elbm.value + "-" + elby.value)) {
		alert(invalid_birthdate);
		elbd.focus();
		return;
	}
}

function diceSubmitForm(total, language) {
	if (!(elfn = document.getElementById('ctl00_ContentPlaceHolder_OracleDice_FirstName'))) return;
	if (!(elln = document.getElementById('ctl00_ContentPlaceHolder_OracleDice_LastName'))) return;
	if (elfn.value.length < 2) return;
	if (elln.value.length < 2) return;
	
	if (!(ele = document.getElementById('ctl00_ContentPlaceHolder_OracleDice_Email'))) return;
	if (!IsValidEmail(ele.value)) return;

	elbd = document.getElementById('ctl00_ContentPlaceHolder_OracleDice_BirthDay');
	elbm = document.getElementById('ctl00_ContentPlaceHolder_OracleDice_BirthMonth');
	elby = document.getElementById('ctl00_ContentPlaceHolder_OracleDice_BirthYear');
	if (!IsValidDate(elbd.value + "-" + elbm.value + "-" + elby.value)) return;

	if (!(elt = document.getElementById('diceTotal'))) return;
	elt.value = total;

	if (!(frm = document.getElementById('aspnetForm'))) return;
	frm.submit();
}

var countriesTimer;
function ToggleCountries(id) {
	var container = document.getElementById(id);
	if (!container) return;
	if (container.style.display != "block") {
		container.style.display = "block";
		countriesTimer = setTimeout("ToggleCountries('" + id + "');", 2000);
	} else {
		container.style.display = "none";
	}
}

function ResetCountriesTimer(id) {
	clearTimeout(countriesTimer);
}

function SetCountriesTimer(id) {
	countriesTimer = setTimeout("ToggleCountries('" + id + "');", 100);
}

function toggleMoreBlogIntroText() {
	if (document.getElementById('moreText').style.display == 'none') {
		document.getElementById('moreText').style.display = 'inline';
	} else {
		document.getElementById('moreText').style.display = 'none';
	}
}

/*
function toggleCalendar (sender) {
	var cal = document.getElementById('calContainer');
	
	if (cal.style.display == 'block') {
		cal.style.display = 'none';
	} else {
		cal.style.display = 'block';
		
		var pos = findPos (sender)[1] - findPos (cal)[1];
		
		cal.style.top = pos.toString()  + 'px';
	}
}

function initCalendar(state) {
	// Sets the show state of the calendar after page loads.
	document.getElementById('calContainer').style.display = state;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

*/