/*****************************************************************************************
*	FUNZIONI PER FAR MUOVERE LO SPAN ATTENDEREP PREGO CON LA PAGINA (anche quando sgrullo)
******************************************************************************************/
function setVariables(){
	if (navigator.appName == "Netscape") {
		if (parseInt(navigator.appVersion) >= 5){
			v=".top=";
			h=".left=";
			dS="document.getElementById(\"";sD="\").style";
			y="window.pageYOffset";
			x="window.pageXOffset";
		}
		else {
			v=".top=";
			h=".left=";
			dS="document.";
			sD="";
			y="window.pageYOffset";
			x="window.pageXOffset";
		}
	}
	else {
	//ENTRO QUI
		h=".pixelLeft=";
		v=".pixelTop=";
		dS="";
		sD=".style";
		y="document.body.scrollTop";
		x="document.body.scrollLeft";
	}
	checkLocationA()
}

movex=0,movey=0,xdiff=0,ydiff=0,ystart=0,xstart=0
var elFake ;


function checkLocation(){
	object="obj";
	yy=eval(y);
	xx=eval(x);
	ydiff=ystart-yy;
	xdiff=xstart-xx;
	
	if ((ydiff<(-1))||(ydiff>(1))) {
		movey=Math.round(ydiff/10) ;
		ystart-=movey ;
	}
	if ((xdiff<(-1))||(xdiff>(1))) {
		movex=Math.round(xdiff/10) ; 
		xstart-=movex ;
	}
	
	if (ystart>=10){
		
		var alldiv = document.body.getElementsByTagName("DIV");
		nu = alldiv.length ;
		var altro_div = null ;
	
		
		for(r=0;r<nu;r++){
			if("loading" == alldiv[r].getAttribute('id')){
				altro_div = alldiv[r].getAttribute('id');		
			}
		}
		
		elFake = document.getElementById(altro_div).style ;
		var newY = ystart + ((screen.height) / 2) - 150 ;
		eval("elFake"+".top="+newY) ;
		
	} 
	else {
		var alldiv = document.body.getElementsByTagName("DIV");
		nu = alldiv.length ;
		var altro_div = null ;
	
		
		for(r=0;r<nu;r++){
			if("loading" == alldiv[r].getAttribute('id')){
				altro_div = alldiv[r].getAttribute('id');		
			}
		}
		
		elFake = document.getElementById(altro_div).style ;
		var newY = ((screen.height) / 2) - 150 ;
		eval("elFake"+".top="+newY) ;
	}


	var alldiv = document.body.getElementsByTagName("DIV");
	nu = alldiv.length ;
	var altro_div = null ;

	
	for(r=0;r<nu;r++){
		if("loading" == alldiv[r].getAttribute('id')){
			altro_div = alldiv[r].getAttribute('id');		
		}
	}
	
	elFake = document.getElementById(altro_div).style ;
	var newX = xstart ;
	//eval("elFake"+".left="+newX) ;
		
	setTimeout("checkLocation()",10);
}

function checkLocationA(){
	ystart=eval(y);
	xstart=eval(x);
}



/********************************************************************************************/



 


function showHint(idHint) {
	var ajaxObj = new ClassAJAX() ;
	ajaxObj.setExecute(true) ;	
	ajaxObj.setElement('hintContainer') ;
	
	ajaxObj.runAJAX ('../../ajax/ajax.php?action=hintShow&idHint='+idHint) ;
	
	var elem = document.getElementById('hintContainer') ;
	elem.style.display = 'inline' ;
	
	
	
	
	if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  
	l = (myWidth - 400) / 2 ;
	t = (myHeight - 150) / 2 ;
	
	elem.style.top = t ;
	elem.style.left = l ;
	
 	
}

function openHint(idHint) {
 	
	//eval("setTimeout('showHint("+idHint+")',900)" ) ;

}


function closeHint(idHint) {
var elem = document.getElementById('hintContainer') ;
	elem.style.display = 'none' ;	
}

 

 
/*******************************************************************
*					PARTE PRODUCER
*******************************************************************/


function toggleDisplay(fO){
	
	var ns4 = (document.layers);
	var ie4 = (document.all && !document.getElementById);
	var ie5 = (document.all && document.getElementById);
	var ns6 = (!document.all && document.getElementById);


	if(ie5 || ns6){
		if (document.getElementById(fO).style.display=="none") {
		document.getElementById(fO).style.display="inline";
		}else{
		document.getElementById(fO).style.display="none";
		}
	}

	if(ie4){
		if (document.all[fO].style.display=="none") {
		document.all[fO].style.display="inline";
		}else{
		document.all[fO].style.display="none";
		}
	}	
}
 



function changeContents(webpath,container) {

	var url = "" ;
	
	url  = webpath  ;
	
 
	var ajaxObj = new ClassAJAX();
	ajaxObj.setExecute(false) ;
	ajaxObj.setReturn(true) ;
	ajaxObj.runAJAX(url) ;

	var html = "" ;
	var htmlOld = "" ;

	myInterval = window.setInterval(
	function() {
		htmlOld = html ;
		html = ajaxObj.getHtml() ;
		if (html != false) {
		
			if (htmlOld == html) {

				window.clearInterval(myInterval);

				var elem = eval("document.getElementById('"+container+"') ;") ;
				 
				//alert(html);
				
				elem.innerHTML=html ;

			}

		} else {
			
		}
	}
	,1) ; 
}















function popup(url_pagina,w,h,sw_scroll) {


          /*w = 500;
          h = 400;*/
          l = (screen.width - w) / 2;
          t = (screen.height - h) / 2;

          wnd = window.open(url_pagina,"","fullscreen=0,channelmode=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+sw_scroll+", resizable=no, width="+w+", height="+h+", left="+l+", top="+t);
          wnd.focus();

}

function riporta_data(year,month,day) {
        self.close();
        opener.setData(day,month,year);
}

function riporta_data(year,month,day) {
        self.close();
        opener.setData(day,month,year);
}

function riporta_data_src(year,month,day) {
        self.close();
        opener.setDataSrc(day,month,year);
}

function riporta_data_in(year,month,day) {
        self.close();
        opener.setDataIn(day,month,year);
}

function riporta_data_out(year,month,day) {
        self.close();
        opener.setDataOut(day,month,year);
}

function riporta_data_in_src(year,month,day) {
        self.close();
        opener.setDataInSrc(day,month,year);
}

function riporta_data_out_src(year,month,day) {
        self.close();
        opener.setDataOutSrc(day,month,year);
}

function riporta_data_in_ical(year,month,day) {
        self.close();
        opener.setDataInIcal(day,month,year);
}


function setDataInIcal(day,month,year) {
var day = String(day) ;
var month = String(month) ;
var year = String(year) ;

        if(day.length == 1)day = "0" + day ;
        if(month.length == 1)month = "0" + month ;

        dateVis=day+'-'+month+'-'+year;
        date=year+month+day;

        document.form_ical.data_in_ical.value = date;
        document.form_ical.data_in_ical_vis.value = dateVis;
}

function riporta_data_out_ical(year,month,day) {
        self.close();
        opener.setDataOutIcal(day,month,year);
}

function setDataOutIcal(day,month,year) {
var day = String(day) ;
var month = String(month) ;
var year = String(year) ;

        if(day.length == 1)day = "0" + day ;
        if(month.length == 1)month = "0" + month ;

        dateVis=day+'-'+month+'-'+year;
        date=year+month+day;

        document.form_ical.data_out_ical.value = date;
        document.form_ical.data_out_ical_vis.value = dateVis;
}


function setData(day,month,year) {
var day = String(day) ;
var month = String(month) ;
var year = String(year) ;

        if(day.length == 1)day = "0" + day ;
        if(month.length == 1)month = "0" + month ;

        dateVis=day+'-'+month+'-'+year;
        date=year+month+day;

        document.form.data.value = date;
        document.form.data_vis.value = dateVis;
}

function setDataIn(day,month,year) {
var day = String(day) ;
var month = String(month) ;
var year = String(year) ;

        if(day.length == 1)day = "0" + day ;
        if(month.length == 1)month = "0" + month ;

        dateVis=day+'-'+month+'-'+year;
        date=year+month+day;

        document.form.data_in.value = date;
        document.form.data_in_vis.value = dateVis;
}

function setDataOut(day,month,year) {
var day = String(day) ;
var month = String(month) ;
var year = String(year) ;

        if(day.length == 1)day = "0" + day ;
        if(month.length == 1)month = "0" + month ;

        dateVis=day+'-'+month+'-'+year;
        date=year+month+day;

        document.form.data_out.value = date;
        document.form.data_out_vis.value = dateVis;
}

function setDataInSrc(day,month,year) {
var day = String(day) ;
var month = String(month) ;
var year = String(year) ;

        if(day.length == 1)day = "0" + day ;
        if(month.length == 1)month = "0" + month ;

        dateVis=day+'-'+month+'-'+year;
        date=year+month+day;

        document.form_src.data_in_src.value = date;
        document.form_src.data_in_src_vis.value = dateVis;
}


function setDataOutSrc(day,month,year) {
var day = String(day) ;
var month = String(month) ;
var year = String(year) ;

        if(day.length == 1)day = "0" + day ;
        if(month.length == 1)month = "0" + month ;

        dateVis=day+'-'+month+'-'+year;
        date=year+month+day;

        document.form_src.data_out_src.value = date;
        document.form_src.data_out_src_vis.value = dateVis;
}

function setDataSrc(day,month,year) {
var day = String(day) ;
var month = String(month) ;
var year = String(year) ;

        if(day.length == 1)day = "0" + day ;
        if(month.length == 1)month = "0" + month ;

        dateVis=day+'-'+month+'-'+year;
        date=year+month+day;

        document.form_src.data_src.value = date;
        document.form_src.data_src_vis.value = dateVis;
}



function cambiaFoto(num,url,container) {
	var url = "" ;
	
	url  = webpath  ;
	
	var ajaxObj = new ClassAJAX();
	ajaxObj.setExecute(false) ;
	ajaxObj.setReturn(true) ;
	ajaxObj.runAJAX(url) ;

	var html = "" ;
	var htmlOld = "" ;

	myInterval = window.setInterval(
	function() {
		htmlOld = html ;
		html = ajaxObj.getHtml() ;
		if (html != false) {
		
			if (htmlOld == html) {

				window.clearInterval(myInterval);

				var elem = eval("document.getElementById('"+container+"') ;") ;
				 
				elem.innerHTML=html ;

			}

		} else {
			
		}
	}
	,1) ;
}

function doSendmail() {

	var nome = document.registrazione.f_nome.value ;
	var cognome = document.registrazione.f_cognome.value ;
	var email = document.registrazione.f_email.value ;
	var testata = document.registrazione.f_testata.value ;

	var url = "php/press.php?action=lista&tipo_press=doSendMail" ;
	url += "&nome="+nome ;
	url += "&cognome="+cognome ;
	url += "&email="+email ;
	url += "&testata="+testata ;
 
	changeContents(url,'container') ;

}

function checkform() {
	var sw = 0;
	var msg = '';
	
	var nome = document.docform.nome.value;
	var cognome = document.docform.cognome.value;
	var indirizzo = document.docform.indirizzo.value;
	var citta = document.docform.citta.value;
	var cap = document.docform.cap.value;
	var provincia = document.docform.provincia.value;
	var tel = document.docform.tel.value;
	var email = document.docform.email.value;
	var login = document.docform.login.value;
	var passwd = document.docform.passwd.value;
	var modello_imb = document.docform.modello_imb.value;
	var nome_imb = document.docform.nome_imb.value;
	var anno_imb = document.docform.anno_imb.value;
	var porto_imb = document.docform.porto_imb.value;
	var motore_imb = document.docform.motore_imb.value;
	var hp_imb = document.docform.hp_imb.value;

	var the_box1 = document.docform.checklegge[0].checked;
		
		var x = document.docform.email.value;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(x)) {
		//alert('YES! Correct email address');
		} else {
		
		msg += "Indirizzo email inesatto.\n" ;
		
		sw = 1 ;	
		} 


		if (!nome) {
		msg += "devi inserire il nome.\n" ;
		sw = 1 ;
		}
		
		if (!cognome) {
		msg += "devi inserire il cognome.\n" ;
		sw = 1 ;
		}
		if (!indirizzo) {
		msg += "devi inserire l\' indirizzo.\n" ;
		sw = 1 ;
		}
		if (!cap) {
		msg += "devi inserire il cap.\n" ;
		sw = 1 ;
		}
		if (!citta) {
		msg += "devi inserire la citta.\n" ;
		sw = 1 ;
		}
		if (!provincia) {
		msg += "devi inserire la provincia.\n" ;
		sw = 1 ;
		}
		if (!tel) {
		msg += "devi inserire il telefono.\n" ;
		sw = 1 ;
		}
		if (!email) {
		msg += "devi inserire l\' email.\n" ;
		sw = 1 ;
		}
		if (!login) {
		msg += "devi inserire il nome utente.\n" ;
		sw = 1 ;
		}		
		if (!passwd) {
		msg += "devi inserire la password.\n" ;
		sw = 1 ;
		}		
		if (!modello_imb) {
		msg += "devi inserire il modello.\n" ;
		sw = 1 ;
		}
		if (!nome_imb) {
		msg += "devi inserire il nome modello.\n" ;
		sw = 1 ;
		}
		if (!anno_imb) {
		msg += "devi inserire l\'anno.\n" ;
		sw = 1 ;
		}
		if (!porto_imb) {
		msg += "devi inserire il porto.\n" ;
		sw = 1 ;
		}
		if (!motore_imb) {
		msg += "devi inserire il motore.\n" ;
		sw = 1 ;
		}
		if (!hp_imb) {
		msg += "devi inserire i cavalli motore.\n" ;
		sw = 1 ;
		}
		


		
		
		if (the_box1 == true) {
		msg += "Devi accettare la clausola.\n" ;
		
		sw = 1 ;
		}
		
		
		
		if(sw == 1 ) {
			
			alert(msg);
			return false ;
		
		}


}

