var firstNameEl = $('first-name');
if(firstNameEl != null) {
  Event.observe(window, 'load', function() {
    $('first-name').focus();
    $('hidden').update('<input name="process-download" type="hidden" value="1"/>')
  });
}

var downloadFormEl = $('download-form');
if(downloadFormEl != null) {
  Event.observe('download-form', 'submit', function(evt) {
    if ($('first-name').value == '')
      return stopIt(evt, 'first-name', 'First Name is required.');

    if ($('last-name').value == '')
      return stopIt(evt, 'last-name', 'Last Name is required.');

    if ($('company').value == '')
      return stopIt(evt, 'company', 'Company is required.');

    if ($('email').value == '')
      return stopIt(evt, 'email', 'Email is required.');

    if ($('email-2').value == '')
      return stopIt(evt, 'email-2', 'Email confirmation is required.');

    if ($('email').value != $('email-2').value)
      return stopIt(evt, 'email', 'Emails do not match.');

    if ($('email').value.indexOf('@') < 0 || $('email').value.indexOf('.') < 0)
      return stopIt(evt, 'email', 'Email is not valid.');
  });
}

function stopIt(evt, id, message) {
  $(id).focus();
  alert(message);
  Event.stop(evt);
  return false;
}

function gup(name) {
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.href);
  if (results == null)
    return "";
  else
    return results[1];
}

function showWarning() {
  Element.show('reject-warning');
  return false;
}