// JavaScript Document
$(function(){
		   
    function validateEmail(email) {
		// TODO
		return true;
    }
	
	$('body').delegate('form#contact-form', 'submit', function(ev){
		ev.preventDefault();
		var f = $('#contact-form')
		  , mask = $("#form-sending")
		  , customer = {}
		  ;
	
      customer.name = $('form#contact-form [name="name"]').val();
		  customer.email = $('form#contact-form [name="email"]').val();
		  customer.phone = $('form#contact-form [name="phone"]').val();
		  customer.message = $('form#contact-form [name="message"]').val();
		
		if (!customer.email || customer.email.length < 7 || !customer.name || customer.name.length < 3) {
			alert("Invalid name or email: " + customer.name + "," + customer.email);
			return false;
		}
		
	    mask.show();
		mask.html('Sending...');
		$.post($('#contact-form').attr('action'), f.serialize(), function() {	
			mask.html('Thank you for requesting more information about SpotterRF. <br/> You should expect a response within 24 hours, a confirmation email has been sent to you. <iframe id="RSIFrame" name="RSIFrame" style="width:10px; height:10px; border: 0px" src="thank-you.html"></iframe>');
setTimeout(function () { mask.hide(); }, 3000)
_gaq.push(['_trackEvent', 'offers', 'submit-form', 'contact-us']);
		});
	});
	
	
	
  $('body').delegate('form.datasheet-form', 'submit', function(ev){
		ev.preventDefault();
		var f = $('form.datasheet-form')
		  , mask = $("#form-sending-email")
		  , customer = {}
		  ;
		customer.email = $('form.datasheet-form [name="email"]').val();
		
		if (!customer.email || customer.email.length < 7) {
			alert("Invalid name or email: " + customer.name + "," + customer.email);
			return false;
		}
		
		
	    mask.show();
		

		mask.html('Sending...');
		$.post($('form.datasheet-form').attr('action'), f.serialize(), function() {	
			mask.html('Thank you for requesting the M600C Datasheet. <br/> A confirmation email with the attached document has been sent to you. <iframe id="RSIFrame" name="RSIFrame" style="width:10px; height:10px; border: 0px" src="thank-you.html"></iframe>');
		setTimeout(function () { mask.hide(); }, 3000)

_gaq.push(['_trackEvent', 'offers', 'submit-form', 'request-datasheet']);

		});
		
	});
  
  $('body').delegate('form#reference-design', 'submit', function(ev){
		ev.preventDefault();
		var f = $('#reference-design')
		  , mask = $("#form-sending")
		  , customer = {}
		  ;
	
        customer.name = $('#reference-design [name="name"]').val();
		customer.email = $('#reference-design [name="email"]').val();
		
		if (!customer.email || customer.email.length < 7 || !customer.name || customer.name.length < 3) {
			alert("Invalid name or email: " + customer.name + "," + customer.email);
			return false;
		}
		
	    mask.show();
		mask.html('Sending...');
		$.post($('#reference-design').attr('action'), f.serialize(), function() {	
			mask.html('Thank you for requesting the reference design of the radar force protection backpack kit. <br/> You should expect a response within 24 hours, a confirmation email has been sent to you. <iframe id="RSIFrame" name="RSIFrame" style="width:10px; height:10px; border: 0px" src="thank-you.html"></iframe>');
setTimeout(function () { mask.hide(); }, 3000)
_gaq.push(['_trackEvent', 'offers', 'submit-form', 'request-reference-design']);
		});
	});
  

  /*
    emulate html5's placeholder for older browsers
  */
  $('body').delegate('form#contact-form [name=name]', 'blur', function () {
    if (/^\s*$/.exec(this.value)) {
      this.value='Name';
    }
  });
  $('body').delegate('form#contact-form [name=name]', 'focus', function () {
    if ('Name' === this.value) {
      this.value='';
    }
  });
  $('body').delegate('form#contact-form [name=email]', 'blur', function () {
    if (/^\s*$/.exec(this.value)) {
      this.value='Email';
    }
  });
  $('body').delegate('form#contact-form [name=email]', 'focus', function () {
    if ('Email' === this.value) {
      this.value='';
    }
  });
  $('body').delegate('form#contact-form [name=phone]', 'blur', function () {
    if (/^\s*$/.exec(this.value)) {
      this.value='Phone';
    }
  });
  $('body').delegate('form#contact-form [name=phone]', 'focus', function () {
    if ('Phone' === this.value) {
      this.value='';
    }
  });
  
});

