
function getArgs() {
  var args = new Object();
  var query = location.search.substring(1);
  var pairs = query.split("&");
  for (var i = 0; i < pairs.length; i++) {
    var pos = pairs[i].indexOf('=');
    if (pos == -1)
        continue;
    var argname = pairs[i].substring(0, pos);
    var value = pairs[i].substring(pos+1);
    value = value.replace(/\+/g, " ");
    args[argname] = unescape(value);
  }
  return args;
}


function ensure_in_window (winname) {
  // window.alert("host=" + window.document.location.host);
  if (window.name == winname || 
      ( window.document.location.host.indexOf('romantasy.com')    == -1 &&
        window.document.location.host.indexOf('romantasyweb.com') == -1))
  {}
  else { var newURL = '/index.html?BodyURL=ZXQ' + 
                       escape(window.document.location.pathname) ;
         window.top.document.location = newURL; 
       }
}


function ensure_in_body () { ensure_in_window ('Body'); }


function maybe_override_body_target (bodyTarget) {
  var argTarget  = getArgs()["BodyURL"];
  if (typeof argTarget == "string") 
     { bodyTarget = argTarget; 
       if (bodyTarget.indexOf('ZXQ') == 0)
          { bodyTarget = unescape(bodyTarget.substring(3)); }
     }
  return bodyTarget;  
}


function get_title_from_args () {
  var the_title = getArgs()["Title"];
  // window.alert('Title:' + the_title);
  if (typeof the_title == "string") 
     { return unescape(the_title); }
  // punt - worth a try if all else fails!
  else { return window.opener.document.title; }
}


function get_href_from_args () {
  var the_HREF = getArgs()["HREF"];
  // window.alert('HREF:' + the_HREF);
  if (typeof the_HREF == "string") 
     { return unescape(the_HREF); }
  // punt - worth a try if all else fails!
  else { return window.opener.document.location.href; }
}


function popitup () {
  var IEp = navigator.appName.indexOf("Microsoft") != -1;

  var sizeString = 
     (IEp ? 'width=700,height=750' : 'innerWidth=700,innerHeight=750');

  var win = window.open
       ('http://' + window.document.location.hostname + 
        '/scripts/url-form.html' +
        '?Title=' + escape(window.document.title) +
        '&HREF='  + escape(window.document.location.href),
        'locWindow','resizable=yes,scrollbars=yes,' + 
        sizeString + ',alwaysRaised=yes');
  win.focus();
  return false;
}


