function toggleAll()
{
	if($('il_testo'))
	{
		Effect.toggle($('il_testo'),'appear');
		Effect.toggle($('form'),'appear');
		
		if($('form').visible())
		{
			$('bottone2').src = 'images/pop/bottone_info2.jpg';
		}
		else
		{
			$('bottone2').src = 'images/pop/bottone_info2_on.jpg';
		}
	}
	else return;
}


function searchLabelByInput(input)
{
	var i;
	var labels = $$('label');
	for(i=0;i<labels.length;i++)
	{
		if(labels[i].readAttribute('for') == input) return Element.extend(labels[i]);  
	}
	return null;
}

function toggleLabelState(element, label_frat)
{
	var elemento = Element.extend(element);	
	//var label_fratello = Element.extend(label_frat);
	
	var label = searchLabelByInput(label_frat);
	
	

	if(elemento.className.match('off'))
	{
		elemento.className = elemento.className.replace('off', 'on');
		label.className = label.className.replace('on', 'off');
	}
	else
	{
//		elemento.className = elemento.className.replace('on', 'off');
//		label.className = label.className.replace('off', 'on');
		
	}
	
	
}



/*

======================================================================================================

 This script was tested with the following systems and browsers:

 - Windows XP: IE 6, NN 4, NN 7, Opera 7
 - Mac OS X:   IE 5, Safari 1

 If you use another browser or system, this script may not work for you - sorry.

------------------------------------------------------------------------------------------------------

 USAGE:

 Use the toolTip-function with mouse-over and mouse-out events (see example below).

 - To show a tooltip, use this syntax: toolTip(text, width in pixels, opacity in percent)
   Note: width and opacity are optional

 - To hide a tooltip, use this syntax: toolTip()

------------------------------------------------------------------------------------------------------

 EXAMPLE:

 <a href="#" onMouseOver="toolTip('Just a test', 150)" onMouseOut="toolTip()">some text here</a>

======================================================================================================
*/
  function TOOLTIP() {
//----------------------------------------------------------------------------------------------------
// Configuration
//----------------------------------------------------------------------------------------------------
    this.width = 400;                     // width (pixels)
    this.bgColor = '#C9DFF4';             // background color
    this.textColor = '#A00000';           // text color
    this.borderColor = '#003295';         // border color
    this.opacity = 80;                    // opacity (percent) - doesn't work with all browsers
    this.cursorDistance = 3;              // distance from cursor (pixels)

    // don't change
    this.text = '';
    this.obj = 0;
    this.sobj = 0;
    this.active = false;

// -------------------------------------------------------------------------------------------------------
// Functions
// -------------------------------------------------------------------------------------------------------
    this.create = function() {
      if(!this.sobj) this.init();

      var t = '<table border=0 cellspacing=0 cellpadding=4 width=' + this.width + ' bgcolor=' + this.bgColor + '><tr>' +
              '<td align=center><font color=' + this.textColor + '>' + this.text + '</font></td></tr></table>';

      if(document.layers) {
        t = '<table border=0 cellspacing=0 cellpadding=1><tr><td bgcolor=' + this.borderColor + '>' + t + '</td></tr></table>';
        this.sobj.document.write(t);
        this.sobj.document.close();
      }
      else {
        this.sobj.border = '1px solid ' + this.borderColor;
        this.setOpacity();
        if(document.getElementById) document.getElementById('ToolTip').innerHTML = t;
        else document.all.ToolTip.innerHTML = t;
      }
      this.show();
    }

    this.init = function() {
      if(document.getElementById) {
        this.obj = document.getElementById('ToolTip');
        this.sobj = this.obj.style;
      }
      else if(document.all) {
        this.obj = document.all.ToolTip;
        this.sobj = this.obj.style;
      }
      else if(document.layers) {
        this.obj = document.ToolTip;
        this.sobj = this.obj;
      }
    }

    this.show = function() {
      var ext = (document.layers ? '' : 'px');
      var left = mouseX;

      if(left + this.width + this.cursorDistance > winX) left -= this.width + this.cursorDistance;
      else left += this.cursorDistance;

      this.sobj.left = left + ext;
      this.sobj.top = mouseY + this.cursorDistance + ext;

      if(!this.active) {
        this.sobj.visibility = 'visible';
        this.active = true;
      }
    }

    this.hide = function() {
      if(this.sobj) this.sobj.visibility = 'hidden';
      this.active = false;
    }

    this.setOpacity = function() {
      this.sobj.filter = 'alpha(opacity=' + this.opacity + ')';
      this.sobj.mozOpacity = '.1';
      if(this.obj.filters) this.obj.filters.alpha.opacity = this.opacity;
      if(!document.all && this.sobj.setProperty) this.sobj.setProperty('-moz-opacity', this.opacity / 100, '');
    }
  }

//----------------------------------------------------------------------------------------------------
// Build layer, get mouse coordinates and window width, create tooltip-object
//----------------------------------------------------------------------------------------------------
  var tooltip = mouseX = mouseY = winX = 0;

  if(document.layers) {
    document.write('<layer id="ToolTip"></layer>');
    document.captureEvents(Event.MOUSEMOVE);
  }
  else document.write('<div id="ToolTip" style="position:absolute; z-index:99"></div>');
  document.onmousemove = getMouseXY;

  function getMouseXY(e) {
    if(document.all) {
      mouseX = event.clientX + document.body.scrollLeft;
      mouseY = event.clientY + document.body.scrollTop;
    }
    else {
      mouseX = e.pageX;
      mouseY = e.pageY;
    }
    if(mouseX < 0) mouseX = 0;
    if(mouseY < 0) mouseY = 0;

    if(document.body && document.body.offsetWidth) winX = document.body.offsetWidth - 25;
    else if(window.innerWidth) winX = window.innerWidth - 25;
    else winX = screen.width - 25;

    if(tooltip && tooltip.active) tooltip.show();
  }

  function toolTip(text, width, opacity) {
    if(text) {
      tooltip = new TOOLTIP();
      tooltip.text = text;
      if(width) tooltip.width = width;
      if(opacity) tooltip.opacity = opacity;
      tooltip.create();
    }
    else if(tooltip) tooltip.hide();
  }


function isValidEmail(addressS)
{
	emailRegexp = RegExp('^[A-Za-z0-9._-]+[@]([A-Za-z0-9-]+[.])+([A-za-z]{2,4})$', 'i');
	if (emailRegexp.test(addressS)) return true
	else return (false);
}


function checkForm()
{
	
	var validate = true;
	if($('errore')) $('errore').remove();

//	nome	
	if($('frm_nome').value == '')
	{
		$('frm_nome').up('td').setStyle({'background': '#FBFF98'});
		var parent = searchLabelByInput('frm_nome').up('td');
		parent.setStyle({'background': '#FBFF98'});
		validate = false;
	}
	else
	{
		$('frm_nome').up('td').setStyle({'background': ''});
		var parent = searchLabelByInput('frm_nome').up('td');
		parent.setStyle({'background': ''});
	}
	
//	telefono
	if($('frm_telefono').value == '')
	{
		$('frm_telefono').up('td').setStyle({'background': '#FBFF98'});
		var parent = searchLabelByInput('frm_telefono').up('td');
		parent.setStyle({'background': '#FBFF98'});
		validate = false;
	}
	else
	{
		$('frm_telefono').up('td').setStyle({'background': ''});
		var parent = searchLabelByInput('frm_telefono').up('td');
		parent.setStyle({'background': ''});
	}
	
//	mail
	if(!isValidEmail($('frm_email').value))
	{
		$('frm_email').up('td').setStyle({'background': '#FBFF98'});
		var parent = searchLabelByInput('frm_email').up('td');
		parent.setStyle({'background': '#FBFF98'});
		validate = false;
	}
	else
	{
		$('frm_email').up('td').setStyle({'background': ''});
		var parent = searchLabelByInput('frm_email').up('td');
		parent.setStyle({'background': ''});
	}
	
//	privacy
	if(!$('frm_privacy').checked)
	{
		$('frm_privacy').up('p').setStyle({'background': '#FBFF98'});
		validate = false;
	}
	else
	{
		$('frm_privacy').up('p').setStyle({'background': ''});
	}
	
	
	if(!validate)
	{
		var errore = document.createElement('p');
		errore.setAttribute('id', 'errore');
		$('form').appendChild(errore);
		
		var errore_text =document.createTextNode('Compilare i campi evidenziati');
		$('errore').appendChild(errore_text);
		
		new Effect.Highlight('errore',{duration: 2.0});
	}
	
	
				var d = new Date();
				param = d.getTime();
				
				document.forms['form_preventivo'].secure.value = param;
				

	
	return validate;
}
