var type = ''; $(function() { var mousex = 0; var mousey = 0; $().mousemove(function(e){ mousex = e.pageX; mousey = e.pageY; }); $('#showRecurring').click(function(){ hideForms(); $('#recurringOnly').show(0); }); $('#showTransaction').click(function(){ hideForms(); $('#transactionOnly').show(0); }); $('#showBoth').click(function(){ hideForms(); $('#both').show(0); }); $('.lookUpButton').click(function(){ fetchInvoice(this); }); $('.clearButton').click(function(){ var thisSplit = this.id.split("_"); clearInvoice(thisSplit[0]); }); $('.upperRight').hover(function(){ var x = mousex + 10; var y = mousey + 10; $('#upperRight').css({position: 'absolute', top: y, left: x, border: '1px solid #000000'}).show(0); }); $('.upperRight').mouseout(function(){ $('#upperRight').hide(0); }); $('.bottomRight').hover(function(){ var x = mousex + 10; var y = mousey + 10; $('#bottomRight').css({position: 'absolute', top: y, left: x, border: '1px solid #000000'}).show(0); }); $('.bottomRight').mouseout(function(){ $('#bottomRight').hide(0); }); hideForms(); if(type.length > 0){ $('#'+type).show(0); } }); function hideForms(){ $('#both').hide(0); $('#recurringOnly').hide(0); $('#transactionOnly').hide(0); $('#upperRight').hide(0); $('#bottomRight').hide(0); } function fetchInvoice(elem){ var idSplit = elem.id.split("_"); var amountId = "#"+idSplit[0]+"_hostingAmount"; var invoiceId = "#"+idSplit[0]+"_hostingInvoice"; var skuId = "#"+idSplit[0]+"_sku"; var dispId = "#"+idSplit[0]+"_display"; var invoice = $(invoiceId).val(); var amount = $(amountId).val(); var sroot = '' $.post('/'+sroot+'invoice/lookup',{invoice: invoice, amount: amount},function(data){ if(data.errors.length > 0){ var errors = ''; var i; for(i = 0; i < data.errors.length;i++){ errors += data.errors[i] + "\n"; } alert(errors); }else{ $(skuId).val(data.sku); //lockInvoice(amountId,invoiceId); $(dispId).html('Invoice #: '+data.invoice+' Invoice Amount: $'+data.amount).show(0); alert("Your invoice has been found."); } },'json'); } function routeValidation(id){ var val = false; switch(id){ case"t_submit": val = validateTransaction(); break; case"b_submit": val = validateBoth(); break; case"r_submit": val = validateRecurring(); break; } return val; } function lockInvoice(amountId,invoiceId){ $(amountId).attr("disabled", true); $(invoiceId).attr("disabled", true); } function clearInvoice(idLetter){ $('#'+idLetter+'_hostingAmount').removeAttr("disabled").val(''); $('#'+idLetter+'_hostingInvoice').removeAttr("disabled").val(''); $('#'+idLetter+'_sku').val(''); $('#'+idLetter+'_display').html(''); } function validateTransaction(){ var total = parseFloat($('#t_total').val()); if(total < 1.00){ alert('Please enter a total of $1.00 or more'); return false; } return true; } function validateRecurring(){ if($('#r_sku').val() == ''){ alert("Please make sure you clicked \"Look up\" after entering the invoice and amount values."); return false; } return true; } function validateBoth(){ var total = parseFloat($('#b_total').val()); if(total < 1.00){ alert('Please enter a total of $1.00 or more'); return false; } if($('#b_sku').val() == ''){ alert("Please make sure you clicked \"Look up\" after entering the invoice and amount values."); return false; } return true; }