var testing = 0;

// HELP WINDOW
function popHelpWindow() {
 window.open('help/index.htm', 'Help', 'width=750,height=500,scrollbars=yes')
}

// HOOHIKI CONNECT
var child;

function spawnChild() {
  if ((testing == 0) || (window.location.href.toLowerCase() == "/jud/Hoohiki/main.htm?dev")) {
    child = window.open('connecting.htm','Hoohiki','left=1,top=1,width=500,height=300,resizable,scrollbars=1,status=1');
    window.location.replace('connect.jsp');
    /* maximizeWindow(child); */
  } else {
    displayDevMsg();
  }
}

function redirect() {
 child = window.open('Search.jsp','Hoohiki');
 /* maximizeWindow(child); */
}

function maximizeWindow(win) {
  if (win.screen) {
    var aw = screen.availWidth;
    var ah = screen.availHeight;
    win.moveTo(0, 0);
    win.resizeTo(aw, ah);
  }
}

// HOOHIKI DISCONNECT
function monitorChild() {
 setTimeout('confirmChild()',30);
}

function confirmChild() {
 if (child.closed) {
  location.href="Disconnect.jsp";
 }
}

// PREVENT BOOKMARKING
function validateWindow() {
  setTimeout('window.close()',600000);
  standard_in = "/jud/hoohiki/main.htm?spawn=1";

  if (opener == null) {
     displayErrorMsg();  
  } else {
    parent_url = opener.parent.location.href.toLowerCase();
    start = parent_url.indexOf(standard_in);
    if (start < 0) {
      displayErrorMsg();  
    }
  }
}

function displayDevMsg() {
 document.open("text/html", "replace");
 document.write("<HTML>");
 document.write("<HEAD>");
 document.write("<TITLE>Ho'ohiki</TITLE>");
 document.write("</HEAD>");
 document.write("<BODY BGCOLOR='#ffffff'>");
 document.write("<FONT FACE=Arial SIZE=4>");
 document.write("Development in progress please use the production <A HREF='http://166.122.201.55/hostpublisher/hoohiki/main.htm'>Ho'ohiki system</A>.");
 document.write("</FONT>");
 document.write("</BODY>");
 document.write("</HTML>");
 document.close(); 
}

function displayErrorMsg() {
 document.open("text/html", "replace");
 document.write("<HTML>");
 document.write("<HEAD>");
 document.write("<TITLE>Ho'ohiki</TITLE>");
 document.write("</HEAD>");
 document.write("<BODY BGCOLOR='#ffffff'>");
 document.write("<FONT FACE=Arial SIZE=4>");
 document.write("ERROR:  Ho'ohiki cannot be bookmarked.  Please click here to enter the <A HREF='http://www.courts.state.hi.us/'>Ho'ohiki system</A>.");
 document.write("</FONT>");
 document.write("</BODY>");
 document.write("</HTML>");
 document.close(); 
}

// PRINTING
var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage() {
 if (pr) {
  window.print()
 } else if (da && !mac) {
  vbPrintPage()
 } else {
  alert("Sorry, your browser doesn't support this feature.");
  return false;
 }
}

// DISABLE RIGHT MOUSE BUTTON
document.oncontextmenu = function(){return false}

if(document.layers) {
 window.captureEvents(Event.MOUSEDOWN);
 window.onmousedown = function(e){
  if (e.target==document) return false;
 }
} else {
 document.onmousedown = function(){return false}
}

// PREVENT MULTIPLE SUBMITS
var submitFlag = 0;

function checkStatus() {
 if (submitFlag == 0) {
  submitFlag = 1;
  return true;
 } else {
  return false;
 }
}
