function validateForm() {
  var msg = '';  

//  if($('is_water_temp').value == '')
//    msg += J1 + '\n';
    
//  if($('multiple_locations').value == '')
//    msg += J2 + '\n';
    
  for(i=0; i<=lc; i++) {

//    if($('type_'+i).value == '')
//      msg += J3 + i + '.\n';
      
    if($('n_employees_'+(i+1)).value == '') { alert(J4 + (i + 1) + '.\n');return false;}

    if($('m_visitors_per_month_'+(i+1)).value == '') $('m_visitors_per_month_'+(i+1)).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();
  }
}

function locChanged() {
  if($('multiple_locations_0').checked){
    addLocation();
    $('tr_msg').hide();
    $('tr_add_loc').hide();
    $('tr_btn').show();
  } else if($('multiple_locations_1').checked){
    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);

      new Control.Slider('h_employees_'+lc , 'employees_'+lc,
      {
           range: $R(1,50),
           sliderValue: 1,
           lc: lc,
           onChange: function(v){ $('n_employees_'+this.lc).value = Math.round(v); },
           onSlide: function(v) { $('n_employees_'+this.lc).value = Math.round(v); }
       } );

       new Control.Slider('h_visitors_'+lc , 'visitors_'+lc,
      {
           range: $R(1,50),
           sliderValue: 1,
           lc: lc,
           onChange: function(v){ $('m_visitors_per_month_'+this.lc).value = Math.round(v); },
           onSlide: function(v) { $('m_visitors_per_month_'+this.lc).value = Math.round(v); }
       } );

    }
  });    
}

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();
    }
  });    
}