var ie4     = false;
var ie5     = false;
var ns4     = false;
var ns6     = false;
var mac     = false;
var loaded  = false;
var testing = false;

if(document.layers){origWidth=innerWidth;origHeight=innerHeight;onresize=function(){if(innerWidth!=origWidth||innerHeight!=origHeight)location.reload()}}else{onresize=function(){window.location.reload();}}
function Init(){
  SetBrowser();
  PreloadImages();
  loaded = true;
  }
function SetBrowser(){
  agent = navigator.userAgent.toLowerCase();
  mac   = (agent.indexOf("mac")!=-1);
  ie4   = (document.all && !document.getElementById) ? true : false;
  ie5   = (document.all && document.getElementById)  ? true : false;
  ns4   = (document.layers)                          ? true : false;
  ns6   = (document.getElementById && !document.all) ? true : false;
  if (testing){ alert("agent: "+agent+"\nmac: "+mac+"\nie4: "+ie4+"\nie5: "+ie5+"\nns4: "+ns4+"\nns6: "+ns6+"\n"); }
  }
function RollOn(id){
  if      (ie4){ eval('document.images["img'+id+'"].src = ImgOn[id].src'); }
  else if (ns4){ eval('document.images["img'+id+'"].src = ImgOn[id].src'); }
  else         { eval('document.getElementById("img'+id+'").src = ImgOn[id].src'); }
  }
function RollOff(id){
  if      (ie4){ eval('document.images["img'+id+'"].src = ImgOff[id].src'); }
  else if (ns4){ eval('document.images["img'+id+'"].src = ImgOff[id].src'); }
  else         { eval('document.getElementById("img'+id+'").src = ImgOff[id].src'); }
  }
function PreloadImages(){
  var num_images = 10;
  ImgOff = new Array(num_images);
  for (var i=0; i<num_images; i++){ ImgOff[i] = new Image(); }
  ImgOff[0].src = "images/btn_quote_a.gif";
  ImgOff[1].src = "images/btn_insurance_a.gif";
  ImgOff[2].src = "images/btn_aviation_a.gif";
  ImgOff[3].src = "images/btn_about_a.gif";
  ImgOff[4].src = "images/btn_contact_a.gif";
  ImgOff[5].src = "images/btn_quote_a.gif";
  ImgOff[6].src = "images/btn_insurance_a.gif";
  ImgOff[7].src = "images/btn_aviation_a.gif";
  ImgOff[8].src = "images/btn_about_a.gif";
  ImgOff[9].src = "images/btn_contact_a.gif";
  
  ImgOn = new Array(num_images);
  for (var i=0; i<num_images; i++){ ImgOn[i] = new Image(); }
  ImgOn[0].src = "images/btn_quote_b.gif";
  ImgOn[1].src = "images/btn_insurance_b.gif";
  ImgOn[2].src = "images/btn_aviation_b.gif";
  ImgOn[3].src = "images/btn_about_b.gif";
  ImgOn[4].src = "images/btn_contact_b.gif";
  ImgOn[5].src = "images/btn_quote_b.gif";
  ImgOn[6].src = "images/btn_insurance_b.gif";
  ImgOn[7].src = "images/btn_aviation_b.gif";
  ImgOn[8].src = "images/btn_about_b.gif";
  ImgOn[9].src = "images/btn_contact_b.gif";
  }
function SetFocus(fieldname,formname){if (formname == ''){ formname = 'form'; }if (eval("document."+formname+".elements[fieldname].value == ''")){ eval("document."+formname+".elements[fieldname].focus();"); }}
function Popup(title,filename,w,h,scroll,resizable){if (title == ''){ title = 'popup'; }if (scroll == 'scroll'){ scroll = 'yes'; }else{ scroll = 'no'; }if (resizable == 'lock'){ resizable = 'no'; }else{ resizable = 'yes'; }winOptions = eval("'width="+w+",height="+h+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scroll+",resizable="+resizable+",copyhistory=no'");window.open(filename,title,winOptions);return;}
//display numbers in proper format
function formatMoney(SourceString) {
  //var SourceString;
  //SourceString = String(document.form.amount.value);
  SourceString = SourceString.replace(/[,\$]/g,'');
  var FinalString='', Amount = SourceString.split('.'), Dollars = Amount[0].length-1, C, j;
  for (j = 0; j <= Dollars; j++) {
  FinalString += C = Amount[0].charAt(j);
  if ((j<Dollars) && ((Dollars-j) % 3 == 0) && (C != '-')) FinalString += ','; }
  if (!Amount[1]) { Amount[1] = '00'; }
  if (Amount[1].length == 1) { Amount[1] += '0'; }
  //document.form.amount.value = '$' + FinalString + '.' + Amount[1];
  return FinalString + '.' + Amount[1];
}
function formatMoney_OLD(amount){
  //re = /[^-.0-9]/g;
  re = /[^-0-9]/g;
  var s = "";
  var decimal;
  val = new String(amount);
  amount = val.replace(re, "");
  len = amount.length + 2;
  if (!amount.indexOf(".")) len++;
 
  amount = parseFloat(amount);
  neg = (amount < 0) ? true : false;
  if (neg) {
    amount = Math.abs(amount);
    --len;
    }
  if (!(isNaN(amount))){
    //round to nearest cent
    amount = new String(amount * 100);
    amount = amount.substring(0,len);
    amount = Math.ceil(amount);
    amount = amount / 100;
 
    //format the output
    s = new String(amount);
    decimal = s.indexOf(".");
    if (decimal == -1){
      //whole number
      // s+= ".00";
      }
    else{
      if (decimal == (s.length - 2)){
        //needs a trailing zero
        s+= "0";
        }
      }
    //add commas
    //decimal = s.indexOf(".");
    decimal = s.length;
    if (decimal > 3) {
      s = s.substring(0, decimal-3) + "," + s.substring(decimal-3, s.length);
      comma = s.indexOf(",");
      while (comma > 3) {
        s = s.substring(0, comma-3) + "," + s.substring(comma-3, s.length);
        comma = s.indexOf(",");
        }
      }
    }
  else{
    //not a number so return zero
    //s = "0.00";
    s = "0";
    }
  if (neg) s = '-' + s;
  return s;
  }