/***************************************************************************
	In some browsers, when the focus is on a textbox/password/checkbox,
	the "enter" key will cause the form to submit.  This cript will act as
	the "onKeyPress" event handler for these form elements and prevent
	the "enter" key from submitting.
	
	This behavior will force the user to click the "Save" button so that we
	can make sure the button's "click" event is properly executed on the
	server side.
	
	This work around is necessary because this control is being embedded in
	Sitecore pages which have already have a form tag.
***************************************************************************/
function filterStatesByCountry() {
    var strCountry = jQuery(listCountries).val();

    var count = 0;
    jQuery(listStates).children().each(function() {
        if (jQuery(this).val().substr(0, 2) == strCountry || jQuery(this).val() == 'other' || jQuery(this).val() == '') {
            jQuery(this).show();
            count++;
        }
        else {
            jQuery(this).hide();
        }
    });

    if (count == 2)
        listStates.selectedIndex = listStates.options.length - 1;
    else
        listStates.selectedIndex = 0;
}

function disableEnterKey(e) {
    var key;
    
    if (window.event)
        key = window.event.keyCode;    // for Internet Explorer
    else
        key = e.which;                 // for Firefox

    if (key == 13)                     // 13 is the "enter" key
        return false;
    else
        return true;
}

jQuery(document).ready(function(){
  jQuery('input:text,input:password,input:checkbox').bind('keypress', function(e) {
      return disableEnterKey(e);
  });
  
  jQuery("#mainform").validate({
      errorPlacement: function(error, element) { } 
  });
});

