// textfieldsupport.js - Generate table containing text entry fields // 04-12-15 V1.31 - GTFC Tweaked V102 some CSS changes and set all input fields to widest one. // 03-12-15 V1.31 - GTFC Tweaked V101 to add optional override to PencePerChar for lines 2-5. // 23-02-15 V1.31 - Use jQ to add handler for choices with styles // 11-12-14 V1.30 - Tidier way of holding style value in drop-down option. Added classname to table. Better code for choice options. // 10-12-13 V1.29 - Correct tablestyle default text // 13-11-13 V1.28 - Allow custom Add Engraving / No Engraving fields. EngravingMode for uppercase. // 31-01-12 Amended to fix interaction with Leon Paul BTO code when radio button clicked. // 20-01-12 Use jQuery for init. Amended to not display penceperchar if 0 // 13-11-09 Amended to add mandatory engraving capability // START some user definable fields var warntext = 'You must enter some text!'; // warning if no text entered var leftstyle = 'font-size:10px'; // left info column // the INPUT fields (NB width is computed) the font family should match the default Font Choice var inputstyle = 'height: 15px; font-family: Arial; font-size: 10px; text-align: center; border-width: 0px; background-color: #ffffff'; var rightstyle = 'font-size:10px'; // right info column var countstyle = 'font-size:10px'; // the text count area // END some user definable fields var textitems = new Array(); // we'll list all text items here function to2digits(num){ // return 2 decimal digits string of number var sign = num < 0 ? '-' : ''; // determine sign num = Math.abs(num); var whole = Math.floor(num); // no of pounds var fraction = Math.round((num - whole) * 100); // Number of Fraction (2 decimal places) if ( fraction > 99 ) fraction = 99; var res = fraction < 10 ? "0" + fraction.toString() : fraction.toString(); // make 2 digits return(sign + whole.toString() + '.' + res); } function handleEnter (field, event) { // disable enter key for our text fields var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode; if (keyCode == 13) { // we may need field.onchange(); here (if we used an onchange routine) return false; // disable submit } return true; } function countallchars(prodref){ var chars = 0; var maxlines = document.getElementById('inf0' + '_' + prodref).value; for ( var i = 1; i <= maxlines; i++ ) // for all length entries { if ( document.getElementById('inf' + i + '_' + prodref) ) { var thisline = document.getElementById('inf' + i + '_' + prodref).value thisline = thisline.replace(/\s/g,''); // remove spaces chars += thisline.length; } } return chars; } function engtoupper(prodref){ var maxlines = document.getElementById('inf0' + '_' + prodref).value; for ( var i = 1; i <= maxlines; i++ ) // for all length entries { if ( document.getElementById('inf' + i + '_' + prodref) ) { document.getElementById('inf' + i + '_' + prodref).value = document.getElementById('inf' + i + '_' + prodref).value.toUpperCase(); } } } function linepencepercharused(linepenceperchar){ return ( linepenceperchar[0] != '' || linepenceperchar[1] != '' || linepenceperchar[2] != '' || linepenceperchar[3] != '') } function displaycount(maxlines, prodref, freechars, penceperchar, engravingcharge, mode, linepenceperchar){ if ( mode == 'uppercase' ) engtoupper(prodref); // Upper Case if required var charcost = ''; var totalcost = ''; var paidcost = 0; var totpaidlinechars = 0; var chars = countallchars(prodref); engravingcharge = engravingcharge - 0; if ( chars > 0 ) { if ( linepencepercharused(linepenceperchar) ) // have multi-line pricing { for ( var i=1; i<=maxlines; i++ ) { var thispenceperchar = i == 1 ? penceperchar : linepenceperchar[i-2]; // use penceperchar for first line if ( (i>1) && (thispenceperchar == '') ) thispenceperchar = penceperchar; // use penceperchar if other lines empty // current line char count if ( document.getElementById('inf' + i + '_' + prodref) ) { var thisline = document.getElementById('inf' + i + '_' + prodref).value thisline = thisline.replace(/\s/g,''); // remove spaces var thislinechars = thisline.length; if ( thislinechars > freechars ) { var paidchars = thislinechars - freechars; totpaidlinechars += paidchars - 0; paidcost += paidchars * thispenceperchar / 100; } freechars = freechars - thislinechars; if ( freechars < 0 ) freechars = 0; } } charcost = ' at £' + to2digits(paidcost); } else { if ( chars > freechars ) { var paidchars = chars - freechars; var paidcost = paidchars * penceperchar / 100; charcost = ''; if ( penceperchar > 0 ) { charcost += ' (' + (chars - freechars) + ' at '; charcost += ( penceperchar < 100 ) ? penceperchar + 'p' : '£' + to2digits(penceperchar / 100); charcost += ' -> £' + to2digits(paidcost) + ')'; } } } if ( engravingcharge > 0 ) totalcost = ' Total: £' + to2digits(paidcost + engravingcharge); document.getElementById('inf0_' + prodref).disabled = false; } else { document.getElementById('inf0_' + prodref).disabled = true; } document.getElementById('count-' + prodref).innerHTML = 'Characters: ' + chars + charcost + totalcost; } function setupfields(lengths, maxsize, overlap, prodref, freechars, penceperchar, engravingcharge, mode, linepenceperchar){ // set up text fields var maxsize = maxsize - 0; // the maximum width to show text field size at var overlap = overlap - 0; // extra size (above text line size) to display // (allows wide characters to be seen) document.write('
Bad TEXT' + (i + 1) + 'LENGTH ' + lengths[i] + ' | ||
' + (bits[2] ? bits[2] : ' ') + ' | '); document.write(''); document.write(' | Max: ' + bits[1] + ' |
Bad TEXT' + (i + 1) + 'LENGTH ' + lengths[i] + ' | ||
Characters: 0 |