var mapstep2;
var componentIdList = new Array();
var dlg = "";

$(document).ready(function(){
		$("#nextbtn2").click(function(){
			gostep3('');
		});
		
		
		
		$.ajaxSetup({
					// Disable caching of AJAX responses */
    	cache: false,
		error:function(x,e){
			if(x.status==0){
			alert('You are offline!!\n Please Check Your Network.');
			}else if(x.status==404){
			alert('Requested URL not found.');
			}else if(x.status==500){
			alert('Internal Server Error.');
			}else if(e=='parsererror'){
			alert('Error.\nParsing JSON Request failed.');
			}else if(e=='timeout'){
			alert('Request Time out.');
			}else {
			alert('Unknow Error.\n'+x.responseText);
			}
			$.unblockUI();
		}
	});

});

function _blockUI()
{
	$.blockUI({  
			 message : '<h2><img src="/images/loader.gif" align="absmiddle"/> Loading...</h2>',
			 css: { 
			 border: 'none', 
            padding: '15px', 
            backgroundColor: '#000035', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .95, 
			color: '#FFFFFF'
        	} ,
			overlayCSS:  { 
        		backgroundColor: '#FFFFFF', 
        		opacity:         0.2
    		}
			}); 
}

function gostep2back()
{
			_blockUI();
			if (mapstep2['anno'] != undefined)
			{
			$.get("booking_step2.asp", 
					{	anno:mapstep2['anno'],
						mese:mapstep2['mese'],
						giorno:mapstep2['giorno'],
						adults:mapstep2['adults'],
						children:mapstep2['children'] ,
						childrenAge:mapstep2['childrenAge'],
						ship:mapstep2['ship'] ,
						region:mapstep2['region'],
						portofcall:mapstep2['portofcall'],
						paxtype:mapstep2['paxtype'],
						cruiseid:mapstep2['cruiseid']	},
				   function(data){	
				   				
				          $("#prova").html(data);
				      		$.unblockUI();
				   });
			}
			else
			{
				$.get("booking_step2.asp", 
					{	themecruise: 'y'	},
				   function(data){	
				   				
				          $("#prova").html(data);
				      		$.unblockUI();
				   });
			}
			
}


function gostep2backforAddcruise()
{
			_blockUI();
			if (mapstep2['anno'] != undefined)
			{
			$.get("../booking_step2forAddcruise.asp", 
					{	anno:mapstep2['anno'],
						mese:mapstep2['mese'],
						giorno:mapstep2['giorno'],
						adults:mapstep2['adults'],
						children:mapstep2['children'] ,
						childrenAge:mapstep2['childrenAge'],
						ship:mapstep2['ship'] ,
						region:mapstep2['region'],
						portofcall:mapstep2['portofcall'],
						paxtype:mapstep2['paxtype'],
						cruiseid:mapstep2['cruiseid']	},
				   function(data){	
				   				
				          $("#prova").html(data);
				      		$.unblockUI();
				   });
			}
			else
			{
				$.get("../booking_step2forAddcruise.asp", 
					{	themecruise: 'y'	},
				   function(data){	
				   				
				          $("#prova").html(data);
				      		$.unblockUI();
				   });
			}
			
}


function gostep2forAddcruise()
{
	_blockUI();
			$.post("../booking_step2forAddcruise.asp", 
				   $("#myForm").serialize(),
				   function(data){	
				           $("#prova").html(data);
				      		$.unblockUI();
				   });
}

function gostep2()
{
			_blockUI();
			$.post("booking_step2.asp", 
				   $("#myForm").serialize(),
				   function(data){	
				           $("#prova").html(data);
				      		$.unblockUI();
				   });
}

function gostep2_1()
{
			_blockUI();
			$.post("booking_step2_1.asp", 
				   $("#myForm").serialize(),
				   function(data){	
				           $("#prova").html(data);
				      		$.unblockUI();
				   });
}


function gostep3(cruiseid)
	{
		_blockUI();
		if (cruiseid == "")
			cruiseid = $("#cruise").val();
		var cruiseonly = "";
		var themecd = "";
		if ($("#cruiseonly") != null)
	    cruiseonly = $("#cruiseonly").val();
		var themecd = "";
		if ($("#themecd") != null)
		themecd = $("#themecd").val();
		if (cruiseonly != "0" && cruiseonly != "1")
			cruiseonly = "1";
	    if (cruiseid == "")
		{
			alert("An error has occured\n Please repeat you search");
			location.href = "booking.asp";
		}
		$.get("booking_step3.asp", 
			   {cruise: cruiseid,
			   cruiseonly: cruiseonly,
			   themecd: themecd},
			   function(data){	
				           $("#prova").html(data);
				      		$.unblockUI();
				   });
				
	}
	
	function gostep3forAddcruise(cruiseid)
	{
		_blockUI();
		if (cruiseid == "")
			cruiseid = $("#cruise").val();
		var cruiseonly = "";
		var themecd = "";
		if ($("#cruiseonly") != null)
	    cruiseonly = $("#cruiseonly").val();
		var themecd = "";
		if ($("#themecd") != null)
		themecd = $("#themecd").val();
		if (cruiseonly != "0" && cruiseonly != "1")
			cruiseonly = "1";
	    if (cruiseid == "")
		{
			alert("An error has occured\n Please repeat you search");
			location.href = "CRUISE.asp";q
		}
		
		$.get("../booking_step3forAddcruise.asp", 
			   {cruise: cruiseid,
			   cruiseonly: cruiseonly,
			   themecd: themecd,
			   samepax: $("#samepax").val(),
			   paxbar: $("#paxbar").val()},
			   function(data){	
				           $("#prova").html(data);
				      		$.unblockUI();
				   });
				
	}

function gostep4(ctg)
	{
		_blockUI();
		//alert($("#compid").val());
			$.post("booking_step4.asp", 
				   $("#myForm").serialize(),
				    function(data){	
				           //alert(data);
				           $("#prova").html(data);
				      		$.unblockUI();
				   });

	}
	
	function gostep4forAddcruise(ctg)
	{
		_blockUI();
		//alert($("#compid").val());
			$.post("../booking_step4forAddcruise.asp", 
				   $("#myForm").serialize(),
				    function(data){	
				           //alert(data);
				           $("#prova").html(data);
				      		$.unblockUI();
				   });

	}

	function gostep5(cabinno,catgcode)
	{
		_blockUI();
		
		$.post("booking_step5_to_recap.asp", 
				   $("#myForm").serialize(),					
				   function(data){	
				   		   $("#prova").html(data);
				      		$.unblockUI();
				   });
	}
	
	function gostep5forAddcruise(cabinno,catgcode)
	{
		_blockUI();
		
		$.post("../booking_step5_to_recapforAddcruise.asp", 
				   $("#myForm").serialize(),					
				   function(data){	
				   		   $("#prova").html(data);
				      		$.unblockUI();
				   });
	}
	
	 function finalizebooking()
	{
			_blockUI();
			$("input[type='text']").each(function(i){
             if ($(this).attr("id").match("themecd"))
                 $(this).attr("readonly","");
				 $(this).attr("disabled","");
     		});
			$.post("booking_step7_to_recap_2.asp", 
				   $("#myForm").serialize(),
				    function(data){	
					       //console.log(data);
					      if (data.substring(0,3) == "err")
						  {
							  var mylink = "booking.asp";
/*							  $("#prova").html(<input type='button' class='buttonPrevious' value='Indietro' onclick='javascript:location.href=booking.asp'></div>");*/
							  $("#prova").html("<div style=\"width:756px;height:300px\"><span class=\"testo\" style=\"position:relative;top:150px\"><h2>" + data.substring(3) + "</b></h2><br><br><input type=\"button\" class=\"buttonPrevious\" value=\"Indietro\" onclick=\"javascript:location.href=\'booking.asp'\">");
						  }
						  else
						  {
							 location.href = "/b2b/ricerca_pratiche_risultati_to_detail.asp?bookingnr=" + data;
						  }
				          $.unblockUI();
				   });
	}
	
	
	function finalizebookingforAddcruise()
	{
			_blockUI();
			$("input[type='text']").each(function(i){
             if ($(this).attr("id").match("themecd"))
                 $(this).attr("readonly","");
				 $(this).attr("disabled","");
     		});
			
			$.post("addbooking2.asp", 
				   $("#myForm").serialize(),
				    function(data){	
					       //console.log(data);
					      if (data.substring(0,3) == "err")
						  {
							  var mylink = "../booking.asp";
/*							  $("#prova").html(<input type='button' class='buttonPrevious' value='Indietro' onclick='javascript:location.href=booking.asp'></div>");*/
							  $("#prova").html("<div style=\"width:756px;height:300px\"><span class=\"testo\" style=\"position:relative;top:150px\"><h2>" + data.substring(3) + "</b></h2><br><br><input type=\"button\" class=\"buttonPrevious\" value=\"Indietro\" onclick=\"javascript:location.href=\'../booking.asp'\">");
						  }
						  else
						  {
							 location.href = "/b2b/ricerca_pratiche_risultati_to_detail.asp?bookingnr=" + data;
						  }
				          $.unblockUI();
				   });
	}
	
	function gofwd(pi,panno,pmese,pgiorno,padult,pchildrenage,pship,pport,pnchildren,pregion,pthemecruise,paxtype)
	{
		_blockUI();
		
		
		$.get("booking_step2.asp", { page: pi,
	                                 anno: panno,
	                                 mese: pmese,
	                                 giorno: pgiorno,
	                                 adult: padult,
	                                 childrenage:pchildrenage,
	                                 ship:pship,
	                                 port:pport,
									 children:pnchildren,
									 region:pregion,
									 themecruise:pthemecruise,
									 paxtype:paxtype
	                                 },
	   function(data){		   
		           $("#prova").html(data);
		   $.unblockUI();
	  	}
	  );
		 
		
	}


   function ceccisModal(url)
	 {
	 
		 dlg = viewModalnew(url, "Add Air",750,300);	
	 }

