function setSelected(selIndex, type)
{
   $('#userData #'+type+'State :nth-child('+selIndex+')').attr('selected', 'selected');
}


function hideOptions(start, end, type)
{   
   $('#userData #'+type+'State option').show();
   $('#userData #'+type+'State option').slice(start, end).hide();//attr('disabled', 'disabled');   
}

function disableStates(type)
{
   $('#userData #'+type+'State').attr('disabled', 'disabled');
}

function enableStates(type)
{
   $('#userData #'+type+'State').removeAttr('disabled');
}


function checkStates(type)
{
   if($('#userData #'+type+'Country').val() == 'USA')
   {
      enableStates(type);
      hideOptions(51, 63, type);
      //setSelected(1, type);
   }   
   else if($('#userData #'+type+'Country').val() == 'CAN')
   {
      enableStates(type);
      hideOptions(0, 51, type);
      //setSelected(52, type);
   }
   else
   {
      disableStates(type);
   }
}



$(document).ready(function(){
    
   /*
   //check shipping part of form
   //checkStates('s');
   
   $('#userData #sCountry').change(function(){
   
      checkStates('s');
   
   });
   
   
   //check billing part of form
   //needed for place order form
   checkStates('b');
   
   $('#userData #bCountry').change(function(){
   
      checkStates('b');
   
   });
   */
   
   $('#countShipping').hide();
   $('#apsUpdateButton').hide();


   $('#aps').change(function () {
   
      $('#cartForm').submit();
      
   });
   
   
   $('#sCountry.reload').change(function () {
   
      $('#userData').submit();
      
   });
   
   
   $('#sMethod').change(function () {
   
      $('#userData').submit();
      
   });
   
});