var INPUTCOLOR = ""; //colore del bordo dell'input di default var INPUTERROR = "1px solid #FF9900"; var GIORNI = Array("lun","mar","mer","gio","ven","sab","dom"); var timeOutId; //Timeout di alertWin var URLSITO = 'https://cardiologyexcellence.com/'; var SCMD = 'login'; var LOGGEDIN = false; /* ALERT ********************************/ function alertSwal(ty,ti,mex,fn){ //type = warning, error, success, info, question if(fn==undefined) fn=function(){}; swal({ title: ti, text: mex, type: ty, timer: 60000}, function(confirm){ setTimeout(fn,200); }); }; function confirmSwal(mex,fn,fn2){ swal({ title: "ALERT", text: mex, type: 'warning', showCancelButton: true, confirmButtonText: 'Ok', cancelButtonText: 'Annulla' }, function(confirm){ if(confirm){ setTimeout(fn,200); }else{ setTimeout(fn2,200); } }); } function viewLoader(mex){ var ldr = document.getElementById('nonsolospinner'); var ldrdiv = document.getElementById('nonsolospinnerdiv'); ldr.firstChild.innerHTML = mex; ldr.style.display = "block"; ldrdiv.style.display = "block"; } function hideLoader(cont,dbg){ if(dbg){ if(typeof(cont)!='string') cont = JSON.stringify(cont); var ldr = document.getElementById('nonsolospinner'); ldr.firstChild.innerHTML = cont; }else{ var ldr = document.getElementById('nonsolospinner'); var ldrdiv = document.getElementById('nonsolospinnerdiv'); ldr.style.display = "none"; ldrdiv.style.display = "none"; ldr.firstChild.innerHTML = ''; } } function notificaTopRight(tot,img,nome,qta){ var tmpl = '
'+ '
TOTALE: € '+tot+'
'+ '
'+ '
'+ '' + '
'+ '
'+ nome+'
'+qta+ '
'+ '
'+ '
'; $.notify({ message: tmpl, },{ z_index: 1051, delay: 4000, animate: { enter: 'animated fadeInDown', exit: 'animated fadeOutUp' } }); } /* DEBUG ********************************/ function ja(o){ alert(JSON.stringify(o)); console.log(JSON.stringify(o)); } function sja(o){ var str = ''; for(var i in o){ if(str!='') str +=','; str += i +":" + typeof o[i]; } alert(str); } /* FORM ********************************/ function normalizeCampo(obj){ obj.style.borderBottom = INPUTCOLOR; } function ctrlKey(e,o){ if(e.keyCode==13) document.getElementById(o).click(); } function toUri(obj){ var strUri=''; if(obj.name!="" && obj.name!=undefined){ switch(obj.type){ case 'checkbox': case 'radio': if((obj.type === 'radio' || obj.type === 'checkbox') && obj.checked) { var val=(obj.value!=='')? obj.value : '1'; strUri += '&'+obj.name+'='+encodeURIComponent(val); }else{ strUri += '&'+obj.name+'='; } break; default: strUri += '&'+obj.name+'='+encodeURIComponent(obj.value); break; } } return strUri; } function buildUri(obj){ var strUri =''; for(var n=0; n0) fields['dataId'] = []; for(var n=0; n stringify of objects //mode=mix => key= stringify for array and key=value for the rest //mode=php => key[]=val1&...key[]=valn for array and key=value for the rest if(mode==undefined) mode = 'php'; var strUri = ''; var objUri = {}; var mixUri = ''; for(var i in this.nodes){ var v = this.getValue(i); objUri[i.replace('[]','')]=v; if(v.constructor === Array){ v.forEach(function(e){ strUri += '&'+i+'='+encodeURIComponent(e); }); mixUri += '&'+encodeURIComponent(i.replace('[]',''))+'='+encodeURIComponent(JSON.stringify(v)); }else{ strUri += '&'+encodeURIComponent(i)+'='+encodeURIComponent(v); mixUri += '&'+encodeURIComponent(i)+'='+encodeURIComponent(v); } } switch(mode){ case 'json': return JSON.stringify(objUri); break; case 'mix': return mixUri; break; case 'php': return strUri; break; } } return form; } /* validazione campi */ function indirizzoEmailValido(indirizzo) { if (window.RegExp) { var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)"; var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; var regnv = new RegExp(nonvalido); var regv = new RegExp(valido); if (!regnv.test(indirizzo) && regv.test(indirizzo)) return true; return false; }else { if(indirizzo.indexOf("@") >= 0) return true; return false; } } function controlForm(frm,nome,fld1,fld2,tipo){ if(tipo==undefined) tipo = ''; switch(tipo){ case "":// controlla se il campo e vuoto false (quindi ="" o =0...tanti zeri) if(frm.getValue(fld1) == false){ alertSwal('warning',nome, 'Missing field',frm.focus.bind(frm,fld1)); INPUTCOLOR = frm.getElement(fld1).style.borderBottom; frm.getElement(fld1).style.borderBottom = INPUTERROR; return false; } return true; break; case "_":// controlla se il campo = vuoto con "" if(frm.getValue(fld1) == ""){ alertSwal('warning',nome, 'Missing field',frm.focus.bind(frm,fld1)); INPUTCOLOR = frm.getElement(fld1).style.borderBottom; frm.getElement(fld1).style.borderBottom = INPUTERROR; return false; } return true; break; case "@": // controlla la validita del campo mail if(!indirizzoEmailValido(frm.getValue(fld1))){ alertSwal('warning',nome, 'invalid format',frm.focus.bind(frm,fld1)); INPUTCOLOR = frm.getElement(fld1).style.borderBottom; frm.getElement(fld1).style.borderBottom = INPUTERROR; return false; } return true; break; case "hS":// controlla se il campo autoSuggest = vuoto if(frm.getValue(fld2) == ""){ if(frm.getValue(fld1) == false){ alertSwal('warning',nome, 'Missing field',frm.focus.bind(frm,fld1)); }else{ alertSwal('warning',nome, 'Not listed in the available data ',frm.focus.bind(frm,fld1)); } INPUTCOLOR = frm.getElement(fld1).style.borderBottom; frm.getElement(fld1).style.borderBottom = INPUTERROR; return false; }else{ return true; } break; case "date<": if(frm.getValue(fld2) != "" && frm.getValue(fld1) != ""){ var arr1 = frm.getValue(fld1).split("-"); var arr2 = frm.getValue(fld2).split("-"); var d1 = new Date(arr1[2],arr1[1]-1,arr1[0]); var d2 = new Date(arr2[2],arr2[1]-1,arr2[0]); var r1 = d1.getTime(); var r2 = d2.getTime(); if(r1 > r2){ alertSwal('warning',nome, 'Le date sono invertite',frm.focus.bind(frm,fld1)); INPUTCOLOR = frm.getElement(fld1).style.borderBottom; frm.getElement(fld1).style.borderBottom = INPUTERROR; return false; } return true; }else{ return true; } break; case "ore<": if(frm.getValue(fld2)!="" && frm.getValue(fld1)!="" && frm.getValue(fld2)!="00:00" && frm.getValue(fld1)!="00:00"){ var arr1 = frm.getValue(fld1).split(":"); var arr2 = frm.getValue(fld2).split(":"); arr1[0]= parseInt(arr1[0],10); arr1[1]= parseInt(arr1[1],10); arr2[0]= parseInt(arr2[0],10); arr2[1]= parseInt(arr2[1],10); if(arr1[0] > arr2[0] || (arr1[0] == arr2[0] && arr1[1] > arr2[1])){ alertSwal('warning',nome, 'Gli orari sono invertiti',frm.focus.bind(frm,fld1)); INPUTCOLOR = frm.getElement(fld1).style.borderBottom; frm.getElement(fld1).style.borderBottom = INPUTERROR; return false; } return true; }else{ return true; } break; case "n": // controlla se il campo e' un numero if(isNaN(frm.getValue(fld1).replace(',','.'))){ alertSwal('warning',nome, 'Il campo deve contenere solo numeri',frm.focus.bind(frm,fld1)); INPUTCOLOR = frm.getElement(fld1).style.borderBottom; frm.getElement(fld1).style.borderBottom = INPUTERROR; return false; }else{ return true; } break; case "=": // confronta due campi if(frm.getValue(fld1) != frm.getValue(fld2)){ alertSwal('warning', nome, 'fields mismatch',frm.focus.bind(frm,fld1)); INPUTCOLOR = frm.getElement(fld1).style.borderBottom; frm.getElement(fld1).style.borderBottom = INPUTERROR; return false; }else{ return true; } break; case "cf": // controlla codice fiscale var r = new RegExp("^[a-zA-Z]{6}[0-9]{2}[a-zA-Z][0-9]{2}[a-zA-Z][0-9]{3}[a-zA-Z]$"); if(!r.test(frm.getValue(fld1))){ alertSwal('warning',nome, 'Invalid format',frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; }else{ return true; } break; case "pi": // controlla partita iva var r = new RegExp("^[0-9]{11}$"); if(!r.test(frm.getValue(fld1))){ alertSwal('warning',nome, 'Invalid format',frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; }else{ return true; } break; case "cf_pi": // controlla codice fiscale or Partita iva var r1 = new RegExp("^[a-zA-Z]{6}[0-9]{2}[a-zA-Z][0-9]{2}[a-zA-Z][0-9]{3}[a-zA-Z]$"); var r2 = new RegExp("^[0-9]{11}$"); if(!r1.test(frm.getValue(fld1)) && !r2.test(frm.getValue(fld1))){ alertSwal('warning',nome, 'Invalid format',frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; }else{ return true; } break; case "sdi": // controlla codice sdi var r = new RegExp("^[a-zA-Z0-9]{7}$"); if(!r.test(frm.getValue(fld1))){ alertSwal('warning',nome, 'Invalid format',frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; }else{ return true; } break; case "c<": // controlla se il campo e' piu' corto di un tot if(frm.getValue(fld1).length < fld2){ alertSwal('warning',nome, "minimum length " +fld2+ " chars",frm.focus.bind(frm,fld1)); frm.getElement(fld1).style.border = INPUTERROR; return false; }else{ return true; } break; // TODO case "h": // controlla se il campo hidden = vuoto if(document.getElementById(id2).value == false){ alertWinScroll(id, 400, ""+nome+": missin field"); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF9900"; return false; }else{ return true; } break; case "c": // controlla se il campo e' piu' lungo di un tot if(document.getElementById(id).value.length > id2){ var c = "chars"; if(id2==1) c = "char"; alertWinScroll(id, 400, ""+nome+": field must be at least "+id2+" "+c); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF9900"; return false; }else{ return true; } break; case "n=": // controlla se il campo e' lungo n if(document.getElementById(id).value.length != id2){ var c = "chars"; if(id2==1) c = "char"; alertWinScroll(id, 400, ""+nome+": field must be " +id2+ " "+c); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF0000"; return false; }else{ return true; } break; case "v<": // controlla se il valore del campo e' < di tot if(parseInt(document.getElementById(id).value)>id2){ alertWin(nome+": value of the field must be lower than "+id2); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF0000"; return false; }else{ return true; } case "v>": // controlla se il valore del campo e' > di tot if(parseInt(document.getElementById(id).value)=": // controlla se il valore del campo e' >= di tot if(parseInt(document.getElementById(id).value)= del I if(convDate(document.getElementById(id).value)>convDate(document.getElementById(id2).value)){ alertWin(nome+": field value must be greater or equal to the previous"); document.getElementById(id2).focus(); document.getElementById(id2).style.border = "1px solid #FF0000"; return false; }else{ return true; } break; case "doc": // controllo se il file = un doc obj = document.getElementById(id); var extensions = new Array(); extensions[1] = "doc"; extensions[0] = "docx"; extensions[2] = "pdf"; extensions[3] = "rtf"; /*extensions[4] = "bmp";*/ var image_file = obj.value; var image_length = image_file.length; var pos = image_file.lastIndexOf('.') + 1; var ext = image_file.substring(pos, image_length); var final_ext = ext.toLowerCase(); for (i = 0; i < extensions.length; i++){ if(extensions[i] == final_ext){ return true; } } alertWinScroll(id, 400, ""+nome+": invalid format"); document.getElementById(id).focus(); document.getElementById(id).style.border = "1px solid #FF9900"; return false; break; case "img": // controllo se il file = una img obj = document.getElementById(id); var extensions = new Array(); extensions[1] = "jpg"; extensions[0] = "jpeg"; extensions[2] = "gif"; extensions[3] = "png"; /*extensions[4] = "bmp";*/ var image_file = obj.value; var image_length = image_file.length; var pos = image_file.lastIndexOf('.') + 1; var ext = image_file.substring(pos, image_length); var final_ext = ext.toLowerCase(); for (i = 0; i < extensions.length; i++){ if(extensions[i] == final_ext){ return true; } } alertWin("Seleziona un'immagine con una delle seguenti estensioni:\n\n gif, jpeg, jpg"); return false; break; default: alertWin("tipo non riconosciuto"); return false; } } // ********************* Modale ****************** // Eventi nella pagina function addEvent(obj, evType, fn){ if(obj.addEventListener){ obj.addEventListener(evType, fn, true); return true; } else if (obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r; } else { return false; } } function once(e,fn) { target = (e.currentTarget) ? e.currentTarget : e.srcElement; if(target.removeEventListener){ target.removeEventListener(e.type, fn); }else{ target.detachEvent('on'+e.type, fn); } target['on'+e.type]=null;//inline event var args = Array.prototype.slice.call(arguments); var dump = args.shift(); dump = args.shift(); fn.apply(this, args); try { var new_e = new e.constructor(e.type, e); target.dispatchEvent(new_e); }catch(err) {} } function isMobile() { try{ document.createEvent("TouchEvent"); return true; } catch(e){ return false; } } /* Matematica ********************************/ /*** Returns a random integer between min (inclusive) and max (inclusive)*/ function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } function genPass(n){ // Generazione password casuale if(n<4) return ""; var lets = "abcdefghiljkmnopqrstuvwxyz"; var nums = "0123456789"; var spes = "!$%&()=?*[]<>"; var elaborazione = ''; var nLet = n-4; var nNum = 2; var nLetM = 1; var nSpe = 1; for (var contatore=0; contatore').val(z).html(z)); if(ex==z) obj[0].lastChild.selected = true; } } function daysInMonth(month, year) { return new Date(year, month, 0).getDate(); } function getAge(dob){ var year = Number(dob.substr(0, 4)); var month = Number(dob.substr(5, 2)) - 1; var day = Number(dob.substr(8, 2)); var today = new Date(); var age = today.getFullYear() - year; if (today.getMonth() < month || (today.getMonth() == month && today.getDate() < day)) { age--; } return age; } function convDate(data){ dummy2 = data.split("-").reverse().join("-"); return dummy2; } function toJSDate (dateTime) { var dateTime = dateTime.split(" "); var date = dateTime[0].split("-"); var time = dateTime[1].split(":"); date[1] = date[1]==0?11:--date[1]; return new Date(date[0], date[1], date[2], time[0], time[1], time[2], 0); } function dataPicker(id,open,current){ if(open==undefined) open=0;// istanzia ed apri il picker if(current==undefined) current=true;//On show, use the current date/time var obj; if(typeof id == 'string'){ obj = $('#'+id); }else{ obj = $(id); }; obj.datetimepicker({ locale:'it', format: 'DD-MM-YYYY', icons: { time: "fa fa-clock-o", date: "fa fa-calendar", up: "fa fa-chevron-up", down: "fa fa-chevron-down", previous: 'fa fa-chevron-left', next: 'fa fa-chevron-right', today: 'fa fa-screenshot', clear: 'fa fa-trash', close: 'fa fa-remove', inline: true }, useCurrent:current //debug:true }).on('dp.change', function (ev) { $(obj[0]).trigger( "change" ); //obj.trigger( "change" ); }); if(open){ obj[0].onfocus=function(){}; obj.blur(); obj.focus(); }; } function timePicker(id,open,current){ if(open==undefined) open=0; if(current==undefined) current=true; var obj; if(typeof id == 'string'){ obj = $('#'+id); }else{ obj = $(id); }; obj.datetimepicker({ locale:'it', format: 'H:mm', // use this format if you want the 24hours timepicker //format: 'h:mm A', //use this format if you want the 12hours timpiecker with AM/PM toggle icons: { time: "fa fa-clock-o", date: "fa fa-calendar", up: "fa fa-chevron-up", down: "fa fa-chevron-down", previous: 'fa fa-chevron-left', next: 'fa fa-chevron-right', today: 'fa fa-screenshot', clear: 'fa fa-trash', close: 'fa fa-remove', inline: true }, useCurrent:current //On show, use the current date/time //debug:true }).on('dp.change', function (ev) { $(obj[0]).trigger( "change" ); }); if(open){ // istanzia ed apri il picker obj[0].onfocus=function(){}; obj.blur(); obj.focus(); }; } function isNumeric(val) { return val !== "NaN" && (+val)+'' === val + '' } //****************************************** //********** GOOGLE MAP ********** //****************************************** var map; var cellX = 0; var cellY = 0; var marker = null; function initMap(x,y) { cellX = document.getElementById(x); cellY = document.getElementById(y); var zoom = 14; if(cellX.value == "" || cellX.value == "0") cellX.value = "37.5319673"; if(cellY.value == "" || cellY.value == "0") { cellY.value = "14.0360382"; zoom=7; }; var latLng = new google.maps.LatLng(Number(cellX.value),Number(cellY.value)); var iconColor = new google.maps.MarkerImage("http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png"); var geocoder = new google.maps.Geocoder(); var infowindow = new google.maps.InfoWindow({content: ""}); var myOptions = { zoom: zoom, center: latLng, mapTypeControl: true, mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU }, zoomControl: true, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map"), myOptions); var marker = new google.maps.Marker({ position: latLng, title: 'Sposta', map: map, icon: iconColor, draggable: true }); function updateMarkerPosition(latLng) { cellX.value = String(Math.round(latLng.lat() * 1000000) / 1000000); cellY.value = String(Math.round(latLng.lng() * 1000000) / 1000000); } // Update current position info. updateMarkerPosition(latLng); google.maps.event.addListener(marker, 'dragend', function() { updateMarkerPosition(marker.getPosition()); }); google.maps.event.addListener(marker, 'drag', function() { updateMarkerPosition(marker.getPosition()); }); var googleSeachControlDiv = document.createElement('DIV'); var googleSeachControl = new GoogleSeachControl(googleSeachControlDiv, map); googleSeachControlDiv.index = 1; map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(googleSeachControlDiv); function GoogleSeachControl(controlDiv, map) { controlDiv.style.margin = '5px'; var controlUI = document.createElement('DIV'); controlUI.style.backgroundColor = 'white'; controlUI.style.cursor = 'pointer'; controlUI.style.textAlign = 'center'; controlUI.title = "Cerca"; controlDiv.appendChild(controlUI); var controltxtbox = document.createElement('input'); controltxtbox.setAttribute("id", "txt_googleseach"); controltxtbox.setAttribute("type", "text"); controltxtbox.setAttribute("value", ""); controlUI.appendChild(controltxtbox); var controlbtn = document.createElement('input'); controlbtn.setAttribute("id", "btn_googleseach"); controlbtn.setAttribute("type", "button"); controlbtn.setAttribute("value", "Cerca"); controlUI.appendChild(controlbtn); controltxtbox.onkeyup = function(){ctrlKey(event,'btn_googleseach');}; google.maps.event.addDomListener(controlbtn, 'click', function() { GoogleSeachAddress(); }); } function GoogleSeachAddress() { var address = document.getElementById("txt_googleseach").value; if (geocoder) { geocoder.geocode({ 'address': address }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); newLatLng = new google.maps.LatLng(results[0].geometry.location.lat(),results[0].geometry.location.lng()); marker.setPosition(newLatLng); cellY.value = String(Math.round(results[0].geometry.location.lng() * 1000000) / 1000000); cellX.value = String(Math.round(results[0].geometry.location.lat() * 1000000) / 1000000); infowindow.setContent("
lat " + results[0].geometry.location.lat() + "
lng " + results[0].geometry.location.lng() + "
hai cercato:" + address + "
"); infowindow.open(map, marker); /*google.maps.event.addListener(marker, 'click', function() { infowindow.open(map, marker); });*/ } else { alert("Indirizzo non trovato, risposta del geocoder: " + status); } }); } } } //****************************************** //********** FINE GOOGLE MAP ********** //****************************************** /******************FILES******************/ function engageSingleFoto(id,tbl,btn){ $("#"+btn+id).uploadFile({ url:"https://cardiologyexcellence.com/addFoto", fileName:"myfile", multiple:false, dragDrop:false, showFileCounter:false, //maxFileCount:1, //sequential:true, //sequentialCount:2, acceptFiles:"image/*", maxFileSize: 33554432, sizeErrorStr: "troppo grande. Max: ", abortStr:"interrompi", cancelStr:"annulla", doneStr:"fatto", multiDragErrorStr: "Drag & Drop multiplo di file non autorizzato.", extErrorStr:"estenzione non autorizzata.", uploadErrorStr:"Upload non autorizzato.", maxFileCountErrorStr:"non autorizzato. Numero massimo di files: ", uploadStr:"Carica...", deletelStr: "Elimina", formData: {"id": id,"tbl":tbl}, showPreview:true, statusBarWidth:'auto', previewWidth: "auto", //previewHeight: "335px", onLoad:function(obj){ $.post('https://cardiologyexcellence.com/loadFoto',"id="+id+"&tbl="+tbl,function(){},'json') .done(function(data){ for(var i=0;i 0) { item.msrc = childElements[0].getAttribute('src'); // thumbnail url if(childElements.length > 1) { item.title = childElements[1].innerHTML; // caption (contents of figure) } } var mediumSrc = el.getAttribute('data-med'); if(mediumSrc) { size = el.getAttribute('data-med-size').split('x'); // "medium-sized" image item.m = { src: mediumSrc, w: parseInt(size[0], 10), h: parseInt(size[1], 10) }; } // original image item.o = { src: item.src, w: item.w, h: item.h }; items.push(item); } return items; }; // find nearest parent element var closest = function closest(el, fn) { return el && ( fn(el) ? el : closest(el.parentNode, fn) ); }; var onThumbnailsClick = function(e) { e = e || window.event; e.preventDefault ? e.preventDefault() : e.returnValue = false; var eTarget = e.target || e.srcElement; var clickedListItem = closest(eTarget, function(el) { return el.tagName === 'A'; }); if(!clickedListItem) { return; } var clickedGallery = clickedListItem.parentNode; var childNodes = clickedListItem.parentNode.childNodes, numChildNodes = childNodes.length, nodeIndex = 0, index; for (var i = 0; i < numChildNodes; i++) { if(childNodes[i].nodeType !== 1) { continue; } if(childNodes[i] === clickedListItem) { index = nodeIndex; break; } nodeIndex++; } if(index >= 0) { openPhotoSwipe( index, clickedGallery ); } return false; }; var photoswipeParseHash = function() { var hash = window.location.hash.substring(1), params = {}; if(hash.length < 5) { // pid=1 return params; } var vars = hash.split('&'); for (var i = 0; i < vars.length; i++) { if(!vars[i]) { continue; } var pair = vars[i].split('='); if(pair.length < 2) { continue; } params[pair[0]] = pair[1]; } if(params.gid) { params.gid = parseInt(params.gid, 10); } return params; }; var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) { var pswpElement = document.querySelectorAll('.pswp')[0], gallery, options, items; items = parseThumbnailElements(galleryElement); // define options (if needed) options = { galleryUID: galleryElement.getAttribute('data-pswp-uid'), getThumbBoundsFn: function(index) { // See Options->getThumbBoundsFn section of docs for more info var thumbnail = items[index].el.children[0], pageYScroll = window.pageYOffset || document.documentElement.scrollTop, rect = thumbnail.getBoundingClientRect(); return {x:rect.left, y:rect.top + pageYScroll, w:rect.width}; }, addCaptionHTMLFn: function(item, captionEl, isFake) { if(!item.title) { captionEl.children[0].innerText = ''; return false; } captionEl.children[0].innerHTML = item.title + '
Photo: ' + item.author + ''; return true; }, }; if(fromURL) { if(options.galleryPIDs) { // parse real index when custom PIDs are used // https://photoswipe.com/documentation/faq.html#custom-pid-in-url for(var j = 0; j < items.length; j++) { if(items[j].pid == index) { options.index = j; break; } } } else { options.index = parseInt(index, 10) - 1; } } else { options.index = parseInt(index, 10); } // exit if index not found if( isNaN(options.index) ) { return; } options.mainClass = 'pswp--minimal--dark'; options.barsSize = {top:0,bottom:0}; options.captionEl = true; options.fullscreenEl = true; options.shareEl = false; options.bgOpacity = 0.85; options.tapToClose = true; options.tapToToggleControls = false; if(disableAnimation) { options.showAnimationDuration = 0; } // Pass data to PhotoSwipe and initialize it gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options); // see: http://photoswipe.com/documentation/responsive-images.html var realViewportWidth, useLargeImages = false, firstResize = true, imageSrcWillChange; gallery.listen('beforeResize', function() { var dpiRatio = window.devicePixelRatio ? window.devicePixelRatio : 1; dpiRatio = Math.min(dpiRatio, 2.5); realViewportWidth = gallery.viewportSize.x * dpiRatio; if(realViewportWidth >= 1200 || (!gallery.likelyTouchDevice && realViewportWidth > 800) || screen.width > 1200 ) { if(!useLargeImages) { useLargeImages = true; imageSrcWillChange = true; } } else { if(useLargeImages) { useLargeImages = false; imageSrcWillChange = true; } } if(imageSrcWillChange && !firstResize) { gallery.invalidateCurrItems(); } if(firstResize) { firstResize = false; } imageSrcWillChange = false; }); gallery.listen('gettingData', function(index, item) { if( useLargeImages ) { item.src = item.o.src; item.w = item.o.w; item.h = item.o.h; } else { item.src = item.m.src; item.w = item.m.w; item.h = item.m.h; } }); gallery.init(); /* fullscreen mode on photo click, don't close gallery on esc */ //gallery.ui.getFullscreenAPI().enter(); /* or fullscreen and close the gallery on esc let psAPI = gallery.ui.getFullscreenAPI(); psAPI.enter(); gallery.listen('close', function (name) { psAPI.exit(); });*/ }; // select all gallery elements var galleryElements = document.querySelectorAll( gallerySelector ); for(var i = 0, l = galleryElements.length; i < l; i++) { galleryElements[i].setAttribute('data-pswp-uid', i+1); galleryElements[i].onclick = onThumbnailsClick; } // Parse URL and open gallery if it contains #&pid=3&gid=1 var hashData = photoswipeParseHash(); if(hashData.pid && hashData.gid) { openPhotoSwipe( hashData.pid, galleryElements[ hashData.gid - 1 ], true, true ); } }; // ********************* Admin ****************** function newPass(obj,num){ document.getElementById(obj).value = genPass(num); } // ********************* Login ****************** function ctrlLogin(obj){ var frm = formica(obj); flag = true; flag = flag && controlForm(frm, 'E-mail','email',''); if(frm.getValue('email')!=''){ flag = flag && controlForm(frm, 'E-mail','email','','@'); } flag = flag && controlForm(frm, 'Password','pass',''); if(flag){ viewLoader('Loading...'); $.post('https://cardiologyexcellence.com/validate',frm.buildUri('php'),function(){},'json') .done(function(resp){ if(resp.s=="ko"){ alertSwal('error','Access denied', 'Wrong e-mail or password'); }else if(resp.s=="ok"){ window.location.reload(false); }else if(resp.s=="eml"){ alertSwal('warning','User not verified', 'Your account must be activated by our staff, we will inform you by e-mail.'); } }).fail(function(){alertSwal('error','', "Errore di connessione");}) .always(function(resp){hideLoader(resp,0);}); } } // ********************* Signin ****************** function ctrlSignin(obj){ var frm = formica(obj); flag = true; flag = flag && controlForm(frm, 'Name','nome',''); flag = flag && controlForm(frm, 'Surname','cognome',''); flag = flag && controlForm(frm, 'Email','email',''); if(frm.getValue('email')!=''){ flag = flag && controlForm(frm, 'Email','email','','@'); } flag = flag && controlForm(frm, 'Country','country',''); flag = flag && controlForm(frm, 'Affiliation (organization)','affiliazione',''); flag = flag && controlForm(frm, 'Medical speciality','interesse',''); flag = flag && controlForm(frm, 'Password','pass',''); flag = flag && controlForm(frm, 'Password','pass','6','c<'); flag = flag && controlForm(frm, 'Password','pass','pass2','='); if(flag && frm.getValue("informativa")==false){ flag=false; alertSwal('warning',"Policy on the processing of data", "Accept missing.",function(){frm.focus("informativa")}); } if(flag){ viewLoader('Loading......'); $.post('https://cardiologyexcellence.com/signin',frm.buildUri('php'),function(){},'json') .done(function(resp){ if(resp.result=="dup"){ alertSwal('error','Sign in canceled', 'Email already exists, choose a different one'); }else if(resp.result=="ok"){ var fn = function(){window.location.reload(false);}; //alertSwal('success','Registration done', 'we will validate your registration, and notify you by email.',fn); alertSwal('success','Registration done', 'now you can log in using your e-mail and password.',fn); }else if(resp.result=="ko"){ alertSwal('error','Sign in not valid', 'Mandatory fields are missing'); } }).fail(function(){alertSwal('error','', "Connection error");}) .always(function(resp){hideLoader(resp,0);}); } } function saveUserData(userData){ viewLoader('Loading......'); $.post('https://cardiologyexcellence.com/userData', {oauth_provider:'facebook',userData: JSON.stringify(userData)}, function(){},'json') .done(function(resp){ if (resp.result=="ok") { window.location.reload(false); } else { alertSwal('warning','Richiesta Facebook', 'richiesta annullata o non autorizzata.'); } }).fail(function(){alertSwal('error','', "Errore di connessione");}) .always(function(resp){hideLoader(resp,0);}); } function forgottenPass(obj) { var frm = formica(obj); flag = true; flag = flag && controlForm(frm, 'Email','emailF',''); flag = flag && controlForm(frm, 'Email','emailF','','@'); if (flag) { viewLoader('Loading......'); $.post('https://cardiologyexcellence.com/forgottenPass', frm.buildUri('php'), function () {}, 'json').done(function (resp) { if (resp.s == "ok") { alertSwal('success','', 'You will receive an email to reset your password ','window.location.href=URLSITO'); } else if (resp.s == 'no') { alertSwal('error','', "Email not found"); } else { alertSwal('error','', "Errore durante la modifica"); } }).fail(function () { alertSwal('error','', "Errore di connessione"); }).always(function (resp) {hideLoader(resp,0);}); } } function changePass(obj) { var frm = formica(obj); flag = true; flag = flag && controlForm(frm, 'Password','password',''); flag = flag && controlForm(frm, 'Password','password','6','c<'); flag = flag && controlForm(frm, 'Passwords','password','password2','='); if (flag) { viewLoader('Loading...'); $.post('https://cardiologyexcellence.com/resetPass', frm.buildUri('php'), function () {}, 'json').done(function (resp) { if (resp.s == "ok") { alertSwal('success','', 'Password changed',"location.href='https://cardiologyexcellence.com/login'"); } else { alertSwal('error','', "Modify error"); } }).fail(function () { alertSwal('error','', "Connection error"); }).always(function (resp) { hideLoader(resp,0); }); } } function stopAllVideo(){ $('iframe.item').each(function(){ this.contentWindow.postMessage('{"event":"command","func":"stopVideo","args":""}', '*') }); } function contactCommunity(obj){ var frm = formica(obj); flag = true; flag = flag && controlForm(frm, 'Subject','subject',''); flag = flag && controlForm(frm, 'Message','message',''); if (flag) { viewLoader('Loading...'); $.post('https://cardiologyexcellence.com/contact', frm.buildUri('php'), function () {}, 'json').done(function (resp) { if (resp.s == "ok") { fn = function(){$('#profilo').modal('toggle');}; alertSwal('success','Message sent', 'e-mail sent successfully',fn); } else if (resp.s == 'dup') { alertSwal('error','User not fount', "email address not available"); } else { alertSwal('error','', "Send error"); } }).fail(function () {alertSwal('error','', "Connection error"); }).always(function (resp) {hideLoader(resp,0);}); } } // ################ POST ############### function engageMultiFotoPost(btn,list){// file di post nuovo (con id 0) $("#"+btn).uploadFile({ url:"https://cardiologyexcellence.com/addPostFile", fileName:"myfile", multiple:false, dragDrop:false, showFileCounter:false, acceptFiles:"image/*, .pdf, text/plain, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/msword, application/vnd.ms-powerpoint", maxFileSize: 33554432, sizeErrorStr: "too big. Max: ", abortStr:"abort", cancelStr:"cancel", doneStr:"done", multiDragErrorStr: "Drag & Drop not available.", extErrorStr:"file extension forbidden.", uploadErrorStr:"Upload error.", maxFileCountErrorStr:"forbidden. Max files number: ", uploadStr:' Add image or doc (Max: 32MB)', deletelStr: "Delete", formData: {}, onError: function (files, status, errMsg, pd) { alertSwal('error','Loading error for: ', JSON.stringify(files)); }, customProgressBar: function(obj,s){// butto l'interfaccia this.statusbar=""; this.abort = $("
").appendTo(this.statusbar).hide(); this.cancel = $("
").appendTo(this.statusbar).hide(); this.filename = $("
").appendTo(this.statusbar).hide(); this.progressDiv = $("
").appendTo(this.statusbar).hide(); this.done = $("
").appendTo(this.statusbar).hide(); this.progressbar = $("
").appendTo(this.progressDiv); this.del = $("
").appendTo(this.statusbar).hide(); }, onSuccess: function (files, data, xhr, pd) { //pd.statusbar.hide(); data = JSON.parse(data); if(data.error==undefined){ var allegatiBox = document.getElementById(list); var fn = function(){}; if(data.fs){ var fn = function(){allegatiBox.innerHTML = data.fs;}; } alertSwal('success','Upload done.', '',fn); }else{ alertSwal('error','Upload error: ', data.error); } return false; }, onCancel:function(files,pd){ alertSwal('warning','Load cancel in: ',JSON.stringify(files)); } }); } function engageMultiFotoPostOld(btn,list,idPost){// file di post vecchio (con id valido) $("#"+btn).uploadFile({ url:"https://cardiologyexcellence.com/addPostFileOld", fileName:"myfile", multiple:false, dragDrop:false, showFileCounter:false, acceptFiles:"image/*, .pdf, text/plain, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/msword, application/vnd.ms-powerpoint", maxFileSize: 33554432, sizeErrorStr: "too big. Max: ", abortStr:"abort", cancelStr:"cancel", doneStr:"done", multiDragErrorStr: "Drag & Drop not available.", extErrorStr:"file extension forbidden.", uploadErrorStr:"Upload error.", maxFileCountErrorStr:"forbidden. Max files number: ", uploadStr:' Add image or doc (Max: 32MB)', deletelStr: "Delete", formData: {'idPost':idPost}, onError: function (files, status, errMsg, pd) { alertSwal('error','Loading error for: ', JSON.stringify(files)); }, customProgressBar: function(obj,s){// butto l'interfaccia this.statusbar=""; this.abort = $("
").appendTo(this.statusbar).hide(); this.cancel = $("
").appendTo(this.statusbar).hide(); this.filename = $("
").appendTo(this.statusbar).hide(); this.progressDiv = $("
").appendTo(this.statusbar).hide(); this.done = $("
").appendTo(this.statusbar).hide(); this.progressbar = $("
").appendTo(this.progressDiv); this.del = $("
").appendTo(this.statusbar).hide(); }, onSuccess: function (files, data, xhr, pd) { //pd.statusbar.hide(); data = JSON.parse(data); if(data.error==undefined){ var allegatiBox = document.getElementById(list); var fn = function(){}; if(data.fs){ var fn = function(){allegatiBox.innerHTML = data.fs;}; } var p = social.postsD.get(idPost); p.pObj.addFile(data.att); alertSwal('success','Upload done.', '',fn); }else{ alertSwal('error','Upload error: ', data.error); } return false; }, onCancel:function(files,pd){ alertSwal('warning','Load cancel in: ',JSON.stringify(files)); } }); } function delPostFile(id,clb){ confirmSwal('Do you want to delete this attach?',function(){ viewLoader("Deleting..."); var strUri = "&id="+id; $.post('https://cardiologyexcellence.com/delPostFile',strUri,function(){},'json') .done(function(resp){ if(resp.s=="ok"){ alertSwal('success',"Attach deleted", '', clb); }else if(resp.s=="noajax"){ alertSwal('error','Access denied', ''); }else{ alertSwal('error',"Delete error", ''); } }) .fail(function(){alertSwal('error',"Connection error", '');}) .always(function(resp){hideLoader(resp,0);}); }); } function delPostFileOld(id,clb){ confirmSwal('Do you want to delete this attach?',function(){ viewLoader("Deleting..."); var strUri = "&id="+id; $.post('https://cardiologyexcellence.com/delPostFile',strUri,function(){},'json') .done(function(resp){ if(resp.s=="ok"){ alertSwal('success',"Attach deleted", '', clb); var p = social.postsD.get(resp.idPost); p.pObj.delFile(resp.att); }else if(resp.s=="noajax"){ alertSwal('error','Access denied', ''); }else{ alertSwal('error',"Delete error", ''); } }) .fail(function(){alertSwal('error',"Connection error", '');}) .always(function(resp){hideLoader(resp,0);}); }); } // foto profilo function engageMultiFotoProfile(btn,dom){// file di post nuovo (con id 0) $("#"+btn).uploadFile({ url:"https://cardiologyexcellence.com/addProfileFile", fileName:"myfile", multiple:false, dragDrop:false, showFileCounter:false, acceptFiles:"image/*", maxFileSize: 33554432, sizeErrorStr: "too big. Max: ", abortStr:"abort", cancelStr:"cancel", doneStr:"done", multiDragErrorStr: "Drag & Drop not available.", extErrorStr:"file extension forbidden.", uploadErrorStr:"Upload error.", maxFileCountErrorStr:"forbidden. Max files number: ", uploadStr:' Change profile picture (Max: 32MB)', deletelStr: "Delete", formData: {}, onError: function (files, status, errMsg, pd) { alertSwal('error','Loading error for: ', JSON.stringify(files)); }, customProgressBar: function(obj,s){// butto l'interfaccia this.statusbar=""; this.abort = $("
").appendTo(this.statusbar).hide(); this.cancel = $("
").appendTo(this.statusbar).hide(); this.filename = $("
").appendTo(this.statusbar).hide(); this.progressDiv = $("
").appendTo(this.statusbar).hide(); this.done = $("
").appendTo(this.statusbar).hide(); this.progressbar = $("
").appendTo(this.progressDiv); this.del = $("
").appendTo(this.statusbar).hide(); }, onSuccess: function (files, data, xhr, pd) { //pd.statusbar.hide(); data = JSON.parse(data); if(data.error==undefined){ var ele = document.getElementById(dom); var fn = function(){}; if(data.s=='ok'){ var fn = function(){ele.src = URLSITO+data.f+'?' + new Date().getTime()}; } alertSwal('success','Upload done.', '',fn); }else{ alertSwal('error','Upload error: ', data.error); } return false; }, onCancel:function(files,pd){ alertSwal('warning','Load cancel in: ',JSON.stringify(files)); } }); } function addPost(){ // new_commentModal var testo = document.getElementById('new_commentModal'); var allegati = document.getElementById('allegatiList'); flag = true; if(testo.value.trim()==''){ alertSwal('warning',"Post empty", 'please fill out the post content',function(){testo.focus()}); flag = false; } if(flag){ viewLoader("Sending..."); var strUri = "txt="+encodeURIComponent(testo.value); $.post('https://cardiologyexcellence.com/addPost',strUri,function(){},'json') .done(function(resp){ if(resp.s=="ok"){ var clb = function(){ testo.value = ''; allegati.innerHTML = ''; $('#newpost').modal('toggle'); social.getUpdate(); } alertSwal('success',"Post sent", '', clb); }else if(resp.s=="noajax"){ alertSwal('error','Access denied', ''); }else{ alertSwal('error',"Error on sending post", ''); }}) .fail(function(){alertSwal('error',"Connection error", '');}) .always(function(resp){hideLoader(resp,0);}); } } function modProfile(obj){ var frm = formica(obj); flag = true; flag = flag && controlForm(frm, 'Name','nome',''); flag = flag && controlForm(frm, 'Surname','cognome',''); flag = flag && controlForm(frm, 'Email','email',''); if(frm.getValue('email')!=''){ flag = flag && controlForm(frm, 'Email','email','','@'); } if(frm.getValue('pass')!=''){ flag = flag && controlForm(frm, 'Password','pass','6','c<'); flag = flag && controlForm(frm, 'Password','pass','pass2','='); } if(flag){ viewLoader('Loading......'); $.post('https://cardiologyexcellence.com/modProfile',frm.buildUri('php'),function(){},'json') .done(function(resp){ if(resp.result=="dup"){ alertSwal('error','Profile editing canceled', 'Email already exists, choose a different one'); }else if(resp.result=="ok"){ var fn = function(){window.location.reload(false);}; alertSwal('success','Profile modified', '',fn); }else if(resp.result=="ko"){ alertSwal('error','Profile editing not valid', 'Mandatory fields are missing'); } }).fail(function(){alertSwal('error','', "Connection error");}) .always(function(resp){hideLoader(resp,0);}); } }