// Funzioni utilizzate per l'engine Atena
var scrolltitle="";
var lengthscroll=0;
var startscroll=1;
var scrolldelay=5;
var titleobj =null;
var titlediv =null;
var repeatscroll=0; //enter 0 to not repeat scrolling after 1 run, othersise, enter 1
var idtimeout = null;
var iframehide="no";

var getFFVersion = navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
var FFextraHeight = parseFloat(getFFVersion) >= 0.1 ? 16 : 0; // extra height in px to add to iframe in FireFox 1.0 + browsers

if(typeof(site) == "undefined" || site == undefined) {
	site=parent.site;
} else {
	if(site=="" || site=="undefined") site=parent.site;
}
if(typeof(atenaservice) == "undefined" || atenaservice == undefined) {
	atenaservice=parent.atenaservice;
} else {
	if(atenaservice=="" || atenaservice=="undefined") atenaservice=parent.atenaservice;
}

if(typeof(nomeazienda) == "undefined" || nomeazienda == undefined) {
	nomeazienda=parent.nomeazienda;
} else {
	if(nomeazienda=="" || nomeazienda=="undefined") nomeazienda=parent.nomeazienda;
}

function openWindow(url, title, width, height){
	
	openPopWin(atenaservice + site + "/" + url, title, width, height);
}

function openSheetTratta(link,id,flag,width,height){
	var url = atenaservice + site + "/" + link + "?idtratta=" + id + "&islistino=" + flag;
//	parent.openGreyBox(null, url, height, width);
	openPopWin(url, "Atena Viaggi - Dettaglio Tratta", width, height);
//	ApriFinestra('', url, width, height, "1", "0");
}

function openSheetProduct(request_ID, comando) {
//		doc=getRef("corpo");
//		if(! doc)
//			doc=getRef("corpo",parent);
//		doc.src = "../TravelServlet?site=" + site + "&azione=Prodotto&comando=" + comando + "&request_ID="+request_ID;
		url = atenaservice + "TravelServlet?site=" + site + "&azione=Prodotto&comando=" + comando + "&request_ID="+request_ID;
		loadCorpo(url, "Scheda Offerta ");
}

function newProduct() {
//		doc=getRef("corpo");
//		if(! doc)
//			doc=getRef("corpo",parent);
//		doc.src = atenaservice + "TravelServlet?site=" + site + "&azione=Prodotto&comando=sheet&request_ID=0";
	url = atenaservice + "TravelServlet?site=" + site + "&azione=Prodotto&comando=sheet&request_ID=0";
	loadCorpo(url, "Scheda Offerta ");
}

function openProductPage(npage){
	url = atenaservice + "TravelServlet?site=" + site + "&azione=Prodotto&comando=view&tocatalog=1";
	if(npage)
		url += ("&newpage=" + npage);
	loadCorpo(url, "Lista Offerte ");
}

function loadCarrello(){
	url = atenaservice + "TravelServlet?site=" + site + "&azione=Carrello&comando=lista";
	loadCorpo(url, "Il tuo carrello ");
}

function loadCorpo(url, titolo, toresize){
	var target = getRef("corpo");
	target.src=url;
	if(toresize)
		resizeCaller();
//   	if(titolo)
//		setTitolo(titolo);
		
}

// utilizzato per popolare la DIV che contiene il form di ricerca
function CB_Search(res_html){
   var target = getLyr("celsearch");
   testo = res_html.replace("siteXXX",site);
   target.write(testo);
}

function getSearch(){
   var HttpReq = new FCAjax("search.html", CB_Search, "GET", true);
   HttpReq.SendData();

}

function CB_Load(res_html, CB_caller, titolo){
   	var target = getRef("corpo", CB_caller);
//   	if(target.tagName=="IFRAME")
//   	else
   	target.innerHTML = res_html;
   	if(titolo)
		setTitolo(titolo);
}



function sendForm(form, titolo) {
	frm = getRef(form);
	frm.submit();
	setTitolo(titolo);
}

function searchProduct(){
	setTitolo("Lista Offerte ");
}

function openPanel(){
	frm = getRef("frmlogin");
	if(frm.login.value=="" || frm.password.value==""){
		alert("Inserire Login e Password");
		return false;
	}
	frm.target="";
	frm.comando.value="openpanel"
	frm.action="http://travel.atena.it/TravelServlet";
	frm.submit();
}

function sendLogin()
{
	frm = getRef("frmlogin");
	if(frm.login.value=="" || frm.password.value==""){
		alert("Inserire Login e Password");
		return false;
	}
	frm.target="corpo";
	frm.action="http://travel.atena.it/TravelServlet";
	frm.submit();
}

function validateUser(){
   	var dView = getRef("divLogin");
	dView.src= atenaservice + "TravelServlet?site=" + site + "&azione=checkuser";
//	resizeFrame("divLogin", 60)	
}


function openGreyBox(url)
{
	GB_showCromeless("", url);
}

function openGreyBox(caption,url,height,width)
{
	GB_showCromeless(caption, url,height, width,"");
}

function openPopWin(url, title, width, height){
	var trattewin=dhtmlwindow.open("fcbox", "iframe", url, nomeazienda + " - " + title, "width=" + width + "px,height=" + height + "px,resize=0,scrolling=1,center=1", "recal");
	trattewin.onclose=function(){ 
		return true;
	};
}


function sendUtenti() {
	objForm = getRef("frmAnagUtenti");
	if(!isEmpty(objForm.txtlogin,"Username")) return false;
	if(!isEmpty(objForm.txtpassword,"Password")) return false;		
	if(!isEmpty(objForm.txtnome,"Nome")) return false;
	if(!isEmpty(objForm.txtcognome,"Cognome")) return false;	
	if(!CheckEmail(objForm.txtemail.value)) return false;

	if(objForm.legge675[1].checked) {
		alert("Dare il consenso al trattamento dei dati personali per proseguire");
		return false;
	}

	gg = objForm.txtGG.value;
	mm = objForm.txtMM.value;
	aa = objForm.txtAA.value;

	txtDalle = objForm.txtDalle.value;
	txtAlle = objForm.txtAlle.value;

	if((gg!="") && (mm!="") && (aa!="")) {
		if(CheckData(gg,mm,aa," Data di nascita "))	objForm.txtdatanascita.value = FormattaDataMySQL(gg,mm,aa);
		else return false;
	}
	objForm.txtfasciaoraria.value = txtDalle + "-" + txtAlle;
	sendForm("frmAnagUtenti","TravelServlet","Il mio profilo ");
}
// NOTE per il momento, finchè si usa IFRAME bisogna utilizzare il formato delle seguenti funzioni
// aggiungere di seguito eventuali funzioni che dovrebbero stare su panel.html

function setHidden(form,nomeoggetto,valore) {
	var dcorpo = getRef("corpo");
	alert(dcorpo.name);
	alert(form);
	var oggetto = getRef(form,dcorpo.document);
	alert(oggetto);
	/*f = eval(oggetto + '.' + form);
	alert(f);
	alert(oggetto.name);
	var objForm = getRef(form);
	alert(objForm);
	var oggetto = eval(objForm + '.' + nomeoggetto);
	oggetto.value = valore;
	alert(oggetto.value);*/

}

function SetProductPage(npage){
	var dcorpo = getRef("corpo");
	url = atenaservice + "TravelServlet?site=" + site + "&azione=Prodotto&comando=view&tocatalog=1";
	if(npage)
		url += ("&newpage=" + npage);
	dcorpo.src = url;	
	resizeCaller();
	setTitolo("Lista Offerte ");
}

//Document title scroller- By Graeme Robinson (me@graemerobinson.co.uk)
//Exlusive permission granted to Dynamic Drive to include this script in their DHTML archive.
//For full source code, terms of use visit http://www.dynamicdrive.com
function setTitolo(titolo){
	return;
	try{
		titleobj = getLyr("tdTitolo");
		titlediv = getLyr("divTitolo");
		if (titleobj){
			lengthscroll=0;
			startscroll=1;
			scrolldelay=5;
			repeatscroll=0;
			titlediv.write(titolo);
			startscroll=titlediv.w()*-1;
			lengthscroll=titleobj.w()-titlediv.w();
			titlediv.x(startscroll);
			titlemove("start");
		}	
	}catch(err){}
}

function titlemove(start) {
	if(start && idtimeout)
		clearTimeout(idtimeout);
  if(titleobj){
//	  titl=scrolltitle.substring(startscroll, lengthscroll) + scrolltitle.substring(0, startscroll);
//	  titleobj.innerText=titl;
	  startscroll++;
	  if (startscroll==lengthscroll+1) {
	    startscroll=titlediv.w()*-1;
	    if (repeatscroll==0)
			return;
	  }
	  titlediv.x(startscroll);
	  idtimeout = setTimeout("titlemove()",scrolldelay);
  }
}

