//JQUERY
$(document).ready(function(){

$("#subscribeContainer").hide();
$("#newsArchive").hide();
$("#newsletterThanks").hide();
$("#pleaseFilter").hide();


$("#newsArchiveLink").click(function () {
  	//	$("#simplePagerNavContent").slideToggle(50);
	$("#simplePagerNavContent").fadeToggle(150)
});    
						

$("#subscribeToggleBt").click(function () {
  	$("#subscribeContainer").slideToggle("slow,");
});  

   						   
//tabtabtab
if (jQuery.support.opacity) { fondu = 'img/tab.png'; } else { fondu = 'img/tab-ie.gif'; }

$("#tab-link-partners").toggle(
	  function () { 
		mostraBarra();
		attivaPartner();
		},
	  function () { 
		nascondiBarra();
		}
);

$("#tab-link-hotels").toggle(
	  function () { 
		mostraBarra();
		attivaHotel();
		},
	  function () { 
		nascondiBarra();
		}
);
	
errore = estraiURL("credentials_error") + estraiURL("denied_error") + estraiURL("disabled_error") + estraiURL("already_logged_error") + estraiURL("session_exist_error");
type   = estraiURL("type");

if (errore != "") {
	mostraBarra();
	if (type == "partner") { attivaPartner(); }	
	if (type == "hotel")   { attivaHotel(); }	
}
	
$("#box-subscribe INPUT.campo").focus( function() {
		$(this).val("");			   
	});

var highestCol = Math.max($("#box-package").height(),$("#box-partner").height());
	$("#box-package").height(highestCol);
	$("#box-partner").height(highestCol);	
});



//UTILITY
//accesso partner e HOTELS
function invia()
{
	if (selezionato == "partner") { destinazione = "http://online.bestoftravel.cz/booking/j_spring_security_check"; }
	if (selezionato == "hotel")   { destinazione = "http://online.bestoftravel.cz/hotel-extranet/j_spring_security_check"; }
    document.accesso.method = "post";
    document.accesso.action = destinazione;
    document.accesso.submit();
}

function mostraBarra() {
	$("#tab").animate({top:"0px"},250); 
}

function nascondiBarra() {
	$("#tab").animate({top:"-50px"},250); 
	$("#tab-link").css({'background':'url(' + fondu + ') no-repeat 0 0px'}); 
}

function attivaPartner() {
	$("#tab-link").css({'background':'url(' + fondu + ') no-repeat 0 -30px'}); 
	selezionato = "partner";
	$("#type").val("partner");
}

function attivaHotel() {
	$("#tab-link").css({'background':'url(' + fondu + ') no-repeat 0 -60px'}); 
	selezionato = "hotel";
	$("#type").val("hotel");
}

jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);
}; 

//estraggo URL
function estraiURL(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
