function seat_info(what, vc, lc, aid, eid, ntix) {
  if ( ntix > 10 ) {
    if ( !confirm("This ad has " + ntix + " tickets and could take some time to display\nall " +
                  what + " information.\n\nClick 'OK' to proceed, or 'Cancel' to show only the first 10 seats") ) {
      ntix = 10;
    }
  }
  parent.parent.location = "/cgi/make_x.pl?venue_code=" + vc +
                                        "&layout_code=" + lc +
					"&info_type=" + what +
					"&lsid=" + aid +
					"&event_id=" + eid +
					"&num_seats=" + ntix;
  return(false);
}
function set_all(theform, val)
{
  if ( theform.tickets ) {
    if ( theform.tickets.length ) {
      for ( var i = 0; i < theform.tickets.length; i++ ) {
        theform.tickets[i].checked = val;
      }
    } else {
      theform.tickets.checked = val;
    }
  }
  return false;
}
function confirm_delete()
{
  return window.confirm('Are you sure you want to delete the selected tickets?');
}

var TICKET_OP_UPDATE = 1;
var TICKET_OP_DELETE = 2;

//dga old validate_ticket
//function validate_ticket(theform, op) {
//  if ( ! theform.tickets ) {
//    return false;
//  }
//  if ( op == TICKET_OP_UPDATE ) {
//    if ( theform.price.value == "" ) {
//      window.alert("Please enter a new ticket price!");
//      theform.price.focus();
//      return false;
//    }
//    price_value = parseFloat(theform.price.value);
//    if ( price_value <= 0 || (_js_version && _js_version >= 1.1 && isNaN(price_value)) ) {
//      window.alert("Please specify a positive price value (e.g. 22.50).");
//      theform.price.focus();
//      return false;
//    }
//    theform.price.value = price_value;
//  }
//  var ntix;
//  if ( theform.tickets.length ) {
//    ntix = theform.tickets.length;
//    var i;
//    for ( i = 0; i < theform.tickets.length; i++ ) {
//      if ( theform.tickets[i].checked ) {
//        break;
//      }
//    }
//  } else {
//    ntix = 1;
//    if ( !theform.tickets.checked ) {
//      i = ntix;
//    }
//  }
//  if ( i >= ntix ) {
//    window.alert("You should select at least one seat for this operation.");
//    return false;
//  }
//  if ( op == TICKET_OP_DELETE ) {
//    return( confirm_delete() );
//  }
//  return true;
//}


function validate_ticket(theform, op) {
  if ( ! theform.tickets ) {
    return false;
  }
  if ( op == TICKET_OP_UPDATE ) {
    //dga- this block derived from validation code in /trader/navbar_seatmap.thtml
    //     should merge into a common libary call
    var dis0_present = false; 
    for (var dis_num = 0; dis_num < 6; dis_num++) {
      // Validate all discount fields.
      // Require dis0 be filled in (regular price)
      if (eval('theform.price' + dis_num) &&
          eval('theform.price' + dis_num + '.value.length > 0')) {
        // dis_num is present and not empty so perform further validation
        var price1 = eval('theform.price' + dis_num + '.value');
        var price = parseFloat(price1);
        var dis_name = eval('theform.dis_name' + dis_num + '.value');
        if (dis_num == 0) {
          dis0_present = true;
        }
        if ((price <= 0) || (_js_version && _js_version >= 1.1 && isNaN(price))) {
          // inform user of entry error and bail
          window.alert(
            "The specified price, '" + price1 +
            "' is invalid.  Please specify a positive price value (e.g. 22.50)."); 
          eval('theform.price' + dis_num + '.focus()');
          return false;
        }
      }
    }
    if (!dis0_present) {
      // no dis0 so inform user and bail
      window.alert("Please specify a regular admission price (" + theform.dis_name0.value + ")."); 
      theform.price0.focus();
      return false;
    }
  }
  var ntix;
  if ( theform.tickets.length ) {
    ntix = theform.tickets.length;
    var i;
    for ( i = 0; i < theform.tickets.length; i++ ) {
      if ( theform.tickets[i].checked ) {
        break;
      }
    }
  } else {
    ntix = 1;
    if ( !theform.tickets.checked ) {
      i = ntix;
    }
  }
  if ( i >= ntix ) {
    window.alert("You should select at least one seat for this operation.");
    return false;
  }
  if ( op == TICKET_OP_DELETE ) {
    return( confirm_delete() );
  }
  return true;
}

function do_submit_ticket(theform, op)
{
  if ( validate_ticket(theform, op) ) {
    theform.ticket_op.value = op;
    theform.submit();
  }
  return false;
}
