/*scroll menu*/
if (document.getElementById){
document.write('<style type="text/css">\n')
document.write('.menu_int{display: none;}\n')
document.write('</style>\n')
}

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 checkMail(str) {
		var re_valid_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
		return re_valid_mail.test(str);
}

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("menusx").getElementsByTagName("span");
		if(el.style.display != "block"){
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="menu_int")
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

function controllamail(valore, campo,form){
	valore = trim(valore);
	if (valore!=""){
   	var f = document.forms[form];
   	var els = f.elements;   		
   		if (!checkMail(valore)) {
   				alert("La mail non e' corretta");
   				els[campo.name].value = "";
   				setTimeout(function(){els[campo.name].focus();els[campo.name].select();},10);
   		}
	}else{
	   		return ;
	}
}

function initMenu(obj){
	if((typeof(obj) == 'undefined')||(obj == null)){
		var el = document.getElementById("sub_1");
	}else{
		var el = document.getElementById(obj);	
	}
	var ar = document.getElementById("menusx").getElementsByTagName("span");
	if(el.style.display != "block"){
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="menu_int")
				ar[i].style.display = "none";
			}
			el.style.display = "block";
	}
}

function openPopupInterno(contenuto,w,h){
	if (w=='') w='400';
	if (h=='') h='300';
		window.open("../popup.php?idcontenuto="+contenuto,'wndPopup','width='+w+',height='+h+',resizable=no,scrollbars=no,toolbar=no,status=yes,location=no,left=50,top=50');
}

function accedi(){
	var f = document.forms["login"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["username"].value==""){
		errore+="Codice cliente\n";
	}
	if (els["pwd"].value==""){
		errore+="Password\n";
	}	
	if (errore!=""){
		alert(msg+errore);
	}else{
		f.submit();
	}
}

function inviaContatti(){
	var f = document.forms["contatti"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["riferimento"].value==""){
		errore+="Persona di riferimento\n";
	}
	if (els["ragionesoc"].value==""){
		errore+="Ragione sociale\n";
	}
	if (els["telefono"].value==""){
		errore+="Recapito telefonico\n";
	}
	if (els["mail"].value==""){
		errore+="Email\n";
	}		
	if (els["area"].value==0){
		errore+="Area di contatto\n";
	}		
	if (els["messaggio"].value==""){
		errore+="Messaggio\n";
	}	
	if(!els["acconsento"].checked){
		errore +="Acconsentire al trattamento dei dati personali\n";
	}	

	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;
		f.submit();
	}
}

function iscrivinewsletter(){
	var f = document.forms["newsletter"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["nome"].value==""){
		errore+="Nome\n";
	}
	if (els["cognome"].value==""){
		errore+="Cognome\n";
	}	
	if (els["mail"].value==""){
		errore+="Email\n";
	}	
		if(!els["acconsento"].checked){
		errore +="Acconsentire al trattamento dei dati personali\n";
	}	
	if (errore!=""){
		alert(msg+errore);
	}else{
		f.submit();
	}	
	
}

function viewmsg(msg){
   if((typeof(msg) != 'undefined')&&(msg != null)&&(msg!="")){
    alert(msg);
   }
}

function richiedipwd(){
	var f = document.forms["richiedipass"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["piva"].value==""){
		errore+="Partita IVA\n";
	}
	if (els["codice"].value==""){
		errore+="Codice cliente\n";
	}	
	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;		
		f.submit();
	}	
}

function ricordapass(){
	var f = document.forms["ricordapass"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["piva"].value==""){
		errore+="Partita IVA\n";
	}
	if (els["codice"].value==""){
		errore+="Codice cliente\n";
	}	
	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;		
		f.submit();
	}	
}
function cambiapwd(){
	var f = document.forms["modpassword"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["newpwd"].value==""){
		errore+="Nuova password\n";
	}
	if (els["confpwd"].value==""){
		errore+="Conferma nuova password\n";
	}	
	if ((els["newpwd"].value!="")&&(els["confpwd"].value!="")){
		 if((els["newpwd"].value)!=(els["confpwd"].value)){
		 errore+="La password immessa è diversa da quella confermata\n";
		 }
	}
	
	
	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;		
		f.submit();
	}	
}

function ricnecessita(obj,num){
	var f = document.forms["customer"];
	var els = f.elements;
	if (obj.value!=""){
		 if(num==0){
		 		els["area"].value = obj.value;
			}else{
				els["areaint"].value = obj.value;
			}
		 f.submit();
	}
}

function inviaCustomer(){
	var f = document.forms["customer"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";

	if (els["riferimento"].value==""){
		errore+="Riferimento\n";
	}
	if (els["mail"].value==""){
		errore+="E-mail\n";
	}	
	if (els["telefono"].value==""){
		errore+="Telefono\n";
	}	
	if (els["area"].value=="0"){
		errore+="Necessità\n";
	}	
	if (typeof(els["areaint"]) != 'undefined'){
		 if (els["areaint"].value=="0"){
		 		errore+="Problema\n";
		 }
	}
  	
  if (typeof(els["richiestacampi"]) != 'undefined'){
  	var richiestac = els["richiestacampi"].value;
  	if (richiestac==1){
  		 if(els["numdoc"].value=="0"){
  		 	errore+="Numero documento di trasporto\n";
  		}	
  		if(els["datadoc"].value=="0"){
  		 	errore+="Data documento di trasporto\n";
  		 }	
  	}
	}
	if (els["messaggio"].value==""){
		errore+="Messaggio\n";
	}	
	
	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;		
		f.submit();
	}		
}

function ricerca(){
	var f = document.forms["ricerca"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";

	if (trim(els["stringadac"].value)==""){
		errore+="Stringa da cercare\n";
	}
	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;		
		f.submit();
	}		
}



/**********************************************************************************   
ScrollText 
*   Copyright (C) 2001 <a href="/dhtmlcentral/thomas_brattli.asp">Thomas Brattli</a>
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by <a href="/dhtmlcentral/thomas_brattli.asp">Thomas Brattli</a> 
*********************************************************************************/

function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new lib_bwcheck()


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

You set the width and height of the divs inside the style tag, you only have to
change the divScrollTextCont, Remember to set the clip the same as the width and height.
You can remove the divUp and divDown layers if you want. 
This script should also work if you make the divScrollTextCont position:relative.
Then you should be able to place this inside a table or something. Just remember
that Netscape crash very easily with relative positioned divs and tables.

Updated with a fix for error if moving over layer before pageload.

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


//If you want it to move faster you can set this lower, it's the timeout:
var speed = 20

//Sets variables to keep track of what's happening
var loop, timer

//Object constructor
function makeObj(obj,nest){
    nest=(!nest) ? "":'document.'+nest+'.'
	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
  	this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
	this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight
	this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight
	this.up=goUp;this.down=goDown;
	this.moveIt=moveIt; this.x=0; this.y=0;
    this.obj = obj + "Object"
    eval(this.obj + "=this")
    return this
}

// A unit of measure that will be added when setting the position of a layer.
var px = bw.ns4||window.opera?"":"px";

function moveIt(x,y){
	this.x = x
	this.y = y
	this.css.left = this.x+px
	this.css.top = this.y+px
}

//Makes the object go up
function goDown(move){
	if (this.y>-this.scrollHeight+oCont.clipHeight){
		this.moveIt(0,this.y-move)
			if (loop) setTimeout(this.obj+".down("+move+")",speed)
	}
}
//Makes the object go down
function goUp(move){
	if (this.y<0){
		this.moveIt(0,this.y-move)
		if (loop) setTimeout(this.obj+".up("+move+")",speed)
	}
}

//Calls the scrolling functions. Also checks whether the page is loaded or not.
function scroll(speed){
	if (scrolltextLoaded){
		loop = true;
		if (speed>0) oScroll.down(speed)
		else oScroll.up(speed)
	}
}

//Stops the scrolling (called on mouseout)
function noScroll(){
	loop = false
	if (timer) clearTimeout(timer)
}
//Makes the object
var scrolltextLoaded = false
function scrolltextInit(){
	oCont = new makeObj('divScrollTextCont')
	oScroll = new makeObj('divText','divScrollTextCont')
	oScroll.moveIt(0,0)
	oCont.css.visibility = "visible"
	//Modificato da Gio
	if (oScroll.clipHeight > oCont.clipHeight){
		document.getElementById("divDown").style.display = ""
		document.getElementById("divUp").style.display = ""
	}
	scrolltextLoaded = true
}

function scrollInternaInit(){
	oCont = new makeObj('divScrollTextpag')
	oScroll = new makeObj('divText','divScrollTextpag')
	oScroll.moveIt(0,0)
	oCont.css.visibility = "visible"
	//Modificato da Gio
	if (oScroll.clipHeight > oCont.clipHeight){
		document.getElementById("divDownpag").style.display = ""
		document.getElementById("divUppag").style.display = ""
	}
	scrolltextLoaded = true
}

function scrollhistoryInit(){
	oCont = new makeObj('divScrollTextpag')
	oScroll = new makeObj('divhistory','divScrollTextpag')
	oScroll.moveIt(0,0)
	oCont.css.visibility = "visible"
	//Modificato da Gio
	if (oScroll.clipHeight > oCont.clipHeight){
		document.getElementById("divDownpag").style.display = ""
		document.getElementById("divUppag").style.display = ""
	}
	scrolltextLoaded = true
}


function scrollOfferteInit(){
	oCont = new makeObj('divScrollOfferte')
	oScroll = new makeObj('divOfferte','divScrollOfferte')
	oScroll.moveIt(0,0)
	oCont.css.visibility = "visible"
	//Modificato da Gio
	if (oScroll.clipHeight > oCont.clipHeight){
		document.getElementById("divDownpag").style.display = ""
		document.getElementById("divUppag").style.display = ""
	}
	scrolltextLoaded = true
}

