/*
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Title : Vinimania.com javascript
Author : Michele De Angelis
Description : #######
Created : 03.09.2007
Modified : ######
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/

/*
Modifica Cristiano 21.10.2007
Aggiunta funzione controlla_campi_ricerca
*/

function controlla_campi_ricerca()
{
	if (document.ricerca_avanzata.nazione.value==0 && document.ricerca_avanzata.regione.value==0 && document.ricerca_avanzata.zona.value==0 && document.ricerca_avanzata.produttore.value==0 && document.ricerca_avanzata.categoria.value==0 && document.ricerca_avanzata.tipo.value==0 && document.ricerca_avanzata.nomevino.value=='')
	{
		alert('Inserire almeno un parametro di ricerca');
		return false;
	}
	if (document.ricerca_avanzata.nomevino.value!='' && document.ricerca_avanzata.nomevino.value.length<3)
	{
		alert('Il campo Nome Vino deve essere lungo almeno 3 caratteri');
		return false;
	}
	document.ricerca_avanzata.submit();
}

function controlla_campi_ricerca_semplice()
{
	if (document.ricerca.nomevino.value.length<3)
	{
		alert('Il campo ricerca deve essere lungo almeno 3 caratteri');
		return false;
	}
	document.ricerca.submit();
}


function getPageSize()
{
	/*
		array[0] = larghezza pagina
		array[1] = altezza pagina
		array[2] = larghezza finestra
		array[3] = altezza finestra
	*/
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function initDropdownMenu()
{
	var array_sottomenu = $$('.submenu');

	var sottomenu;
	var menu_padre;

	for(var i=0;i<array_sottomenu.length;i++)
	{
		sottomenu = array_sottomenu[i];
		menu_padre = sottomenu.up();
		sottomenu.setStyle(
		{
			'position': 'absolute',
			'left': '0px',
			'top': '36px',
			'border-top': '10px solid #9B4B0A',
			'width': '211px',
			'height': 'auto',
			'background': '#7F3E08',
			'opacity': '0.9'
		});
		sottomenu.hide();
		menu_padre.onmouseover = function()
		{
			this.className = 'active';
			//alert(sottomenu.inspect());

			this.getElementsByTagName('UL')[0].style.display="";
			if(navigator.userAgent.match('MSIE'))
			{
				this.setStyle({'padding-right': '22px','left': '0px'});
			}
			//sottomenu.show();


		}
		menu_padre.onmouseout = function()
		{
			this.className = this.className.replace('active', '');
			//sottomenu.hide();
			this.getElementsByTagName('UL')[0].style.display="none";
			if(navigator.userAgent.match('MSIE'))
			{
				this.setStyle({'left': '-1'});
			}
		}

		var sottomenu_figli = sottomenu.immediateDescendants();
		for(var j=0;j<sottomenu_figli.size();j++)
		{
			var li = sottomenu_figli[j];
			li.setStyle(
			{
				'float': 'none',
				'height': '31px',
				'border': 'none',
				'background': 'url(\'images/background/freccina.gif\') no-repeat 10px 14px',
				'border-bottom': '1px solid #98663C'
			});
			li.down().setStyle({'font-weight':'normal'});
			li.onmouseover = function()
			{
				this.down().setStyle(
				{
					'font-weight': 'bold'
				});
			}
			li.onmouseout = function()
			{
				this.down().setStyle(
				{
					'font-weight': 'normal'
				});
			}
		}
	}
}

function check_mail(id_obj, msg_txt)
  {
  el = document.getElementById(id_obj);

  if(el)
    {
    address = el.value;

    if (msg_txt == null)
      msg_txt = "Attenzione, indirizzo e-mail non corretto.";
    re = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    if (!re.test(address))
      {
      if (msg_txt != "")
        alert(msg_txt);
      return false;
      }
    else
      return true;
    }
  else
    {
    alert("Errore: impossibile trovare ID="+id_obj);
    return false;
    }
  }

/*
*****************************
Richiamo e load delle funzioni
*/
function allFunctions()
{
	initDropdownMenu();
}
if (window.attachEvent)
{
	window.attachEvent("onload", allFunctions);
}
else
{
	window.onload=allFunctions;
}