(function(){function s(g,b,d){var c=document.createElement("canvas");r(g,c,b,d);return c.toDataURL("image/jpeg",b.quality||.8)}function r(g,b,d,c){var t=g.naturalWidth,n=g.naturalHeight,h=d.width,e=d.height,f=b.getContext("2d");f.save();d=d.orientation;switch(d){case 5:case 6:case 7:case 8:b.width=e;b.height=h;break;default:b.width=h,b.height=e}switch(d){case 2:f.translate(h,0);f.scale(-1,1);break;case 3:f.translate(h,e);f.rotate(Math.PI);break;case 4:f.translate(0,e);f.scale(1,-1);break;case 5:f.rotate(.5*
Math.PI);f.scale(1,-1);break;case 6:f.rotate(.5*Math.PI);f.translate(0,-e);break;case 7:f.rotate(.5*Math.PI);f.translate(h,-e);f.scale(-1,1);break;case 8:f.rotate(-.5*Math.PI),f.translate(-h,0)}b=g.naturalWidth;1048576<b*g.naturalHeight?(d=document.createElement("canvas"),d.width=d.height=1,d=d.getContext("2d"),d.drawImage(g,-b+1,0),b=0===d.getImageData(0,0,1,1).data[3]):b=!1;b&&(t/=2,n/=2);b=document.createElement("canvas");b.width=b.height=1024;d=b.getContext("2d");if(c){c=n;var m=document.createElement("canvas");
m.width=1;m.height=c;m=m.getContext("2d");m.drawImage(g,0,0);for(var m=m.getImageData(0,0,1,c).data,l=0,p=c,k=c;k>l;)0===m[4*(k-1)+3]?p=k:l=k,k=p+l>>1;c=k/c;c=0===c?1:c}else c=1;h=Math.ceil(1024*h/t);e=Math.ceil(1024*e/n/c);for(m=c=0;c<n;){for(p=l=0;l<t;)d.clearRect(0,0,1024,1024),d.drawImage(g,-l,-c),f.drawImage(b,0,0,1024,1024,p,m,h,e),l+=1024,p+=h;c+=1024;m+=e}f.restore()}function k(g){if(window.Blob&&g instanceof Blob){var b=new Image,d=window.URL&&window.URL.createObjectURL?window.URL:window.webkitURL&&
window.webkitURL.createObjectURL?window.webkitURL:null;if(!d)throw Error("No createObjectURL function found to create blob url");b.src=d.createObjectURL(g);this.blob=g;g=b}if(!g.naturalWidth&&!g.naturalHeight){var c=this;g.onload=function(){var b=c.imageLoadListeners;if(b){c.imageLoadListeners=null;for(var d=0,h=b.length;d<h;d++)b[d]()}};this.imageLoadListeners=[]}this.srcImage=g}k.prototype.render=function(g,b){if(this.imageLoadListeners){var d=this;this.imageLoadListeners.push(function(){d.render(g,
b)})}else{b=b||{};var c=this.srcImage.naturalWidth,k=this.srcImage.naturalHeight,n=b.width,h=b.height,e=b.maxWidth,f=b.maxHeight,m=!this.blob||"image/jpeg"===this.blob.type;n&&!h?h=k*n/c<<0:h&&!n?n=c*h/k<<0:(n=c,h=k);e&&n>e&&(n=e,h=k*n/c<<0);f&&h>f&&(h=f,n=c*h/k<<0);var c={width:n,height:h},l;for(l in b)c[l]=b[l];l=g.tagName.toLowerCase();"img"===l?g.src=s(this.srcImage,c,m):"canvas"===l&&r(this.srcImage,g,c,m);if("function"===typeof this.onrender)this.onrender(g)}};"function"===typeof define&&define.amd?
define([],function(){return k}):this.MegaPixImage=k})();
$(document).ready(function(){function s(a,b,d,g){a instanceof google.maps.LatLng?(g=d,d=b):a=new google.maps.LatLng(a,b);k();$("[cid='latitudeInput']").val(a.lat());$("[cid='longitudeInput']").val(a.lng());d&&q.panTo(a);p=new google.maps.Marker({position:a,map:q,draggable:!0,animation:g?google.maps.Animation.DROP:null});google.maps.event.addListener(p,"dragend",function(a){s(a.latLng,!1,!1);c(a.latLng,function(a,b){h(b,a)?($("[cid='enderecoInput']").val(a),$("#adrress-incident").html(a)):($("[cid='enderecoInput']").val(e),
$("#adrress-incident").html(e),r(e),k())})})}function r(a){v&&clearTimeout(v);$("#pop-message").html(a).show();v=setTimeout(function(){$("#pop-message").fadeOut()},4E3)}function k(){p&&(p.setMap(null),google.maps.event.clearListeners(p,"dragend"),p=null);$("[cid='latitudeInput']").val("");$("[cid='longitudeInput']").val("")}function g(){w||(w=!0,navigator.geolocation&&navigator.geolocation.getCurrentPosition(function(a){u=new google.maps.LatLng(a.coords.latitude,a.coords.longitude);s(u,!0,!0);c(a.coords.latitude,
a.coords.longitude,function(a,b){h(b,a)?($("[cid='enderecoInput']").val(a),$("#adrress-incident").html(a)):($("[cid='enderecoInput']").val(e),$("#adrress-incident").html(e),r(e),k(),q.setCenter(m))})},function(){s(m,!0,!0);c(m,function(a,b){h(b,a)?($("[cid='enderecoInput']").val(a),$("#adrress-incident").html(a)):($("[cid='enderecoInput']").val(e),$("#adrress-incident").html(e),r(e),k(),q.setCenter(m))})},{enableHighAccuracy:!0}))}function b(a,b){try{var c=new Image;b&&-1<b.indexOf("image")&&(c.onload=
function(){var a=c.height/c.width*800,d;d=(800).toFixed(0);var a=a.toFixed(0),e=document.createElement("canvas"),g=e.getContext("2d");-1<=navigator.userAgent.indexOf("Android")?(e.width=d,e.height=a,g.drawImage(c,0,0,d,a)):(new MegaPixImage(c)).render(e,{width:d,height:a});if(a=e.toDataURL(b))$("input[type=file]")[0].value=null,$("[cid='imageResidedFileBase64Input']").val(a),$("[cid='imageResidedFileTypeInput']").val(b)},c.src=a)}catch(d){}}function d(a){$("#errosPanel").append(a+"<br/>")}function c(a,
b,c){var d;a instanceof google.maps.LatLng?(d=a,c=b):d=new google.maps.LatLng(a,b);f.geocode({latLng:d},function(a,b){b==google.maps.GeocoderStatus.OK&&"function"==typeof c&&c(a[0].formatted_address,d)})}function t(a,b,c){if(a){if(-1==a.indexOf("Guarda")||-1==a.indexOf("guarda"))a+=", Guarda";f.geocode({address:a},function(a,d){d==google.maps.GeocoderStatus.OK&&(s(a[0].geometry.location,b,!0),"function"==typeof c&&c(a[0].geometry.location,a[0].formatted_address))})}}function n(){var a=$("[cid='enderecoInput']").val();
a&&t(a,!0,function(a,b){h(a,b)?($("[cid='enderecoInput']").val(b),$("#adrress-incident").html(b)):($("[cid='enderecoInput']").val(e),$("#adrress-incident").html(e),k())})}function h(a,b){return a||b?a?l.contains(a):b?-1<b.indexOf("6300")||-1<b.indexOf("Guarda"):!1:!1}var e="Localiza\u00e7\u00e3o fora da Cidade da Guarda",f=new google.maps.Geocoder,m=new google.maps.LatLng(40.538622,-7.269136),l=new google.maps.LatLngBounds;l.extend(new google.maps.LatLng(40.56293,-7.291447));l.extend(new google.maps.LatLng(40.518315,
-7.225014));var p,x={center:l.getCenter(),zoom:12,minZoom:isMobile()?11:13,mapTypeId:google.maps.MapTypeId.ROADMAP,streetViewControl:!1,zoomControl:!isMobile(),mapTypeControl:!isMobile(),panControl:!isMobile()},w=!1,u,v,q=new google.maps.Map(document.getElementById("map-canvas"),x);$("#photopreview").on("click",function(){$("input[type=file]").click()});$("#photo-upload").on("click",function(){$("input[type=file]").click()});$("input[type=file]").on("change",function(){var a=$("input[type=file]")[0].files[0];
if(a&&-1<a.type.indexOf("image/")){$("#photo-upload").html(a.name);var c=new FileReader;c.readAsDataURL(a);c.onload=function(c){$("[cid='imageResidedFileBase64Input']").val("");$("[cid='imageResidedFileTypeInput']").val("");$("#uploadPreviewImage").attr("src",c.target.result);b(c.target.result,a.type)}}else $("#uploadPreviewImage").attr("src",""),$("#photo-upload").html("")});$("#map-search").on("click",n);$("#openmapa").on("click",function(){$("#incidentmap").addClass("opened").css("height",$(window).height()+
108);$("body").css("height",$(window).height()+108);$("body").scrollTop(0);google.maps.event.trigger(q,"resize");g();p?q.panTo(p.getPosition()):q.panTo(l.getCenter());google.maps.event.addListener(q,"dragstart",function(){$("body").scrollTop(0)})});$("#closemapa").on("click",function(){$("#incidentmap").removeClass("opened");$("body").css("height","100%");google.maps.event.clearListeners(q,"dragstart")});$("#resetmapa").on("click",function(){u?(r("Definiu para a sua posi\u00e7\u00e3o atual"),s(u,
!0,!0),c(u,function(a,b){h(b,a)?($("[cid='enderecoInput']").val(a),$("#adrress-incident").html(a)):($("[cid='enderecoInput']").val(e),$("#adrress-incident").html(e),r(e),k())})):(r("Definiu para a posi\u00e7\u00e3o inicial"),$("[cid='enderecoInput']").val(""),$("#adrress-incident").html(""),k(),q.panTo(l.getCenter()))});$("input[type=submit]").on("click",function(){$("#errosPanel").html("");var a=$("[cid='nomeInput']").val(),b=$("[cid='emailInput']").val(),c=$("[cid='categoriaInput']").val(),e=$("input[type=file]")[0].files[0],
g=$("[cid='latitudeInput']").val(),h=$("[cid='longitudeInput']").val(),f=!1;""==a.trim()&&(d("Deve indicar o seu nome"),f=!0);""==b.trim()?(d("Deve indicar o seu email"),f=!0):(a=b.trim(),/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(a)||
(d("Deve indicar um email v\u00e1lido"),f=!0));""==c.trim()&&(d("Deve indicar uma categoria"),f=!0);g&&h||(d("Deve indicar um endere\u00e7o ou escolher um ponto no mapa"),f=!0);e&&(-1==e.type.indexOf("image/")?(d("Apenas s\u00e3o permitidos ficheiros do tipo imagem"),f=!0):5242880<e.size&&(d("Apenas s\u00e3o permitidos ficheiros com m\u00e1ximo de 5MB"),f=!0));f&&$("html, body").animate({scrollTop:$("article").offset().top},"500","swing");return!f});$("[cid='enderecoInput']").on("keypress",function(a){13==
a.keyCode&&(n(),a.preventDefault())});$("[cid='enderecoInput']").on("focus",function(a){$("[cid='enderecoInput']").val()==e&&($("[cid='enderecoInput']").val(""),$("#adrress-incident").html(""))});google.maps.event.addListener(q,"click",function(a){s(a.latLng,!1,!1);c(a.latLng,function(a,b){h(b,a)?($("[cid='enderecoInput']").val(a),$("#adrress-incident").html(a)):($("[cid='enderecoInput']").val(e),$("#adrress-incident").html(e),r(e),k())})});(new google.maps.Rectangle({map:q,clickable:!1,strokeWeight:1,
strokeOpacity:.1,fillOpacity:.05})).setBounds(l);isMobile()||g()});