var popWindow = null;
window.onunload = function() {};
window.onload = basicLoad;



function basicLoad() {

  mainLoad();

  popUpWindow(0,0);

  document.getElementById("closeWin").onclick = closeWindows;
  document.getElementById("openWin").onclick = openWindows;

}



function popUpWindow(leftPos,topPos) {

  popWindow = window.open("", "popWin", "location,scrollbars=yes,width=300,height=200,left="+leftPos+",top="+topPos);
  var newDoc = popWindow.document;

  newDoc.title = "Generated Window";
  newDoc.bgColor = "#000000";
  newDoc.fgColor = "#FFFFFF";

  newDoc.body.innerHTML = "<h2>Generated Pop Up Window</h2><p>This is a window that was generated with Javascript and designed to pop up when this page loaded.<\/p>";

  newDoc.body.innerHTML += "<p>Basically, the same as a pop up ad.</p>";

}



function windowOpen(winName) {

  if(winName && !winName.closed) {

    return true;

  }

  return false;

}



function closeWindows() {

  if(windowOpen(popWindow)) {

    popWindow.close();

  } else {

    alert("No pop up windows are open!");

  }

  return false;

}



function openWindows() {

  var allRadios = document.getElementsByTagName("input");

  for(i=0; i < allRadios.length; i++) {


    if(allRadios[i].checked) {

	var winPos = allRadios[i].value;

    }

  }

  var topPos = (winPos.indexOf("bottom") == -1) ? 0 : screen.availHeight-200;
  var leftPos = (winPos.indexOf("Right") == -1) ? 0 : screen.availWidth-300;



  if(windowOpen(popWindow)) {

    popWindow.moveTo(leftPos,topPos);
    popWindow.focus();

  } else {

    popUpWindow(leftPos,topPos);
    popWindow.focus();

  }

  return false;

}
