//Javascript
  $(function(){
			$.fn.fancyzoom.defaultsOptions.imgDir='../listenozze/script/js/jqueryfancyzoom/img/';//very important must finish with a /
        $('#gallery a').fancyzoom(); 
        $('a.tozoom').fancyzoom({Speed:400});
        $('a').fancyzoom({overlay:0.8});
        $("img.fancyzoom").fancyzoom();
			$('#alert_div').corner();
			$('#menu_2').corner("bottom 12px");
			$('#logo_cont').corner("top 12px");
			$('#logo_cont_2').corner("top 12px");
			$('#copy_ext').corner("top 12px");
			$('#copyright').corner("top 12px");
			$('#carrello').corner("bottom 12px");
/*			setTimeout(function(){
			 $('span').corner("bl tr 20px");
			},400);*/
	});
//INIZIALIZZAZIONE GOOGLE MAPS
// var initialize = function() {
function initialize(){
  var geocoder = new google.maps.Geocoder();
  var latlng = new google.maps.LatLng(42.745334,12.738430);
  var options = {
    zoom: 5,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById('map'), options);
}
//FUNZIONE PER CREARE LA MAPPA E CENTRARLA SULL INDIRIZZO DELLA FESTA
function createMap(){
	var geocoder = new google.maps.Geocoder();
  var address = document.getElementById("address").value;
  if(address!=""){
  	if(geocoder){
    	geocoder.geocode( {'address': address}, function(results,status) {
    		if (status == google.maps.GeocoderStatus.OK) {
    			var options = {
    				zoom: 12,
    				center: results[0].geometry.location,
    				mapTypeId: google.maps.MapTypeId.ROADMAP
    			};
    		var map = new google.maps.Map(document.getElementById('map'), options);
    		var marker = new google.maps.Marker({position: results[0].geometry.location, map: map});
    		} else {
    			alert("Problema nella ricerca dell'indirizzo: " + status);
      		}
    	});
    }
  }else{
    alert_div('Inserisci un indirizzo per visualizzarlo sulla mappa');
    $('#address').focus();
    return false;
  }
}
//CARICA TYNIMCE
function carica_tiny(){
  $('textarea.tinymce').tinymce({
    script_url : '../documenti/tiny_mce_jq/tiny_mce.js',

// tinyMCE.init({
	// General options
  	mode : "textareas",
  	theme : "advanced",
  	readonly : true,
  
  	// Theme options
  	theme_advanced_buttons1 : "bold",
  	theme_advanced_disable : "bold",
  
  	// Example content CSS (should be your site CSS)
  	content_css : "css/content.css",
  
  	// Replace values for the template plugin
  	template_replace_values : {
  		username : "Some User",
  		staffid : "991234"
  	}
  });
}
//FUNZIONE MYFILE-BROWSER
function myFileBrowser (field_name, url, type, win) {

    // alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing

    /* If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
       the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
       These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */

    var cmsURL = "/honeymooners/gestione-adv/components/ajax/action-ajax.php" //window.location.toString();    // script URL - use an absolute path!
    if (cmsURL.indexOf("?") < 0) {
        //add the type as the only query parameter
        cmsURL = cmsURL + "?type=" + type + "&action=elenco_immagini";
    }
    else {
        //add the type as an additional query parameter
        // (PHP session ID is now included if there is one at all)
        cmsURL = cmsURL + "&type=" + type;
    }

    tinyMCE.activeEditor.windowManager.open({
        file : cmsURL,
        title : 'My File Browser',
        width : 660,  // Your dimensions may differ - toy around with them!
        height : 400,
        resizable : "yes",
        inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
        close_previous : "no"
    }, {
        window : win,
        input : field_name
    });
    return false;
  }
//FUNZIONE VERIFICA DATA
function IsDate(txtDate)
{
    try
    {
      if(txtDate.length==19){
        if(isNaN(txtDate.substring(0, 4))||txtDate.substring(4, 5) != "-"||isNaN(txtDate.substring(5, 7))||txtDate.substring(7, 8) != "-" ||isNaN(txtDate.substring(8, 10))||txtDate.substring(10,11)!= " " ||isNaN(txtDate.substring(11,13))||txtDate.substring(13,14)!= ":" ||isNaN(txtDate.substring(14,16))||txtDate.substring(16,17)!= ":" ||isNaN(txtDate.substring(17,19)))
        {
          return false;
        }else{
          return true;
        }
      }else if(txtDate.length==10){
        if(isNaN(txtDate.substring(0, 4))||txtDate.substring(4, 5) != "-"||isNaN(txtDate.substring(5, 7))||txtDate.substring(7, 8) != "-"||isNaN(txtDate.substring(8, 10)))
        {
          return false;
        }else{
          return true;
        }
      }else{
          return null;
      }
    }
    catch (e)
    {
        return null;
    }
}
//FUNZIONE DI ATTIVAZIONE LINK --MODIFICARE CON JQUERY--
function attiva_link(sElement,sFunzione,sParametri){
  var parametri='';
  var i=0;
  if(sParametri!='')
	 {
      var vPar = sParametri.split(';');
      for(var iPar in vPar)
      {
        if(i==0)
        {
          parametri = "'" + vPar[iPar] + "'";
        }else{
          parametri = parametri + ",'" + vPar[iPar] + "'";
        }
        ++i;
      }
  }
	sLink = "javascript: " + sFunzione + "(" + parametri + ")";
	$('#'+sElement).attr("href",sLink);
}
//FUNZIONE PER CATTURARE SCRIPT ALL'INTERNO PAGINA CARICATA CON AJAX
EvalJS = function(elementId) {
	var scripts = document.getElementById(elementId).getElementsByTagName('script');
	var code;
	for (var i = 0; i < scripts.length; i++) {
		code =	scripts[i].innerHTML ? scripts[i].innerHTML : 
			scripts[i].text ? scripts[i].text : 
			scripts[i].textContent;
		try {
			eval(code);
		} catch(e) {
			alert(e);
		}
	}
}
//FUNZIONE PER RIEMPIMENTO CAMPO
function riempi_campo(campo,valore,metodo)
{
  metodo=typeof(metodo)!='undefined'?metodo:0;
  sElement=campo;
  if(metodo==0)
  {
    eval("document.getElementById(\"" + sElement + "\")").value = valore;
  }else{
    eval("document.getElementById(\"" + sElement + "\")").value = replace_stringa(valore," ","_");
  }
}
//FUNZIONE PER CAMBIO STRINGA
function replace_stringa(stringa,dasos,sostituto) {
	while (stringa.indexOf(dasos)>-1) {
		pos = stringa.indexOf(dasos);
		stringa = '' + (stringa.substring(0, pos) + sostituto + stringa.substring((pos + dasos.length), stringa.length));
	}
	return stringa;
}
//FUNZIONE PER CAMBIO IMMAGINE CON DIMENSIONI
function cambia_img(sElement,sPercorso,sImage,iW,iH)
{
  var objImm = eval("document.getElementById(\"" + sElement + "\")");
  if(sImage=="no-image" || sImage=="scegli file immagine" || sImage=="Scegli metodo.")
  {
    ImgTag="<img src=\"" + sPercorso + "blank.png\">";
  }else{
    typeof(iW)=='undefined'? ImgTag="<img src=\"" + sPercorso + sImage + "\">" : ImgTag="<img src=\"" + sPercorso + sImage + "\" width=\"" + iW + "\" height=\"" + iH + "\">";;
  }
  objImm.innerHTML=ImgTag;
}
//FUNZIONI PER CALENDARIO
var oldLink = null;
function setActiveStyleSheet(link, title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (oldLink) oldLink.style.fontWeight = 'normal';
  oldLink = link;
  link.style.fontWeight = 'bold';
  return false;
}
// This function gets called when the end-user clicks on some date.
function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field.
  if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel3"))
    cal.callCloseHandler();
}
function closeHandler(cal) {
  cal.hide();                        // hide the calendar
//  cal.destroy();
  _dynarch_popupCalendar = null;
}
function showCalendar(id, format, showsTime, showsOtherMonths) {
  var el = document.getElementById(id);
  if (_dynarch_popupCalendar != null) {
    // we already have some calendar created
    _dynarch_popupCalendar.hide();                 // so we hide it first.
  } else {
    // first-time call, create the calendar.
    var cal = new Calendar(1, null, selected, closeHandler);
    // uncomment the following line to hide the week numbers
    // cal.weekNumbers = false;
    if (typeof showsTime == "string") {
      cal.showsTime = true;
      cal.time24 = (showsTime == "24");
    }
    if (showsOtherMonths) {
      cal.showsOtherMonths = true;
    }
    _dynarch_popupCalendar = cal;                  // remember it in the global var
    cal.setRange(1900, 2070);        // min/max year allowed.
    cal.create();
  }
  _dynarch_popupCalendar.setDateFormat(format);    // set the specified date format
  _dynarch_popupCalendar.parseDate(el.value);      // try to parse the text in field
  _dynarch_popupCalendar.sel = el;                 // inform it what input field we use
  _dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");        // show the calendar
  return false;
}
var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;
var WEEK = 7 * DAY;

function isDisabled(date) {
  var today = new Date();
  return (Math.abs(date.getTime() - today.getTime()) / DAY) > 10;
}
function flatSelected(cal, date) {
  var el = document.getElementById("preview");
  el.innerHTML = date;
}
function showFlatCalendar() {
  var parent = document.getElementById("display");

  var cal = new Calendar(0, null, flatSelected);

  cal.weekNumbers = false;

  cal.setDisabledHandler(isDisabled);
  cal.setDateFormat("%A, %B %e");

  cal.create(parent);

  cal.show();
}
//Funzione per download file
function apri_file(dir,file,idDiv,brel)
{
  brel=typeof(brel)!='undefined'?brel:'siref';
  var percorso = 'includes/download-inc.php?file='+file+'&dir='+dir;
  window.open(percorso,'down_file')
  if(brel=='siref')
  {
    setTimeout(function () {
  	window.location.replace('index.php?do=HO&'+new Date().getTime());
  	}, 1800);
  }
}
function apri_link_new_win(link,nomefi)
{
  window.open(link,nomefi)
  if(nomefi=='siref')
  {
    setTimeout(function () {
  	window.location.replace('index.php?do=HO&'+new Date().getTime());
  	}, 1800);
  }
}
//Funzione per export dei dati
function export_dati(tipo,tabella,campi,where,filename,testa)
{
  var percorso = 'includes/export-inc.php?tipo='+tipo+'&tabella='+tabella+'&campi='+campi+'&clwhere='+where+'&filename='+filename+'&testa='+testa;
  window.open(percorso,'export');
}
