﻿var jsBaseUrl = "http://www.autonoleggiolowcost.com/";
var jsPageTitle = "AutonoleggioLowCost.com";
var jsNewWinMessage = " (apre collegamento in una nuova finestra)";
var jsLoadPrettyPhoto = false;
var jsPageType = "ContenutoHtml";

var addthis_config = { username: "rentit", data_ga_tracker: "pageTracker", ui_click: true, data_track_clickback: true, data_track_linkback: true };

$(document).ready(
   function() {
      $("input:password").bind("cut copy paste", function(e) { e.preventDefault(); alert("Non è consentito il copia e incolla in un campo password."); });
      $(".photo a").prepend("<span></span>"); //appende span per cornici css thumbnail
      if (jsLoadPrettyPhoto == true) { $("a[rel^='lightbox']").prettyPhoto({ theme: 'dark_rounded' }) }; //inizializza prettyPhoto
      if (jsPageType == "HomePage") {
         setTimeout('location.href = "/?refresh=true"', 600000);
      }
      jqTooltip(); //inizializza ToolTip
      SetTargetBlankJQ(); //inizializza class=targetBlank
      popupExternal(); //inizializza rel=external
      SetTextResizing(); //inizializza pulsanti ridimensionamento testo - DA VERIFICARE
   } //function
);        //document.ready

this.jqTooltip = function() {
   xOffset = 10; yOffset = 20; /* CONFIG */
   $("a.tooltip").hover(function(e) {
      this.t = this.title; this.title = ""; $("body").append("<p id='jqTooltip'>" + this.t + "</p>");
      $("#jqTooltip").css("top", (e.pageY - xOffset) + "px").css("left", (e.pageX + yOffset) + "px").fadeIn("fast");
   },
	function() { this.title = this.t; $("#jqTooltip").remove(); }
	);
   $("a.tooltip").mousemove(function(e) { $("#jqTooltip").css("top", (e.pageY - xOffset) + "px").css("left", (e.pageX + yOffset) + "px"); });
};

function switchViews(obj) { $('#' + obj).slideToggle(); }

function SetTargetBlankJQ() { $("a.targetBlank").each(function(e) { var newTitle = $(this).attr("title") + jsNewWinMessage; $(this).removeAttr("title"); $(this).attr("title", newTitle); $(this).click(function() { window.open(this.href); return false; }) }); };

function SetTextResizing() {
   var FontSizeMin = 10; var FontSizeMax = 22;
   $("#NewsCharDn").click(function() {
      //testo articolo
      size = parseInt($("#testoArticolo").css("font-size")) - 1 + "px";
      if (parseInt(size) >= FontSizeMin) { $("#testoArticolo").css("font-size", size); }
      sizeP = parseInt($("#testoArticolo p").css("font-size")) - 1 + "px";
      if (parseInt(sizeP) >= FontSizeMin) { $("#testoArticolo p").css("font-size", size); }
      sizeD = parseInt($("#testoArticolo div").css("font-size")) - 1 + "px";
      if (parseInt(sizeD) >= FontSizeMin) { $("#testoArticolo div").css("font-size", size); }
      return false;
   });
   $("#NewsCharUp").click(function() {
      //testo articolo
      size = parseInt($("#testoArticolo").css("font-size")) + 1 + "px";
      if (parseInt(size) < FontSizeMax) { $("#testoArticolo").css("font-size", size); }
      sizeP = parseInt($("#testoArticolo p").css("font-size")) + 1 + "px";
      if (parseInt(sizeP) < FontSizeMax) { $("#testoArticolo p").css("font-size", size); }
      sizeD = parseInt($("#testoArticolo div").css("font-size")) + 1 + "px";
      if (parseInt(sizeD) < FontSizeMax) { $("#testoArticolo div").css("font-size", size); }
      return false;
   });
}

//utilizzo: <a href='url' rel='external' /> oppure <a href='url' rel='external[640,480]' />
function popupExternal() {
   var popupRE = /external\[(\d+),(\d+)\]/gi; var links = $('a[rel^="external"]'); var rel, width, height;
   links.click(function() {
      rel = $(this).attr('rel');
      if (rel == "external") { window.open($(this).attr('href')); return false; } 
      else if (rel.match(popupRE)) {
         width = RegExp.$1; height = RegExp.$2;
         window.open($(this).attr('href'), '', 'width=' + width + ',height=' + height + ',scrollbars=yes'); return false;
      }
   });
   links.each(function(e) {
      rel = $(this).attr('rel');
      if (rel == "external" || rel.match(popupRE)) {
         var newTitle = $(this).attr("title") + jsNewWinMessage; $(this).removeAttr("title"); $(this).attr("title", newTitle);
      }
   });
}

function centreWinPopUp(pageFile, popUpName, w, h, scroll, resize) {
   var winLeft = (screen.width - w) / 2;
   var winTop = (screen.height - h) / 2;
   winProperties = 'height=' + h + ',width=' + w + ',top=' + winTop + ',left=' + winLeft + ',scrollbars=' + scroll + ',toolbar=no,resizable=' + resize + ',status=no'
   if (!window.winPopUp)
   { winPopUp = window.open(pageFile, popUpName, winProperties) }
   else {
      if (!winPopUp.closed)
      { winPopUp.focus(); }
      else
      { winPopUp = window.open(pageFile, popUpName, winProperties) }
   }
}

function newwin(url, nome, larghezza, altezza) {
   finestra = window.open(url, nome, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=" + larghezza + ",height=" + altezza);
   return false;
}

function getFrameBookingHome() {
    document.write("<iframe src='/utils/BookingFormHome.aspx' id='BookingFormHome' frameborder='0' border='0'></iframe>");
}

function AddToFavorites() {
   if (window.sidebar) // firefox
      window.sidebar.addPanel(jsPageTitle, jsBaseUrl, "");
   else if (window.opera && window.print) { // opera
      var elem = document.createElement('a');
      elem.setAttribute('href', jsBaseUrl);
      elem.setAttribute('title', jsPageTitle);
      elem.setAttribute('rel', 'sidebar');
      elem.click();
   }
   else if (document.all) // ie
      window.external.AddFavorite(jsBaseUrl, jsPageTitle);
}

function SendEncodedEmail(encodedEmail) {
   var email = "";
   for (i = 0; i < encodedEmail.length; ) {
      var letter = "";
      letter = encodedEmail.charAt(i) + encodedEmail.charAt(i + 1)
      email += String.fromCharCode(parseInt(letter, 16));
      i += 2;
   }
   location.href = email;
}

function getCookie(Name) {
   var re = new RegExp(Name + "=[^;]+", "i"); //construct RE to search for target name/value pair
   if (document.cookie.match(re)) //if cookie found
      return document.cookie.match(re)[0].split("=")[1] //return its value
   return ""
}

function setCookie(name, value) {
   var today = new Date();
   var expiry = new Date(today.getTime() + 60 * 24 * 60 * 60 * 1000);
   document.cookie = name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
}


