    var agt=navigator.userAgent.toLowerCase();

    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);
    
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);

    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

    var is_opera = (agt.indexOf("opera") != -1);
    var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

var ip_array = ['8','4','6','3','1','9','2','7','0','5'];

// checking login variables
function submitLogon(type) {
  var logOBJ = document.getElementById('LOGN');
  var formOBJ = document.getElementById('LOGONFORM');
  if (type=="ON") {    
    var unOBJ = document.getElementById('USERNAME_INPUT');
    var upOBJ = document.getElementById('USERPASSWORD_INPUT');
    var checkedOK = [false, false];
    if (unOBJ.value.length > 0) { checkedOK[0]=true; }
    if (upOBJ.value.length > 0) { checkedOK[1]=true; }
    if (!checkedOK[0] || !checkedOK[1]) {
      var errorOCC = "THE FOLLING ERROR OCCURRED : \n";
      if (!checkedOK[0]) errorOCC=errorOCC+"USERNAME NOT ENTERED! \n";
      if (!checkedOK[1]) errorOCC=errorOCC+"PASSWORD NOT ENTERED! \n";
      alert(errorOCC);
    } else {
       upOBJ.value=submitentry(upOBJ);
       logOBJ.value=type;
       formOBJ.submit();
    }   
  } else if (type=="OFF") {
     logOBJ.value=type;
     formOBJ.submit();
  }
}

// changing the middle frames location
function changeMILoc(menu_sel, submenu_sel,page_url) {
  if (page_url == "" ){
  } else if (page_url == "javascript:void(0)") {
  } else if (page_url == "javascript:void(0);") {
  } else {
    window.status = "Loading selected menu...";
    var middle_info_iframe = window.frames['MIDDLE_IFRAME'];
    var menu_files_iframe = window.frames['M_FILES_IFRAME'];
    if (middle_info_iframe) { middle_info_iframe.location = page_url+"?MI="+menu_sel+"&SMI="+submenu_sel+"&CLEAR_OBJ=true"; }
    if (menu_files_iframe) { menu_files_iframe.location = "TopicsPage.asp"+"?MI="+menu_sel+"&SMI="+submenu_sel+"&CLEAR_OBJ=true"; }
  }
}

function clearDLValues(option) {
  var download_file = document.getElementById('DOWNLOAD_FILE');
  var file_sel = document.getElementById('SEARCH_FILE_SEL');
  if (option == 1) {
    if (download_file) document.getElementById('DOWNLOAD_FILE').value="false";
    if (file_sel) document.getElementById('SEARCH_FILE_SEL').value="-1";
  } else if (option == 2) {
    if (download_file) document.getElementById('DOWNLOAD_FILE').value="false";
  } else if (option == 3) {
    if (file_sel) document.getElementById('SEARCH_FILE_SEL').value="-1";
  }
}

// searching for files
function searchFiles(search_value) {
  clearDLValues(1);
  document.getElementById("SEARCH_FILES").value=search_value;
  document.getElementById('CENTERPAGEFORM').submit();
}

function downloadFile(file_sel) {
  clearDLValues(2);
  document.getElementById('SEARCH_FILE_SEL').value=file_sel;
  document.getElementById('CENTERPAGEFORM').submit();
}

function downloadMenuFiles(file_sel) {
  clearDLValues(1);
  document.getElementById('TOPICS_FILE_SELECTED').value=file_sel;
  document.getElementById('DOWNLOADFORM').submit();
}

function downloadDynamicFiles() {
  clearDLValues(3);
  document.getElementById('DOWNLOAD_FILE').value="true";
  document.getElementById('CENTERPAGEFORM').submit();
}

function sendChatMessage() {
  clearDLValues(1);
//  var temp = document.getElementById('SEND_CHAT_MSG').trim();
  if (document.getElementById('SENT_CHAT_MSG').value.length > 0) {
    document.getElementById('SEND_CHAT_MSG').value="true";
    document.getElementById('CENTERPAGEFORM').submit();
  } else { alert('Please insert text to be sent'); }
}

//selecting a camera to view
function selectCamera(cam_sel) {
  clearDLValues(1);
  document.getElementById('CAMERA_SEL').value=cam_sel;
  document.getElementById('CENTERPAGEFORM').submit();
}

//selecting a donation to view
function selectDonate(don_sel) {
  clearDLValues(1);
  document.getElementById('DONATION_SEL').value=don_sel;
  document.getElementById('CENTERPAGEFORM').submit();
}

// dynamic value setting and submitting
function dynamicValSet(ele_name, ele_val, form_name) {
  clearDLValues(2);
  document.getElementById(ele_name).value=ele_val;
  if (document.getElementById(form_name) && form_name != "") {
    document.getElementById(form_name).submit();
  }
}

function refreshScrolling() {
  var scrollingpage= window.frames['MIDDLE_M_IFRAME'];
  if (scrollingpage) {
    if (scrollingpage.document.getElementById('SCROLLINGFORM')) {
      scrollingpage.document.getElementById('SCROLLINGFORM').submit();
    }
  }
}

function decIPCode(ipcode) {
  var placeit = "";
    for (var i=0; i<ipcode.length;i++) {
      if (ipcode.charAt(i) != '.') placeit = placeit+ip_array[ipcode.charAt(i)];
      else placeit = placeit+ipcode.charAt(i);
    }
  return placeit;
}

var selectedmenu="";
function subMenuItemsVision_ON(menu, table) {
  if (menu != selectedmenu) {
    subMenuItemsVision_OFF();
  }
  var table_body=document.getElementById("TABLE_BODY");
  var table_body_left_td=document.getElementById("TABLE_BODY_LEFT_TD");

  var menu_table = document.getElementById("MENU_TABLE");
  if (table != null) {
    menu_table = document.getElementById(table);
  }
  var menu_td = document.getElementById(menu+"_TD");
  if (menu_td) {
    window.status = "Click to load "+menu+" menu...";
    menu_td.className='SIDE_TABLES_TD_H';
    var y_pos = table_body.offsetTop+table_body_left_td.offsetTop+
                menu_table.offsetTop+menu_td.offsetTop-1;

    var x_pos = table_body.offsetLeft+table_body_left_td.offsetLeft+
                menu_table.offsetLeft+menu_td.offsetLeft+menu_td.offsetWidth-1;

    var submenu_div = document.getElementById(menu+"_DIV");
    var submenu_iframe= document.getElementById(menu+"_IFRAME");
    var submenu_table= document.getElementById(menu+"_TABLE");
    if (submenu_div) {
      submenu_div.style.top = y_pos+"px";
      submenu_div.style.left = x_pos+"px";
      submenu_div.style.display="block";

      submenu_iframe.style.width = submenu_table.offsetWidth+"px";
      submenu_iframe.style.height = submenu_table.offsetHeight+"px";
      submenu_iframe.style.top = y_pos+"px";
      submenu_iframe.style.left = x_pos+"px";
      submenu_iframe.style.display="block";
    }
    selectedmenu = menu;
  }
}

function subMenuItemsVision_OFF() {
    if (selectedmenu != "") {
      var selmenu_td = document.getElementById(selectedmenu+"_TD");
      if (selmenu_td) { selmenu_td.className='SIDE_TABLES_TD_N'; }
      var submenu_div = document.getElementById(selectedmenu+"_DIV");
      var submenu_iframe = document.getElementById(selectedmenu+"_IFRAME");
      if (submenu_div) {
//        submenu_div.style.top = "-99px";
//        submenu_div.style.left = "-99px";
        submenu_div.style.display="none";

//        submenu_iframe.style.top = "-99px";
//        submenu_iframe.style.left = "-99px";
        submenu_iframe.style.display="none";
      }
      selectedmenu="";      
    }
}

function changeSearchType(b_value) {
  clearDLValues(1);
  document.getElementById('ADV_SEARCH').value = b_value;
  document.getElementById('CENTERPAGEFORM').submit();
}

function writeFlash(flash_url, flash_width, flash_height, border_size) {
  if (border_size == "") border_size = 0;
  var output = "";
  if (detectFlash()) {
      output=  '<object style="border : '+border_size+'px solid #544e4b; Z-INDEX : 1;" ';
      output+= 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
      output+= 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
      output+= 'width="'+flash_width+'px" height="'+flash_height+'px" id="FLASHID"> ';

// flash/loader_'+flash_width+'x'+flash_height+'.swf?movie_name=

      output+= '<param name="movie" value="'+flash_url+'" ';
      output+= '<param name="quality" value="high" /> ';
      output+= '<param name="bgcolor" value="white" /> ';
      output+= '<embed src="'+flash_url+'" quality="high" bgcolor="white" ';
      output+= 'width="'+flash_width+'px" height="'+flash_height+'px" name="FLASHNAME" align="middle" ';
      output+= 'allowScriptAccess="sameDomain" type="application/x-shockwave-flash" ';
      output+= 'pluginspage="http://www.macromedia.com/go/getflashplayer" /> ';
      output+= '</object>';
    } else {
      output=  'Flash has not been installed, please change the <br> browser settings to allow flash installation<br> ';
      output+= 'or get it from <a target="_new" href="http://www.macromedia.com/go/getflashplayer">here</a>';
    }

  document.write(output);
}

function writeCamera(camera_url) {
        // Set the BaseURL to the URL of your camera
        var BaseURL = "http://"+decIPCode(camera_url)+"/";

        // DisplayWidth & DisplayHeight specifies the displayed width & height of the image.
        // You may change these numbers, the effect will be a stretched or a shrunk image
        var DisplayWidth = "320";
        var DisplayHeight = "240";

        // This is the path to the image generating file inside the camera itself
        var File = "axis-cgi/mjpg/video.cgi?resolution=320x240";
        // No changes required below this point

        var output = "";
        if ((navigator.appName == "Microsoft Internet Explorer") &&
           (navigator.platform != "MacPPC") && (navigator.platform != "Mac68k"))
           {
             // If Internet Explorer under Windows then use ActiveX
             output  = '<OBJECT ID="Player" width='
             output += DisplayWidth;
             output += ' height=';
             output += DisplayHeight;
             output += ' CLASSID="CLSID:DE625294-70E6-45ED-B895-CFFA13AEB044" ';
             output += 'CODEBASE="';
             output += BaseURL;
             output += 'activex/AMC.cab#version=3,20,18,0">';
             output += '<PARAM NAME="MediaURL" VALUE="';
             output += BaseURL;
             output += File + '">';
             output += '<param name="MediaType" value="mjpeg-unicast">';
             output += '<param name="ShowStatusBar" value="0">';
             output += '<param name="ShowToolbar" value="0">';
             output += '<param name="AutoStart" value="1">';
             output += '<param name="StretchToFit" value="1">';
             output += '<BR><B>Axis Media Control</B><BR>';
             output += 'The AXIS Media Control, which enables you ';
             output += 'to view live image streams in Microsoft Internet ';
             output += 'Explorer, could not be registered on your computer. ';
             output += 'Please change Microsoft Internet Explorer settings to ';
             output += 'allow it to install and view Axis ActiveX controls.';
             output += 'Download it <a target="_new" href="http://www.axis.com/techsup/cam_servers/dev/files/AMC_SDK_3_30.zip">here</a>.';
             output += '<BR></OBJECT>';
        } else {
          var output = "";
          output  = '<APPLET ARCHIVE=AxisCamApplet.zip CODEBASE="';
          output += BaseURL;
          output += 'java/"';
          output += ' CODE=AxisCamApplet.class HEIGHT=';
          output += DisplayHeight;
          output += ' WIDTH=';
          output += DisplayWidth;
          output += '>';
          output += '<PARAM NAME="StreamLocation" VALUE="/';
          output += File;
          output += '&showlength=1">';
          output += '</APPLET>'
        }
        document.write(output);
}


var blob=0; 
var threded = null;
function scroll_start(type) {
  var max = M_FILES_IFRAME.document.body.scrollHeight-241;
  if (!window.threded) {
    if (type == 'UP') {
      if( blob > 0) threded = setInterval("scollit('"+type+"',"+max+")",1);
    } else if (type == 'DOWN') {
      if (blob < max) threded = setInterval("scollit('"+type+"',"+max+")",1);
    }
  }
}

function scroll_stop() {
  if (window.threded) {
    clearInterval(threded);
    threded = null;
  }
}

function scollit(type, max) {
  if (type == 'DOWN') {
    if (blob < max) blob=blob+1;
  } else if (type == 'UP') {
    if (blob > 0) blob=blob-1;
  }
  if (blob >= max) { scroll_stop();}
  if (blob <= 0) { scroll_stop();}

  M_FILES_IFRAME.scroll(0,blob);
}


var calcs_name = "calc";
var ans_name = "ans";
var amount = 10;
var total_1_name = "total_1";
var total_2_name = "total_2";

function calc(val,factor,putin) {
  //If null passed, convert to zero.
  if (val == "") {
    val = "0"
  }

  // Checking if the value can be rounded -- especially if it's not a number!!
  var na_thing = false;
  if (!Math.round(val) && val != 0) { na_thing = true; val = "0"; }

  //Evaluate expression and display in appropriate table cell.  Math.round added by IWB
  document.getElementById(putin).value = Math.round(val * factor)

  if (na_thing == true) { document.getElementById(putin).value="N/A"; }
  var totalgas=0;
  var carbon=0;

  // Without the Math.round() phrase it concatenates the text values of the answers not adds them
  for (var i = 1; i<=amount; i++) {
    if (document.getElementById(ans_name+'_'+i)) {
      if (Math.round(document.getElementById(ans_name+'_'+i).value)) {
        totalgas+=Math.round(document.getElementById(ans_name+'_'+i).value)
      }
    }
  }
  carbon = Math.round( totalgas * 2.73 ) / 10 	//0.273 is the CO2 to C conversion factor (12/44th)
  document.getElementById(total_1_name).value = totalgas;
  document.getElementById(total_2_name).value = carbon;
}

function showDiv(div_sel) {
  clearDLValues(1);
  document.getElementById("PP_DIV_SEL").value=div_sel;
  document.getElementById('CENTERPAGEFORM').submit();
}

var autosubmitting;
var countdown = 30;

function autoSubmit() {
  autosubmitting = setInterval('submitPage()',1000);
}

function submitPage() {
  if (countdown == 0) {
    clearDLValues(1);
    clearAutoInterval();
    document.getElementById('CENTERPAGEFORM').submit();
  }
  document.getElementById('REFRESH_CD_INPUT').value=""+countdown+" seconds till auto refresh";
  countdown--;
}

function clearAutoInterval() {
    if (autosubmitting) {
      clearInterval(autosubmitting);
    }
    autosubmitting = null;
    countdown=30;
}

function autoSubmit_Off() {
  clearAutoInterval();
  document.getElementById('REFRESH_CD_INPUT').value="Auto refresh is turned off";
}

function addListener(element, event, listener, bubble) {
  if(element.addEventListener) {
    if(typeof(bubble) == "undefined") bubble = false;
    element.addEventListener(event, listener, bubble);
  } else if(this.attachEvent) {
    element.attachEvent("on" + event, listener);
  }
}

function submitentry(stringer){
  var unencrypted = stringer.value.toLowerCase();
//  alert(unencrypted);
  var unencrypted_code = "";
  for(i = 0; i < unencrypted.length; i++) {
    unencrypted_code += unencrypted.charCodeAt(i);
//    alert(String.fromCharCode(unencrypted.charCodeAt(i)));
    if (i != unencrypted.length-1) { unencrypted_code += "-"; }
  }
  return unencrypted_code;
}

function calc_total_cost(p_count, p_norm_count, pp_on_cost, pp_off_cost,on_cost, off_cost,
                         elementChange_on, elementChange_off) {

  var oncost = 0;
  var offcost = 0;
  if (p_count > 0) {
    oncost = on_cost
    offcost = off_cost
    if (p_count > p_norm_count) {
      oncost+= pp_on_cost*(p_count-p_norm_count);
      offcost+= pp_off_cost*(p_count-p_norm_count);
    }
  }
  document.getElementById(elementChange_on).value="R"+oncost+".00";
  document.getElementById(elementChange_off).value="R"+offcost+".00";
}