///////// START OF CONFIGURABLE VALUES //////////////

// set 'theForm' to the ID/Name of the form
var svformName  = ('theForm').toString();

var svbidArray = { 2: 1, 4: 1, 6: 1, 8:1, 10:1, 12:1, 14:1, 16:1, 18:1, 20:1 };

// Set to one MORE than you want to show (above)
var svbidLimit = 17; 

// set to percentage (whole number) you want the bids to increment
var svbidInc    = 10;

// set first line (default text) of list box IF it populates
var svlistdef = 'Select Maximum Bid';

// Setting to tell us how to concatenate form element names
var svisPost  = 1;    // 1 to use post values, 0 for pre values

// next define the prefixes, postfixes for the bid box, max bid box and list box,
// so if your item number was 1000, and you set bidpre to 'bid_' then you'd have bid_1000
// the form element id... and THEN there is the single text box hack.....
var svFields = {
              list: [ 'bid','max','list' ],
              pre: { 
                     'bid': 'bid_',
                     'max': 'maxbid',
                     'list': 'maxshow'
                    },
              post: {
                     'bid': '',
                     'max': '-max',
                     'list': '-maxshow'
                    },
              single: {  // HACK, pure and simple
                     pre: { 
                           'bid': 'hide_',
                           'max': '',
                           'list': 'maxshow'
                          },
                    post: {
                           'bid': '-hide',
                           'max': '',
                           'list': '-maxshow'
                          }
                    }
};




///////// END OF CONFIGURABLE VALUES //////////////

function svgetFenames( id, single ){
    var names = {};
    var list = svFields.list;
    var i;
    for( i=0; i< list.length; i++ ){
        var fe = list[i];
        if(svisPost ){ 
            single ? ( names[fe] = svFields.single.post[fe] ) 
                   : ( names[fe] = svFields.post[fe] );
            names[fe] = ( id + names[fe] ).toString();
        }
        else{ 
            single ? ( names[fe] = svFields.single.pre[fe] ) 
                   : ( names[fe] = svFields.pre[fe] ); 
            names[fe] = ( names[fe] + id ).toString(); 
        }
    }
    
    return names;
}
// Populate list box based on input value in bid box, no value no list...
function svshowMaxDD(id, single){    
    id=id.toString();
    
    var fels = svgetFenames( id, single );    
    var feIn   = fels.bid;   
    var feMax  = fels.max;
    var feShow = fels.list;

    var amount =  document.getElementById(feIn).value; // document.forms[svformName][feIn].value;
    // reset the max bid box IF we're single 
    if( !single ){ document.getElementById(feMax).value = ''; }
    
    if( amount ){ // strip out nasties 
        var re = /[^\.\d]/g;
        amount = amount.replace(re, "");
    }
    amount && ( amount = Math.ceil(amount) );
    
    if( !amount ){ return; }    
   
    // some shorthand to ease typo problems
    var sb = document.getElementById(feShow); // document.forms[svformName][feShow];
    // reset options.....
    sb.options.length=0;
    sb.options[0] =new Option( svlistdef, '0', false, false);
    
    var i;
    var tmp;
    var bid;
    var s = 1; // select option index, different than i in loop
    for( i = 1; i < svbidLimit; i++ ){
        tmp = Math.ceil( amount * svbidInc/100);
        amount += tmp;
        bid = Math.ceil( amount );
        if( svbidArray[i] ){  
            bidf = bid.toString();            
            bidf = bidf+'.00 ('+i+' bids)'; 
            sb.options[s] =new Option( bidf, bid, false, false);
            s++;
        }
    }
}

// sets max bid box to selected value in list box
function svsetMax( id, single ){
    id = id.toString();
    var fels = svgetFenames( id, single );    
    var feIn   = fels.bid;   
    var feMax  = fels.max;
    var feShow = fels.list;
    var obj = document.getElementById(feShow);
    var val = obj.options[obj.selectedIndex].value;
    val || ( val = '' );
    val > 0 || (val = '');
  //  if( !val && single ){ val = document.getElementById(feIn).value  }
    document.getElementById(feMax).value = val;    
}








