// JavaScript Document
function Browser() {
  var ua, s, i;
  this.isIE    = false;
  this.isNS    = false;
  this.version = null;
  ua = navigator.userAgent;
  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

var digitsOnly = /[1234567890+]/g;
var dataOnly = /[1234567890\/]/g;
var orarioOnly = /[1234567890:]/g;
var numberOnly = /[1234567890]/g;
var integerOnly = /[0-9\.]/g;
var alphaOnly = /[A-Z]/g;
var alphadigitsOnly = /[1234567890ABCDEFGHILMNOPQRSTUVZWYKXJabcdefghilmnopqrstuvzwyjkx' ]/g;

function restrictCharacters(myfield, e, restrictionType) {
	if (!e) var e = window.event
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	var character = String.fromCharCode(code);
	if (code==27) { this.blur(); return false; }
	if (!e.ctrlKey && code!=9 && code!=8 && code!=36 && code!=37 && code!=38 && (code!=39 || (code==39 && character=="'")) && code!=40) {
		if (character.match(restrictionType)) {
			return true;
		} else {
			return false;
		}
		
	}
}

function openScheda(divId){
	var classClose = (typeof openScheda.arguments[1] == 'undefined') ? 'closeAll' : openScheda.arguments[1];
	var jq_obj = $('.'+classClose)
	for(var i = 0;i < jq_obj.length;i++){
		if (document.getElementById(jq_obj[i].id).style.display != "none"){
			$("#"+jq_obj[i].id).slideUp("slow");
		}
	}
	if (document.getElementById(divId).style.display == "none"){
		$("#"+divId).slideDown("slow");
	} else {
		$("#"+divId).slideUp("slow");
	}
}

function openSchedaClass(divId){
	if ($("."+divId).css("display") == "none"){
		$("."+divId).fadeIn();
	} else {
		$("."+divId).fadeOut();
	}
}

function addBookmark(title,url) {
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
}

/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
/*----FUNZIONI DI CONVALIDA FORM-----------------------------------------------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
function ConvalidaContattiForm(lingua) {	
	var index = parseInt(lingua);
	erroreLinguaArray = new Array("ERRORE", "ERROR");
	$("#dialog-message").dialog( "option", "title", erroreLinguaArray[index] );
	var nome = document.contattiForm.nome.value;
	nomeArray = new Array("Il campo nome &eacute; obbligatorio", "Name is required");
	var cognome = document.contattiForm.cognome.value;
	cognomeArray = new Array("Il campo cognome &eacute; obbligatorio", "Surname is required");
	var email = document.contattiForm.email.value;
	emailArray = new Array("Il campo email non &eacute; corretto", "Email is incorrect");
	var oggetto = document.contattiForm.oggetto.value;
	oggettoArray = new Array("Il campo oggetto &eacute; obbligatorio", "Subject is required");
	var messaggio = document.contattiForm.messaggio.value;
	messaggioArray = new Array("Il campo messaggio &eacute; obbligatorio", "Message is required");
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if ((nome == "") || (nome == undefined)) {
	   $("#alertBox").html(nomeArray[index]);
	   $("#dialog-message").dialog('open');
	} else if ((cognome == "") || (cognome == undefined)) {
	   $("#alertBox").html(cognomeArray[index]);
	   $("#dialog-message").dialog('open');
	} else if ((!email_reg_exp.test(email) || (email == "") || (email == undefined))) {
	   $("#alertBox").html(emailArray[index]);
	   $("#dialog-message").dialog('open');
	} else if ((oggetto == "") || (oggetto == undefined)) {
	   $("#alertBox").html(oggettoArray[index]);
	   $("#dialog-message").dialog('open');
	} else if ((messaggio == "") || (messaggio == undefined)) {
	  $("#alertBox").html(messaggioArray[index]);
	  $("#dialog-message").dialog('open');
	} else {
	   $('#contattiForm').submit();
	}
}

function ConvalidaPreventivoForm(lingua) {	
	var index = parseInt(lingua);
	erroreLinguaArray = new Array("ERRORE", "ERROR");
	$("#dialog-message").dialog( "option", "width", 300 );
	$("#dialog-message").dialog( "option", "title", erroreLinguaArray[index] );
	var azienda = document.preventivoForm.azienda.value;
	aziendaArray = new Array("Il campo nome dell&acute;azienda &eacute; obbligatorio", "Company is required");
	
	var address1 = document.preventivoForm.indirizzo1.value;
	address1Array = new Array("Il campo indirizzo &eacute; obbligatorio", "Address is required");
	var city = document.preventivoForm.citta.value;
	cityArray = new Array("Il campo citt&agrave; &eacute; obbligatorio", "City is required");
	var zip = document.preventivoForm.cap.value;
	zipArray = new Array("Il campo cap &eacute; obbligatorio", "Zipcode is required");
	var provincia = document.preventivoForm.provincia.value;
	provinciaArray = new Array("Il campo provincia &eacute; obbligatorio", "State is required");
	var telefono = document.preventivoForm.telefono.value;
	telefonoArray = new Array("Il campo telefono &eacute; obbligatorio", "Telephone is required");
	
	var nome = document.preventivoForm.nome.value;
	nomeArray = new Array("Il campo nome &eacute; obbligatorio", "Name is required");
	var cognome = document.preventivoForm.cognome.value;
	cognomeArray = new Array("Il campo cognome &eacute; obbligatorio", "Surname is required");
	var email = document.preventivoForm.email.value;
	emailArray = new Array("Il campo email non &eacute; corretto", "Email is incorrect");
	var servizioRichiesto = document.preventivoForm.servizio_richiesto.value;
	servizioRichiestoArray = new Array("Il campo servizio richiesto &eacute; obbligatorio", "Subject is required");
	var messaggio = document.preventivoForm.messaggio.value;
	messaggioArray = new Array("Il campo messaggio &eacute; obbligatorio", "Message is required");
	
	var privacy = document.preventivoForm.privacy.checked;
	privacyArray = new Array("Il campo privacy &eacute; obbligatorio", "Privacy is required");
	
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if ((azienda == "") || (azienda == undefined)) {
	   $("#alertBox").html(aziendaArray[index]);
	   $("#dialog-message").dialog('open');
	} else if ((address1 == "") || (address1 == "undefined")) {
		$("#alertBox").html(address1Array[index]);
		$("#dialog-message").dialog('open');
	} else if ((zip == "") || (zip == "undefined")) {
		$("#alertBox").html(zipArray[index]);
		$("#dialog-message").dialog('open');
	} else if ((city == "") || (city == "undefined")) {
		$("#alertBox").html(cityArray[index]);
		$("#dialog-message").dialog('open');
	} else if ((provincia == "") || (provincia == "undefined")) {
		$("#alertBox").html(provinciaArray[index]);
		$("#dialog-message").dialog('open');
	} else if ((nome == "") || (nome == undefined)) {
	   $("#alertBox").html(nomeArray[index]);
	   $("#dialog-message").dialog('open');
	} else if ((cognome == "") || (cognome == undefined)) {
	   $("#alertBox").html(cognomeArray[index]);
	   $("#dialog-message").dialog('open');
	} else if ((!email_reg_exp.test(email) || (email == "") || (email == undefined))) {
	   $("#alertBox").html(emailArray[index]);
	   $("#dialog-message").dialog('open');
	} else if ((telefono == "") || (telefono == undefined)) {
	   $("#alertBox").html(telefonoArray[index]);
	   $("#dialog-message").dialog('open');
	} else if ((servizioRichiesto == "") || (servizioRichiesto == undefined)) {
	   $("#alertBox").html(servizioRichiestoArray[index]);
	   $("#dialog-message").dialog('open');
	} else if ((messaggio == "") || (messaggio == undefined)) {
	  $("#alertBox").html(messaggioArray[index]);
	  $("#dialog-message").dialog('open');
	} else if ((privacy == false) || (privacy == undefined)) {
	  $("#alertBox").html(privacyArray[index]);
	  $("#dialog-message").dialog('open');
	} else {
	   $('#preventivoForm').submit();
	}
}

function doRefreshConvalida(divId) { 
  $("#"+divId).hide();
  $("#"+divId).html("");
}



