

/*****************************************************************************/
var old_cemetery_id = null;
function handle_cemetery_id_changed( val )
{
	if( val.toString().length <= 0 )
    return;

  if( old_cemetery_id != null )
  {
    document.getElementById("cem_" + old_cemetery_id).className = "cemetery_off";
  }// end if()

  window.setTimeout(function() {
      document.getElementById("cem_" + val).className = "cemetery_on";
    }, 500);
  old_cemetery_id = val;
}// end handle_cemetery_id_changed( val )



/*****************************************************************************/
function ValidateNewRecord( form )
{
  // Check the email address:
  if( form.email_address.value != "" )
  {
    // Simple validation:
    if( ! /^[^\s]+\@[^\s]+\.[^\s]+$/.test( form.email_address.value ) )
    {
      alert("Email Address appears invalid.  Please check it and try again.");
      form.email_address.focus();
      return false;
    }// end if()
  }// end if()

  // Also validate the security code:
  if( form.security_code.value == "" )
  {
    alert("Security code is required");
    form.security_code.focus();
    return false;
  }
  else
  {
    var httpOb = XmlHttp.create();
    httpOb.open("GET", "/handlers/recproj.captcha.validate?security_code=" + escape(form.security_code.value) + "&r=" + Math.random(), false);
    httpOb.send(null);
    if( httpOb.responseText != "OK" )
    {
      alert("Security code is invalid");
      form.security_code.focus();
      return false;
    }// end if()
  }// end if()

  return true;
}// end ValidateNewRecord( form )


/*****************************************************************************/
function handle_state_id_changed( form )
{
  var county_sel = form.county_id;
  var type_sel = form.record_type_id;

//  var county_sel = document.getElementById("county_id");
//  var type_sel = document.getElementById("record_type_id");

  if( type_sel.options[type_sel.selectedIndex].value.toString() != "8" )
  {
    // Cannot select a specific county unless we are looking for 'public' records:
    county_sel.innerHTML = "";
    county_sel.options[0] = new Option("-- All Counties --", "");
    return;
  }// end if()

  populate_county_list( form );
}// end handle_state_id_changed()


/*****************************************************************************/
function handle_state_id2_changed( form )
{
//  var county_sel = document.getElementById("county2_id");
  var county_sel = form.county_id;

  if( document.getElementById("record_type_id2").value.toString() != "8" )
  {
    // Cannot select a specific county unless we are looking for 'public' records:
    county_sel.innerHTML = "";
    county_sel.options[0] = new Option("-- All Counties --", "");
    return;
  }// end if()

  populate_county_list2( form );
}// end handle_state_id_changed()



/*****************************************************************************/
function handle_state_id_lightbox_changed( form )
{
  var county_sel = form.county_id;  // document.getElementById("county_id_lightbox");

  if( document.getElementById("record_type_id_lightbox").value.toString() != "8" )
  {
    // Cannot select a specific county unless we are looking for 'public' records:
    county_sel.innerHTML = "";
    county_sel.options[0] = new Option("-- All Counties --", "");
    return;
  }// end if()

  populate_county_list_lightbox( form );
}// end handle_state_id_changed()


/*****************************************************************************/
function populate_county_list_lightbox( form )
{
  var state_sel = form.state_id;
  var state_id = state_sel.options[ state_sel.selectedIndex ].value;
  var county_sel = form.county_id;

//  var state_sel = document.getElementById("state_id_lightbox");
//  var state_id = state_sel.options[ state_sel.selectedIndex ].value;
//  var county_sel = document.getElementById("county_id_lightbox");

  var httpOb = XmlHttp.create();
  httpOb.open("GET", "/handlers/recproj.json.counties?state_id=" + state_id, true);
  httpOb.onreadystatechange = function() {
    if( httpOb.readyState == 4 )
    {
      var data = eval( httpOb.responseText );
      county_sel.innerHTML = "";
      for( var i = 0; i < data.length; i++ )
      {
        var rec = data[i];
        county_sel.options[i] = new Option(rec.county_name, rec.county_id);
      }// end for()
    }// end if()
  };
  county_sel.innerHTML = "";
  county_sel.options[0] = new Option("[ Loading Data... ]","");
  httpOb.send( null );

}// end populate_county_list()


/*****************************************************************************/
function populate_county_list2( form )
{
  var state_sel = form.state_id;
  var state_id = state_sel.options[ state_sel.selectedIndex ].value;
  var county_sel = form.county_id;

//  var state_sel = document.getElementById("state_id2");
//  var state_id = state_sel.options[ state_sel.selectedIndex ].value;
//  var county_sel = document.getElementById("county_id2");

  var httpOb = XmlHttp.create();
  httpOb.open("GET", "/handlers/recproj.json.counties?state_id=" + state_id, true);
  httpOb.onreadystatechange = function() {
    if( httpOb.readyState == 4 )
    {
      var data = eval( httpOb.responseText );
      county_sel.innerHTML = "";
      for( var i = 0; i < data.length; i++ )
      {
        var rec = data[i];
        county_sel.options[i] = new Option(rec.county_name, rec.county_id);
      }// end for()
    }// end if()
  };
  county_sel.innerHTML = "";
  county_sel.options[0] = new Option("[ Loading Data... ]","");
  httpOb.send( null );

}// end populate_county_list()


/*****************************************************************************/
function populate_county_list( form )
{
  var state_sel = form.state_id;
  var state_id = state_sel.options[ state_sel.selectedIndex ].value;
  var county_sel = form.county_id;

//  var state_sel = document.getElementById("state_id");
//  var state_id = state_sel.options[ state_sel.selectedIndex ].value;
//  var county_sel = document.getElementById("county_id");

  var httpOb = XmlHttp.create();
  httpOb.open("GET", "/handlers/recproj.json.counties?state_id=" + state_id, true);
  httpOb.onreadystatechange = function() {
    if( httpOb.readyState == 4 )
    {
      var data = eval( httpOb.responseText );
      county_sel.innerHTML = "";
      for( var i = 0; i < data.length; i++ )
      {
        var rec = data[i];
        county_sel.options[i] = new Option(rec.county_name, rec.county_id);
      }// end for()
    }// end if()
  };

  county_sel.innerHTML = "";
  county_sel.options[0] = new Option("[ Loading Data... ]","");
  httpOb.send( null );

}// end populate_county_list()


/*****************************************************************************/
function handle_record_type_id_changed( form )
{
//  var type_sel = document.getElementById("record_type_id");
//  var county_sel = document.getElementById("county_id");

  var type_sel = form.record_type_id;
//  var state_sel = form.state_id;
//  var state_id = state_sel.options[ state_sel.selectedIndex ].value;
  var county_sel = form.county_id;

  if( type_sel.options[type_sel.selectedIndex].value.toString() != "8" )
  {
    // Cannot select a specific county unless we are looking for 'public' records:
    county_sel.innerHTML = "";
    county_sel.options[0] = new Option("-- All Counties --", "");
    return;
  }// end if()

  // We can show a list of counties - we have selected "public" records:
  populate_county_list( form );
}// end handle_record_type_id_changed()


function show_lightbox()
{
  // First get the record-type/state/county IDs:
  var form = document.forms['left_search_form'];
  var record_type_id = form.record_type_id.options[ form.record_type_id.selectedIndex ].value;
  var state_id = form.state_id.options[ form.state_id.selectedIndex ].value;
  var county_id = form.county_id.options[ form.county_id.selectedIndex ].value;

  var httpOb = XmlHttp.create();
  httpOb.open("GET", "/inc/add-a-record-lightbox.asp?record_type_id=" + record_type_id + "&state_id=" + state_id + "&county_id=" + county_id, true);
  httpOb.onreadystatechange = function() {
    if( httpOb.readyState == 4 )
    {
      document.getElementById("light").innerHTML = httpOb.responseText;
    }// end if()
  };

  document.getElementById('light').style.display = "block";
  document.getElementById('fade').style.display = "block";
  httpOb.send( null );

  window.scrollTo(0,0);
}// end show_lightbox()


window.addEvent("domready", function(e) {
  $('nav_death_records').addEvent('mouseover', function() {
    clearTimeout( menu_timeout );
    show_menu(this, $('cemetery_popup'));
  });
  $('nav_death_records').addEvent('mouseout', function() {
    menu_timeout = setTimeout(function() {
      hide_menu( $('cemetery_popup') );
    }, 1000);
  });

  $('cemetery_popup_a').addEvent('mouseover', function() {
    clearTimeout( menu_timeout );
  });
  $('cemetery_popup_a').addEvent('mouseout', function() {
  	menu_timeout = setTimeout(function() {
      hide_menu($('cemetery_popup'));
    }, 500);
  });

  $('obituary_popup_a').addEvent('mouseover', function() {
    clearTimeout( menu_timeout );
  });
  $('obituary_popup_a').addEvent('mouseout', function() {
  	menu_timeout = setTimeout(function() {
      hide_menu($('cemetery_popup'));
    }, 500);
  });
});


var menu_timeout = null;
function show_menu(who, menu)
{
  if( menu_timeout )
    clearTimeout(menu_timeout);

  menu.setStyle('display', 'block');
  var pos = who.getPosition(false);
  var size = who.getSize();
  var left = pos.x + size.x + 2;
  var top  = pos.y;
  menu.setPosition({ x: left, y: top });
}// end show_menu(who, menu)


function hide_menu(menu)
{
  menu.setStyle('display', 'none');
}// end hide_menu(menu)



