if (urlDominio == "" || typeof( urlDominio ) == "undefined")
{
	// La URL predefinita e' sempre quella di TRAVEL.CO
	urlDominio = "http://www.travelco.it/it/";
}
	
function creaTabellaViaggio(queryString, idTabella, Destinazione)
{
	jQuery("#tabella_" + idTabella).jqGrid({ 
		url: urlDominio + 'webservices/proxy-tabelle.php?' + queryString + '&actionUrl=intranet_tabella_travelco',
		datatype: "json", 
			
		gridComplete: function()
		{
			var _righe = $("#tabella_" + idTabella + " .jqgrow");
			for (var i = 0; i < _righe.length; i++) 
			{
				// ! cells[11] corrisponde a catalogo, ultimo elemento ! //
				if (_righe[i].cells[11].innerHTML == "1")
					_righe[i].attributes["class"].value += " catalogoAttivo ";
			}
		}, // gridComplete
		
		colNames:['Struttura', 'Categoria', 'Partenza', 'Partenza da', 'Durata', 'Trattamento', 'Tipologia', 'T.O.', 'Prezzo Totale', 'Prezzo', 'Delta %', 'Catalogo'], 
		colModel:[ 
				  {name:'Hotel',index:'Hotel', width:120, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Categoria',index:'Categoria', width:70, align: 'center', searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Data_partenza',index:'Data_partenza', width:75, searchoptions: { sopt: ['eq', 'lt', 'gt']}}, 
				  {name:'Aeroporto',index:'Aeroporto', width:120, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Durata',index:'Durata', width:100, search:false}, 
				  {name:'Trattamento',index:'Trattamento', width:80, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Tipologia',index:'Tipologia', width:80, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Tour_Operator',index:'Tour_Operator', width:80, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Prezzo_totale',index:'Prezzo_totale', width:80, align: 'center', searchoptions: { sopt: ['le', 'lt', 'gt', 'ge', 'eq']}},
				  {name:'Prezzo_TC',index:'Prezzo_TC', width:40, align: 'center', searchoptions: { sopt: ['le', 'lt', 'gt', 'ge', 'eq']}},				  
				  {name:'DeltaPercentuale',index:'DeltaPercentuale', width:70, align: 'center'},
				  {name:'Catalogo',index:'Catalogo', hidden:true, search:false}
				 ], 
		rowList:[10,20,30, 50, 100], 
		rowNum:20, 
		height: "100%", 
		pager: "#pager_" + idTabella,
		caption: Destinazione,
		sortname: "Data_partenza",
		viewrecords: true		
	}); 
	
	jQuery("#tabella_" + idTabella).jqGrid('navGrid','#pager_' + idTabella, {edit:false,add:false,del:false,multipleSearch : true, searchtext:"Ricerca"}); 
	
}

function creaTabellaViaggioLastWeek(queryString, idTabella, Destinazione)
{
	jQuery("#tabella_" + idTabella).jqGrid({ 
		url: urlDominio + 'webservices/proxy-tabelle.php?' + queryString + '&actionUrl=intranet_tabella_last_minute_travelco',
		datatype: "json", 
		colNames:['Struttura', 'Categoria', 'Partenza', 'Partenza da', 'Durata', 'Trattamento', 'Tipologia', 'T.O.', 'Prezzo Totale', 'Prezzo', 'Delta %'], 
		colModel:[ 
				  {name:'Hotel',index:'Hotel', width:115, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Categoria',index:'Categoria', width:70, align: 'center', searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Data_partenza',index:'Data_partenza', width:75, searchoptions: { sopt: ['eq', 'lt', 'gt']}}, 
				  {name:'Aeroporto',index:'Aeroporto', width:90, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Durata',index:'Durata', width:100, search: false}, 
				  {name:'Trattamento',index:'Trattamento', width:110, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Tipologia',index:'Tipologia', width:80, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Tour_Operator',index:'Tour_Operator', width:80, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Prezzo_totale',index:'Prezzo_totale', width:80, align: 'center', searchoptions: { sopt: ['le', 'lt', 'gt', 'ge', 'eq']}},
				  {name:'Prezzo_TC',index:'Prezzo_TC', width:40, align: 'center', searchoptions: { sopt: ['le', 'lt', 'gt', 'ge', 'eq']}},
				  {name:'DeltaPercentuale',index:'DeltaPercentuale', width:70, align: 'center'}
				 ], 
		rowList:[10,20,30, 50, 100], 
		rowNum:20, 
		height: "100%", 
		pager: "#pager_" + idTabella,
		caption: Destinazione,
		sortname: "Data_partenza"		
	}); 
	
	jQuery("#tabella_" + idTabella).jqGrid('navGrid','#pager_' + idTabella, {edit:false,add:false,del:false,multipleSearch : true, searchtext:"Ricerca"}); 
} 

function creaTabellaViaggioLastWeekPubblico(queryString, idTabella, Destinazione)
{
	jQuery("#tabella_" + idTabella).jqGrid({ 
		url: urlDominio + 'webservices/proxy-tabelle.php?' + queryString + '&actionUrl=servizi_tabella_last_minute_travelco',
		datatype: "json", 
		colNames:['Struttura', 'Categoria', 'Partenza', 'Partenza da', 'Durata', 'Trattamento', 'Tipologia', 'T.O.', 'Prezzo Totale', 'Prezzo'], 
		colModel:[ 
				  {name:'Hotel',index:'Hotel', width:120, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Categoria',index:'Categoria', width:70, align: 'center', searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Data_partenza',index:'Data_partenza', width:75, searchoptions: { sopt: ['eq', 'lt', 'gt']}}, 
				  {name:'Aeroporto',index:'Aeroporto', width:110, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Durata',index:'Durata', width:100, search: false}, 
				  {name:'Trattamento',index:'Trattamento', width:110, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Tipologia',index:'Tipologia', width:80, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Tour_Operator',index:'Tour_Operator', width:80, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Prezzo_totale',index:'Prezzo_totale', width:80, align: 'center', searchoptions: { sopt: ['le', 'lt', 'gt', 'ge', 'eq']}},
				  {name:'Prezzo_TC',index:'Prezzo_TC', width:80, align: 'center', searchoptions: { sopt: ['le', 'lt', 'gt', 'ge', 'eq']}}
				 ], 
		rowList:[10,20,30, 50, 100], 
		rowNum:20, 
		height: "100%", 
		pager: "#pager_" + idTabella,
		caption: Destinazione,
		sortname: "Data_partenza"		
	}); 
	
	jQuery("#tabella_" + idTabella).jqGrid('navGrid','#pager_' + idTabella, {edit:false,add:false,del:false,multipleSearch : true, searchtext:"Ricerca"}); 
} 


function creaTabellaViaggioPubblica(queryString, idTabella, Destinazione)
{
	jQuery("#tabella_" + idTabella).jqGrid({ 
		url: urlDominio + 'webservices/proxy-tabelle.php?' + queryString + '&actionUrl=servizi_tabella_travelco_pubblica',
		datatype: "json", 
		colNames:['Struttura', 'Categoria', 'Partenza', 'Partenza da', 'Durata', 'Trattamento', 'Tipologia', 'T.O.', 'Prezzo Totale', 'Prezzo'], 
		colModel:[ 
				  {name:'Hotel',index:'Hotel', width:120, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Categoria',index:'Categoria', width:70, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Data_partenza',index:'Data_partenza', width:75, searchoptions: { sopt: ['eq', 'lt', 'gt']}}, 
				  {name:'Aeroporto',index:'Aeroporto', width:120, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Durata',index:'Durata', width:100, search:false}, 
				  {name:'Trattamento',index:'Trattamento', width:140, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Tipologia',index:'Tipologia', width:80, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Tour_Operator',index:'Tour_Operator', width:80, searchoptions: { sopt: ['bw', 'cn']} },
				  {name:'Prezzo_totale',index:'Prezzo_totale', width:60, searchoptions: { sopt: ['le', 'lt', 'gt', 'ge', 'eq']}},
				  {name:'Prezzo_TC',index:'Prezzo_TC', width:60, align: 'center', searchoptions: { sopt: ['le', 'lt', 'gt', 'ge', 'eq']}}
				 ], 
		rowList:[10,20,30, 50, 100], 
		rowNum:20, 
		autowidth:true, 
		height: "100%", 
		pager: "#pager_" + idTabella,
		caption: Destinazione,
		sortname: "Data_partenza"
	}); 
	
	if (typeof( nascondiColonna ) != 'undefined')
	{
		jQuery("#tabella_" + idTabella).hideCol(nascondiColonna).trigger("reloadGrid");
		if (typeof( nuovaLargezzaTabella ) != 'undefined')
			jQuery("#tabella_" + idTabella).setGridWidth(nuovaLargezzaTabella, true);
	}
	jQuery("#tabella_" + idTabella).setGridWidth('100%', true);
	jQuery("#tabella_" + idTabella).jqGrid('navGrid','#pager_' + idTabella, {edit:false,add:false,del:false,multipleSearch : true, searchtext:"Ricerca"}); 
}

function creaTabellaComunicazioni(queryString)
	{
		$("#comunicazioni").jqGrid({ 
			url:'comunicazioni_travelco.php?' + queryString, 
			datatype: "json", 
			colNames:['Data', 'Titolo', 'Fornitore', 'Allegati'], 
			colModel:[ 
					  {name:'Data',index:'Data', formatter: 'date', width:80, searchoptions: { sopt: ['eq', 'lt', 'gt']}},  
					  {name:'Titolo',index:'Titolo', width:320, searchoptions: { sopt: ['bw', 'cn']} },
					  {name:'Fornitore',index:'Fornitore', width:150, searchoptions: { sopt: ['bw', 'cn']} }, 
					  {name:'Allegato',index:'document_filename', width:360, searchoptions: { sopt: ['bw', 'cn']} }
					 ], 
			rowList:[10,20,30,50,100], 
			rowNum:20, 
			height: "100%", 
			width: "100%",
			pager: "#pager_comunicazioni",
			caption: "Comunicazioni",
			sortname: "Data",
			sortorder: "desc"			
		}); 
		
	jQuery("#comunicazioni").jqGrid('navGrid','#pager_comunicazioni', {edit:false,add:false,del:false,multipleSearch : true, searchtext:"Ricerca"}); 
	}

 $(document).ready(function(){
	
	$("a[rel*=external]").live('click', function(){
	  this.target = "_blank";
	});
							  
	$(".delme").focus(function(){
		if ($(this).is('input')) {
			var orival = $(this).val();
			$(this).val("");
		}else{
			var orival = $(this).html();
			$(this).html("");
		}

		$(this).blur(function(){
			if($(this).is('input')){
				if ($(this).val() != "" && $(this).val() != orival) {
					$(this).removeClass('delme').unbind('blur').unbind('focus');
				}else{
					$(this).val(orival);
				}
			}else{
				if ($(this).html() != "" && $(this).html() != orival) {
					$(this).removeClass('delme').unbind('blur').unbind('focus');
				}else if ($.browser.safari && $(this).val() != "" && $(this).val() != orival) {
					$(this).removeClass('delme').unbind('blur').unbind('focus');
				}else{
					$(this).html(orival);
				}
			}
		});
	});
	
	$(".checklist .checkbox-select").click(
				function(event) {
					event.preventDefault();
					$(this).parent().addClass("selected");
					$(this).parent().find(":checkbox").attr("checked","checked");
					
				}
			);
			
	$(".checklist .checkbox-deselect").click(
		function(event) {
			event.preventDefault();
			$(this).parent().removeClass("selected");
			$(this).parent().find(":checkbox").removeAttr("checked");
			
		}
	);

	
});
