/*

Copyright Ã‚Â© 2009. Larry Staton Jr.
Version: 2.0 - Remove variables from global namespace; passes JSLint tests
Version: 1.5 - Stop action from continuing
Version: 1.4 - Add validation
Version: 1.3 - IE still sucks
Version: 1.2 - Changes to help withd routing Rails and URLs
Version: 1.1 - Rails implementation for QuoTE
Version: 1.0
Version: 0.9 - IE sucks
Version: 0.5 - Fixed window resizing for non-tab users
Version: 0.2 - Script works on Firefox
Version: 0.1 - Event listeners attached and script works on Safari/WebKit

*/

var LS = {

  zip : 28078,

  insurance_type : 1,

  validate_zip_code : function(e) {

    if (!e) {
      e = window.event;
      e.returnValue = true;
    }
    LS.zip = document.getElementById('target').value;
    if ( !(/(^\d{5}$)/).test(LS.zip)) {
      alert("Please enter a valid ZIP code in the ZIP code field.");
      if (e.returnValue) {
        e.returnValue = false;
      }
      else {
        e.preventDefault();
        return false;
      }
    }
    else {
      LS.open_new_quote_window(LS.zip);
    }
    return 0;

  },

  open_new_quote_window : function(zip) {
  LS.insurance_kw = document.getElementById('subid3').value;
   
	
    window.open("http://quotes.usinsuranceonline.com/homecontact.php?refID=12761&refCampaign=TBI&kw=TBI", null, 'fullscreen=yes, toolbars=yes, scrollbars=yes, menubar=yes, location=yes');
  },

  attach_event_listeners : function() {
    var quote_form = document.getElementById('get_a_quote');
    if (document.addEventListener) { // DOM Level 2
      quote_form.addEventListener('submit', function(e) { return LS.validate_zip_code(e); } , false);
    }
    else { // IE 5+ Event Model
      quote_form.attachEvent('onsubmit', function() { return LS.validate_zip_code(); });
    }
  }
};

if (window.attachEvent) {
  window.attachEvent('onload', LS.attach_event_listeners);
}
else if (window.addEventListener) {
  window.addEventListener('load', LS.attach_event_listeners, false);
}
else {
  document.addEventListener('load', LS.attach_event_listeners, false);
}


