
function Espandi(esegui,NomeElemento){
//alert('carlo');
document.getElementById(NomeElemento).style.display=esegui;
}
function ReplaceAll(Stringa,OLD_Char,NEW_Char)
{
var NewStringa = Stringa;
var StringaSplit = Stringa.split(OLD_Char);
for(Isplit in StringaSplit){
NewStringa = NewStringa.replace(OLD_Char,NEW_Char);
}
return NewStringa;
}
function ConvertToHtml(TMPTxt)
{
TMPTxt = ReplaceAll(TMPTxt,"&xlxtx;","<");
TMPTxt = ReplaceAll(TMPTxt,"&xgxtx;",">");
TMPTxt = ReplaceAll(TMPTxt,"&ylyty;","&lt;");
TMPTxt = ReplaceAll(TMPTxt,"&ygyty;","&gt;");
return TMPTxt;
}
// $(function() {
 $(document).ready(function () {
 //city č il id nome della cittā da NON memorizzare
 $("#cityIDCityMinibox").autocomplete({
 source: function(request, response) {
 $.ajax({
 url: "http://ws.geonames.org/searchJSON",
 dataType: "jsonp",
 data: {
 featureClass: "P",
 style: "full",
 maxRows: 15,
 lang: "it",
 name_startsWith: request.term
},
 success: function(data) {
 response($.map(data.geonames, function(item) {
 
 var provincia = "";
 if (item.adminCode2 != undefined ) provincia = item.adminName2 + "(" + item.adminCode2 + ") ";
 var resulcity = item.name + (item.adminName1 ? ", " + item.adminName1 : "") + (provincia ? ", " + provincia : "") + ", " + item.countryName ;
 var resulcity = StringCity(item.name,item.adminName1,item.countryName,item.adminCode2,item.adminName2);
 return {
 CityName: item.name,
 RegionName: item.adminName1 ,
 CountryName: item.countryName,
 CountyCode: item.adminCode2,
 CountyName: item.adminName2,
 label2: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName + ", " + item.geonameId + " Provincia: (" + item.adminCode2 + ")" + " Provincia: (" + item.adminName2 + ")",
 label: resulcity ,
 value: item.name,
 idvalue: item.geonameId,
 idvalue2: item.adminCode2
}
}))
}
})
},
 minLength: 1
 ,
 select: function(event, ui) {
 //idCity č il id codice della cittā da memorizzare
 document.getElementById("IDCityMinibox").value = ui.item.idvalue;
 
},
 open: function() {
 $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
 close: function() {
 $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
});
var AjaxAlertResult = (function (urlajax,dataajax,successmessage, errormessage) {
$.ajax({
 type: "POST",
 url: urlajax,
 data: dataajax,
 cache: false,
 success: function(){
 alert(successmessage);
},
 error: function(){
 alert(errormessage);
}
});
});
var RichiestaAjax3 = (function (url,DivRis) {
$.ajax({
 url: url,
 cache: true,
 success: function(html){
 $(DivRis).html(html);
}
});
});
var RichiestaAjax4 = (function (url,DivRis) {
$.ajax({
 url: url,
 cache: false,
 success: function(html){
 $(DivRis).html(html);
}
});
});
var scriviCookie = (function (nomeCookie,valoreCookie,durataCookie) {
 var scadenza = new Date();
 var adesso = new Date();
 scadenza.setTime(adesso.getTime() + (parseInt(durataCookie) * 60000));
 document.cookie = nomeCookie + '=' + escape(valoreCookie) + '; expires=' + scadenza.toGMTString() + '; path = /';
});
function leggiCookie(nomeCookie)
{
 if (document.cookie.length > 0)
 {
 var inizio = document.cookie.indexOf(nomeCookie + "=");
 if (inizio != -1)
 {
 inizio = inizio + nomeCookie.length + 1;
 var fine = document.cookie.indexOf(";",inizio);
 if (fine == -1) fine = document.cookie.length;
 return unescape(document.cookie.substring(inizio,fine));
}else{
 return "";
}
}
 return "";
}
function cencellaCookie(nomeCookie)
{
 scriviCookie(nomeCookie,'',-1);
}
function verificaCookie()
{
 document.cookie = 'verifica_cookie';
 var testcookie = (document.cookie.indexOf('verifica_cookie') != -1) ? true : false;
 return testcookie;
}
function StringCity(CityName,RegionName,CountryName,CountyCode,CountyName) {
 var provincia = "";
 if (CountyCode != undefined ) provincia = CountyName + "(" + CountyCode + ") ";
 
 var resulcity = CityName + (RegionName ? ", " + RegionName : "") + (provincia ? ", " + provincia : "") + ", " + CountryName ;
 return resulcity;
}
function StringCityToMap(CityName,RegionName,CountryName,CountyCode,CountyName) {
 var provincia = "";
 if (CountyCode != undefined ) provincia = "(" + CountyCode + ") ";
 
 var resulcity = CityName + (provincia ? "" + provincia : "") + ", " + CountryName ;
 return resulcity;
}
function getcityToViewMaps(geonameId,TagResult,addressMaps,TagResultMaps) {
$.getJSON("http://ws.geonames.org/getJSON?lang=it&geonameId="+ geonameId +"&callback=?",
 {'uID': geonameId},
 function(data){
 var resulcity = StringCityToMap(data.name,data.adminName1,data.countryName,data.adminCode2,data.adminName2);
// showMapJquery("Cerignola","Via Avellino 20","#" + TagResultMaps);
 showMapJquery(resulcity,addressMaps,"#" + TagResultMaps);
// showMapJquery(resulcity,addressMaps,"#" + TagResultMaps);
 // document.onload=initializeMaps(TagResultMaps);
 document.getElementById(TagResult).innerHTML = resulcity;
 //var addressMaps = document.getElementById("address").innerHTML;
//showAddress(resulcity +', ' + addressMaps);
 //showAddress(resulcity +', via Canne 11');
});
 
}
function getcityToViewMapsOLD(geonameId,TagResult,addressMaps,TagResultMaps) {
$.getJSON("http://ws.geonames.org/getJSON?lang=it&geonameId="+ geonameId +"&callback=?",
 {'uID': geonameId},
 function(data){
 var resulcity = StringCity(data.name,data.adminName1,data.countryName,data.adminCode2,data.adminName2);
 document.onload=initializeMaps(TagResultMaps);
 document.getElementById(TagResult).innerHTML = resulcity;
 //var addressMaps = document.getElementById("address").innerHTML;
showAddress(resulcity +', ' + addressMaps);
 //showAddress(resulcity +', via Canne 11');
});
 
}
function getcityToView(geonameId,TagResult) {
$.getJSON("http://ws.geonames.org/getJSON?lang=it&geonameId="+ geonameId +"&callback=?",
 {'uID': geonameId},
 function(data){
// var resulcity = StringCity(data.name,data.adminName1,data.countryName,data.adminCode2,data.adminName2);
 var resulcity = StringCityToMap(data.name,data.adminName1,data.countryName,data.adminCode2,data.adminName2);
 document.getElementById(TagResult).innerHTML = resulcity;
// var addressMaps = document.getElementById("address").innerHTML;
//showAddress(resulcity +', ' + addressMaps);
 //showAddress(resulcity +', via Canne 11');
});
 
}
function getcityToText(geonameId,TagResult) {
 // da inserire per il text edit
$.getJSON("http://ws.geonames.org/getJSON?lang=it&geonameId="+ geonameId +"&callback=?",
 {'uID': geonameId},
 function(data){
 //var resulcity = StringCity(data.name,data.adminName1,data.countryName,data.adminCode2,data.adminName2);
 
 document.getElementById(TagResult).innerText = data.name; //resulcity;
// $("#"+TagResult).value = data.name; 
// $("#"+TagResult).text(data.name);
//$("#cityIDComuneMinibox").append("Password is too short");
});
}
function SetupMaps() {
document.write([
 '<scr'+'ipt src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=', {
 '192.168.40.202': 'ABQIAAAAs_itiooRYfs8omXf7OSCZxT_Rl1m9X8PdmrTb7F_p14TcVuGKxQp-3wLmDLamac4aOgrM4RYktVoMw',
 'domain2.com': 'apikey2',
 'domain3.com': 'apikey3',
 'domainN.com': 'apikeyN'
}[window.location.host],
 '" type="text/javascript"><\/sc'+'ript>'
].join(''));
}
function showMapJquery(CityMaps,addressMaps,ResultMaps) {
$(function()
{
 
$(ResultMaps).gMap({markers: [{address: addressMaps + ", " + CityMaps,
 html: addressMaps}],
 address: addressMaps + ", " + CityMaps,
 zoom: 16});
}); 
}
 var map = null;
 var geocoder = null;
 function initialize() {
 if (GBrowserIsCompatible()) {
 map = new GMap2(document.getElementById("map_canvas"));
map.addControl(new GLargeMapControl);
 //map.setCenter(new GLatLng(37.4419, -122.1419), 15);
 // map.addControl(new GSmallMapControl());
 //map.addControl(new GNavLabelControl());
//map.setMapType(G_SATELLITE_MAP)
 geocoder = new GClientGeocoder();
}
}
 function initializeMaps(TagResult) {
 if (GBrowserIsCompatible()) {
 map = new GMap2(document.getElementById(TagResult));
map.addControl(new GLargeMapControl);
// map.setCenter(new GLatLng(37.4419, -122.1419), 13);
 // map.addControl(new GSmallMapControl());
 //map.addControl(new GNavLabelControl());
//map.setMapType(G_SATELLITE_MAP)
 geocoder = new GClientGeocoder();
}
}
 function showAddress(address) {
 if (geocoder) {
 geocoder.getLatLng(
 address,
 function(point) {
 if (!point) {
 alert(address + " not found");
} else {
 map.setCenter(point, 15);
 var marker = new GMarker(point);
 map.addOverlay(marker);
 marker.openInfoWindowHtml(address);
}
}
 );
}
}
function DecToHex(n){
//converte da decimale (0..255) a esadecimale (stringa a due caratteri)
hex=n.toString(16);
if(hex.length==1) hex="0"+hex; 
return hex.toUpperCase();
}
function HexToDec(s){
//converte da stringa esadecimale a numero decimale
return parseInt(s,16);
}

