
var virtualRootApplicationPath = '';

function openCabinDetails(idpackage, idcabin) {
	var params = '?item=cabin&idpackage=' + idpackage + '&id=' + idcabin;
	openPopUpDetails(params, 390, 590, 'no');
}

function openCabinDetailsCabins(idpackage, idcabin) {
	var params = '?item=cabins&idpackage=' + idpackage + '&id=' + idcabin;
	openPopUpDetailsCabins(params, 610, 420, 'no');
}

function openCabinDetailsForShip(idship, idcabin) {
	var params = '?item=cabin&idship=' + idship + '&id=' + idcabin;
	openPopUpDetails(params, 390, 590, 'no');
}

function openCabinPlanDetails(idpackage, idcabin) {
	var params = '?item=cabinplan&idpackage=' + idpackage + '&id=' + idcabin;
	openPopUpDetails(params, 390, 590, 'no');
}

function openCabinPlanDetailsForShip(idship, idcabin) {
	var params = '?item=cabinplan&idship=' + idship + '&id=' + idcabin;
	openPopUpDetails(params, 390, 590, 'no');
}

function openPublicAreaDetails(idpackage, idpublicarea) {
	var params = '?item=publicarea&idpackage=' + idpackage + '&id=' + idpublicarea;
	openPopUpDetails(params, 390, 590, 'no');
}

function openPublicAreaDetailsForShip(idship, idpublicarea) {
	var params = '?item=publicarea&idship=' + idship + '&id=' + idpublicarea;
	openPopUpDetails(params, 390, 590, 'no');
}

function openDeckPlanDetails(idpackage, iddeck) {
	var params = '?item=deckplan&idpackage=' + idpackage + '&id=' + iddeck;
	openPopUpDetails(params, 390, 590, 'no');
}
function openCruiseGallery(idpackage, idcruise) {
	var params = '?item=cruisegallery&idpackage=' + idpackage + '&id=' + idcruise;
	openPopUpDetails(params, 390, 590, 'no');
}
function openShipGallery(idpackage, idship) {
	var params = '?item=shipgallery&idpackage=' + idpackage + '&id=' + idship;
	openPopUpDetails(params, 390, 590, 'no');
}

function openShipGalleryByShip(idship) {
	var params = '?item=shipgallery&idship=' + idship + '&id=' + idship;
	openPopUpDetails(params, 390, 590, 'no');
}

function openPhotoGallery(idphotogallery) {
	var params = '?item=photogallery&idphotogallery=' + idphotogallery + '&id=' + idphotogallery;
	openPopUpDetails(params, 390, 590, 'no');
}

function openPress(id) {
	var params = '?item=press&idpress=' + id + '&id=' + id;
	openPopUpDetails(params, 390, 590, 'no');
}

function openTestedForYou(id) {
	var params = '?item=testedForYou&idtestedforyou=' + id + '&id=' + id;
	openPopUpDetails(params, 390, 590, 'no');
}

function openPortOfCallDetails(idPortOfCalldetail) {
	var params = '?item=portofcalldetail&idpackage=-1&id=' + idPortOfCalldetail;
	openPopUpDetails(params, 390, 590, 'no');
}

function openPopUpDetails(params, _width, _height, scroolbars) {
	openPopUpBox('/aspx/PopUpDetails.aspx' + params, _width, _height);
}

function openPopUpDetailsCabins(params, _width, _height, scroolbars) {
	openPopUpBox('/aspx/PopUpDetails.aspx' + params, _width, _height);
}


function swapImage(filename) {
	var imgMain = document.getElementById('image_main');
	if (imgMain == null)
		return;
	imgMain.src = virtualRootApplicationPath + '/aspx/showimage.aspx?f=../uploads/' + filename + '&w=360&h=250';
}

function swapImageNet(filename) {

	var path = virtualRootApplicationPath + '/aspx/showimage.aspx?f=../uploads/' + filename + '&w=360&h=250&Fix=false';

	jQuery('div.mainImage > img').attr('src', path);
}

function swapImageNetForRepeater(filename, divId) {

	var path = virtualRootApplicationPath + '/aspx/showimage.aspx?f=../uploads/' + filename + '&w=270';

	jQuery("#" + divId + " > div.leftcol > div.imgBg > img").attr('src', path);
}

function swapImageNew(imagemainname, filename, width) {
	var imgMain = document.getElementById(imagemainname);
	if (imgMain == null)
		return;
	imgMain.src = virtualRootApplicationPath + '/aspx/showimage.aspx?f=../uploads/' + filename + '&w=' + width;
}

/* generic function to open popup */
function openPopUp(url, width, height, scroolbars, windowname) {
	width = (width == null) ? 300 : width;
	height = (height == null) ? 490 : height;
	scroolbars = (scroolbars == null) ? "no" : scroolbars;
	if (windowname == null)
		windowname = '_blank';
	popup = window.open(url, windowname, 'toolbar=no,scrollbars=' + scroolbars + ',location=no,directories=no,width=' + width + ',height=' + height);
	popup.focus();
	return popup;
}


/* generic function to open popup */
function openPrintingPopUp(url, width, height, scroolbars, windowname) {
	width = (width == null) ? 1 : width;
	height = (height == null) ? 1 : height;
	scroolbars = (scroolbars == null) ? "no" : scroolbars;
	if (windowname == null)
		windowname = '_blank';
	popup = window.open(url, windowname, 'toolbar=no,scrollbars=' + scroolbars + ',location=no,directories=no,width=' + width + ',height=' + height);
	popup.focus();
	return popup;
}

/* generic function to open popup */
function openPopUpBox(url, _width, _height) {
	_width = (_width == null) ? 300 : _width;
	_height = (_height == null) ? 300 : _height;

	page = virtualRootApplicationPath + url;

	jQuery(document).ready(function () {
		jQuery.fancybox
			({
				'width': _width,
				'height': _height,
				'autoScale': false,
				'transitionIn': 'fade',
				'transitionOut': 'fade',
				'type': 'iframe',
				'scrolling': 'no',
				'enableEscapeButton': true,
				'href': page,
				'showCloseButton': true,
				'onClosed': function () {
					/*restore default body*/
					document.body.style.overflow = "auto";
					document.body.style.paddingRight = "0";
				}
			});
		document.body.style.overflow = "hidden";
		document.body.style.paddingRight = "17px";
	});
}

/* generic function to open div */

function showHideBox(bodyId, imgId) {


	var b = document.getElementById(bodyId).className;
	var i = document.getElementById(imgId).className;



	if (i == 'titleClose') {

		document.getElementById(imgId).className = 'titleOpen';
		document.getElementById(bodyId).className = 'boxVisible';

	}
	else {

		document.getElementById(imgId).className = 'titleClose';
		document.getElementById(bodyId).className = 'boxHide';

	}
}


function showMenu(obj) {
	var e = obj.style.height;

	if (e == '25px') {
		obj.style.height = '100%';
	}

	if (e == '100%') {
		obj.style.height = '25px';
	}
	else {
		obj.style.height = '100%';
	}
}

function showHideCabinCategory(idtbody) {
	var tbody = document.getElementById('category_' + idtbody);
	var tdtitle = document.getElementById('title_' + idtbody);
	if (tbody.style.display == '') {
		tbody.style.display = 'none';
		tdtitle.className = 'titleclose';
	}
	else {
		tbody.style.display = '';
		tdtitle.className = 'titleopen';
	}
}

function showHideBlock(idBlock) {
	var object = $("block_" + idBlock);
	var objtitle = $('tit_' + idBlock);
	if (object.style.display == '') {
		object.style.display = 'none';
		objtitle.removeClassName('opened');
		objtitle.addClassName('closed');
	}
	else {
		object.style.display = '';
		objtitle.removeClassName('grdClosed');
		objtitle.addClassName('grdOpened');
	}
}

function showHideWucSearchTab(idWucSearchToShow, idWucSearchToHide) {
	var wucSearchToShow = document.getElementById(idWucSearchToShow);
	if (wucSearchToShow != null) {
		wucSearchToShow.style.display = 'block';
	}
	var wucSearchToHide = document.getElementById(idWucSearchToHide);
	if (wucSearchToHide != null) {
		wucSearchToHide.style.display = 'none';
	}
}

function openLink(link) {
	window.open(link, "_self");
}

function goTop() {
	if ($('idAnchorTop') == null) {
		new Insertion.Top($$('body')[0], '<a href="javascript: void(0);" id="idAnchorTop" name="anchorTop" ></a>  ');
	}
	if (window.location.href.indexOf('#anchorTop') > 0)
		window.location = window.location;
	else
		window.location = window.location + '#anchorTop';
}

function printPackageWithMonth() {
	var month = jQuery('#hiddenMonth').val();
	printPackage(month);
}

function printPackage(urlRwMonth) {
	var conjunction;
	var url;

	if (urlRwMonth != null && urlRwMonth != '') {
		conjunction = urlRwMonth.indexOf('?') > 0 ? '&' : '?';
		url = urlRwMonth + conjunction + 'print=1';
	}
	else {
		conjunction = window.location.href.indexOf('?') > 0 ? '&' : '?';
		url = window.location.href + conjunction + 'print=1';
	}

	if ($('packageDescriptionBox').getStyle('display') != 'none') {
		url += '&packageDescriptionBox=1';
	}

	var cabins = $A($$('tbody'));
	cabins.each(function (obj) {
		if ($(obj).identify().startsWith('category_')) {
			if ($(obj).getStyle('display') != 'none')
				url = url + '&' + $(obj).identify() + '=1';
		}
	});

	openPrintingPopUp(url, 950, 590, 'yes');
}

function arrangePrint() {
	var query = $H(window.location.href.toQueryParams());
	query.each(function (pair) {
		if ($(pair.key) != null) {
			$(pair.key).show();
			if (pair.key == 'packageDescriptionBox')
				$(pair.key).removeClassName('boxHide');
		}
	});
	var packageCondition = jQuery('#packageConditionsBox');
	if (packageCondition != null) {
		jQuery('#packageConditionsBox').show();
	}
	window.print();
}
function showHideBoxEfx(title, body) {

	titleObj = $(title);
	bodyObj = $(body);
	if (titleObj == null || bodyObj == null)
		return;
	titleObj.toggleClassName("open");
	titleObj.toggleClassName("close");
	Effect.toggle(bodyObj, 'slide', { duration: 0.6 });
}
function openShowMi() {
	//todo: spostare il link web.config
	conspsite = window.open('http://call.showmi.tv/call/cha2', "", "toolbars=no,channelmode=no,status=no,fullscreen=yes,scrollbars=yes,resizable=yes");
}
function checkShowMiButton() {
	var url = virtualRootApplicationPath + '/ashx/Proxy.ashx?http://call.showmi.tv/btn_free/cha2';
	// notice the use of a proxy to circumvent the Same Origin Policy.
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function (transport) {
			if (transport.responseText == 'ok') {
				$('callShowMiContainer').show();
			}
		}
	});
}

function JqueryCheckShowMiButton() {
	var url = virtualRootApplicationPath + '/ashx/Proxy.ashx?http://call.showmi.tv/btn_free/cha2';
	jQuery.ajax(
				 {
					 method: 'get',
					 url: url,
					 success: function (msg) {
						 if (msg == 'ok')
						 { jQuery('#callShowMiContainer').show(); }
					 }
				 });
}


function CallNewsLetter() {
	openPopUpBox('/aspx/PopUpNewsletter.aspx', 420, 280);
}


function LoadPopUpInDiv(object, item, idPackage, id, tabSelected, tabOther1, tabOther2, tabOther3, showclose, idCobrand) {
	var params = {
		item: item,
		idPackage: idPackage,
		id: id,
		Key: object,
		Tab: tabSelected,
		showclose: showclose,
		idCobrand: idCobrand
	};

	url = virtualRootApplicationPath + '/aspx/PopUpDetails.aspx?' + jQuery.param(params);

	jQuery("#" + tabOther1).removeClass('selected');
	jQuery("#" + tabOther2).removeClass('selected');

	if (tabOther3 != undefined)
	  jQuery("#" + tabOther3).removeClass('selected');
  
	jQuery("#" + tabSelected).addClass('selected');

	jQuery("#" + object).html('<p><img src="../images/loading.gif" width="32" height="32" /></p>');
	jQuery("#" + object).show();
	jQuery("#" + object).load(url + ' #onlyContent', function (responseText, textStatus, req) {
		if (textStatus == "error") {
			jQuery("#" + object).html('<p style="dispay: none;">..ops..</p>');
		}
		});
	return false;
}

function CloseDiv(object, tab) {
	jQuery("#" + object + "").hide();
	jQuery("#" + tab + "").removeClass('selected');
}
