var menu=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();
function replaceImg(id)
{
	if(document.getElementById(id).src=="http://www.atswellness.com/images/"+id+".jpg")
		document.getElementById(id).src="images/over/"+id+".jpg";
	else
		document.getElementById(id).src="images/"+id+".jpg";
}
function checkEmail(id){
	var email=document.getElementById(id).value;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) {
		document.getElementById(id).style.border="1px solid #F00";
		return false;
		}else{
		document.getElementById(id).style.border="1px solid #060";
		return true;
		}
}
function selezionaElemento(id_elemento) {
  if( document.getElementById ) {
  //mozilla
  //alert("document.getElementById");
    return document.getElementById(id_elemento); }
  if( document.all ) {
  //IE
  //alert("document.all");
    return document.all[id_elemento]; }
  if( document.layers ) {
  //netScape
   //alert("document.layers");
    if( document.layers[id_elemento] ) { 
	//alert("document.layers[divID]");
	return document.layers[id_elemento]; }
	}
  return false;
}

function regEmail(){
	id=selezionaElemento('email').value;
	if(checkEmail('email'))
	{
		if (window.XMLHttpRequest) { 
			// Mozilla, Safari, ...
			http_request = new XMLHttpRequest();
			} else if (window.ActiveXObject) { 
			// IE
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
		if (!http_request) {
				alert('ERRORE:\nNon riesco a creare una istanza XMLHTTP');
				return false;
			}
			http_request.onreadystatechange = function() {
				if (http_request.readyState == 4) {
					if (http_request.status == 200) {
						if(http_request.responseText!=""){
							selezionaElemento('result').innerHTML=http_request.responseText;
							selezionaElemento('email').value="";
							document.getElementById('email').style.border="1px solid #000";
						}else{
							selezionaElemento('result').innerHTML="Errore nel registrare l'email";
						}
					} else {
						alert('Si è verificato un problema con la richiesta');
					}
				} 
			};
			http_request.open('GET', 'save_email.php?email='+id, true);
			http_request.send(null);
	}
}
function sendForm()
{
	oggetto=selezionaElemento('oggetto').value;
	cognome=selezionaElemento('cognome').value;
	nome=selezionaElemento('nome').value;
	email=selezionaElemento('femail').value;
	messaggio=selezionaElemento('messaggio').value;
	if(checkEmail('femail'))
	{
		if(oggetto!="" && cognome!="" && nome!="" && messaggio!=""){
			if (window.XMLHttpRequest) { 
				// Mozilla, Safari, ...
				http_request = new XMLHttpRequest();
				} else if (window.ActiveXObject) { 
				// IE
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
			if (!http_request) {
					alert('ERRORE:\nNon riesco a creare una istanza XMLHTTP');
					return false;
				}
				http_request.onreadystatechange = function() {
					if (http_request.readyState == 4) {
						if (http_request.status == 200) {
							if(http_request.responseText!=""){
								selezionaElemento('risp').innerHTML="<b>Richiesta inviata con successo</b>";
								selezionaElemento('femail').value="";
								selezionaElemento('oggetto').value="";
								selezionaElemento('cognome').value="";
								selezionaElemento('nome').value="";
								selezionaElemento('messaggio').value="";
								document.getElementById('femail').style.border="1px solid #000";
							}else{
								selezionaElemento('risp').innerHTML="Errore nell'invio della richiesta<br>";
							}
						} else {
							selezionaElemento('risp').innerHTML="Errore nell'invio della richiesta<br>"+http_request.status;
						}
					} 
				};
				http_request.open('GET', 'sendForm.php?email='+email+'&nome='+nome+'&cognome='+cognome+'&oggetto='+oggetto+'&messaggio='+messaggio, true);
				http_request.send(null);
		}
		else
		{
			selezionaElemento('risp').innerHTML="<span style=\"color:#F00;\"><b>Inserire tutti i campi</b></span>";
		}
	}
}
function contactPressed(){
	var http_request;
	if (window.XMLHttpRequest) { 
		// Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		} else if (window.ActiveXObject) { 
		// IE
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
		}
	if (!http_request) {
			alert('ERRORE:\nNon riesco a creare una istanza XMLHTTP');
			return false;
		}
		http_request.open('GET', 'admin/writefile.php', true);
		http_request.send(null);
	}