// JavaScript Document
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
function goPage(npage){
	
	document.changePage.page.value = npage;
	document.changePage.submit();
	
}
function goDiv(ndiv,npage){
	
	document.changeDiv.pagediv.value = ndiv;
	document.changeDiv.page.value = npage;
	document.changeDiv.submit();
	
}
function openWindow(apri, w, h) {
        var style = "top=0, left=0,width="+w+", height="+h+",status=no, menubar=no, toolbar=no, scrollbars=yes";
		window.open(apri, "", style);
}

function changeMail() {
 if (!document.getElementsByTagName) return false;
 var span = document.getElementsByTagName("span");
 for (var i=0; i < span.length; i++) {
  if (span[i].className.match('email')) {
   var innerspan = span[i].getElementsByTagName("span")[0].firstChild.nodeValue;
   span[i].innerHTML = "<a href='mailto:"+innerspan+"@wfactory.it'>"+innerspan+"@wfactory.it"
  }
 }
}

function validContactLand(theForm){
	var nome = theForm.nome.value;
	var email = theForm.email.value;
	var messaggio = theForm.messaggio.value;
	
	if(nome == ''){
		alert("inserire il nome");
		theForm.nome.focus();
		return(false);
	}
	
	if(email == ''){
		alert("inserire il proprio indirizzo email");
		theForm.email.focus();
		return(false);
	}
	else
	{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email)){
			alert('Per favore inserisci un indirizzo email valido');
			theForm.email.focus();
			return(false);
		}
	}
	
	if(messaggio == ''){
		alert("inserire il testo del messaggio");
		theForm.messaggio.focus();
		return(false);
	}
	privacy = -1;
	if (theForm.privacy.checked) {
			privacy = 1;
	}
	
	if (privacy == -1) {
		alert("Devi accettare le condizioni sulla Privacy");
		return false;
	}
	
	
	
	
	return(true);
}

//contatto x preventivo
function validContact(theForm){

	var azienda = theForm.azienda.value;
	var email = theForm.email.value;
	
	if(azienda == ''){
		alert("inserire il nome dell\'azienda");
		theForm.azienda.focus();
		return(false);
	}
	
	if(email == ''){
		alert("inserire il proprio indirizzo email");
		theForm.email.focus();
		return(false);
	}
	else
	{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email)){
			alert('Per favore inserisci un indirizzo email valido');
			theForm.email.focus();
			return(false);
		}
	}
	privacy = -1;
	if (theForm.privacy.checked) {
			privacy = 1;
	}
	
	if (privacy == -1) {
		alert("Devi accettare le condizioni sulla Privacy");
		return false;
	}
	
	
	
	
	return(true);
}
//metodo di pagamento e url
function validInfoOne(theForm)
{
	var url = theForm.url.value;
	var filterUrl = /^(([a-zA-Z0-9\-])+\.)+(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(!filterUrl.test(url))
	{
		alert("Per favore inserisci un url valido nel campo 1. (ad es. \"www.dominio.it\")");
		theForm.url.focus();
		return(false);
	}
	
	return(true);
}
//metodo di pagamento e url
function validInfo()
{
	var url = document.payinfo.elements["url[]"];
	var filterUrl = /^(([a-zA-Z0-9\-])+\.)+(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var u = 0;	
	for(var i=0;i<url.length;i++)
	{
		u++;
		if(!filterUrl.test(url[i].value)){
			alert('Per favore inserisci un url valido nel campo '+u+'. (ad es. \"www.dominio.it\")');
			url[i].focus();
			return(false);
		}
	}
	return(true);
}
//recupero password
function validRecPasswd(theForm){
	var email = theForm.email.value;
	if(email == ''){
		alert("inserire l\'indirizzo email");
		theForm.email.focus();
		return(false);
	}
	else
	{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email)){
			alert('Per favore inserisci un indirizzo email valido');
			theForm.email.focus();
			return(false);
		}
	}
	return(true);
}
//registrazione cliente
function validRegister(theForm){

	var ragsociale = theForm.ragsociale.value;
	var piva = theForm.piva.value;
	var nome = theForm.nome.value;
	var cognome = theForm.cognome.value;
	var provincia = theForm.provincia.options[theForm.provincia.selectedIndex].value;
	var comune = theForm.comune.options[theForm.comune.selectedIndex].value;
	var indirizzo = theForm.indirizzo.value;
	var cap = theForm.cap.value;
	var telefono = theForm.telefono.value;
	var email = theForm.email.value;
	var codfiscale = theForm.codfiscale.value;
	var username = theForm.username.value;
	var password = theForm.password.value;
	var confirmpassword = theForm.confirmpassword.value;
	
	
	
	if(nome == ''){
		alert("inserire il nome");
		theForm.nome.focus();
		return(false);
	}
	if(cognome == ''){
		alert("inserire il cognome");
		theForm.cognome.focus();
		return(false);
	}
	if(provincia == '0'){
		alert("inserire la provincia");
		theForm.provincia.focus();
		return(false);
	}
	if(comune == '0'){
		alert("inserire il comune");
		theForm.comune.focus();
		return(false);
	}
	if(indirizzo == ''){
		alert("inserire l\'indirizzo");
		theForm.indirizzo.focus();
		return(false);
	}
	if(cap == ''){
		alert("inserire il cap");
		theForm.cap.focus();
		return(false);
	}
	if(telefono == ''){
		alert("inserire il telefono");
		theForm.telefono.focus();
		return(false);
	}
	if(email == ''){
		alert("inserire l\'indirizzo email");
		theForm.email.focus();
		return(false);
	}
	else
	{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email)){
			alert('Per favore inserisci un indirizzo email valido');
			theForm.email.focus();
			return(false);
		}
	}
	if(ragsociale != ''){
		if(piva == ''){
			alert("inserire la partita iva");
			theForm.piva.focus();
			return(false);
		}
	}
	if(codfiscale == ''){
		alert("inserire il codice fiscale");
		theForm.codfiscale.focus();
		return(false);
	}
	if(username == ''){
		alert("inserire l\'username");
		theForm.username.focus();
		return(false);
	}
	if(password == ''){
		alert("inserire la password");
		theForm.password.focus();
		return(false);
	}
	if(confirmpassword == ''){
		alert("inserire la password di conferma");
		theForm.confirmpassword.focus();
		return(false);
	}
	if(password != confirmpassword){
		alert("le password non corrispondono");
		theForm.confirmpassword.focus();
		return(false);
	}
	
	privacy = -1;
	if (theForm.privacy.checked) {
			privacy = 1;
	}
	
	if (privacy == -1) {
		alert("Devi accettare le condizioni sulla Privacy");
		return false;
	}
	
	termini = -1;
	if (theForm.termini.checked) {
			termini = 1;
	}
	
	if (termini == -1) {
		alert("Devi accettare le condizioni contrattuali");
		return false;
	}
	
	return(true);
}

addLoadEvent(changeMail);

function validLogin(theForm){
	
	var username = theForm.username.value;
	var password = theForm.password.value;
	
	if(username == ''){
		alert("inserire l\'username");
		theForm.username.focus();
		return(false);
	}
	if(password == ''){
		alert("inserire la password");
		theForm.password.focus();
		return(false);
	}
	
	return(true);
}
// JavaScript Document
function validDownload(theForm){
	
	var nome = theForm.nome.value;
	var email = theForm.email.value;
	
	if(nome == ''){
		alert("inserire il nome");
		theForm.nome.focus();
		return(false);
	}
	/*
	if(cognome == ''){
		alert("inserire il cognome");
		theForm.cognome.focus();
		return(false);
	}
	*/
	if(email == ''){
		alert("inserire il proprio indirizzo email");
		theForm.email.focus();
		return(false);
	}
	else
	{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email)){
			alert('Per favore inserisci un indirizzo email valido');
			theForm.email.focus();
			return(false);
		}
	}
	privacy = -1;
	if (theForm.privacy.checked) {
			privacy = 1;
	}
	
	if (privacy == -1) {
		alert("Devi accettare le condizioni sulla Privacy");
		return false;
	}
	
	return(true);
}
// JavaScript Document
function validBuy(theForm){
	
	var nome = theForm.nome.value;
	var cognome = theForm.cognome.value;
	var email = theForm.email.value;
	var telefono = theForm.telefono.value;
	
	if(nome == ''){
		alert("inserire il nome");
		theForm.nome.focus();
		return(false);
	}
	if(cognome == ''){
		alert("inserire il cognome");
		theForm.cognome.focus();
		return(false);
	}
	if(telefono == ''){
		alert("inserire il numero di telefono");
		theForm.telefono.focus();
		return(false);
	}
	
	if(email == ''){
		alert("inserire il proprio indirizzo email");
		theForm.email.focus();
		return(false);
	}
	else
	{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email)){
			alert('Per favore inserisci un indirizzo email valido');
			theForm.email.focus();
			return(false);
		}
	}
	privacy = -1;
	if (theForm.privacy.checked) {
			privacy = 1;
	}
	
	if (privacy == -1) {
		alert("Devi accettare le condizioni sulla Privacy");
		return false;
	}
	
	return(true);
}
function askDeleteOrder() {

	if (confirm("Vuoi veramente annullare l'ordine ?")) {
		return(true);
	}
	else {
		return(false);
	}   
}
function infoBonifico(tot,ordine){
	var msg = "Effettuare un bonifico di "+ tot;
	msg += " euro, specificando come oggetto 'WFiles ordine n. "+ ordine;
	msg += "'\n";
	msg += "I dati per il bonifico sono i seguenti:\n\n";
	msg += "Webfactory srl \n Banca Monte dei Paschi di Siena \n IBAN: IT 38 U 01030 15801 000000997048 \n\n";
	msg += "Una volta effettuato il pagamento è necessario l'invio della copia contabile del bonifico insieme al testo ";
	msg += "dell'email inviata, per fax ( 099 7796368 ) o allegando una scansione via email ( wfiles@wfactory.it ).";
	alert(msg);
}

function validDatipers(theForm){
	
	var password = theForm.password.value;
	var confirmpassword = theForm.confirmpassword.value;
	
	if(password == ''){
		alert("inserire la password");
		theForm.password.focus();
		return(false);
	}
	if(confirmpassword == ''){
		alert("inserire la password di conferma");
		theForm.confirmpassword.focus();
		return(false);
	}
	if(password != confirmpassword){
		alert("le password non corrispondono");
		theForm.confirmpassword.focus();
		return(false);
	}
	
	return(true);
}

function showpresence(presence)
   {
      var innerFrame = document.getElementById('innerFrame');
         
      var statusIcon = document.createElement('img');
      statusIcon.style.border = 'none';
      statusIcon.src = presence.icon.url;
      statusIcon.width = presence.icon.width;
      statusIcon.height = presence.icon.height;
      statusIcon.alt = presence.statusText;
      statusIcon.title = presence.statusText;

      var displayName = document.createElement('span');
      displayName.style.fontFamily = 'Tahoma, Verdana, sans-serif';
      displayName.style.fontSize = '9pt';
      displayName.title = presence.displayName;
      
      var statusText = document.createElement('span');
      statusText.style.fontFamily = 'Tahoma, Verdana, sans-serif';
      statusText.style.fontSize = '9pt';
      statusText.title = presence.statusText;
      
      var br = document.createElement('br');
      
      innerFrame.appendChild(statusIcon);
      innerFrame.appendChild(br);
      innerFrame.appendChild(displayName);
      innerFrame.appendChild(br);
      innerFrame.appendChild(statusText);
      
      if ((displayName.innerText !== undefined)&&(statusText.innerText !== undefined))
      {
         displayName.innerText = presence.displayName;
         statusText.innerText = presence.statusText;
      }
      else if ((displayName.textContent != undefined)&&(statusText.textContent !== undefined))
      {
         displayName.textContent == presence.displayName;
         statusText.textContent == presence.statusText;
      }
   }