window.addEvent('domready',function(){
  Element.Properties.checked = {
    get: function(){
      return this.checked;
    },
    set: function(v){
      this.checked = (v === false)? false:true;
      this.setAttribute('checked', this.checked);
    }
  }
  var sendEmail = new Request({
    url:'estimate.php',
    async:true,
    method:'post',
    headers:{
      'Content-type':'application/x-www-form-urlencoded'
    }
  });
  sendEmail.addEvents({
    'success':function(t){
      $('email-results').set('html',t);
      Recaptcha.reload();
      if( t.test( "email successfully sent", "i" ) ){
        document.getElementById('estimate-form').reset();
      }
    },
    'request':function(){
      $('email-results').empty();
      var loadingPic = new Element('img', {
        'src':'http://www.elkremodeling.com/elk2/files/ccLibraryFiles/Filename/000000001502/loading9.gif',
        'alt':''
      }).inject($('email-results'));
    }
  });
  $('submit-button').addEvent('click',function(){
    var nqdata = 'recaptcha_response_field='+$('recaptcha_response_field').get('value')+'&recaptcha_challenge_field='+$('recaptcha_challenge_field').get('value');
    $$('.left .chb').each(function(a){
      if( a.get('checked') == true ){
        nqdata += '&'+a.get('id')+'='+a.get('value');
      }
    });
    $$('.p_info .required','#p_info_comments').each(function(b){
      nqdata += "&"+b.get('id')+'='+b.get('value'); 
    });
    sendEmail.send(nqdata);
  });
});