// ==ClosureCompiler== // @compilation_level SIMPLE_OPTIMIZATIONS // @output_file_name remote.min.js // ==/ClosureCompiler== /***************************************************************** * file: remote.js * * Abundatrade calculator communication and processing scripts. * Handles the AJAX calls to the Abundatrade server. * *****************************************************************/ /* jQuery('td:contains("024543525998")').parent() .find('td') .wrapInner('
') .parent() .find('td > div') .slideUp("slow", function(){ jQuery(this).parent().parent().remove(); }); ^^ Hides a row ^^ jQuery('#my_table > tbody > tr') .find('td') .wrapInner('
') .parent() .find('td > div') .slideDown("slow", function(){ var $set = jQuery(this); $set.replaceWith($set.contents()); ^^ adds a row ^^ }); */ /** * The number of items [defunct] */ var number_item = 1; /** * A list of items to clean up */ var itemsToDispose = []; /* * function: clear_product_code() * * Format the product code with alphanumerics only. * */ function clean_product_code(element) { element.value = element.value.replace(/\W+/g, ""); } /* * function: validateEmail() * * prevalidates an email address * */ function validateEmail(email, confirm) { if (email.toLowerCase() == confirm.toLowerCase()) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); } else return 'nomatch'; } function abundatrade_logout() { var request = jQuery.ajax({ type: 'POST', url: 'http://' + abundacalc.server + '/trade/process/user/logout/', dataType: 'jsonp' }); request.done(function(data) { get_login_status(); }); } var just_logging_in = false; function abundatrade_login() { just_logging_in = true; submit_modal(null, null); } var loggedIn = false; function get_login_status() { if (jQuery("#login_status_abundatrade").val() != null) { jQuery("#login_status_abundatrade").get(0).innerHTML = ""; var request = jQuery.ajax( { type: 'POST', url: 'http://' + abundacalc.server + '/trade/process/user/status/', dataType: 'jsonp' } ); request.done(function(data) { if (data.status) { jQuery('#login_status_abundatrade').get(0).innerHTML = "Hello " + data.first_name + " " + data.last_name + " logout"; if (data.first_name == 'Super Cow') loggedIn = false; else loggedIn = true; } else { jQuery('#login_status_abundatrade').get(0).innerHTML = "Login/Register"; loggedIn = false; } }); } } /* * function: clear_session() * * Clear out all data for this session, including prior saved data. * Request goes to the backend to clear data. * */ function clear_session(obj) { if (!jQuery(obj).hasClass('disabled')) { jQuery.prompt( 'Are you sure you want to delete the entire listing?', { buttons: { Delete: true, Cancel: false }, callback: function (v, m, f) { if (v) { var request = jQuery.ajax( { type: 'GET', url: 'http://' + abundacalc.server + '/trade/process/request.php', data: 'action=clear_session', dataType: 'jsonp' }); request.done(function (data) { //jQuery('#abundaCalcTbl > tbody').children().remove(); jQuery('#abundaCalcBody_request').children().remove(); data.total_qty = "0.00"; data.currency_for_total = "$"; data.total = "0.00"; display_totals(data); }); request.fail(function (jqXHR, textStatus, errorThrown) { alert("Request failed: " + textStatus + " - " + errorThrown); }); } } } ); } number_item = 1; } /* * function: new_session() * * Give user a new session id. This detaches any prior connection to the backend data. * */ function new_session(this_link) { number_item = 1; var request = jQuery.ajax( { type: 'GET', url: 'http://' + abundacalc.server + '/trade/process/request.php', data: 'action=new_session', dataType: 'jsonp' }); request.done(function (data) { }); request.fail(function (jqXHR, textStatus, errorThrown) { //alert("Request failed: " + textStatus + " - " + errorThrown); please_wait(false); }); } /* * function: display_totals() * * Render the header/footer totals from JSONP data. * */ function display_totals(data) { jQuery('#product_code').val(''); jQuery('#item_count').html(data.total_qty); jQuery('#total_item_count').html(data.total_qty); jQuery('#grand_total').html(data.currency_for_total + data.total); jQuery('#total_prevaluation').html(data.currency_for_total + data.total); // Turn off the UI Lock // please_wait(false); // Enable/Disable Submit based on Total Qty // if (jQuery('#total_item_count').text() > 0) { jQuery('#submitList').removeClass('disabled'); jQuery('#submitList').removeAttr('style'); } else { jQuery('#submitList').addClass('disabled'); jQuery('#submitList').attr('style', 'cursor:default'); } // Set the delete button // jQuery('.delete_this_row').attr('onclick', 'delete_the_row(this); return false;'); jQuery('#product_qty').val('1'); jQuery('#product_code').focus(); } /** * Opens the bulk upload bin real pretty like */ function bulk_open() { //do accordian stuff jQuery("#bulk_button").slideUp(1000); jQuery("#abundaCalcTbl").fadeOut(400).delay(100); jQuery("#second_content").slideUp(500); jQuery("#top_input_section").fadeOut(500); jQuery("#bulk").slideDown(500); return false; } /* Closes the bulk upload bin and reloads the session */ function bulk_close_window() { jQuery("#bulk").slideUp(500); jQuery("#top_input_section").fadeIn(500); jQuery("#second_content").slideDown(500); jQuery("#abundaCalcTbl").delay(100).fadeIn(400); jQuery("#bulk_button").slideDown(1000); load_previous_session(false); return false; } /** Gets the rows for the bulk upload bin */ function rows() { var lines; var TA = jQuery("#bulk_upload").val(); if (document.all) { // IE lines = TA.split("\r\n"); } else { //Mozilla lines = TA.split("\n"); } return lines; } /** The bulk upload final page for submission */ var bulk_final = "
Your submission has been sent to Abundatrade for processing. We're getting the real time values of your items right now and will send you an email when it is complete. The progress bar below is how far along we are at processing your items.

0%
"; /** Submits a bulk upload */ function bulk_submit_items() { submit_modal(submit_bulk, bulk_final); return; //stop execution here and delete all this and below later } /** Displays the bulk upload status */ function display_bulk_upload(display_prompt, id) { if (display_prompt) { jQuery.prompt({ state: { html: bulk_final, buttons: {}} }, {}); } var donot_reset = false; if (id == null) { id = abundacalc['upload_id']; donot_reset = true; } var stop = setInterval(function () { var request = jQuery.ajax( { type: 'POST', url: 'http://' + abundacalc.server + '/trade/process/request.php', data: "action=get_status&id=" + id, dataType: 'jsonp' }); request.success(function (data) { if (data.error == false || data.on == 0) { percent = data.on / data.total * 100; if (data.on == 1 && data.total == 1) { jQuery("#progress").get(0).innerHTML = "Processing complete -- building your email"; } else if (data.on == 2 && data.total == 2) { //processing complete clearInterval(stop); jQuery("#bar").css('width', percent + "%") jQuery("#progress").get(0).innerHTML = "Processing complete -- sending your valuation to you "; jQuery("#percent").get(0).innerHTML = Math.round(percent) + "%"; if (!donot_reset) { fin = setInterval(function () { clearInterval(fin); jQuery.prompt.close(); bulk_close_window(); load_previous_session(true); }, 2000); } } else { //display status jQuery("#bar").css('width', percent + "%") jQuery("#progress").get(0).innerHTML = data.on + " of approx. " + data.total; jQuery("#percent").get(0).innerHTML = Math.round(percent) + "%"; } } }); }, 1000); } /** Submits the jsonp bulk upload list */ function submit_bulk(val) { str = ""; jQuery.each(val, function (i, obj) { str += '&' + i + '=' + obj; }); str += '&bulkinput=' + encodeURI(jQuery("#bulk_upload").val()); str += '&location=' + window.location.href; var request = jQuery.ajax( { type: 'POST', url: 'http://' + abundacalc.server + '/trade/process/bulk_copy.php', data: str, dataType: 'jsonp' }); request.success(function (data) { new_session(); id = data[0].data; display_bulk_upload(false, id); }); } /* * function: delete_the_row() * * Delete a selected row. * */ function delete_the_row(obj) { var product_code = jQuery(obj).parents('tr').children('.upc').text(); var request = jQuery.ajax( { type: 'GET', url: 'http://' + abundacalc.server + '/trade/process/deleteItem.php', data: 'product=' + product_code, dataType: 'jsonp' }); request.success(function (data) { display_totals(data); }); //count affected rows x = jQuery('td:contains("' + product_code + '")'); number_item -= x.length; //jQuery(obj).parents('tr').remove(); jQuery('td:contains("' + product_code + '")').parent() .find('td') .wrapInner('
') .parent() .find('td > div') .slideUp("slow", function () { jQuery(this).parent().parent().remove(); }); } /* * function: load_previous_session() * * Lookup the session on the Abundatrade backend and * load up the table based on the results. * */ function load_previous_session(pretty) { var request = jQuery.ajax( { type: 'GET', url: 'http://' + abundacalc.server + '/trade/process/request.php', data: 'action=load_previous_session', dataType: 'jsonp' }); request.success(function (data) { for (i = 0; i < data.length; i++) { part = data[i]; part.row = jQuery.parseJSON(part.row); part = build_row(part); jQuery('#abundaCalcTbl').prepend(part.row_html); if (pretty) { jQuery('td:contains("' + part.product_code + '")').parent() .find('td') .wrapInner('
') .parent() .find('td > div') .slideDown("slow", function () { var $set = jQuery(this); $set.replaceWith($set.contents()); }) } display_totals(part); } //build_row(data); //jQuery('#abundaCalcTbl > tbody').prepend(data.row_html); //jQuery('#abundaCalcTbl').prepend(data.row_html); //display_totals(data); }); request.fail(function (jqXHR, textStatus, errorThrown) { alert("Request failed: " + textStatus + " - " + errorThrown); }); } /** Compresses duplicates */ function addDuplicatesToQuantity(inputUPC, newupc) { var upcs = $$('td.upc'); var quantities = $$('td.quantity'); var duplicateQuantity = 0; //Compare the new UPC to each UPC in the existing list for (var idx = 0; idx < upcs.length; idx++) { //Check for existing UPCs matching the new UPC if (inputUPC == upcs[idx].children[0].innerHTML) { //Add the found UPC's quantity to the new UPC's //quantity duplicateQuantity += parseInt(quantities[idx].children[0].innerHTML); queueForDisposal(upcs[idx].getParent()); } } } /** The last item looked up */ var lastItem; /** Removes an item */ function Remove_Item(product_code) { var selector = 'td:contains("' + product_code + '")'; x = jQuery(selector); number_item -= x.length; number_item++; jQuery(selector).parents('tr').remove(); } /** Displays a waiting spinning thingy while we look up a product */ function waitFor(product_code) { jQuery('#product_code').val(''); row_html = " " + product_code + "
Getting the realtime values for your item
waiting
"; jQuery('#abundaCalcTbl').prepend(row_html); } /* * function: lookup_item * */ function lookup_item(obj) { if (!jQuery(obj).hasClass('disabled')) { // The product code must be at least 6 digits // if (jQuery('#product_code').val().length > 5) { //please_wait(true); serial = jQuery("#abundaInput").serialize(); item_code = jQuery('#product_code').val(); //Remove_Item(item); waitFor(item_code); var request = jQuery.ajax( { type: 'GET', url: 'http://' + abundacalc.server + '/trade/process/request.php', data: serial, dataType: 'jsonp' }); request.done(function (data) { Remove_Item(item_code); data.row = jQuery.parseJSON(data.row); Remove_Item(data.product_code); build_row(data); lastItem = data; jQuery('#abundaCalcTbl').prepend(data.row_html); jQuery('td:contains("' + data.product_code + '")').parent() .find('td') .wrapInner('
') .parent() .find('td > div') .slideDown("slow", function () { var $set = jQuery(this); $set.replaceWith($set.contents()); }) display_totals(data); }); request.fail(function (jqXHR, textStatus, errorThrown) { alert("Request failed: " + textStatus + " - " + errorThrown); please_wait(false); }); // Warn if not at least 3 digits // } else { jQuery.prompt('The product code must be at least 6 characters long.
Enter a UPC or Amazon ASIN.'); } } return false; } /* * function: please_wait() * * = true, show wait (lock UI) * false, hide wait (unlock UI) */ function please_wait(UILocked) { } /** A regular submission final page */ var regular_display = "

Sending your trade request and locking in your quote!
Give our pecking pigeons a second

"; function displayLogin() { if (!loggedIn) { return '

'+ '

'+ '
'+ '
'+ 'Forgot your password?'; } return '

Welcome back!

'; } function displayLoginButtons() { if (loggedIn) { return {Cancel: 0, 'Ready to submit': 1}; } else { if (just_logging_in) { return {Cancel: 0, Login: -1, Register: 1}; } return {Cancel: 0, Login: -1, Register: 1, 'Continue as Guest': 2}; } } function checkpass() { orig = jQuery("#password").val(); conf = jQuery("#confirmPass").val(); if (orig.length < 8) { jQuery("#shortpass").show(); return; } else { jQuery("#shortpass").hide(); } if (conf.length == 0) { return; } else if (orig != conf){ jQuery("#badpass").show(); jQuery("#goodpass").hide(); } else { jQuery("#goodpass").show().delay(2000).fadeOut(); jQuery("#badpass").hide(); } } function checkemail() { if (!isguest) { jQuery("#researching").fadeIn(); request = jQuery.ajax({ url: "http://" + abundacalc.server + "/trade/process/user/create/", dataType: "jsonp", data: "email="+jQuery("#email_abundatrade").val() }); request.done(function(data) { jQuery("#researching").hide(); if (data.error != "invalid request") { jQuery("#bademail").show(); } else { jQuery("#bademail").hide(); } }); } } isguest = false; function hide_for_guest() { isguest = true; //jQuery("").hide(); jQuery("#confirmPass").hide(); jQuery("#label_confirm").hide(); jQuery("#label_pass").hide(); jQuery("#password").hide(); } function processLogin(ev, but, message, val) { if (loggedIn) { if (but == 0) { return 0; } if (but == 1) { jQuery.prompt.goToState('state5'); return false; } } else { if (but == 0) return 0; if (but == 1) { Register(register_pass(),regular_finish, submit_my_list); } if (but == 2) { hide_for_guest(); jQuery.prompt.goToState('state1'); } if (but == -1) { jQuery("#logging_on").fadeIn(); request = jQuery.ajax({ url: 'http://' + abundacalc.server + '/trade/process/user/login/', dataType: 'jsonp', data: 'user='+jQuery('#abundatrade_user').val()+'&password='+jQuery("#abundatrade_password").val()+"&remember="+jQuery("#remember").is(":checked") }); request.done(function(data) { if (data.error) { jQuery("#logging_on").fadeOut(); jQuery("#login_error").delay(800).show(); } else { jQuery("#login_error").hide(); if (just_logging_in) { get_login_status(); just_logging_in = false; jQuery.prompt.close(); } else { get_login_status(); just_logging_in = false; loggedIn = true; jQuery.prompt.goToState('state5'); } } }); } return false; } } function display_promo() { if (loggedIn) { return '

'; } else { return 'How did you hear about us?
' + '
' + ''+ '' + '' + '' + '
' + '

' + '
' + '
'; } } /** Submit a list */ function submit_modal(callback_to_submit, final_display) { var state = 1; if (loggedIn) state = 5; var states = { state0: { html: displayLogin(), buttons: displayLoginButtons(), focus: 1, submit: function (ev, but, message, val) { if (loggedIn) { if (but == 0) { return 0; } if (but == 1) { jQuery.prompt.goToState('state5'); return false; } } else { if (but == 0) return 0; if (but == 1) { Register(register_pass(),final_display, callback_to_submit); } if (but == 2) { Register(register_guest(), final_display, callback_to_submit) } if (but == -1) { jQuery("#logging_on").fadeIn(); request = jQuery.ajax({ url: 'http://' + abundacalc.server + '/trade/process/user/login/', dataType: 'jsonp', data: 'user='+jQuery('#abundatrade_user').val()+'&password='+jQuery("#abundatrade_password").val()+"&remember="+jQuery("#remember").is(":checked") }); request.done(function(data) { if (data.error) { jQuery("#logging_on").fadeOut(); jQuery("#login_error").delay(800).show(); } else { jQuery("#login_error").hide(); if (just_logging_in) { get_login_status(); just_logging_in = false; jQuery.prompt.close(); } else { get_login_status(); just_logging_in = false; loggedIn = true; jQuery.prompt.goToState('state5'); } } }); } return false; } } }, state1: { html: '
'+ '

' + '

' + '

' + '
' + '', buttons: { Cancel: 0, Next: 1 }, focus: 1, submit: function (ev, but, message, val) { fname = message.children('#name_first'); lname = message.children('#name_last'); sexm = message.children('#sex'); if (but != 0) { if (val['sex'] == -1) { sexm.css("border", "solid #ff0000 2px"); return false; } if (val['first_name'] == '') { fname.css("border", "solid #ff0000 2px"); return false; } else { fname.css("border", ""); } if (val['last_name'] == '') { lname.css("border", "solid #ff0000 2px"); return false; } else { lname.css("border", ""); } if (validateEmail(val['email'], val['confirm_email']) == 'nomatch') { jQuery.prompt.goToState('nomatch'); } else if (validateEmail(val['email'], val['confirm_email'])) { state += but; jQuery.prompt.goToState('state' + state); } else { jQuery.prompt.goToState('invalid'); } return false; } else { jQuery.prompt.close(); } } }, state2: { html: '

'+ '

' + '

'+ '

'+ '

'+ '

'+ '', buttons: {Back: -1,Cancel:0, Next: 1}, submit: function (ev, but, message, val) { if (but != 0) { if (!isguest) { pass = message.children('password'); conf = message.children('confirmPass'); if (val['password'] != val['confirmPass']) { jQuery('#password').css("border", "solid #ff0000 2px"); jQuery('#confirmPass').css("border", "solid #ff0000 2px"); jQuery('#badpass').show(); return false; } if (val['password'].length < 8) { jQuery("#password").css("border", "solid #ff0000 2px"); jQuery("#shortpass").show(); return false; } } if (val['address_zip'] == '') { jQuery("#address_zip").css("border", "solid #ff0000 2px"); return false; } if (val['address_state'] == '') { jQuery("#address_state").css("border", "solid #ff0000 2px"); return false; } if (val['address_city'] == '') { jQuery("#address_city").css("border", "solid #ff0000 2px"); return false; } if (val['address_street'] == '') { jQuery("#address_street").css("border", "solid #ff0000 2px"); return false; } state+= but; jQuery.prompt.goToState('state' + state); return false; } jQuery.prompt.close(); } }, state3: { buttons: { Back: -1, Cancel: 0, Next: 1 }, focus: 2, submit: function (ev, but, message, val) { if (but != 0) { lname = message.children('#referrals'); if (val['hvReferral'] == '-1') { jQuery('#referrals').css("border", "solid #ff0000 2px"); return false; } else { jQuery('#referrals').css("border", "") } if (val['phone_request'] == 'on') { state += but; } else { if (but == 1) { state += 2; } else { state += but; } } if (state == 5 && just_logging_in) { jQuery.each(val, function (i, obj) { str += '&' + i + '=' + obj; }); request = jQuery.ajax( { type: 'POST', url: 'http://' + abundacalc.server + '/trade/process/user/create/', data: '?action=create_user' + str, dataType: 'jsonp' }); request.done(function(data) { get_login_status(); just_logging_in = false; jQuery.prompt.close(); }); } else { jQuery.prompt.goToState('state' + state); } return false; } else { jQuery.prompt.close(); } }, html: display_promo() }, state4: { html: '', buttons: { Back: -1, Cancel: 0, Next: 1 }, focus: 2, submit: function (ev, but, message, val) { if (but != 0) { lname = message.children('#phone_type'); if (val['phone_type'] == '') { lname.css("border", "solid #ff0000 2px"); return false; } else { lname.css("border", ""); } state += but; if (state == 5 && just_logging_in) { jQuery.each(val, function (i, obj) { str += '&' + i + '=' + obj; }); request = jQuery.ajax( { type: 'POST', url: 'http://' + abundacalc.server + '/trade/process/user/create/', data: '?action=create_user' + str, dataType: 'jsonp' }); request.done(function(data) { get_login_status(); just_logging_in = false; jQuery.prompt.close(); }); } else { jQuery.prompt.goToState('state' + state); } return false; } else { jQuery.prompt.close(); } } }, state5: { html: '

Please Note

The values shown on the calculator are a pre-valuation.

Item quality needs to be verified for final valuation.

This valuation is not a commitment.

All data is kept private.

', buttons: [{ title: 'Back', value: -1 }, { title: 'Cancel', value: 0 }, { title: 'Agree and Submit', value: 'submit'}], focus: 2, submit: function (ev, but, message, val) { if (but == "submit") { jQuery.prompt.goToState('finish'); callback_to_submit(val); return false; } if (but != 0) { if (val['scanner'] == 'on') { state += but; } else if (but == -1) { state -= 2; } else { state += but; } jQuery.prompt.goToState('state' + state); return false; } else { jQuery.prompt.close(); } isguest = false; } }, invalid: { html: '

Email address invalid


Please enter a valid email address.

', buttons: { OK: true }, focus: 0, submit: function (v, m, f) { jQuery.prompt.goToState('state1'); return false; } }, nomatch: { html: '

Email Addresses don\'t match!


Please check your email address to make sure it is correct.

', buttons: { OK: true }, focus: 0, submit: function (v, m, f) { jQuery.prompt.goToState('state1'); return false; } }, finish: { html: final_display, buttons: {} } }; var str = ''; jQuery.prompt(states, { callback: function (ev, v, m, f) { if (v) { } else { please_wait(false); } } }); } /* * function: submit_the_list() * * Submit The List via AJAX request. * */ function submit_the_list(obj) { if (!jQuery(obj).hasClass('disabled') && (jQuery('#total_item_count').text() > 0)) { submit_modal(submit_my_list, regular_display); } } /** Submission of a list done the old fashioned way via jsonp */ function submit_my_list(f) { str = ""; jQuery.each(f, function (i, obj) { str += '&' + i + '=' + obj; }); if (isguest) { str += '&guest=true'; } var request = jQuery.ajax( { type: 'GET', url: 'http://' + abundacalc.server + '/trade/process/submit.php', data: 'action=submit_list' + str, dataType: 'jsonp' }); request.done(function (data) { // No errors // if (data.error == '') { jQuery('#abundaCalcTbl > tbody').children().remove(); display_totals(data); //jQuery.prompt('Your list has been received.
Thank you for submitting your list to Abundatrade.'); window.location = abundacalc.thanks; new_session(); } else { jQuery.prompt('Your list could not be sent.
' + data.error); please_wait(false); } }); request.fail(function (jqXHR, textStatus, errorThrown) { alert("Request failed: " + textStatus + " - " + errorThrown); please_wait(false); }); } function submitGiftCard() { jQuery('input[name=Submit]').attr("disabled", "disabled"); jQuery('input[name=Submit]').attr("value", "Creating your giftcard ... please wait") jQuery('input[name="specialid:9573"]').remove(); jQuery('input[name=listid]').val('48277'); jQuery('form[name=icpsignup] div div div').get(0).innerHTML += "" jQuery('input[name=formid]').val('3389'); jQuery('input[name=reallistid]').val('1'); jQuery('input[name=doubleopt]').val('0'); var email = getParameterByName('email'); var key = getParameterByName('key'); if (jQuery(this).data('submit-me')) { return true; } var request = jQuery.ajax( { type: 'GET', url: 'http://dev.' + abundacalc.server + '/trade/process/createGiftCard.php', data: 'email=' + email + "&key=" + key, dataType: 'jsonp', context: this, success: function(data) { jQuery(this).data('submit-me', true).submit(); } }); return false; } /* * When the document has been loaded... * */ jQuery(document).ready(function () { if (getParameterByName('act') == 'gift') { jQuery('input[name=fields_email]').val(getParameterByName('email')); //jQuery('input[name=Submit]').attr('onclick','return submitGiftCard();'); jQuery('form[name=icpsignup]').submit(submitGiftCard); } if (jQuery("#login_status_abundatrade").val() != null) { if (abundacalc.upload_id) { display_bulk_upload(true); } get_login_status(); /* * Load previous session data from backend. * */ load_previous_session(false); /* Form Submit * * Capture the form submit, and just use it to lookup items. * */ jQuery('#abundaInput').submit(function () { lookup_item(jQuery('#lookupItem').text()); return false; }); /* Lookup Item.click() * * uses Ajax to talk to Abundatrade server. * must use JSONP to allow for cross-site calls and processing * of return data without error. */ //jQuery('#lookupItem').on('click', function () { lookup_item(this); return false; }); /* Submit List.click() * * uses Ajax to talk to Abundatrade server. * must use JSONP to allow for cross-site calls and processing * of return data without error. */ //jQuery('#submitList').on('click', function () { submit_the_list(this); }); /* Delete All.click() * * uses Ajax to talk to Abundatrade server. * and send the delete all action. */ jQuery('#delete_all_top').on('click', function () { clear_session(this); }); jQuery('#delete_all_bottom').on('click', function () { clear_session(this); }); } }); function getParameterByName(name) { name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex = new RegExp(regexS); var results = regex.exec(window.location.search); if(results == null) return ""; else return decodeURIComponent(results[1].replace(/\+/g, " ")); } /** Builds an unknown row */ function build_unknown(code, quantity, id) { return " " + code + "
Unknown Item
Item not found. You may send for valuation
Unkown item
" + quantity + "
$0.00 $0.00 Delete"; } /** Builds an item from a lookup from a json string */ function build_row(data) { data.row_html = ""; if (jQuery("#ready2go").length > 0) { jQuery("#ready2go").remove(); } if (jQuery.isArray(data.row)) { for (var i = 0; i < data.row.length; i++) { row = data.row[i]; if (row.title == "Unknown") { data.row_html = build_unknown(row.product_code, row.quantity, row.item_id); } else { row_price = new Number(row.price_per / 100).toFixed(2); row_total = new Number(row.total_price / 100).toFixed(2); data.row_html += write_html(data, row); } number_item++; } } else { row = data.row; if (row.title == "Unknown") { data.row_html = build_unknown(row.product_code, row.quantity, row.item_id); } else { row_price = new Number(row.price_per / 100).toFixed(2); row_total = new Number(row.total_price / 100).toFixed(2); data.row_html += write_html(data, row); } number_item++; } return data; } /** Write out the html for the row */ function write_html(data, row) { return " " + row.product_code + "
" + row.title + "
" + row.title + "
" + (row.author == null ? '' : row.author) + "
" + (row.category == null ? "" : row.category) + "
" + row.quantity + " " + (row.worthless == true ? "

No Abunda Value

" : "") + (row.overstocked == true ? "Over Stocked Item" : "") + "
" + data.currency_for_total + row_price + "
" + data.currency_for_total + row_total + " Delete"; } /****************************** New Stuff *******************************/ function queueForDisposal(productcode) { var selector = 'td:contains("' + productcode + '")'; itemsToDispose.push(selector); } function disposeQueued() { for (var i = 0; i < itemsToDispose.length; i++) { jQuery(itemsToDispose[i]).parents('tr').remove(); } itemsToDispose = []; }