$(document).ready(function(){

  $('#terms').children().hide();
  $('#terms_submit').hide();
  
  if($.cookie('terms')) {
    var id = $.cookie('terms').toString(); 
    // alert(id);
    $('#'+id).show();
    $('option').each(function(i) {      
      if($(this).val().toString()==id) {
        $(this).attr('selected', 'selected');
      }
    });
  }else{
    //$('#terms1').show();// first is always shown - update: not shown now...
  }
  /*
  #disclaimer_left .i-accept
  */

  // if country not selected then stop user from proceeding.
  $(".checkselected").click(function() {
    if($('select.selectcountry').val()==0) {
      alert('Please select a country');
      return false;
    }
  });

  // if country not selected then stop user from proceeding.
  $("#checkinvestorsselected").click(function() {
    if($('select.selectcountry').val()==0) {
      alert('Please select a country');
      //alert($("#checkselected").attr('href'));
      $("#checkinvestorsselected").attr('href','/investors/investors-terms');
      $.jqm.close('#accept-overlay');
      return false;
    } else {
      return true;
    }
  });
  
  // $('#accept-overlay').jqm();
  // //trigger-accept
  // // if country not selected then stop user from proceeding.
  // $("#trigger-accept").click(function() {
  //   if($('select.selectcountry').val()==0) {
  //     alert('Please select a country');
  //     return false;
  //   }else{
  //     alert('next step');
  //     return $('#accept-overlay').jqmAddTrigger('#trigger-accept');
  //   }
  // });
  
  $('select').change(function() {
    var sel = $(this).val().toString(); 
    // save sel in cookie and call above...
    $.cookie('terms',sel, { expires: 30 }); // last for 30 days.
    
    $('.selectcountry').children(0).attr('selected', '');
    $('.selectcountry').val(sel).attr('option', '0');  
    $('#terms').children().hide();
    $('#'+sel).show('slow');
    //$('#terms_submit').show('slow');

  });
  
  $('#accept-overlay').jqm();  
  
  $('#checkinvestorsaccepted').click(function() {
    $('#accept-overlay').jqmHide(); 
  });
  
});