
if (screen && screen.width) {
	var screenWidth=screen.width;
	var screenHeight=screen.height;
}

function openWindow(theUrl, windowId, width, height, windowOptions) {
	if (theUrl.indexOf('?') < 0) {
		theUrl += '?';
	} else {
		theUrl += '&';
	}

	if (screenWidth && width+70 < screenWidth) {
		theUrl += '&enlargedX=1';
		width+=60;
	}
	if (screenWidth && width > screenWidth+32) {
		if (width > screenWidth+182)
			theUrl += '&resizedX=2';
		else
			theUrl += '&resizedX=1';
		width=screenWidth-8;
	}
	if (screenHeight && height > screenHeight+32) {
		height=screenHeight-40;
		theUrl += '&resizedY=1';
	}
	theUrl += 'width='+width+'&height='+height;

    if (navigator && !navigator.javaEnabled())
        theUrl += '&nojava=1';
    else
        theUrl += '&java=1';

	var theWindow = window.open(theUrl, windowId, 'width='+width+',height='+height+','+windowOptions);
	if (theWindow) {
	    if (theWindow.focus)
	        theWindow.focus();

	    return false;
    }
    return true;
}

function getURLParam(target, strParamName){
  var strReturn = "";
  var strHref = target.location.href;
  if ( strHref.indexOf("&") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("&")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return strReturn;
}

function closeWin() {
  if (window.parent)
    target = window.parent;
  else
    target = window;
  if (target.opener)
    target.close()
  else {
  	from = getURLParam(target, "from");
  	alert(from);
	  if (from.indexOf("jeuxdecartes.net") == -1)
	  	from = "http://www.jeuxdecartes.net/";
  	target.location.href = from;
  }
}
