function validateForm() {
  var msg = '';  
  
  if($('is_water_temp').value == '')
    msg += J1 + '\n';
    
  if($('multiple_locations').value == '')
    msg += J2 + '\n';
    
  for(i=1; i<=lc; i++) {
    
    if($('type_'+i).value == '')
      msg += J3 + i + '.\n';
      
    if($('n_employees_'+i).value == '')
      msg += J4 + i + '.\n';

    if($('m_visitors_per_month_'+i).value == '')
	  $('m_visitors_per_month_'+i).value = 0;
      //msg += 'Please specify number of visitors for location #' + i + '.\n';

    if($('womens_'+i).value == '')
      msg += J5 + i + '.\n';

    if($('access_to_tap_water_'+i).value == '')
      msg += J6 + i + '.\n';

    if($('access_to_electric_'+i).value == '')
      msg += J7 + i + '.\n';

    if($('have_storage_room_'+i).value == '')
      msg += J8 + i + '.\n';
  }
  
  if(msg != '') {
    alert(msg);
    return false;
  }
  return true;
}

function locationsChanged() {
  if($('multiple_locations').value == 0){
    addLocation();
    $('tr_msg').hide();
    $('tr_add_loc').hide();    
    $('tr_btn').show();
  } else if($('multiple_locations').value == 1){
    addLocation();
    $('tr_msg').show();
    $('tr_add_loc').show();
    $('tr_btn').show();
  }
}

lc = 0;
function addLocation() {
  var url = 'getLocation.php?jid=' + ++lc;
  new Ajax.Request(url, {
    method: 'get',
    evalScripts: true,
    onSuccess: function(transport) {
      new Insertion.Bottom($('locs_store'), transport.responseText);
    }
  });    
}

var isIE = (document.all) ? 1 : 0;
function keyFilter(e, strPattern) {  
  var chr = (isIE) ? e.keyCode : e.which;
  var ch = String.fromCharCode(chr);  
  if (chr != 13 && chr != 8 && chr != 0) {
    var re = new RegExp(strPattern);	
    if (ch.search(re) == -1) {
      if(isIE)
        e.returnValue = false;
      else
        e.preventDefault();
    }
  }
}

function showSentEmailMessage() {	
	$('email_1').value = '';
	$('email_2').value = '';
	$('name').value = '';
	$('phone').value = '';
}

function sendEmail1(order_id)
{
  var url = 'get_pdf.php?oid=' + order_id;
  new Ajax.Request(url, {
  	parameters: { email_1: $('email_1').value },
    method: 'post',
    evalScripts: true,
    onSuccess: function(transport) {
      $('sent_msg2').hide();
      $('sent_msg').show();
      showSentEmailMessage();
    }
  });    
}

function sendEmail2(order_id, msg)
{
  var url = 'get_pdf.php?oid=' + order_id;
  new Ajax.Request(url, {
  	parameters: { email_2: $('email_2').value, name: $('name').value, phone: $('phone').value },
    method: 'post',
    evalScripts: true,
    onSuccess: function(transport) {
      $('sent_msg').hide();
      $('sent_msg2').show();
      showSentEmailMessage();
    }
  });    
}