<?php
/**
  @licence GPL 2005-2011  The osCSS developers - osCSS Open Source E-commerce
  @portion code Copyright (c) 2002 osCommerce
  @package osCSS-2 <www http://www.oscss.org>
  @version 2.1.0
  @date  29/01/11, 11:25
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
*/
?>
<script type="text/javascript"><!--
$().ready(function() {
  // Validation de formulaire avec jquery.validate
  $("#checkout_address").validate({
    rules: {
      gender: "required",
      firstname: {
        required: true,
        minlength: <?php echo ENTRY_FIRST_NAME_MIN_LENGTH; ?>
      },
      lastname: {
        required: true,
        minlength: <?php echo ENTRY_LAST_NAME_MIN_LENGTH; ?>
      },
      street_address: {
        required: true,
        minlength: <?php echo ENTRY_STREET_ADDRESS_MIN_LENGTH; ?>
      },
      postcode: {
        required: true,
        minlength: <?php echo ENTRY_POSTCODE_MIN_LENGTH; ?>
      },
      city: {
        required: true,
        minlength: <?php echo ENTRY_CITY_MIN_LENGTH; ?>
      },
      country: "required",
      telephone: {
        required: true,
        minlength: <?php echo ENTRY_TELEPHONE_MIN_LENGTH; ?>,
        number: true
      },
    },
    messages: {
      gender: "<?php echo ENTRY_GENDER_ERROR; ?>",
      firstname: "<?php echo ENTRY_FIRST_NAME_ERROR ?>",
      lastname: "<?php echo ENTRY_LAST_NAME_ERROR ?>",
      street_address: "<?php echo ENTRY_STREET_ADDRESS_ERROR; ?>",
      postcode: "<?php echo ENTRY_POST_CODE_ERROR; ?>",
      city: "<?php echo ENTRY_CITY_ERROR; ?>",
      country: "<?php echo ENTRY_COUNTRY_ERROR; ?>"
    },
    errorElement: "span",
    errorClass: "messageStackError",
    errorPlacement: function(error, element) {
      error.appendTo( element.parent());
    },
    onkeyup: true
  });
  // Listes liées
  if($("#state").val() =='') $("#state").parent().hide();
  $("#country").change( function () {
      $.get("./ajax_exe.php", { action:"create_account", country: this.value },
      function success(data) {
        $("#state").replaceWith(data);
        if ($(data).val() == null) {
          $("#state").parent().hide();
        } else {
          $("#state").parent().show();
        }
      });
  });
});

//--></script>
