var xmlHttp;
var xmlHttp_ritorno;
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
var prevSel=1;
var idAcquisto="2";
var site=" ";
var msgDel=" ";

function redirectToHome(path){
	window.location=path;
}

function openWindow(pagina)
{ 
		win=open(pagina, 'info_pop', 'toolbar=no,status=no,Width=900,Height=700,directories=no,scrollbars=yes,location=no,resize=yes,menubar=no');		
		win.focus();
}

function resetHeight(){
	document.getElementById('leftdiv').style.height="100%";
	document.getElementById('centerdiv').style.height="100%";
	document.getElementById('container').style.height="100%";	
}

function enableStepMenu(){
	if(isset(document.getElementById('main_div_step_menu')))
		document.getElementById('main_div_step_menu').style.display='block';
}

function selectNoDefault(selectField){
	if (document.getElementById(selectField.id).selectedIndex==0) document.getElementById(selectField.id).selectedIndex=prevSel;
	prevSel=1;
}

function storeSelected(selectField){
	prevSel=document.getElementById(selectField.id).selectedIndex;
}

var isAgenzia=0;
function js_login(msg1, msg2, agz){	
    isAgenzia=agz;
	if (document.formLogin.username.value.length<4){
		alert(msg1);
		document.formLogin.username.value="";
		document.formLogin.username.focus();
		return;
	}
	else if (document.formLogin.pwd.value.length<4){
		alert(msg2);
		document.formLogin.pwd.value="";
		document.formLogin.pwd.focus();
		return;
	}
	else 
	{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="check_login.php";		
		var params = "username="+document.formLogin.username.value+"&pwd="+document.formLogin.pwd.value; 
		xmlHttp.onreadystatechange=loginStateChanged;		
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "Keep-Alive");		
		xmlHttp.send(params);		
	}	
}

function loginStateChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   	{ 
	 	   var stringa=xmlHttp.responseText;
			 if (stringa==0)			
			 {
			    document.getElementById("main_login_error").style.display="block";			
					disableLogin(1);
		   }
			 else
			 {
			    //enableLogin(stringa, isAgenzia);
					//alert(stringa);
					var resp=stringa.split("|*|");
					redirectToHome("index.php?lang="+resp[3]);
					//redirectToHome("index.php?lang="+stringa);
		   }
    }
}

function enableLogin(stringa, agz){
	if(agz==1) {
		window.location="./";
		return;
	}
	else{
		var val = stringa.split('-');
		var inner;
		document.getElementById("main_login").style.display="none";
		document.getElementById("main_login_success").style.display="block";		
		document.getElementById("main_login_error").style.display="none";

		var inner_login="<p>";
		var strmaiuscola=stringa.toUpperCase();
		if (strmaiuscola.indexOf("PRIMARETE")==-1)
			 inner_login=inner_login+"<img class=\"clickable\" src=\"./images/logout.gif\"alt=\"logout?\" title=\"logout?\" onClick=\"javascript:this.blur; javascript:js_logout();\"/>";
		inner_login=inner_login+"<strong>"+val[1]+" "+val[0]+"!</strong></p>";
		document.getElementById("main_login_success").innerHTML=inner_login;

		if (isset(document.getElementById("leftdiv_interno")))
		{ 
			 var conf=val[2].substring(0, 1);
		 	 if (conf=="U")
				inner="<ul style=\"margin-left: 20px; padding-top:5px; margin-bottom:10px; color: #32536D;\"><span style=\"font-weight:bold; font-size:14px;\">Menu</span><li style=\"margin-top:5px;\"><a href=\"area_riservata.php?op=1&new=1\" class=\"menu\">Biglietti Emessi</a></li><li style=\"margin-top:5px;\"><a href=\"area_riservata.php?op=2&new=1\" class=\"menu\">Preventivi</a></li><li style=\"margin-top:5px;\"><a href=\"javascript:js_logout()\" class=\"menu\">Logout</a></li>";
			 else
			 	inner="<ul style=\"margin-left: 20px; padding-top:5px; margin-bottom:10px; color: #32536D;\"><span style=\"font-weight:bold; font-size:14px;\">Menu</span><li style=\"margin-top:5px;\"><a href=\"area_riservata.php?op=1&new=1\" class=\"menu\">Biglietti Emessi</a></li><li style=\"margin-top:5px;\"><a href=\"area_riservata.php?op=2&new=1\" class=\"menu\">Preventivi</a></li><li style=\"margin-top:5px;\"><a href=\"area_riservata.php?op=3\" class=\"menu\">Diritti di Prenotazione</a></li><li style=\"margin-top:5px;\"><a href=\"javascript:js_logout()\" class=\"menu\">Logout</a></li>";
			document.getElementById("leftdiv_interno").innerHTML=inner;
			            //"<ul style=\"margin-left: 20px; padding-top:5px; margin-bottom:10px; color: #32536D;\"><span style=\"font-weight:bold; font-size:14px;\">Menu</span><li style=\"margin-top:5px;\"><a href=\"area_riservata.php?op=1\" class=\"menu\">Biglietti Emessi</a></li><li style=\"margin-top:5px;\"><a href=\"area_riservata.php?op=2\" class=\"menu\">Preventivi</a></li><li style=\"margin-top:5px;\"><a href=\"area_riservata.php?op=3\" class=\"menu\">Diritti di Prenotazione</a></li><li style=\"margin-top:5px;\"><a href=\"javascript:js_logout()\" class=\"menu\">Logout</a></li>";
			 document.getElementById("leftdiv_interno").style.display="block";
		}
	  if (isset(document.getElementById("agencyArea")))
		   document.getElementById("agencyArea").style.visibility="visible";	
		if (isset(document.getElementById("newsletter_div")))
			 document.getElementById("newsletter_div").style.display="none";	
		if (isset(document.getElementById("signup")))
			 document.getElementById("signup").style.display="none";		
	}
	if(isset(document.getElementById("signup_page_hidden_check"))) redirectToHome(".");
}
	
function disableLogin(val){
	document.getElementById("main_login").style.display="block";
	document.formLogin.username.value="";
	document.formLogin.pwd.value="";
	if(val) document.formLogin.username.focus();
	document.getElementById("main_login_success").style.display="none";	
	if(isset(document.getElementById("leftdiv_interno")))
		document.getElementById("leftdiv_interno").style.display="none";
	if(isset(document.getElementById("agencyArea")))
		document.getElementById("agencyArea").style.visibility="hidden";
	if(isset(document.getElementById("newsletter_div")))
		document.getElementById("newsletter_div").style.display="block";	
	if(isset(document.getElementById("signup")))
		document.getElementById("signup").style.display="block";		
}
	
function js_logout(){		
	window.location = "./logout.php"	
}

function isEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
		return 1;
	else
		return 0;
}	

function checkContactForm(cForm, msg1, msg2, msg3, msg4){
	var email = cForm.email.value;
	var name = cForm.name.value;
	var subject = cForm.subject.value;
	var message = cForm.message.value;
	if (name.length < 2 || !isNaN(name)){
		alert(msg1);
		cForm.name.value="";
		cForm.name.focus();
		return;
	}	
	if (email.length==0||isEmail(email)==0) {
		alert(msg2);
		cForm.email.value="";
		cForm.email.focus();
		return;
	}
	if (subject.length < 2 || !isNaN(subject)){
		alert(msg3);
		cForm.subject.value="";
		cForm.subject.focus();
		return;
	}
	if (message.length < 2 || !isNaN(message)){
		alert(msg4);
		cForm.message.value="";
		cForm.message.focus();
		return;
	}		
	cForm.submit();
}

// Browser Detect
function checkBrowser(msg1,msg2,msg3, msg4){
	if(BrowserDetect.browser!="Explorer"&&BrowserDetect.browser!="Firefox"&&BrowserDetect.browser!="Safari"){
	   document.getElementById('checkCompatibility').style.display="inline";
	   return msg1;
	}
	else if(BrowserDetect.browser=="Explorer"&&parseInt(BrowserDetect.version)<7){
		document.getElementById('checkCompatibility').style.display="inline";
		return msg2;
	}
	else if(BrowserDetect.browser=="Firefox"&&parseInt(BrowserDetect.version)<3){	
		document.getElementById('checkCompatibility').style.display="inline";
		return msg3;
	}
	else if(BrowserDetect.browser=="Safari"&&(parseInt(BrowserDetect.version)/100)<5){	
		document.getElementById('checkCompatibility').style.display="inline";
		return msg4;
	}
}

function checkBrowserFooter(){
	if(BrowserDetect.browser!="Explorer"&&BrowserDetect.browser!="Firefox"&&BrowserDetect.browser!="Safari"){
		document.getElementById('footer-back').style.display="none";
		document.getElementById('footer-backIE6').style.display="block";
	}
	else if(BrowserDetect.browser=="Explorer"&&parseInt(BrowserDetect.version)<7){
		document.getElementById('footer-back').style.display="none";
		document.getElementById('footer-backIE6').style.display="block";
	}
	else if(BrowserDetect.browser=="Firefox"&&parseInt(BrowserDetect.version)<3){	
		document.getElementById('footer-back').style.display="none";
		document.getElementById('footer-backIE6').style.display="block";
	}
	else if(BrowserDetect.browser=="Safari"&&(parseInt(BrowserDetect.version)/100)<5){	
		document.getElementById('footer-back').style.display="none";
		document.getElementById('footer-backIE6').style.display="block";
	}
}


function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
	return true
}

// stringa data, tipo conversione (0: gg/mm/aaaa->aaaammdd, 1: aaaammdd->gg/mm/aaaa)
function convertDate(dtStr,opt){
	switch(opt){
		case 0:{
			var pos1=dtStr.indexOf(dtCh)
			var pos2=dtStr.indexOf(dtCh,pos1+1)
			var strDay=dtStr.substring(0,pos1)
			var strMonth=dtStr.substring(pos1+1,pos2)
			var strYear=dtStr.substring(pos2+1)
			return strYear+strMonth+strDay;
		}
		case 1:{
			var strDay=dtStr.substring(6);
			var strMonth=dtStr.substring(4,6);
			var strYear=dtStr.substring(0,4);
			return strDay+"/"+strMonth+"/"+strYear;
			}
		default: return 0;	
	}
	return 0;
}

// accetta date nel formato gg/mm/aaaa
function dateCompare(data1, data2){
	var val=-1;
	if (parseInt(convertDate(data1,0))==parseInt(convertDate(data2,0))) val=0;
	else if (parseInt(convertDate(data1,0))>parseInt(convertDate(data2,0))) val=1;
	else if (parseInt(convertDate(data1,0))<parseInt(convertDate(data2,0))) val=2;	
	return val;
}

// data di oggi nel formato 0: gg/mm/aaaaa, 1: aaaammgg
function today(opt){
		var now = new Date();
		var nowDay 	 = now.getDate();
		if(nowDay<10) nowDay = "0"+nowDay;		
		var nowMonth = now.getMonth()+1;
		if(nowMonth<10) nowMonth = "0"+nowMonth;
		var nowYear  = now.getYear();
		switch(opt){
			case 0:{
				return nowDay+"/"+nowMonth+"/"+nowYear;
			}
			case 1:{
				return nowYear+nowMonth+nowDay;
			}
			default: return 0;	
		}
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function bubble (htmlText, idBubble,imgName, link){
	if(!link&&!imgName) document.write("");
	else if(!link) document.write("<image class='"+idBubble+"' id='"+idBubble+"' alt'htmlText' src='images/"+imgName+"'>");
	else document.write("<a href='"+link+"'><image class='"+idBubble+"' id='"+idBubble+"' alt'htmlText' src='images/"+imgName+"'></a>");	
	$(document).ready(function(){		
		$("#"+idBubble).CreateBubblePopup({
											selectable: false,											
											position : 'top',
											align	 : 'center',
											
											innerHtml: htmlText,
		
											innerHtmlStyle: {
																'color':'#000', 
																'text-align':'center'
															},
																				
											themeName: 	'blue',
											themePath: 	'images/jquerybubblepopup-theme'
										 
		});		
	});			
}


function new_bubble (htmlText, idBubble)
{
	$(document).ready(function(){
		if (! $("#"+idBubble).HasBubblePopup())
		{
		$("#"+idBubble).CreateBubblePopup({
											selectable: false,											
											position : 'top',
											align	 : 'center',
											
											innerHtml: htmlText,
		
											innerHtmlStyle: {
																'color':'#000', 
																'text-align':'center'
															},
																				
											themeName: 	'blue',
											themePath: 	'images/jquerybubblepopup-theme'
										 
		});
		}		
	});			
}

//Function isset()
function isset(me) {  
	if (me == null || me == '')  
		return 0;  
	else   return 1; 
} 

//Funzione sleep	
function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}
	
function GetXmlHttpObject()
		{
   	   var xmlHttp=null;
   		 try
   		 {
       		// Firefox, Opera 8.0+, Safari
      		xmlHttp=new XMLHttpRequest();
   		 }
   		 catch (e)
   		 {
       		//Internet Explorer
      		try
      		{
         	 	 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      		}
      		catch (e)
      		{
         	 	 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      		}
   		 }
   		 return xmlHttp;
		}
				 
		
function getAlert(index, val)
		{
		   $.get("./select.php", { id:(index+1), request: 'confirmAlert'}, 
			 function(conf)
			 {				
			    var ar = conf.split( '||');
					if(val<0) alert(ar[index]);
					else alert(ar[index]+" "+val+"!");
			 });
	  }		

function confermaRimuovi(id_biglietto)
{
 		var msg;
		msg="Rimuovere il biglietto " + id_biglietto + "?\nATTENZIONE SE SI PROCEDE IL BIGLIETTO VERRA' ANNULLATO!!!";
 		if (!confirm(msg))
			 msg.close;
 		else
		{
		 	 win=open("area_riservata_annulla_biglietto.php?id_biglietto="+id_biglietto, "Dettaglio", 'toolbar=no,status=no,Width=700,Height=650,directories=no,scrollbars=yes,location=no,resize=yes,menubar=no');
			 win.focus();
			 return;
		}
}  

function scaricaBiglietti(id_biglietto)
{
 		var msg;
		msg="Scaricare i biglietti per la pratica " + id_biglietto + "?";
 		if (!confirm(msg))
			 msg.close;
 		else
		{
		 	 win=open("area_riservata_scarica_biglietti.php?id_biglietto="+id_biglietto, "Dettaglio", 'toolbar=no,status=no,Width=700,Height=650,directories=no,scrollbars=yes,location=no,resize=yes,menubar=no');
			 win.focus();
			 return;
		}
}  

function agencyFeeTable(opt, inizio, fine)
{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			 alert ("Browser does not support HTTP Request");
			 return;
		}
		var url="./order_table.php?requestItem=agencyFeeTable&id="+opt+"&bgn="+inizio+"&fns="+fine;
		xmlHttp.onreadystatechange=orderTTStateChanged;		
		xmlHttp.open("GET",url,true);		
		xmlHttp.send(null);	
}

function orderTicketTable(opt, inizio, fine, req){
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="./order_table.php?requestItem="+req+"&id="+opt+"&bgn="+inizio+"&fns="+fine;
		xmlHttp.onreadystatechange=orderTTStateChanged;		
		xmlHttp.open("GET",url,true);		
		xmlHttp.send(null);	
}

function orderTTStateChanged(){
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   	{ 
	 	var htmlString=xmlHttp.responseText;		
		document.getElementById("main_restricted_div").innerHTML=htmlString;
    }
}

function hideMsg(div1_name, div2_name)
{
 		if (div1_name!="")
			 document.getElementById(div1_name).style.display="none";
 		if (div2_name!="")
			 document.getElementById(div2_name).style.display="none";
}


function salvaPreventivoAj(sess, id_ag, id_u, parametri)
{
	 var msg;
	 msg="Salvare il preventivo " + document.getElementById('id_preventivo').value + "?";
 	 if (!confirm(msg))
			msg.close;
 	 else
	 {
	 		if (document.getElementById('id_preventivo').value=="")
			{
			 	 alert("Per favore, specificate un codice identificativo del preventivo.");
				 document.getElementById('id_preventivo').focus();
			 	 return;
			}
			if (document.getElementById('referente_preventivo').value=="")
			{
			 	 alert("Per favore, specificate il referente del preventivo.");
				 document.getElementById('referente_preventivo').focus();
			 	 return;
			}
			var par = parametri.split('*');
			var num=par[1].split('=');
			var j;
			for (j=0;j<num[1];j++)
			{
			 		if (isset(document.getElementById('booking_andata_'+j)))
					{
					 	 var valori_booking=document.getElementById('booking_andata_'+j).value.split(';');
						 parametri=parametri+"*comp_andata"+j+"="+valori_booking[0]+"*val_andata"+j+"="+valori_booking[10];
					}
			 		if (isset(document.getElementById('booking_ritorno_'+j)))
					{
					 	 var valori_booking=document.getElementById('booking_ritorno_'+j).value.split(';');
						 parametri=parametri+"*comp_ritorno"+j+"="+valori_booking[0]+"*val_ritorno"+j+"="+valori_booking[10];
					}
			}
			document.getElementById('barra_saving').style.display="block";
			xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request");
				return;
			}						
			xmlHttp.onreadystatechange=savePStateChanged;
			xmlHttp.open("GET", "area_riservata_salva_preventivo.php?sess="+sess+"&id_ag="+id_ag+"&id_u="+id_u+"&id_prev="+document.getElementById('id_preventivo').value+"&ref="+document.getElementById('referente_preventivo').value+"&par="+parametri, true);
			xmlHttp.send(null);
	 }
}
function savePStateChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   	{
		 	 var stringa=xmlHttp.responseText;
			 var esito = stringa.split(",");
			 document.getElementById('barra_saving').innerHTML="<div style='font-size: 11px; color: #32536D; font-weight: bold; padding-top: 5px; padding-bottom: 5px;'>"+esito[1]+"</div>";
			 var t=setTimeout("hideMsg('barra_saving', 'preventivoDiv')", 4000);
			 //document.getElementById('barra_saving').style.display="none";
    }
}


/*************************************************************/
/*************************************************************/
/*              SCRIPT PAGINA ticket_details.php             */
/*************************************************************/
/*************************************************************/
//SCARICA UN BIGLIETTO SOLA ANDATA O ANDATA/RITORNO VIA AJAX
//id_ticket --> ID BIGLIETTO DA SCARICARE
//url1      --> URL DA CHIAMARE PER SCARICARE ANDATA
//url2      --> URL DA CHIAMARE PER SCARICARE RITORNO
function scaricaBigliettiAjax(id_ticket,url1,url2)
{
		var msg;
		msg="Scaricare i biglietti per la pratica " + id_ticket + "?";
 		if (!confirm(msg))
			 msg.close;
 		else
		{
			//document.body.style.cursor = "wait";
			if (isset(document.getElementById('barra_loading')))
				 document.getElementById('barra_loading').style.display="block";
			xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request");
				return;
			}
			xmlHttp.onreadystatechange=downloadTTStateChanged;
			xmlHttp.open("GET",url1,true);
			xmlHttp.send(null);
			if (isset(url2))
			{
			 	 sleep(500);
				 xmlHttp_ritorno=GetXmlHttpObject();
				 xmlHttp_ritorno.onreadystatechange=downloadTTStateChanged_ritorno;
				 xmlHttp_ritorno.open("GET",url2,true);
				 xmlHttp_ritorno.send(null);
			}
		}
}
function downloadTTStateChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   	{
			 window.location.reload(true);
			 if (isset(document.getElementById('barra_loading')))
				  document.getElementById('barra_loading').style.display="none";
    }
}
function downloadTTStateChanged_ritorno()
{
    if (xmlHttp_ritorno.readyState==4 || xmlHttp_ritorno.readyState=="complete")
   	{
			 window.location.reload(true);
			 if (isset(document.getElementById('barra_loading')))
					document.getElementById('barra_loading').style.display="none";
    }
}

function showEmailAddress()
{
	 if (document.getElementById('tipo_comunicazione').value=="C")
	 		document.getElementById('email_cliente').style.display="block";
	 else
	 		document.getElementById('email_cliente').style.display="none";
	 return;
}

function startUpload()
{
/*
   if (document.getElementById('titolo_com').value=="")
	 {
	 		alert("Inserire il titolo della Nota/Comunicazione");
			document.getElementById('titolo_com').focus();
			return false;
	 }
   if (document.getElementById('testo_com').value=="")
	 {
	 		alert("Inserire il testo della Nota/Comunicazione");
			document.getElementById('testo_com').focus();
			return false;
	 }
*/   document.getElementById('barra_send_com').style.display= 'block';
   return true;
}

function stopUpload(stringa)
{
	 var esito = stringa.split(",");
	 document.getElementById(esito[1]).innerHTML="<div style='font-size: 11px; color: #32536D; font-weight: bold; padding-top: 5px; padding-bottom: 5px;'>"+esito[2]+"</div>";
	 document.getElementById('titolo_com').value="";
	 document.getElementById('testo_com').value="";
	 document.getElementById('email_addr').value="";
	 document.getElementById('allegato1').value="";
	 document.getElementById('allegato2').value="";
	 var t=setTimeout("hideMsg('"+esito[1]+"', '')", 4000);
   return true;   
}

//   INVIO BILIETTO VIA AJAX DALLA PAGINA DETTAGLIO TICKET   
//   id_ticket --> TICKET ASSOCIATO ALLA COMUNICAZIONE       
//   tipo_comunicazione = 1-->INVIO BIGLIETTO								 
function inviaComunicazioneAj(sess, id_ag, id_u, id_ticket, email_addr, lang, tipo_comunicazione)
{
	 var msg;
	 msg="Inviare il biglietto " + id_ticket + "?";
 	 if (!confirm(msg))
			msg.close;
 	 else
	 {
			document.getElementById('barra_sending').style.display="block";
			xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request");
				return;
			}						
			xmlHttp.onreadystatechange=sendComStateChanged;
			//alert("area_riservata_invia_comunicazione.php?sess="+sess+"&id_ag="+id_ag+"&id_u="+id_u+"&id_ticket="+id_ticket+"&tipo_comunicazione="+tipo_comunicazione+"&email_addr="+email_addr+"&linguacom="+lang);
			xmlHttp.open("GET", "area_riservata_invia_comunicazione.php?sess="+sess+"&id_ag="+id_ag+"&id_u="+id_u+"&id_ticket="+id_ticket+"&tipo_comunicazione=C&sottotipo="+tipo_comunicazione+"&div_sending=barra_sending&email_addr="+email_addr+"&linguacom="+lang, true);
			xmlHttp.send(null);
	 }
}
function sendComStateChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   	{
		 	 var stringa=xmlHttp.responseText;
			 var esito = stringa.split(",");
			 //alert(esito[0]+" --- "+esito[1]);
			 document.getElementById(esito[1]).innerHTML="<div style='font-size: 11px; color: #32536D; font-weight: bold; padding-top: 5px; padding-bottom: 5px;'>"+esito[2]+"</div>";
			 var t=setTimeout("hideMsg('"+esito[1]+"', '')", 4000);
			 //document.getElementById('barra_saving').style.display="none";
    }
}
// FINE INVIO BILIETTO VIA AJAX DALLA PAGINA DETTAGLIO TICKET

/*************************************************************/
/*************************************************************/
/*           FINE SCRIPT PAGINA ticket_details.php           */
/*************************************************************/
/*************************************************************/


function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function js_Keylogin(username,password,chk, e)
{
	var key = window.event ? e.keyCode : e.which;
	if(key==13)
	js_login(username,password,chk);
}

function callSella(url, idTicket){			
		idAcquisto=idTicket;		
		payDel("true")
		window.location=url;		
}

function beforeUnload() {
	var str="";
	if(isset(window.location.href)) {
		str=window.location.href;
		site=str.substr(0,41);		
	}		
	if(idAcquisto=="0") {		
		return;
	}
	else if(notSella()=="true") return;
	else{
		if(confirm(msgDel)) payDel("false");		
		return;
	} 
}

function notSella(){	
	if(site=="https://https://ecomm.sella.it/gestpay/pagam.asp") return "false";
	else return "true";
}

function payDel(wait){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return " ";
	}						
	var url_pay = "pay_status.php?id_acquisto="+idAcquisto+"&wait="+wait;
	xmlHttp.onreadystatechange=payStateChanged;		
	xmlHttp.open("GET",url_pay,true);		
	xmlHttp.send(null);	
}

function payStateChanged(){
	idAcquisto="0";	
}

function salvaPreventivo(idprev)
{
	document.getElementById('id_preventivo').value=idprev;
  document.getElementById('preventivoDiv').style.display = "block";
  document.getElementById('preventivoDiv').style.zIndex = 2;
}

function stampaPreventivo()
{
//$('#preve_div').printElement({printMode:'popup', pageTitle:'Preventivo'}); //, overrideElementCSS:'preventivo_print.css'
$("#preve_div").printElement(
            {
            printMode: 'popup',
						pageTitle:'Preventivo', 
						overrideElementCSS: ['http://www.traghetti.net/styles/print.css']
            });			
/*
   w=window.open();
alert("APERTO");
	 w.document.write($('.preve_div').html());
	 alert($('.preve_div').html());
alert("SCRITTO");
	 w.print();
alert("STAMPATO");
	 w.close();
*/
}

function printit()
{
	if (window.print) 
	{ 
		window.print();   
	} 
	else 
	{ 
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; 
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser); 
		WebBrowser1.ExecWB(6, 1);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";   
	}
} 

function checkUser(){
	var i=1;
	//alert('Registrazione non ancora disponibile');
	if(document.getElementById('loginscelta').value=="" || document.getElementById('passwdscelta').value==""){getAlert(49, '');return;}
	if(isset(document.getElementById('checkloginok')))
		if (document.getElementById('checkloginok').value=="KO"){getAlert(50, '');return;}
	//CONTROLLO CHE ABBIA ACCETTATO LE CONDIZIONI PRIVACY
	if (!document.getElementById('privacy_accept').checked)
	{getAlert(45, '');return;} 
	//CONTROLLO CHE LE 2 EMAIL DIGITATE COINCIDANO
	if (document.getElementById('emailpax_1').value!=document.getElementById('ripeti_emailpax_1').value)
	{getAlert(48, '');return;}
	if (document.getElementById('nomepax_'+i).value=="")
	{	getAlert(51, '');return; }
	if (document.getElementById('cognomepax_'+i).value=="")
	{	getAlert(52, '');return; }
	/*if (document.getElementById('documentopax_'+i).value=="")
	{	getAlert(53, '');return; }
	if (document.getElementById('luogonascitapax_'+i).value=="")
	{	getAlert(54, '');return; }
	 if (document.getElementById('cittapax_1').value=="")
	{	getAlert(57, '');return; }
	if (document.getElementById('cappax_1').value=="")
	{	getAlert(56, '');return; }
	if (document.getElementById('provinciapax_1').value=="--")
	{	getAlert(58, '');return; }
	if (document.getElementById('cellularepax_1').length<5||isNumber(document.getElementById('cellularepax_1'))==0)
	{	getAlert(60, '');return; }*/
	if (document.getElementById('emailpax_1').value==""||isEmail(document.getElementById('emailpax_1'))==0)
	{	getAlert(61, '');return; }
	document.getElementById("signupForm").submit();
}


function js_set_newsis(numPax, ncomp, ar)
{
  var val;
  for (var i=0;i<ncomp;i++)
	{
	   //booking_data = dati_viaggio, pax_req, accom_req, vehicles_req, animals_req, extra_req, prezzi;
		 if (isset(document.getElementById('booking_andata_'+i)))
		 {
	      val=document.getElementById('booking_andata_'+i).value;
		 		var ar_andata=val.split("*|*");

		 		//LE SISTEMAZIONI SONO IN ar_andata[2] AD ES. POL:2:1:2:0:0::E:Poltrona:0,1
		 		var sistemazioni=ar_andata[2].split(";");

		 		//PER OGNI SISTEMAZIONE PRENDO LA LISTA PAX E ASSEGNO A CIASCUN PAX IL CODICE SISTEMAZIONE CORRETTO
		 		for (var j=0;j<sistemazioni.length;j++)
		 		{
	 	       var campi=sistemazioni[j].split(":");  //campi[0]=CODICESIS  campi[2]=TIPOSIS  campi[6]=POSTI_SISTEMAZIONE  campi[8]=DES_SIS   campi[9]=LISTA PAX
					 var passeggeri=campi[9].split(",");
		 			 for (var k=0;k<passeggeri.length;k++)
				   {
					 		//alert('newsis'+i+'0_pax'+(parseInt(passeggeri[k])+1)+"="+campi[2]+'-|||-'+campi[0]+'-|||-'+campi[8]+'-|||-0');
							if (passeggeri[k]=="0" || passeggeri[k]=="1" || passeggeri[k]=="2" || passeggeri[k]=="3" || passeggeri[k]=="4" || passeggeri[k]=="5" || passeggeri[k]=="6" || passeggeri[k]=="7" || passeggeri[k]=="8" || passeggeri[k]=="9")
							{
   	 		      	 document.getElementById('newsis'+i+'0_pax'+(parseInt(passeggeri[k])+1)).value=campi[2]+'-|||-'+campi[0]+'-|||-'+campi[8]+'-|||-'+campi[6];
					 			 //alert('newsis'+i+'0_pax'+(parseInt(passeggeri[k])+1)+"="+campi[2]+'-|||-'+campi[0]+'-|||-'+campi[8]+'-|||-0');
							}
				   }
		    }
		 }
		 //alert(document.getElementById('booking_ritorno_0').value);
		 if (isset(document.getElementById('booking_ritorno_'+i)))
		 {
	   		val=document.getElementById('booking_ritorno_'+i).value;
		 		var ar_ritorno=val.split("*|*");

		 		//LE SISTEMAZIONI SONO IN ar_andata[2] AD ES. POL:2:1:2:0:0::E:Poltrona:0,1
		 		var sistemazioni=ar_ritorno[2].split(";");

		 		//PER OGNI SISTEMAZIONE PRENDO LA LISTA PAX E ASSEGNO A CIASCUN PAX IL CODICE SISTEMAZIONE CORRETTO
		 		for (var j=0;j<sistemazioni.length;j++)
		 		{
	 	       var campi=sistemazioni[j].split(":");  //campi[0]=CODICESIS  campi[2]=TIPOSIS  campi[8]=DES_SIS   campi[9]=LISTA PAX
					 var passeggeri=campi[9].split(",");
		 			 for (var k=0;k<passeggeri.length;k++)
					 {
							if (passeggeri[k]=="0" || passeggeri[k]=="1" || passeggeri[k]=="2" || passeggeri[k]=="3" || passeggeri[k]=="4" || passeggeri[k]=="5" || passeggeri[k]=="6" || passeggeri[k]=="7" || passeggeri[k]=="8" || passeggeri[k]=="9")
   	 		      	 document.getElementById('newsis'+i+'1_pax'+(parseInt(passeggeri[k])+1)).value=campi[2]+'-|||-'+campi[0]+'-|||-'+campi[8]+'-|||-'+campi[6];
					 		//alert('newsis'+i+'1_pax'+(parseInt(passeggeri[k])+1)+"="+campi[2]+'-|||-'+campi[0]+'-|||-'+campi[8]+'-|||-0');
					 }
		    }
		 }
	}

	return;
}


function recalcPrice(id_gruppo, idcomp, numPax, ncomp, ar, id_tratta, cod_tratta, id_tratta_ritorno, key, porto_partenza, porto_arrivo, depdate, deptime, sailingid, shipcode, farecode, lang, phpsess, cod_tratta_ritorno, retdate, rettime, retsailingid, retshipcode, retfarecode, newar, print_bottom, comp_par, ret_comp_par, sistemazioni, ret_sistemazioni, id_agenzia, ipa, buydirect)
{
	var contaEst=0;
	var contaInt=0;
	var contaEstRet=0;
	var contaIntRet=0;
	var strnewsis="";
	var sistemazione;
	var n_esterne=0, n_interne=0, n_esterne_ret=0, n_interne_ret=0;
	var cod_esterne=new Array();
	var des_esterne=new Array();
	var totpax_esterne=new Array();
	var posti_esterne=new Array();
	var cod_interne=new Array();
	var des_interne=new Array();
	var totpax_interne=new Array();
	var posti_interne=new Array();
	var url;

	//ANDATA
	for (var i=1; i <= numPax; i++)
	{
	 	 sistemazione=document.getElementById('newsis'+ncomp+'0_pax'+i).value;
		 //alert("S="+sistemazione);
		 strnewsis=strnewsis+"&newtiposis"+i+"="+sistemazione;
	 	 var tiposis=sistemazione.split('-|||-');   //tiposis[0]=tipo_sistemazione  tiposis[1]=codice_sistemazione   tiposis[2]=descrizione  tiposis[3]=numero posti sistemazione  tiposis[4]=tipo_pax
		 var j=0;
		 var found=0;

		 //CONTROLLO QUANTE CABINE DIVERSE MI SONO STATE RICHIESTE
		 if (tiposis[0]==3)
		 {
				while (j<contaEst && found==0)
				{
						if (cod_esterne[j]==tiposis[1])
							 found=1;
						else
						 	 j++;
				}
				if (found==0) //ANCORA NON PRESENTE: LA AGGIUNGO
				{
						cod_esterne[j]=tiposis[1];
						des_esterne[j]=tiposis[2];
						posti_esterne[j]=parseInt(tiposis[3]);
						if (tiposis[4]!="INFANT" || id_gruppo==48)
						 	 totpax_esterne[j]=1;
						else
						 	 totpax_esterne[j]=0;
						contaEst++;
				}
				else
				{
						if (tiposis[4]!="INFANT" || id_gruppo==48)
						 	 totpax_esterne[j]++;
				}
		 }
		 else if (tiposis[0]==2)
		 {
				while (j<contaInt && found==0)
				{
						if (cod_interne[j]==tiposis[1])
							 found=1;
						else
						 	 j++;
				}
				if (found==0) //ANCORA NON PRESENTE: LA AGGIUNGO
				{
						cod_interne[j]=tiposis[1];
						des_interne[j]=tiposis[2];
						posti_interne[j]=parseInt(tiposis[3]);
						if (tiposis[4]!="INFANT" || id_gruppo==48)
						 	 totpax_interne[j]=1;
						else
						 	 totpax_interne[j]=0;
						contaInt++;
				}
				else
				{
						if (tiposis[4]!="INFANT" || id_gruppo==48)
						 	 totpax_interne[j]++;
				}
		 }
	}
	if (contaInt>0 && id_gruppo==48)
	{
	 	 for (var i=0; i<contaInt; i++)
		 {
		 		 if (posti_interne[i]!=totpax_interne[i])
				 {
				 		alert("Attenzione: devono essere riempiti tutti i "+posti_interne[i]+" posti della sistemazione "+des_interne[i]);
						return;
				 }
		 }
	}
	if (contaEst>0 && id_gruppo==48)
	{
	 	 for (var i=0; i<contaEst; i++)
		 {
		 		 if (posti_esterne[i]!=totpax_esterne[i])
				 {
				 		alert("Attenzione: devono essere riempiti tutti i "+posti_esterne[i]+" posti della sistemazione "+des_esterne[i]);
						return;
				 }
		 }
	}

	for (var i=0; i<contaEst; i++)
	{
	   n_esterne=n_esterne+Math.ceil(totpax_esterne[i]/posti_esterne[i]);
		 cod_esterne[i]="";posti_esterne[i]=0;totpax_esterne[i]=0;
	}

	for (var i=0; i<contaInt; i++)
	{
	   n_interne=n_interne+Math.ceil(totpax_interne[i]/posti_interne[i])
		 cod_interne[i]="";posti_interne[i]=0;totpax_interne[i]=0;
	}

	if (ar==1)
	{
	 	 //RITORNO
		 contaEst=0;contaInt=0;
		 for (var i=1; i <= numPax; i++)
		 {
	 	    sistemazione=document.getElementById('newsis'+ncomp+'1_pax'+i).value;
		 		strnewsis=strnewsis+"&newtiposis"+i+"_ret="+sistemazione;
	 	 		var tiposis=sistemazione.split('-|||-');
		 		var j=0;
				var found=0;
		 		//CONTROLLO QUANTE CABINE DIVERSE MI SONO STATE RICHIESTE
		 		if (tiposis[0]==3)
		 		{
				 	 while (j<contaEst && found==0)
					 {
						   if (cod_esterne[j]==tiposis[1])
							    found=1;
						   else
						 	    j++;
				   }
					 if (found==0) //ANCORA NON PRESENTE: LA AGGIUNGO
				   {
						  cod_esterne[j]=tiposis[1];
							des_esterne[j]=tiposis[2];
							posti_esterne[j]=parseInt(tiposis[3]);
							if (tiposis[4]!="INFANT" || id_gruppo==48)
						 	   totpax_esterne[j]=1;
						  else
						 	   totpax_esterne[j]=0;
						  contaEst++;
				   }
				   else
				   {
						  if (tiposis[4]!="INFANT" || id_gruppo==48)
						 	   totpax_esterne[j]++;
				   }
		    }
		 		else if (tiposis[0]==2)
		 		{
				   while (j<contaInt && found==0)
					 {
						  if (cod_interne[j]==tiposis[1])
							   found=1;
						  else
						 	   j++;
				   }
				   if (found==0) //ANCORA NON PRESENTE: LA AGGIUNGO
				   {
						  cod_interne[j]=tiposis[1];
							des_interne[j]=tiposis[2];
							posti_interne[j]=parseInt(tiposis[3]);
							if (tiposis[4]!="INFANT" || id_gruppo==48)
						 	   totpax_interne[j]=1;
							else
						 	   totpax_interne[j]=0;
						  contaInt++;
				   }
					 else
				   {
						  if (tiposis[4]!="INFANT" || id_gruppo==48)
						 	   totpax_interne[j]++;
				   }
		    }
	   }
		 if (contaInt>0 && id_gruppo==48)
		 {
	 	    for (var i=0; i<contaInt; i++)
		 		{
		 		   if (posti_interne[i]!=totpax_interne[i])
				   {
				 		  alert("Attenzione: devono essere riempiti tutti i "+posti_interne[i]+" posti della sistemazione "+des_interne[i]);
						  return;
				   }
		    }
	   }
		 if (contaEst>0 && id_gruppo==48)
		 {
	 	    for (var i=0; i<contaEst; i++)
		    {
		 		   if (posti_esterne[i]!=totpax_esterne[i])
				   {
				 		  alert("Attenzione: devono essere riempiti tutti i "+posti_esterne[i]+" posti della sistemazione "+des_esterne[i]);
						  return;
				   }
		    }
	   }

		 for (var i=0; i<contaEst; i++)
	      n_esterne_ret=n_esterne_ret+Math.ceil(totpax_esterne[i]/posti_esterne[i]);

	   for (var i=0; i<contaInt; i++)
	   		 n_interne_ret=n_interne_ret+Math.ceil(totpax_interne[i]/posti_interne[i])
	}

	//alert("&newinterne="+n_interne+"&newesterne="+n_esterne+"&newinterne_ret="+n_interne_ret+"&newesterne_ret="+n_esterne_ret);
	document.getElementById("divcomp_"+ncomp).innerHTML = "<div style='width: 610px; text-align:center;'><br /><br /><br /><img src='./images/wait.gif' alt='barra'>Loading...</div>";
	document.getElementById('recalc_div_'+ncomp).style.visibility='hidden';
	strnewsis=strnewsis+"&newinterne="+n_interne+"&newesterne="+n_esterne+"&newinterne_ret="+n_interne_ret+"&newesterne_ret="+n_esterne_ret;

	if (buydirect=="1")
  	 url="http://www.traghetti.net/soap/search_prices_comp_"+id_gruppo+".php?ajax=3&idcomp="+idcomp+"&ncomp="+ncomp+"&id_tratta="+id_tratta+"&codcomp="+cod_tratta+"&id_tratta_ritorno="+id_tratta_ritorno+"&key="+key+"&id_gruppo="+id_gruppo+"&porto_partenza="+porto_partenza+"&porto_arrivo="+porto_arrivo+"&data_andata="+depdate+"&ora_andata="+deptime+"&sailingid="+sailingid+"&shipcode="+shipcode+"&farecode="+farecode+"&lang="+lang+"&page="+phpsess+"&codcomp_ritorno="+cod_tratta_ritorno+"&data_ritorno="+retdate+"&ora_ritorno="+rettime+"&retsailingid="+retsailingid+"&retshipcode="+retshipcode+"&retfarecode="+retfarecode+"&ar="+newar+"&print_bottom="+print_bottom+"&comp_par="+comp_par+"&ret_comp_par="+ret_comp_par+"&sistemazioni="+sistemazioni+"&ret_sistemazioni="+ret_sistemazioni+"&id_agenzia="+id_agenzia+"&ipa="+ipa+strnewsis;
  else
  	 url="http://www.traghetti.net/soap/search_prices_comp_offline.php?ajax=3&idcomp="+idcomp+"&ncomp="+ncomp+"&id_tratta="+id_tratta+"&codcomp="+cod_tratta+"&id_tratta_ritorno="+id_tratta_ritorno+"&key="+key+"&id_gruppo="+id_gruppo+"&porto_partenza="+porto_partenza+"&porto_arrivo="+porto_arrivo+"&data_andata="+depdate+"&ora_andata="+deptime+"&sailingid="+sailingid+"&shipcode="+shipcode+"&farecode="+farecode+"&lang="+lang+"&page="+phpsess+"&codcomp_ritorno="+cod_tratta_ritorno+"&data_ritorno="+retdate+"&ora_ritorno="+rettime+"&retsailingid="+retsailingid+"&retshipcode="+retshipcode+"&retfarecode="+retfarecode+"&ar="+newar+"&print_bottom="+print_bottom+"&comp_par="+comp_par+"&ret_comp_par="+ret_comp_par+"&sistemazioni="+sistemazioni+"&ret_sistemazioni="+ret_sistemazioni+"&id_agenzia="+id_agenzia+"&ipa="+ipa+strnewsis;

//alert(url);
	xmlHttp=GetXmlHttpObject();
//	if (ncomp==0)
		 xmlHttp.onreadystatechange=stateChangedRecalc0;
/*	else if (ncomp==1)
		 xmlHttp.onreadystatechange=stateChangedRecalc1;
	else if (ncomp==2)
		 xmlHttp.onreadystatechange=stateChangedRecalc2;
	else if (ncomp==3)
		 xmlHttp.onreadystatechange=stateChangedRecalc3;
	else if (ncomp==4)
		 xmlHttp.onreadystatechange=stateChangedRecalc4;
	else if (ncomp==5)
		 xmlHttp.onreadystatechange=stateChangedRecalc5;
*/
	xmlHttp.open('GET', url, true);
	xmlHttp.send(null);

	return;
}


function stateChangedRecalc0()
{
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
	 	 	var stringa=xmlHttp.responseText;
			stringa=stringa.replace(/\\\"/g, '"');
			var response = stringa.split("||DIVCOMP||");   //LA RISPOSTA AJAX SARA' ncomp||DIVCOMP||html con i prezzi
			document.getElementById("divcomp_"+response[0]).innerHTML = response[1];
   }
}
/*
function stateChangedRecalc1()
{
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
	 	 	var stringa=xmlHttp.responseText;
			stringa=stringa.replace(/\\\"/g, '"');
			var response = stringa.split("||DIVCOMP||");   //LA RISPOSTA AJAX SARA' ncomp||DIVCOMP||html con i prezzi
			document.getElementById("divcomp_"+response[0]).innerHTML = response[1];
   }
}

function stateChangedRecalc2()
{
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
	 	 	var stringa=xmlHttp.responseText;
			stringa=stringa.replace(/\\\"/g, '"');
			var response = stringa.split("||DIVCOMP||");   //LA RISPOSTA AJAX SARA' ncomp||DIVCOMP||html con i prezzi
			document.getElementById("divcomp_"+response[0]).innerHTML = response[1];
   }
}

function stateChangedRecalc3()
{
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
	 	 	var stringa=xmlHttp.responseText;
			stringa=stringa.replace(/\\\"/g, '"');
			var response = stringa.split("||DIVCOMP||");   //LA RISPOSTA AJAX SARA' ncomp||DIVCOMP||html con i prezzi
			document.getElementById("divcomp_"+response[0]).innerHTML = response[1];
   }
}

function stateChangedRecalc4()
{
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
	 	 	var stringa=xmlHttp.responseText;
			stringa=stringa.replace(/\\\"/g, '"');
			var response = stringa.split("||DIVCOMP||");   //LA RISPOSTA AJAX SARA' ncomp||DIVCOMP||html con i prezzi
			document.getElementById("divcomp_"+response[0]).innerHTML = response[1];
   }
}

*/

function ApriUrl(url, w, h)
{
		win=open(url, "Dettaglio", 'toolbar=no,status=no,Width='+w+',Height='+h+',directories=no,scrollbars=yes,location=no,resize=yes,menubar=no');
		win.focus();
}

function ApriUrl1(url, w, h, nomewin)
{
		win=open(url, nomewin, 'toolbar=no,status=no,Width='+w+',Height='+h+',directories=no,scrollbars=yes,location=no,resize=yes,menubar=no');
		win.focus();
}

function IsNumDec(Expression)
{
 		var a;
    Expression = Expression.toLowerCase();
    RefString = "0123456789";
		punto=0;
		meno=0;
    for (var i = 0; i < Expression.length; i++)
    {
        var ch = Expression.substr(i, 1);
				if (ch==".")
				{	 punto++;a=1;}
				else if (ch=="-")
				{	 meno++;a=1;}
				else
        	 a = RefString.indexOf(ch, 0);
        if (a == -1 || punto>1 || meno>1)
				{
            return (false);
				}
    }
    return(true);
}

function emetti_tck_submit()
{
	win=open('', 'emetti_biglietto', 'toolbar=no,status=no,Width=800,Height=700,directories=no,scrollbars=yes,location=no,resize=yes,menubar=no');
	//alert("WIN APERTA");
	document.getElementById("emetti_tck").submit();
}


function checkInsurance(this_checkbox, ncomp, and_ret, totale_biglietto)
{
  if (this_checkbox.checked)
	{
	 	 totale_biglietto=parseFloat(totale_biglietto)+parseFloat(this_checkbox.value);
		 totale_biglietto=Math.round(totale_biglietto*Math.pow(10, 2))/Math.pow(10, 2);
		 document.getElementById("insurance_"+and_ret+"_"+ncomp+"_div").innerHTML = "&euro; "+this_checkbox.value;
		 document.getElementById("total_price_"+and_ret+"_"+ncomp+"_div").innerHTML = "&euro; "+totale_biglietto;
		 if (isset(document.getElementById("prezzo_ar_"+ncomp+"_div")))
		 {
		 		var tot_ar=parseFloat(document.getElementById("prezzo_ar_"+ncomp+"_hidden_div").innerHTML);
				tot_ar=parseFloat(tot_ar)+parseFloat(this_checkbox.value);
				tot_ar=Math.round(tot_ar*Math.pow(10, 2))/Math.pow(10, 2);
				document.getElementById("prezzo_ar_"+ncomp+"_hidden_div").innerHTML=tot_ar;
				document.getElementById("prezzo_ar_"+ncomp+"_div").innerHTML="&euro; "+tot_ar;
		 }
	}
	else
	{
		 document.getElementById("insurance_"+and_ret+"_"+ncomp+"_div").innerHTML = "&euro; 0.00";
		 document.getElementById("total_price_"+and_ret+"_"+ncomp+"_div").innerHTML = "&euro; "+totale_biglietto;
		 if (isset(document.getElementById("prezzo_ar_"+ncomp+"_div")))
		 {
		 		var tot_ar=parseFloat(document.getElementById("prezzo_ar_"+ncomp+"_hidden_div").innerHTML);
				tot_ar=parseFloat(tot_ar)-parseFloat(this_checkbox.value);
				tot_ar=Math.round(tot_ar*Math.pow(10, 2))/Math.pow(10, 2);
				document.getElementById("prezzo_ar_"+ncomp+"_hidden_div").innerHTML=tot_ar;
				document.getElementById("prezzo_ar_"+ncomp+"_div").innerHTML="&euro; "+tot_ar;
		 }
	}
}


