function create_dialog(jqObj, options) { jqObj.dialog({ autoOpen: false, modal: true, width: 'auto', hide: 'blind', position: 'center', resizable: false, overlay: { backgroundColor: '#000', opacity: 0.5 } }); if (options) jqObj.dialog('option', options); } function str_repeat(string, count) { var i; var result = ''; for (i = 0; i < count; i++) { result = result + string; } return result; } function sprintf(format, arg) { var result = ''; var regexp = new RegExp('(.*)%(.*)\.(\.)f(.*)', 'i'); var res = regexp.exec(format); if (res) { result = res[1]; var precision = res[3]; var number = ((precision > -1) ? Math.round(parseFloat(arg) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(arg)).toString(); if (number.indexOf('.') == -1) { result = result + number + '.' + str_repeat('0', precision); } else if (number.length - number.indexOf('.') - 1 < precision) { result = result + number + str_repeat('0', precision - (number.length - number.indexOf('.') - 1)); } else { result = result + number; } result = result + res[4]; return result; } else { return false; } } function showMsg(type, msg) { if (type == 'error') { $.achtung({message: msg, className: 'achtungFail', timeout: 0}); } else if (type == 'success') { //$('.achtungFail').achtung('close'); $.achtung({message: msg, className: 'achtungSuccess', timeout: 5}); } else { alert('Unknown error'); } } var indicator; var indicator_count = 0; function spi() { if (jQuery().achtung) { indicator_count++; if (indicator_count == 1) indicator = $.achtung({icon: 'wait-icon', disableClose: true, message: please_wait_lang, timeout: 0}); } } function hpi() { if (jQuery().achtung) { indicator_count--; if (indicator_count == 0) indicator.achtung('close'); } } function loadSafe(container, url, params, callback) { var submit_type = 'GET'; if (typeof params === "string") { submit_type = 'POST'; } else if (typeof params === "function") { callback = params; params = ''; } else { params = ''; } spi(); $.ajax({ 'url': url, 'type': submit_type, 'data': params, 'dataType': 'html', success: function(data){ hpi(); if (data.substr(0, 15) === '{"status":false') { try { var obj = eval('(' + data + ')'); showMsg('error', obj.msg); } catch (err) { alert('Unknown error') } } else { if (typeof container === "object") container.html(data); if (typeof callback === "function") callback(); } } }); }