function reload() {
	window.location.href = window.location.href;
}

function addFeedback( gameid ) {
	openWindow( 'http://www.' + DOMAIN + '/addfeedback.php?id=' + gameid, 600, 450 );
}

function showScoresGame( gameid ) {
	openWindow( 'http://www.' + DOMAIN + '/scorelijsten.html?id=' + gameid, 750, Math.max( getWindowSize()["height"], 600 ) );
}

function showScores() {
	openWindow( 'http://www.' + DOMAIN + '/scorelijsten.html', 750, Math.max( getWindowSize()["height"], 600 ) );
}

function showMedals( username ) {
	openWindow( 'http://www.' + DOMAIN + '/listmedals.php?user=' + username, 750, Math.max( getWindowSize()["height"], 600 ) );
}

function showTrophies( username ) {
	openWindow( 'http://www.' + DOMAIN + '/listtrophies.php?user=' + username, 750, Math.max( getWindowSize()["height"], 600 ) );
}

function showRating( gameid ) {
	openWindow( 'http://www.' + DOMAIN + '/rating.php?id=' + gameid, 750, Math.max( getWindowSize()["height"], 600 ) );
}

function showUserRating( gameid, user ) {
	openWindow( 'http://www.' + DOMAIN + '/rating.php?id=' + gameid + '&user=' + user, 750, Math.max( getWindowSize()["height"], 600 ) );
}

function showAllRatings( gameid ) {
	openWindow( 'http://www.' + DOMAIN + '/allratings.php?id=' + gameid, 750, Math.max( getWindowSize()["height"], 600 ) );
}

function showRatings() {
	openWindow( 'http://www.' + DOMAIN + '/allratings.php', 750, Math.max( getWindowSize()["height"], 600 ) );
}

function showTournament( gameid ) {
	openWindow( 'http://www.' + DOMAIN + '/tournament.php?id=' + gameid, 600, Math.max( getWindowSize()["height"], 600 ) );
}

function showDayscores( gameid ) {
	openWindow( 'http://www.' + DOMAIN + '/dayscores.php?id=' + gameid, 600, Math.max( getWindowSize()["height"], 600 ) );
}

function showPaymentInfo( key ) {
	openWindow( 'http://www.' + DOMAIN + '/payment/?months=0&key=' + key, 550, Math.max( getWindowSize()["height"], 600 ) );
}

function showGiftcardInfo() {
	openWindow( 'http://www.' + DOMAIN + '/giftcard/?months=0', 800, Math.max( getWindowSize()["height"], 600 ) );
}

function openSpeelscherm( game, key, size ) {
	//openWindow( 'http://www.' + DOMAIN + '/spel/'+game+'.html?key=' + key + '&size=' + size, 830, 670 );
	openWindow( 'http://www.' + DOMAIN + '/spel/'+game+'.html?key=' + key + '&size=' + size, 830, 670 );
}

function openGame( game, key, size ) {
	openWindow( 'http://www.' + DOMAIN + '/spel/'+game+'.html?key=' + key + '&size=' + size, 830, 670 );
}

function openDuelInvitation( game, key, size ) {
	openWindow( 'http://www.' + DOMAIN + '/spel/'+game+'.html?key=' + key + '&duel=true&play=true&size=' + size, 830, 670 );
}

function openDuel( game, key, size ) {
	openWindow( 'http://www.' + DOMAIN + '/spel/'+game+'.html?key=' + key + '&duel=true&size=' + size, 830, 670 );
}

function openTournament( game, tid, key, size ) {
	openWindow( 'http://www.' + DOMAIN + '/spel/'+game+'.html?key=' + key + '&tid=' + tid + '&size=' + size, 830, 670 );
}

function openExtGame( id ) {
	openWindow( 'http://www.' + DOMAIN + '/extgame.php?id=' + id, 1030, 760 );
}

function openSpelpuntGame( game ) {
	var tempdate = new Date();
	var winname = "gpcon" + tempdate.getTime();
	var URL = 'http://www.' + DOMAIN + '/spelpunt/'+game+'.html';
	window.open( URL, winname, 'width=770,height=558,scrollbars=1,resizable') ;
}

function openWindow( url, width, height ) {
	var popupSize = new Array();
	popupSize['width'] = width;
	popupSize['height'] = height;
	var windowSize = getWindowSize();
	var windowPosition = getWindowPosition();
	
	var center = getWindowCenterPosition(windowSize, windowPosition, popupSize);
	
	var left = center['left'];
	var top = 0;	//center['top'];
	var tempdate = new Date();
	var winname = "gpcon" + tempdate.getTime();
	var win = window.open(url, winname, 'width='+width+',height='+height+',left='+left+',top='+top+',scrollbars=1,resizable');
	win.focus;
}


function makeRequest(url, parameters,header) {
   var http_request = false;
   if (window.XMLHttpRequest) { // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) {
			if (header!=null && header!='')
				http_request.overrideMimeType(header);
			else
	         http_request.overrideMimeType('text/xml');
      }
   } else if (window.ActiveXObject) { // IE
      try {
         http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e) {}
      }
   }
   if (!http_request) {
      alert('Cannot create XMLHTTP instance');
      return false;
   }
   http_request.open('GET', url + parameters, true);
   http_request.send(null);

   return http_request;
}
function getWindowSize(){

	if(self.innerWidth){
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}else if(document.documentElement && document.documentElement.clientWidth){
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}else if(document.body){
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	windowSize = Array();
	windowSize['width'] = windowWidth;
	windowSize['height'] = windowHeight;
	return windowSize;

}

function setWindowSize(newWidth, newHeight){
	windowSize = getWindowSize();

	extraWidth = newWidth - windowSize['width'];
	extraHeight = newHeight - windowSize['height'];

	window.resizeBy(extraWidth, extraHeight);
}






function getWindowPosition(){
	position = Array();
	if(document.all){
		position['left'] = window.screenLeft;
		position['top'] = window.screenTop;
	}else{
		position['left'] = window.screenX;
		position['top'] = window.screenY;
	}
	return position;
}

function setWindowPosition(left, top){
	window.moveTo(left, top);
}

function moveWindowTop() {
	setWindowPosition(0,0);
}





function getScreenCenterPosition(windowWidth, windowHeight){
	screenSize = getScreenSize();
	centerPosition = Array();
	centerPosition['left'] = (screenSize['width'] - windowWidth) / 2;
	centerPosition['top'] = (screenSize['height'] - windowHeight) / 2;
	return centerPosition;
}

function getWindowCenterPosition(mainWindowSize, mainWindowPosition, centerWindowSize){

	mainWindowPosition['left'] -= 0;
	mainWindowPosition['top'] -= 0;

	centerPosition = Array();
	centerPosition['left'] = mainWindowSize['width'] / 2 - centerWindowSize['width'] / 2 + mainWindowPosition['left'];
	centerPosition['top'] = mainWindowSize['height'] / 2 - centerWindowSize['height'] / 2 + mainWindowPosition['top'];
	return centerPosition;
}

function getScrollPosition(){
	scrollPosition = Array();

	if(typeof(window.pageYOffset) == 'number'){
		scrollPosition['top'] = window.pageYOffset;
		scrollPosition['left'] = window.pageXOffset;
	}
	else if(document.documentElement.scrollTop != undefined){
		scrollPosition['top'] = document.documentElement.scrollTop;
		scrollPosition['left'] = document.documentElement.scrollLeft;
	}
	else if(document.body != undefined){
		scrollPosition['top'] = document.body.scrollTop;
		scrollPosition['left'] = document.body.scrollLeft;
	}
	else {
		scrollPosition['top'] = 0;
		scrollPosition['left'] = 0;
	}

	return scrollPosition;
}
function getElementSize(id){
	elementSize = Array();
	elementSize['width'] = document.getElementById(id).clientWidth;
	elementSize['height'] = document.getElementById(id).clientHeight;
	return elementSize;
}






function val(i) {
	return document.getElementById(i).value;
}
function delval(i) {
	document.getElementById(i).value = '';
}
function setval(elem,val) {
	document.getElementById(elem).value = val;
}

function ShowHide(elem) {
	var x = document.getElementById(elem).style;
	x.display = (x.display == 'block') ? 'none' : 'block';
}

function SetCookie(name, value) {
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape (document.cookie.substring(offset, endstr));
}
function GetCookie(name) {
	var arg = name+"=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function toUrl( url ) {
	if (url.indexOf('://') <= 0)
		url = 'http://' + url;
	return url;
}

function bordered_table( html ) {
	return '<table cellspacing="0" cellpadding="0">' +
		'<tr>' +
		'	<td class="border-top-left"></td>' +
		'	<td class="border-top" colspan="2"></td>' +
		'</tr>' +
		'<tr>' +
		'	<td class="border-left"></td>' +
		'   <td class="border-inside"></td>' +
		html + 
		'	</td>' +
		'	<td class="border-right"></td>' +
		'</tr>' +
		'<tr>' +
		'		<td class="border-bottom-left"></td>' +
		'		<td class="border-bottom" colspan="2"></td>' +
		'</tr>' +
		'</table>';
}

function popup( page ) {
	window.open(page,'_blank','width='+(screen.width-200)+',height='+(screen.height-200)+',left=150,top=50,status=no,location=no,menubar=no,directories=no,toolbar=no,resizable=yes,scrollbars=yes');
}

function str_comp( val1, val2 ) {
	return (val1 != null && val2 != null && val1.trim().toLowerCase() == val2.trim().toLowerCase());
}

function showMsg(elemname) {
	var w = 400; var h = 300; var d = 800;
	var blur = document.getElementById('semi-transparent');
	var msgtable = document.getElementById(elemname);
	//msgtable.style.top = (window.document.body.clientHeight/2)-(h/2)-150;
	msgtable.style.top = 50;
	var size = getDocumentSize();
	blur.style.width = size[0] + 'px';
	blur.style.height = (size[1]+1000) + 'px';
	blur.style.display = 'block';
	msgtable.style.width = size[0] + 'px';
	msgtable.style.height = '500px';
	msgtable.style.display = 'block';
}

function hideMsg(elemname) {
	document.getElementById('semi-transparent').style.display = 'none';
	document.getElementById(elemname).style.display = 'none';
}

function getDocumentSize() {
	var ns6 = document.getElementById && !document.all;
	var width  = window.document.body.clientWidth;
	var height = window.document.body.clientHeight;  
	if (!ns6) {
		if( typeof( window.pageYOffset ) == 'number' ) {
		    //Netscape compliant
		    height += window.pageYOffset;
		    width  += window.pageXOffset;
		} 
		else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		    //DOM compliant
		    height += document.body.scrollTop;
		    width  += document.body.scrollLeft;
		} 
		else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		    //IE6 standards compliant mode
		    height += document.documentElement.scrollTop;
		    width  += document.documentElement.scrollLeft;
		}
		if (width < 0) width = 0;
		if (height < 0) height = 0;  
	}
	return new Array( width, height );
}

function isDecimal(s) {
	if (s == '')
		return true;
	var re = /^\s*(\+|-)?((\d+(\.\d+)?)|(\.\d+))\s*$/;
	return String(s).search(re) != -1;
}
function isMoney(s) {
	if (s == '')
		return true;
	s = s.substr(1,s.length);
	var re = /^\s*(\+|-)?((\d+(\.\d{1,2})?))\s*$/;
	return String(s).search(re) != -1;
}
function isInteger(s) {
	if (s == '')
		return true;
	var re = /^\s*(\+|-)?\d+\s*$/;
	return String(s).search(re) != -1;
}
function isEmail(s) {
	if (s == null)
		return false;
	var re = /^[0-9a-zA-Z\.\-]+@[0-9a-zA-Z\-]+[\.]{1}[0-9a-zA-Z]+[\.]?[0-9a-zA-Z]+$/;
	return String(s).search(re) != -1;
}
function isZipcode(s) {
	s = (s == null) ? "" : s = s.trim();
	var re = /^\d{4}[A-Z]{2}$/;
	return String(s).search(re) != -1;
}

function isDate(s) {
	if (s == null)
		return false;
	// date = yyyy-mm-dd
	var arr = s.split("-");
	if (arr.length < 3)
		return false;
	var d = new Date(arr[0],arr[1],arr[2]);

	var day   = arr[2]; // p@rse date into variables
	var month = arr[1];
	var year  = arr[0];

	if (month < 1 || month > 12)
		return false;

	if (day < 1 || day > 31)
		return false;

	if ((month==4 || month==6 || month==9 || month==11) && day==31)
		return false;

	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap))
			return false;
	}
	return true; // date is valid
}

function emailCheck(s) {
	return isEmail(s);
}


