var win=null;
function NewWindow(mypage,myname,w,h,pos,infocus){
  //UNCOMMENT THIS CODE TO USE COOKIES!
  //if(GetCookie("sid") == "999"){return;}
  //	document.cookie="sid=999; Path=/; Expires= " + getFuture(1);
  
  if(pos=="random"){
  	myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
  	mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
  }
  if(pos=="center"){
  	myleft=(screen.width)?(screen.width-w)/2:100;
  	mytop=(screen.height)?(screen.height-h)/2:100;}
  else if((pos!='center' && pos!="random") || pos==null){
  	myleft=0;
  	mytop=20;}
  settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
  win=window.open(mypage,myname,settings);
  
  //set in front:win.focus() OR in back: win.blur()
  win.focus();
}
// Cookie functions borrowed from ronniemoore.com
function getFuture(f){
  var d = new Date();
  d.setTime(d.getTime() + (86400000 * f));
  return d;
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var tmpI = 0;
  while (tmpI < clen) {
  	var tmpJ = tmpI + alen;
   	if (document.cookie.substring(tmpI, tmpJ) == arg)
  	return getCookieVal (tmpJ);
  	tmpI = document.cookie.indexOf(" ", tmpI) + 1;
  	if (tmpI == 0) break;}
  return null;
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
  	endstr = document.cookie.length;
  	return unescape(document.cookie.substring(offset, endstr));
}
