function bytesToSize(bytes) { var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; if (bytes == 0) return 'n/a'; var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); if (i == 0) return bytes + ' ' + sizes[i]; return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i]; }; $.validator.addMethod("extension", function(value, element, param) { param = typeof param === "string" ? param.replace(/,/g, "|") : "png|jpe?g|gif"; return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i")); }, $.validator.format("Il file deve avere un estensione valida.")); var FileDime = ''; $.validator.addMethod('filesize', function (value, element, param) { FileDime = bytesToSize(param); return this.optional(element) || (element.files[0].size <= param); }, function() { return 'La dimensione del file deve esere minore di ' + FileDime; }); //script form registrazione step - 1 (function ($) { $(document).ready(function () { $.validator.addMethod("noSpace", function (value, element) { return value.indexOf(" ") < 0 && value != ""; }, "Non inserire spazi e non lasciare vuoto"); // validate signup form on keyup and submit var v = $("#apri_ticket").validate({ errorPlacement: function(error, element) { if (element.attr("name") == "privacy1") { error.insertAfter("#privacy1NoSpan"); } else if (element.attr("name") == "privacy2") { error.insertAfter("#privacy2NoSpan"); } else if (element.attr("name") == "privacy3") { error.insertAfter("#privacy3NoSpan"); } else{ error.insertAfter(element); } }, rules: { phone: { required: true, number: true, maxlength: 20, minlength: 6 }, cell: { number: true, maxlength: 20 }, topicId: "required", softwareIDTXT: "required", softwareID: "required", message: { required: true, maxlength: 1000, minlength: 10 }, attachment: { extension: "blueng|blml|bluacu|blucad|bluant|blubim|blubmc|blccp|blcp|blps|blcsa|blugeo|blutp|blutg|blumd|bluita|blupit|bledi|bluc|blsti|bluso|blucont|bswx|xpwe|zip|rar|txt|rtf|doc|docx|pdf|xls|xlsx|xlsm|jpg|jpeg|png|gif|mpeg|csv|log|mdb|mdb|blupt", filesize: 20971520 }, privacy2: { required: true, requiredRadioValue: 1 } }, messages: { phone: { required: "Inserisci un tuo recapito Telefonico", number: "Inserire solo numeri", maxlength: jQuery.format("Inserire al massimo {0} cifre"), minlength: jQuery.format("Inserire almeno {0} cifre") }, cell: { number: "Inserire solo numeri", maxlength: jQuery.format("Inserire al massimo {0} caratteri") }, topicId: "Specificare il tipo di richiesta", softwareIDTXT: "Specificare per quale software", softwareID: "Specificare per quale software", message: { required: "Descrivere il motivo della richiesta", maxlength: jQuery.format("Inserire al massimo {0} caratteri"), minlength: jQuery.format("Inserire almeno {0} caratteri") }, privacy2: { required: "Devi effettuare una selezione per continuare", requiredRadioValue: "Se non accetti questo trattamento non puoi procedere nella richiesta/segnalazione" } } }); $("form#apri_ticket:input,select,textarea").blur(function () { v.element($(this)); }); $("#message").blur(function () { //pulisco campo messaggi var array = []; array[0] = ['select', 'sel_ect']; array[1] = ['insert into', 'ins_ertin_to']; array[2] = ['insert', 'ins_ert']; array[3] = ['update', 'up_date']; array[4] = ['where', 'wh_ere']; array[5] = ['values', 'val_ues']; array[6] = ['delete', 'del_ete']; $('#message').val(function (i, v) { $.each(array, function (i, arr) { //v = v.replace(arr[0], arr[1]); var reg = new RegExp('('+arr[0]+')', 'gi'); v = v.replace(reg, arr[1]); }) return v; }); }); $("#ButtonReg").click(function () { if ($("#softwareID").val() === "99" ) { $("#apri_ticket").submit(function() { $("#dialogTopicIlexos").dialog("open"); return false; }); }; }); //TabIndex Automatico $(':input[type=text], :input[type=submit]:visible, :input[type=reset]:visible, :input[type=password]:visible, :radio:visible, :checkbox, select, textarea:visible, button:visible').each(function (i) { $(this).attr('tabindex', i + 1) }); $("#dialogTopicUtiliz").dialog({ autoOpen: false, modal: true, resizable: false, show: "puff", hide: "puff", height: 250, width: 550, buttons: { Chiudi: function () { $(this).dialog("close"); } } }); $("#dialogTopicSugg").dialog({ autoOpen: false, modal: true, resizable: false, show: "puff", hide: "puff", height: 150, width: 350, buttons: { Chiudi: function () { $(this).dialog("close"); } } }); $("#dialogTopicFormaz").dialog({ autoOpen: false, modal: true, resizable: false, show: "puff", hide: "puff", height: 250, width: 400, buttons: { Chiudi: function () { $(this).dialog("close"); } } }); $("#dialogTopicIlexos").dialog({ autoOpen: false, modal: true, resizable: false, show: "puff", hide: "puff", height: 250, width: 400, buttons: { Chiudi: function () { $(this).dialog("close"); } } }); $('body').on('click', '.ui-widget-overlay', function(){ $('#dialogTopicUtiliz').dialog("close"); $('#dialogTopicSugg').dialog("close"); $('#dialogTopicFormaz').dialog("close"); $('#dialogTopicIlexos').dialog("close"); }); $('#topicId').change(function () { var elem = $(this).val(); if (elem == 6) { $("#dialogTopicUtiliz").dialog("open"); } else if (elem == 15) { $("#dialogTopicSugg").dialog("open"); } else if (elem == 17) { $("#dialogTopicFormaz").dialog("open"); } }); $('#softwareID').change(function () { var elem = $(this).val(); if (elem == "99") { $("#dialogTopicIlexos").dialog("open"); } }); $('#apri_ticket').submit(function() { if ($("#softwareID").val() === "99" ) { $("#dialogTopicIlexos").dialog("open"); return false; } }); }); })(jQuery);