/* Apre in finestra la google map */
function openMap(){
var	stats='toolbar=no,location=yes,directories=no,status=yes,menubar=yes,'
  stats += 'scrollbars=auto,resizable=yes'

  MsgBox = window.open ("","Map",stats)
  if(!MsgBox.closed){
    MsgBox.close();
     MsgBox = window.open ("http://maps.google.it/maps?f=q&source=s_q&hl=it&geocode=&q=CA-BE+di+Berni+Enerio+e+c+snc&sll=47.407557,-2.90283&sspn=18.515426,39.111328&ie=UTF8&hq=CA-BE&hnear=Via+James+Watt,1+41012+Carpi+MO&ll=44.778134,10.853612&spn=0.004547,0.009549&t=h&z=18&iwloc=A","Map",stats)
  }

}

/* valida la form dei contatti */
function validateContact(theForm){

  var message = "campi mancanti o errati:\n missing or wrong fields:\n";
  var result = true;
  if(theForm){

    /* company name */
    if(theForm.company_name.value.length < 3){
      message += "societ�\n";
      result = false;
    }
    if(theForm.city.value.length < 3){
      message += "citt�\n";
      result = false;
    }
    if(! theForm.mail.value.match(/^[\w\.-]+@[\w\.-]+\.[a-z]{2,3}$/) ){
      message += "email\n";
      result = false;
    }

    if(result == false){
      alert(message);
    }

  }
  return result;

}

/* valida la form richiesta password */
function validateRequest(theForm){

  var message = "campi mancanti o errati:\n missing or wrong fields:\n";
  var result = true;
  if(theForm){

    /* company name */
    if(theForm.company_name.value.length < 3){
      message += "societ�\n";
      result = false;
    }
    if(theForm.address.value.length < 3){
      message += "indirizzo\n";
      result = false;
    }
    if(theForm.postal_code.value.length < 3){
      message += "CAP\n";
      result = false;
    }
    if(theForm.city.value.length < 3){
      message += "citt�\n";
      result = false;
    }
    if(theForm.phone.value.length < 3){
      message += "telefono\n";
      result = false;
    }
    if(theForm.province.value.length < 1){
      message += "provincia\n";
      result = false;
    }
    if(! theForm.email.value.match(/^[\w\.-]+@[\w\.-]+\.[a-z]{2,3}$/) ){
      message += "email\n";
      result = false;
    }

    if(theForm.username.value.length < 6){
      message += "username (6 caratteri)\n";
      result = false;
    }
    if(theForm.password.value.length < 6){
      message += "password (6 caratteri)\n";
      result = false;
    }

    if(! theForm.privacy.checked){
      message += "consenso privacy\n";
      result = false;
    }

    if(result == false){
      alert(message);
    }

  }
  return result;

}

/* Apre la finestra per il download */
function openDl(filename){
var	stats='toolbar=no,location=no,directories=no,status=no,menubar=no,'
  stats += 'scrollbars=no,resizable=no,screenX=100,screenY=100,height=200,width=200'

  MsgBox = window.open ("","Dl",stats)
  if(!MsgBox.closed){
    MsgBox.close();
    MsgBox = window.open ("site/catalogo/download.php?file="+filename,"Dl",stats)
  }
}

function updateSelect(data, selid){
	var s = document.getElementById(selid);
	
	if(s){
		Dom.addClass(s,'highlight-input');		
		var optgroups = []; 
		var optg = Dom.getChildrenBy (s, function(el){return el.nodeName.toLowerCase() == 'optgroup'});
		for(i = 0; i < optg.length; i++){
			s.removeChild(optg[i]);
		}
		opt_num = data.length;
		var firstOption = s.options[0];
		s.options.length = 0; //trim options
		s.options[0] = firstOption;
		f_type = '';
		j = 0;
		for(i = 0; i < opt_num; i++){
			if(f_type != data[i].format_type){
			  var optgroup = document.createElement("optgroup");
			  optgroup.setAttribute("label", data[i].format_type);
			  j++;
			}
			opt = new Option(data[i].label, data[i].qualifier, false);
			if (YAHOO.env.ua.ie > 0) {
				txt = document.createTextNode(data[i].label);
				opt.appendChild(txt);
			}
			optgroup.appendChild(opt);
			if(f_type != data[i].format_type){
				optgroups.push(optgroup);
			}
			f_type = data[i].format_type;
		}
		for(var i = 0; i < optgroups.length; i ++) {
		  s.appendChild(optgroups[i]);
		}
		Lang.later(1000,this,function() {
			Dom.removeClass(s,'highlight-input');
		});
	}
}

