function invia() {	
	//alert("conferma");
	var AjaxObject = {		
		handleSuccess:function(o){		
			this.processResult(o);	
			document.getElementById("risultato").innerHTML = o.responseText;	
		},
		handleFailure:function(o){		
		},
		processResult:function(o){		
		},
		startRequest:function() {
		var formObject = document.getElementById('dati');  
		YAHOO.util.Connect.setForm(formObject); 
		document.getElementById("risultato").innerHTML = "ATTENDERE<br><img src='yui/progressbar.gif'>";
	   	//YAHOO.util.Connect.asyncRequest('POST', 'http://rvp1.winrent.it/webdev/htdocs/fatture/invia.php', callback, "");
		YAHOO.util.Connect.asyncRequest('POST', 'proxy.php?proxy_url=http://rvp1.winrent.it/webdev/htdocs/fatture/invia.php', callback, "");
		}
	};
	var callback =
	{
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};
AjaxObject.startRequest();
}

function trim(stringa){
    while (stringa.substring(0,1) == ' '){
        stringa = stringa.substring(1, stringa.length);
    }
    while (stringa.substring(stringa.length-1, stringa.length) == ' '){
        stringa = stringa.substring(0,stringa.length-1);
    }
    return stringa;
}


function inviaAvanzata(n) {	
	//alert(trim(document.datiAv.codice.value))
	with (document.datiAv) {
		//alert(date3.value);
		cond = conducente.value;
		cod = trim(codice.value);
		numero = num.value;
		sezione = sez.value;
		dataRA = date3.value;
		pre = prenotazione.value
		dataPre = datapre.value
		//ndoss = dossier.value ;
		numeroF = numFatt.value;
		sezioneF = sezFatt.value;
		dataF = dataFatt.value;

		nopass = true;
		verificaNumero = 0;
		if(trim(cond)!="" && trim(numero)!="" ) {
			nopass = false;
			//verificaNumero = verificaNumero+2;
		}		
		if(trim(numero)!="" && trim(sezione)!="" && trim(dataRA)!="" ) {
			nopass = false;
			//verificaNumero = verificaNumero+1;
		}	
		
		
		/*
		if(trim(numeroF)!="" && trim(sezioneF)!="" && trim(dataF)!="" ) {
			verificaNumero = verificaNumero+1;
		}	
		if(trim(pre)!="" && trim(dataPre)!="") {
			verificaNumero = verificaNumero+2;
		}			
		*/

		if(trim(cond)!="")	 {
			if(cond.length<=5) {
				alert("Attenzione Per il conducente minimo 6 caratteri")	
				return void(0);
			}		
		}
		
		//if(verificaNumero<=3) {
		if(nopass) {
			alert("Attenzione completare tutti i campi rrichiesti")	
			return void(0);
		}			
	}
	
	var AjaxObjectAv = {		
		handleSuccess:function(o){		
			this.processResult(o);	
			var myTabs = new YAHOO.widget.TabView("demo");
			document.getElementById("risultato").innerHTML = o.responseText;	
		},
		handleFailure:function(o){		
		},
		processResult:function(o){		
				
		},
		startRequest:function() {
		var formObject = document.getElementById('datiAv');  		
		YAHOO.util.Connect.setForm(formObject); 
		document.getElementById("risultato").innerHTML = "RICERCA INVIATA,ATTENDERE<br><img src='yui/progressbar.gif'>";
	   	//YAHOO.util.Connect.asyncRequest('POST', 'inviaAvanzata.php', callback, "");
		//YAHOO.util.Connect.asyncRequest('POST', 'proxy.php?proxy_url=http://intranet.winrent.it/fatturesito/inviaAvanzata.php', callback, "");
		YAHOO.util.Connect.asyncRequest('POST', 'http://intranet.winrent.it/fatturesito/inviaAvanzata.php', callback, "");
		

		}
	};
	var callback =
	{
		success:AjaxObjectAv.handleSuccess,
		failure:AjaxObjectAv.handleFailure,
		scope: AjaxObjectAv
	};
AjaxObjectAv.startRequest();
}

function trim(stringa){
    while (stringa.substring(0,1) == ' '){
        stringa = stringa.substring(1, stringa.length);
    }
    while (stringa.substring(stringa.length-1, stringa.length) == ' '){
        stringa = stringa.substring(0,stringa.length-1);
    }
    return stringa;
}


function visFattura(num,sez,data,invio,datanew) {
		//alert(num+sez+datanew)
		//alert(datanew);
		//alert(document.fatture.num.value+document.fatture.sez.value+document.fatture.data.value);
		
		document.form2.numero.value = num;
		document.form2.sezionale.value = sez;	
		document.form2.data.value = datanew;					
				
		//if(invio=="ERIEN3RD" || invio=="ENOL16IE") { // DISABILITATO SERVIVA PER DIFFERENZIARE L'INVIO TRA VISUALIZZ. E INVIO EMAIL
		//document.form2.email.value = "helpdesk@winrent.it";
		document.form2.email.value = "";
		//alert("-"+sez+"-")
		//alert(sez.length)
		testoSez = trim(sez);
		/*
		if(sez=="W ") {
			sez="_"+sez;
		}
		if(sez=="P ") {
			sez="_"+sez;
		}	
		*/
		if(testoSez.length==1) {
			sez="_"+sez;
		}
		theURL = "http://rvp1.winrent.it/webdev/htdocs/documenti/visfatture.php?id="+num+"-"+data+"-"+sez;
		winName = "vfattura"
		features = "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=670";
		vfattura = window.open(theURL,winName,features);
		vfattura.focus();
				//} 				
		document.form2.tipoinvio.value = invio	;
		//document.form2.action = "http://rvp1.winrent.it/webdev/htdocs/documenti/index.php";
		document.form2.action = "http://rvp1.winrent.it/webdev/htdocs/fatture/inviaCK2.php";
		document.form2.target = "cfattura";
		//document.fatture.action = "http://rvp1.winrent.it/webdev/htdocs/documenti/fatture/visfatture.php";
	
		document.form2.submit();
		return false;
}

function visFatturaF(nfile) { // PER FILE PDF GIà CREATI
		theURL = "http://intranet.winrent.it/documentale/"+nfile;
		winName = "vfattura"
		features = "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=670";
		vfattura = window.open(theURL,winName,features);
		vfattura.focus();
		return false;
}

function calendario(x) {
	function passa(type,args,obj) {
		var dates = args[0];
		var date = dates[0];
		var year = date[0], month = date[1], day = date[2];
		var txtDate1 = document.getElementById("data");
		txtDate1.value = day + "/" + month + "/" + year;
	}
	var cal1 = new YAHOO.widget.Calendar("cal1","cal1Container",{navigator:true});
	
	cal1.cfg.setProperty("DATE_FIELD_DELIMITER", "/");
	cal1.cfg.setProperty("MDY_DAY_POSITION", 1);
	cal1.cfg.setProperty("MDY_MONTH_POSITION", 2);
	cal1.cfg.setProperty("MDY_YEAR_POSITION", 3);
	cal1.cfg.setProperty("MD_DAY_POSITION", 1);
	cal1.cfg.setProperty("MD_MONTH_POSITION", 2);
	cal1.cfg.setProperty("MONTHS_SHORT",   ["Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic"]);
	cal1.cfg.setProperty("MONTHS_LONG",    ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"]);
	cal1.cfg.setProperty("WEEKDAYS_1CHAR", ["D", "L", "M", "M", "G", "V", "S"]);
	cal1.cfg.setProperty("WEEKDAYS_SHORT", ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa"]);
	cal1.cfg.setProperty("WEEKDAYS_MEDIUM",["Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab"]);
	cal1.cfg.setProperty("WEEKDAYS_LONG",  ["Domenica", "Lunedi", "Martedi", "Mercoledi", "Giovedi", "Venerdi", "Sabato"]);
	cal1.selectEvent.subscribe(passa, cal1, true);

	cal1.render();	
	
}

YAHOO.namespace("example.container");
function init() {		
	var handleSubmit = function() {		
		document.dati.email.value=document.dlgForm.email.value;
		document.getElementById('inviando').innerHTML = 'Stai inviando via mail a: '+document.dati.email.value;
		this.hide();
	};
	var handleCancel = function() {
		this.cancel();
	};
	var handleSuccess = function(o) {		
	};
	var handleFailure = function(o) {
		alert("Errore nell'invio: " + o.status);
	};
	
	YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("myDialog", 
							{ width : "20em",
							  fixedcenter : true,
							  visible : false, 
							  constraintoviewport : true,
							  buttons : [ { text:"Invia", handler:handleSubmit, isDefault:true },
								      { text:"Elimina", handler:handleCancel } ]
							});
	YAHOO.example.container.dialog1.callback = { success: handleSuccess,
						     failure: handleFailure };	
	YAHOO.example.container.dialog1.render();
	YAHOO.util.Event.addListener("show", "click", YAHOO.example.container.dialog1.show, YAHOO.example.container.dialog1, true);
	YAHOO.util.Event.addListener("hide", "click", YAHOO.example.container.dialog1.hide, YAHOO.example.container.dialog1, true);
}
YAHOO.util.Event.onDOMReady(init);
