function createFormPopupOpener(width,height,name) {
  return function() {
    var win = window.open("", name, "top=40,left=40,width="+width+",height="+height);
    win.focus()
    this.target = win.name
    // this is defined elsewhere in the scope of the page calling this js
    // so as to be able to test the status of this window
    popup_window = win
    return true;
  } 
}

function doFormPopups() {
  if (!document.getElementsByTagName) return false;
  var form=document.getElementsByTagName("form");
  linkRE = new RegExp(/popup(?:(\d+)x(\d+))?(?:-(.*))?/);
  for (var i=0; i < form.length; i++) {   
    if (match = linkRE.exec(form[i].className)) {
      var width  = match[1] ? isNaN(match[1]) ? 500 : match[1] : 500
      var height = match[2] ? isNaN(match[2]) ? 625 : match[2] : 625
      var name   = match[3] ? match[3] : "popup"
      var f = createFormPopupOpener(width,height,name)
      form[i].onsubmit=f
    } 
  } 

  // here's a nice little hack to find submit buttons and check to see if we
  // need to enable them when we set their onsubmit actions
  var inputs=document.getElementsByTagName("input");
  linkRE = new RegExp(/popup-enable/);
  for (var i=0; i < inputs.length; i++) {   
    if (match = linkRE.exec(inputs[i].className)) {
      inputs[i].disabled=false
      inputs[i].value="Play Game"
    } 
  } 
} 

oldUnload = window.onload;
window.onload=doFormPopups;
oldUnload();

// You open the popup by assigning class="popup" to the anchor tag 
// like this:  <form action="http://www.gullbuy.com" class="popup">Search 
// By Name</a></li>
//
// To specify a different size, specify widthxheight after the word popup, e.g.
// class="popup300x200" will open up a popup window with a width of 300 pixels
// and a height of 200 pixels.


