// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


function if_its_a_return(e, what_to_eval){
  var keynum;

  if(window.event){
    keynum = e.keyCode;
  } else if(e.which){
    keynum = e.which;
  }

  if(keynum == 13){ //submit
    eval(what_to_eval);
    return false;
  }
}


function str_repeat(i, m) { for (var o = []; m > 0; o[--m] = i); return(o.join('')); }

function sprintf () {
  var i = 0, a, f = arguments[i++], o = [], m, p, c, x;
  while (f) {
    if (m = /^[^\x25]+/.exec(f)) o.push(m[0]);
    else if (m = /^\x25{2}/.exec(f)) o.push('%');
    else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
      if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) throw("Too few arguments.");
      if (/[^s]/.test(m[7]) && (typeof(a) != 'number'))
        throw("Expecting number but found " + typeof(a));
      switch (m[7]) {
        case 'b': a = a.toString(2); break;
        case 'c': a = String.fromCharCode(a); break;
        case 'd': a = parseInt(a); break;
        case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
        case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
        case 'o': a = a.toString(8); break;
        case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
        case 'u': a = Math.abs(a); break;
        case 'x': a = a.toString(16); break;
        case 'X': a = a.toString(16).toUpperCase(); break;
      }
      a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a);
      c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
      x = m[5] - String(a).length;
      p = m[5] ? str_repeat(c, x) : '';
      o.push(m[4] ? a + p : p + a);
    }
    else throw ("Huh ?!");
    f = f.substring(m[0].length);
  }
  return o.join('');
}
/*
  function recalculate_order_total(){ // the discount never changes; only the vat rate changes, so the total and the vat amount must be updated
    total = 0.0;
    mss = parseFloat($('main_service_subtotal').innerHTML);
    vat_rate = parseFloat($('order_vat_rate').innerHTML);

    vat_amount = (vat_rate / 100) * mss;
    total += mss + vat_amount;
    $('order_vat_amount').innerHTML = sprintf("%.2f", vat_amount);
    $('order_total').innerHTML = sprintf("%.2f", total);
  }

*/
