function MoreOn (id){
	var  r1 = document.getElementById(id+'r1');
	var  r2 = document.getElementById(id+'r2');

	if(r1.style.display=='none'){
		r1.style.display='block';
		r2.style.display='block';
	}
	else
	{
		r1.style.display='none';
		r2.style.display='none';
	}

}

function apriPop(foto) { 
msg=open("","DisplayWindows"," toolbar=no,directories=no,menubar=no,resizable=no"); 
d=msg.document; 
d.write("<head><SCRIP"+"T>") 
d.write("function ridimensiona(){") 
d.write("window.resizeTo(") 
d.write("document.im1.width+11,") 
d.write("document.im1.height+29);") 
d.write("};document.title=document.im1.src;</SCRIP"+"T></head>") 
d.write("<body topmargin=0 leftmargin=0 scroll=no>") 
d.write("<img src='"+foto+"' name='im1' onLoad='ridimensiona()'>") 
d.write("</body>") 
d.close() 
msg.focus() 
}


function setmax(L,C,R,toCont){
	var LHeight = document.getElementById(L).offsetHeight;
	var CHeight = document.getElementById(C).offsetHeight;
	var RHeight = document.getElementById(R).offsetHeight;
	var CoHeight = document.getElementById('main').offsetHeight;
	
	//alert('mai:'+CoHeight);
	//alert('content:'+document.getElementById('content').offsetHeight);
	//alert('BB:'+document.offsetHeight); 	
	//alert(CoHeight); 
	
	var curH=0;
	
	if (curH<LHeight)
		curH=LHeight;
	if (curH<CHeight)
		curH=CHeight;
	if (curH<RHeight)
		curH=RHeight;
	
	//alert(document.getElementById(toCont).style.left); 
		
	if(navigator.appName != "Microsoft Internet Explorer")
		document.getElementById(toCont).style.height=CoHeight-80;
	//if(navigator.appName != "Microsoft Internet Explorer")
	//	document.getElementById(L).style.height=curH+((curH*80)/100);
	
}


function popitup(url,t) {
	newwindow=window.open(url,t,'height=600,width=450, scrollbars=yes');
	if (window.focus){
		newwindow.focus()
	}
	return false;
}

	
function ControllaCF(cf)
{
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return '';
	cf = cf.toUpperCase();
	if( cf.length != 16 )
		return "La lunghezza del codice fiscale non è\n"
		+"corretta: il codice fiscale dovrebbe essere lungo\n"
		+"esattamente 16 caratteri.\n";
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
			return "Il codice fiscale contiene un carattere non valido `" +
				cf.charAt(i) +
				"'.\nI caratteri validi sono le lettere e le cifre.\n";
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
		return "Il codice fiscale non è corretto:\n"+
			"il codice di controllo non corrisponde.\n";
	return "";
}


function ControllaCF2(cf)
{
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return false;
	cf = cf.toUpperCase();
	if( cf.length != 16 )
		return false;
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
			return false;
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
		return false
	return true;
}		
	
	
// Funzione che svuota i campi user e pass in homepage
function emptydata(){
	var ustx = document.getElementById('userLogin');
	var pstx = document.getElementById('passLogin');

	document.getElementById('userLogin').value ="";
	document.getElementById('passLogin').value ="";
}


// Funzione che svuota i campi user e pass in homepage o risistema le scritte username e password se niente è stato digitato.
function checkData(){
	var ustx = document.getElementById('userLogin');
	var pstx = document.getElementById('passLogin');
	
	if(ustx.value=="")
		ustx.value="e-Mail";
	if(ustx.value=="e-Mail")
		pstx.value="Password";
	else
		pstx.type="Password";
}


function validateMail(){
	var mail = document.getElementById('idMail');
	var nome = document.getElementById('idNome');
	var cognome = document.getElementById('idCognome');

	if(mail.value=="" || nome.value=="" || cognome.value==""){
		//mail.value="Username";
		alert("Attenzione non tutti i campi sono stati compilati.");
		return false;
	}
	else{
		if (eMailCheck(mail.value)==false){
			return false;
		}
		else{
			return true;
		}
	}
		
}


function eMailCheck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		   alert("Indirizzo di posta elettronica non valido!")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Indirizzo di posta elettronica non valido!")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Indirizzo di posta elettronica non valido!")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Indirizzo di posta elettronica non valido!")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Indirizzo di posta elettronica non valido!")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Indirizzo di posta elettronica non valido!")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Indirizzo di posta elettronica non valido!")
		    return false
		 }

 		 return true					
	}
	

function checkPayment(){
	var bonifico = document.getElementById('bonifico');
	var contra = document.getElementById('contra');
	var totCart = document.getElementById('totCart');

	//alert(totCart);
	
	if(totCart.value<50){
		if(contra.checked==false && bonifico.checked==false){
			//mail.value="Username";
			alert("Selezionare una modalita' di pagamento.");
			return false;
		}
		/*if(contra.checked==true){
			//mail.value="Username";
			alert("pagamento in contra.");
			return true;
		}
		if(bonifico.checked==true){
			//mail.value="Username";
			alert("pagamento in bonifico.");
			return true;
		}*/
	
	alert("E' necessario un ordine di almeno 50 euro per ultimare la procedura.");
	return false;
	}
	return true;
}


function checkUser(){
	var Email = document.getElementById('Email');
	var CEmail = document.getElementById('CEmail');
	//var PW = document.getElementById('Password');
	//var CPW = document.getElementById('CPassword');
	//var CF = document.getElementById('Codfis');
	var Ind = document.getElementById('Ind');
	var Cap = document.getElementById('Cap');
	var Nome = document.getElementById('Nome');
	var Cognome = document.getElementById('Cognome');
	var Citta = document.getElementById('Citta');
	var Provincia = document.getElementById('Provincia');
	var Paese = document.getElementById('Paese');
	
	var Tel1 = document.getElementById('Tel1');
	var Tel2 = document.getElementById('Tel2');
	var Fax = document.getElementById('Fax');
	
	if(Email.value!=CEmail.value ||Email.value==""||CEmail.value=="")  {
		alert('La mail non corrisponde!');
		return false;
	}	

	/*if(PW.value!=CPW.value||PW.value==""||CPW.value=="")  {
		alert('La password non corrisponde!');
		return false;
	}
	
	if(CF.value=="")  {
		alert('Inserire un codice fiscale!');
		return false;
	}*/
	
	if(Nome.value==""){
		alert("Inserire un nome!");
		return false;
	}
	
	if(Cognome.value=="")  {
		alert('Inserire un cognome!');
		return false;
	}
	
	if(Ind.value==""||Provincia.value==""||Citta.value==""||Cap.value==""||Paese.value=="")  {
		alert('Controllare l\'indirizzo.');
		return false;
	}
	
	
	if(Tel1.value==""&&Tel2.value==""&&Fax.value=="")  {
		alert('Inserire almeno un recapito telefonico.');
		return false;
	}

	return true;

}


function confirmDel(){
	if(window.confirm("Vuoi procedere con la cancellazione?")){
		
		return true;
	}else{
		
		return false;
	}
}

function checkFutureDate(){

	var tdata = document.getElementById('dataArrivo').value;
	var date = new Date(tdata);
	var today = new Date(); 
	
	today.setDate(today.getDate() - 1);

	
	 
	var tokens = tdata.tokenize("/", " ", true);
	var mixdate = tokens[1]+"/"+tokens[0]+"/"+tokens[2]
	
	var date = new Date(mixdate);

	if(date>=today){
		return true;
	}else{
		window.confirm("Errore nella data, deve essere posteriore a oggi!")
		return false;
	}

}




