function isCheckedOtherShop () {
  if ($('#otherShop').attr('checked') == true) {
    $('#areaSelect').attr('disabled', true);
    $('#areaSelect').val('');
    $(".shopSelect").each(function(){
        $(this).find('select').attr('disabled', true);
        $(this).find('select').val('');
      });
  } else {
    $('#areaSelect').removeAttr('disabled');
    $(".shopSelect").each(function(){
        if ($(this).css('display') == 'none') {
          $(this).css('display', 'none');
          $(this).find('select').attr('name', '');
          $(this).find('select').val('');
        }
      });
    if($('#shopSelectDisabled').css('display') == 'block') {
      $('#shopSelectDisabled').css('display', 'block');
    }
  }
}



function BlockEnter(evt){
	evt = (evt) ? evt : event; 
	var charCode=(evt.charCode) ? evt.charCode : 
		((evt.which) ? evt.which : evt.keyCode);
	if ( Number(charCode) == 13 || Number(charCode) == 3) {
		return false;
	} else {
		return true;
	}
}

function attachBlockEnter(formid) {
	var elements = document.forms[formid].elements;
	for (var j=0; j < elements.length; j++) {
      var e = elements[j];
      if (e.type == "text"){
        e.onkeypress=BlockEnter;
      }
	}
}

function switchShopSelect(model) {
  /*
  if (!$("#areaSelect").val()) {
    $("#shopSelect").val('');
    $("#shopSelect").attr('disabled', 'disabled');
  } else {
    $("#shopSelect").attr('disabled', '');
  }

  $("#shopSelect").val('');
  $("#shopSelect option").each(function(){
      if ($("#areaSelect").val() == $(this).attr('class')) {
        $(this).css('display', 'block');
      } else {
        $(this).css('display', 'none');
      }
    });
  */
  $(".shopSelect").each(function(){
      $(this).css('display', 'none');
      $(this).find('select').attr('name', '');
      $(this).find('select').val('');
    });
  $("#shopSelect"+$("#areaSelect").val()).css('display', 'block');
  $("#shopSelect"+$("#areaSelect").val()+' select').attr('name', 'data['+model+'][shopname]');
  $("#shopSelect"+$("#areaSelect").val()+' select').removeAttr('disabled');
}

function switchShopSelectAll() {
  if ($("#OrderPay").val() == 3) {
    $("tr#shopSelectAll").css('display', 'table-row');
  } else {
    $("tr#shopSelectAll").css('display', 'none');
    $("#areaSelect").val('');
    $(".shopSelect select").each(function(){
      $(this).val('');
      });
  }
}

$(document).ready(function(){
    isCheckedOtherShop();
  });


