var jnick = getValue('nick');
//document.write("<h1>" + jnick + "</h1>");

function popup(url, target)
{
	widthHeight = pjirc_screensize() + ",menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,location=no";
	window.open(url,target,widthHeight);
	return true
}

function openchat(oForm)
{
	if (oForm.nick.value.length == 0)
	{
		alert ('You have to fill in a nickname');
	}
	else
	{
		s = oForm.style.value + '?nick=' + oForm.nick.value;
		popup(s,'chatroom');
	}
	return false;
}

function pjirc_screensize() {
   if(!window.screen) return ''
	var w = screen.availWidth < 800 ? screen.availWidth - 10 : 780
	var h = screen.availHeight < 600 ? screen.availHeight - 40 : 560
	return ",width="+w+",height="+h+",top="+((screen.availHeight-h)/4)+',left='+((screen.availWidth-w)/2)
}


//http://www.tek-tips.com/faqs.cfm?fid=5442
function getValue(reference) {
  // First, we load the URL into a variable
  var url = window.location.href;

  // Next, split the url by the ?
  var qparts = url.split("?");

  // Check that there is a querystring, return "" if not
  if (qparts.length == 0)
  {
    return "";
  }

  // Then find the querystring, everything after the ?
  var query = qparts[1];

  // Split the query string into variables (separates by &s)
  var vars = query.split("&");

  // Initialize the value with "" as default
  var value = "";

  // Iterate through vars, checking each one for reference
  for (i=0;i<vars.length;i++)
  {
    // Split the variable by =, which splits name and value
    var parts = vars[i].split("=");
    
    //alert("*parts: " + parts[i] + " *reference: " + reference);
    // Check if the correct variable
    if (parts[0] == reference)
    {
      // Load value into variable
      value = parts[1];

      // End the loop
      break;
    }
  }
  
  // Convert escape code
  value = unescape(value);

  // Convert "+"s to " "s
  value.replace(/\+/g," ");

  // Return the value
  return value;
}


//http://lists.evolt.org/archive/Week-of-Mon-20040126/154773.html
function getParameter(name) {
   var url = window.location.href;
   var paramsStart = url.indexOf("?");

   if(paramsStart != -1){

      var paramString = url.substr(paramsStart + 1);
      var tokenStart = paramString.indexOf(name);

      if(tokenStart != -1){

         paramToEnd = paramString.substr(tokenStart + name.length + 1);
         var delimiterPos = paramToEnd.indexOf("&");

         if(delimiterPos == -1){
            return paramToEnd;
         }
         else {
         	alert(paramToEnd.substr(0, delimiterPos));
            return paramToEnd.substr(0, delimiterPos);
         }
      }
   }
}