// CDPlus Online Web Functions - javascript.js

// Configuration Variables
var sClientName = 'Indian River County';
var sClientDirectory = 'http://cdplusonline.com/irc/';
var sClientCGI = 'http://cdplusonline.com/community/irc/';
var iInnerFrameWidth = 750;

// Other Variables and Properties
var NS4 = (document.layers);
var IE4 = (document.all);
document.domain = 'cdplusonline.com';
window.onerror = stopError;

// ********************************************************
// Outer Functions (call from [outer_frameset].html)
// ********************************************************

function init_outer_frame() {
  var sParam = location.search;
  var oFrame = document.getElementById("main");

  switch (sParam) {
    case "?certificate_access":
    case "?cert":
      oFrame.src = sClientDirectory+'main.html?certificate_access';
      document.title = 'Accessing Certificate Data';
      break;
    case "?code_enforcement":
    case "?code":
      oFrame.src = sClientDirectory+'main.html?code_enforcement';
      document.title = 'Online Code Enforcement';
      break;
    case "?permit_apply":
    case "?apply":
      oFrame.src = sClientDirectory+'main.html?permit_apply';
      document.title = 'Online Permit Application';
      break;
    case "?permit_access":
    case "?access":
    default:
      oFrame.src = sClientDirectory+'main.html?permit_access';
      document.title = 'Accessing Permit Data';
  }
}

// ********************************************************
// Middle Functions (call from main.html)
// ********************************************************

function init_inner_frame() {
  var sParam = location.search;
  var oFrame = document.getElementById("dbframe");

  switch (sParam) {
    case "?certificate_access":
      oFrame.src = sClientCGI+'certLogin';
      document.title = 'Accessing Certificate Data';
      break;
    case "?code_enforcement":
      oFrame.src = sClientCGI+'codeLogin';
      document.title = 'Online Code Enforcement';
      break;
    case "?permit_apply":
      oFrame.src = sClientCGI+'permApply';
      document.title = 'Online Permit Application';
      break;
    case "?permit_access":
    default:
      oFrame.src = sClientCGI+'permLogin';
      document.title = 'Accessing Permit Data';
  }
}

function ResizeIFrame() {
  var iframe = document.getElementById("dbframe");
  var docbod = iframe.contentWindow.document.body;
  iframe.width = iInnerFrameWidth;
  if (!IE4) {
    iframe.height = docbod.offsetHeight + 25; //Extra height FireFox
  } else {
    iframe.height = docbod.scrollHeight;
  }
}

// ********************************************************
// Inner Functions (call from within iFrame documents)
// ********************************************************

function onBodyLoad() {
  //being called, but not currently being utilized
  return true;
}

function CHECK_JOB_VALUE(iLowValue,iHighValue) {
  var oFormElement = document.form1.JOB_VALUE;
  var bBadValue = false;

  if(isNaN(oFormElement.value)==true){bBadValue=true}
  else{if((oFormElement.value < iLowValue) || (oFormElement.value > iHighValue)){bBadValue=true}}
  if(oFormElement.value==''){bBadValue=false}

  if(bBadValue==true) {
    alert("Invalid Job Value.\nMust be an integer number\n between "+iLowValue+" and "+iHighValue+".");
    oFormElement.value=""; 
    oFormElement.focus();   
  }
}

function CHECK_ALT_KEY() {
  var oFormElement = document.form1.ALT_KEY;
  var bBadValue = false;

  if(isNaN(oFormElement.value)==true){bBadValue=true}
  else{if((oFormElement.value < 100000) || (oFormElement.value > 99999999)){bBadValue=true}}
  if(oFormElement.value==''){bBadValue=false}

  if(bBadValue==true) {
    alert("Invalid Alternate Key.\nMust be a 6-8 digit integer number.");
    oFormElement.value=""; 
    oFormElement.focus();   
  }
}

function CHECK_CERT_NBR() {
  var oFormElement = document.form1.CERT_NBR;
  var bBadValue = false;

  if(isNaN(oFormElement.value)==true){bBadValue=true}
  else{if((oFormElement.value < 100) || (oFormElement.value > 99999)){bBadValue=true}}
  if(oFormElement.value==''){bBadValue=false}

  if(bBadValue==true) {
    alert("Invalid Certificate Number.\nMust be a 3-5 digit integer number.");
    oFormElement.value=""; 
    oFormElement.focus();   
  }
}

function pnstrcheck() {
  if(isNaN(document.form1.permitno.value)==true) {
    alert("Invalid Permit Number.");
    document.form1.permitno.value=""; 
    document.form1.permitno.focus();   
  }
}

function cnstrcheck() {
  if(isNaN(document.form1.confirmno.value)==true) {
    alert("Invalid Confirm Number.");
    document.form1.confirmno.value=""; 
    document.form1.confirmno.focus();   
  }
}

function SetChecked(val) {
  len = document.form1.elements.length;
  var i=0;
  for( i=0 ; i<len ; i++) {
    if (document.form1.elements[i].type=='checkbox') {
      document.form1.elements[i].checked=val;
    }
  }
}

// ********************************************************
// Global Functions (call from anywhere)
// ********************************************************

// Generic Error Handler
function stopError() {return true}

// Popup Generator
function popup(sURL,iWidth,iHeight){
  if (iWidth == null) {iWidth = 500}; 
  if (iHeight == null) {iHeight = 500};
  var child = window.open(sURL,"PDSpopup",'toolbar=0,location=0,menubar=0,scrollbars=1,resizable=1,width='+iWidth+',height='+iHeight+',status=1,top=screen.availTop,left=screen.availLeft');
}

// Time Delay Procedure
function SpinWheels(iMilliseconds) {
  var  holdTime = new Date();
  var  currTime = null;
  do { currTime = new Date(); }
  while( currTime-holdTime < iMilliseconds );
}


