// CDPlus Online Web Functions - javascript.js

// Configuration Variables
var sClientName = 'City of Oakland Park';
var sClientDirectory = 'http://cdplusonline.com/oakp/';
var sClientCGI = 'http://cdplusonline.com/community/oakp/';

// 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");

  if (sParam == '?access') {
    oFrame.src = sClientDirectory+'main.html?access';
    document.title = 'Accessing Permit Data';
  }
  else {
    if (sParam == '?apply') {
      oFrame.src = sClientDirectory+'main.html?apply';
      document.title = 'Online Permit Application';
    }
    else {
      oFrame.src = sClientDirectory+'main.html';
      document.title = sClientName+' Online Permitting';
    };
  };
}

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

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

  if (sParam == '?access') {
    oFrame.src = sClientCGI+'permLogin';
    document.title = 'Accessing Permit Data';
  }
  else {
    if (sParam == '?apply') {
      oFrame.src = sClientCGI+'permApply';
      document.title = 'Online Permit Application';
    }
    else {
      oFrame.src = sClientCGI+'permLogin';
      document.title = sClientName+' Online Permitting';
    };
  };
}

function ResizeFrame(w, h) {
  var oFrame = document.getElementById("dbframe");
  oFrame.height = h;
  oFrame.width = w;
}

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

function onBodyLoad() {
  var oBody = document.body;
  var w = oBody.scrollWidth + (oBody.offsetWidth - oBody.clientWidth);
  var h = oBody.scrollHeight + (oBody.offsetHeight - oBody.clientHeight);
  parent.ResizeFrame(w, h);
}

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');
}
