$('#intVal1Label').text('Tag Type');
$('#intVal1').html('<option value="2">Close</option><option value="0">Single</option><option value="1">Open</option>');
$('#stringVal1').hide();$('#stringVal1Span').append('<input type="radio" name="pf" value="p."/>p. <input type="radio" name="pf" value="f."/>f. <input type="text" name="pftext"/> <input type="radio" name="rv" value="r"/>r <input type="radio" name="rv" value="v"/>v');
$('#stringVal1').on('change', function() {
  var vals = $('#stringVal1').val().split('|');
  if (vals.length < 3) return;
  $('input[name=pf]').val([vals[0]]);
  $('input[name=pftext]').val(vals[1]);
  $('input[name=rv]').val([vals[2]]);
});
$('input[name=pf],input[name=rv],input[name=pftext]').on('change', function() {
  $('input[name=rv]').prop('disabled', $('input[name=pf]:checked').val() == 'p.');
  if ($('input[name=pf]:checked').val() == 'p.') $('input[name=rv]').val(['']);
  $('#stringVal1').val($('input[name=pf]:checked').val()+'|'+$('input[name=pftext]').val()+'|'+$('input[name=rv]:checked').val());
});
$('#stringVal2').hide();$('#stringVal2Span').append('Zone <select name="zone"><option></option><option>a</option><option>b</option><option>c</option><option>d</option><option>marg. sup.</option><option>marg. inf.</option><option>marg. dextr.</option><option>marg. sin.</option><option>marg. med.</option><option>marg. med. 1</option><option>marg. med. 2</option><option>marg. med. 3</option></select> Position <select name="position"><option></option><option>quart. 1 inc.</option><option>quart. 1 med.</option><option>quart. 2</option><option>quart. 3</option><option>quart. 4 med.</option><option>quart. 4 des.</option><option>quart. 1 inc. - quart. 2</option><option>quart. 1 inc. - quart. 3</option><option>quart. 1 inc. - quart. 4 med.</option><option>quart. 1 inc. - quart. 4 des.</option><option>quart. 1 med. - quart. 2</option><option>quart. 1 med. - quart. 3</option><option>quart. 1 med. - quart. 4 med</option><option>quart. 1 des. - quart. 4 des.</option><option>quart. 2 - quart. 3</option><option>quart. 2 - quart. 4 med.</option><option>quart. 2 - quart. 4 des.</option><option>quart. 3 - quart. 4 med.</option><option>quart. 3 - quart. 4 des.</option></select>');
$('#stringVal2').on('change', function() {
  var vals = $('#stringVal2').val().split('|');
  if (vals.length < 2) return;
  $('select[name=zone]').val([vals[0]]);
  $('select[name=position]').val([vals[1]]);
});
$('select[name=zone],select[name=position]').on('change', function() {
  $('#stringVal2').val($('select[name=zone]').val()+'|'+$('select[name=position]').val());
});

VMR.serviceRequest('projects/paratexbib/paratext/get', {  docID : currentPageData.docID }, function(o) {
  var xml = $.parseXML(o.text);
  var options = '';
  $(xml).find('feature[featureCode=ParatexBib]').each(function() {
    if (parseInt($(this).attr('pageID')) <= currentPageData.pageID) {
      options += '<option value="'+$(this).attr('featureID')+'">'+$(this).attr('featureID')+' (' + $(this).find('auxData[fieldName=pageFolioNumberType]').text() + $(this).find('auxData[fieldName=pageFolioNumberValue]').text() + $(this).find('auxData[fieldName=pageFolioNumberSide]').text() + ')</option>';
    }

  });
  var curVal = $('#intVal2').val();
  $('#intVal2Span').html('<select style="width:auto;" id="intVal2">' + options+'</select>');
  $('#intVal2').val(curVal);
 });

saveValidation = function() {
  if (!$('#intVal2').val())
    return 'Must select a starting ParatexBib Feature ID';
  return false;
}