// JavaScript Document
function 
updateContent(url, the_div) 
{
	myDiv = the_div;
	myRequest = CreateXmlHttpReq(myHandler);
	myRequest.open("GET", url);
	myRequest.send(null);
}


function 
CreateXmlHttpReq(handler) 
{
	var xmlhttp = null;
	try 
		{
		xmlhttp = new XMLHttpRequest();
		} 
	catch(e) 
		{
		try 
			{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} 
		catch(e) 
			{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	xmlhttp.onreadystatechange = handler;
	return xmlhttp;
} // CreateXmlHttpReq


function 
myHandler(the_div) 
{
	if(myRequest.readyState == 4 && myRequest.status == 200) 
	{
	e = document.getElementById(myDiv);
//alert(myRequest.responseText);
	e.innerHTML = myRequest.responseText;
	}
}

function checkEmail(email) {
  if (window.RegExp) {
    var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    var regnv = new RegExp(nonvalido);
    var regv = new RegExp(valido);
    if (!regnv.test(email) && regv.test(email))
      return true;
    return false;
	}
  else {
    if(email.indexOf("@") >= 0)
      return true;
    return false;
  	}
}

function checkDate(giorno, mese, anno){
	source_date = new Date(anno,mese,giorno);

	if(anno != source_date.getFullYear()) return false;
	if(mese != source_date.getMonth()) return false;
	if(giorno != source_date.getDate()) return false;

	return true;
}

function checkContattaci(modulo) {
if (!checkEmail(modulo.email.value)) 
	{
	modulo.email.select();
	alert("Si prega di inserire un indirizzo email valido");
	return false;
	}
if (!checkDate(modulo.giorno.value, modulo.mese.value, modulo.anno.value)) 
	{
	modulo.giorno.select();
	alert("Si prega di inserire una data di nascita valida");
	return false;
	}
if(!modulo.privacy.checked)
	{
	alert("Prendere visione della nota informativa sulla privacy.");
	return false;
	}
return true;
}

// These defaults should be changed the way it best fits your site
var _POPUP_FEATURES = 'location=0,statusbar=no,menubar=no,width=450,height=500';

function raw_popup(url, target, features) {
    // pops up a window containing url optionally named target, optionally having features
    if (isUndefined(features)) features = _POPUP_FEATURES;
    if (isUndefined(target  )) target   = '_blank';
    var theWindow = window.open(url, target, features);
    theWindow.focus();
    return theWindow;
}

function link_popup(src, features) {
    // to be used in an html event handler as in: <a href="..." onclick="link_popup(this,...)" ...
    // pops up a window grabbing the url from the event source's href
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}

function isUndefined(v) {
    var undef;
    return v===undef;
}

function setNew(url) 
{
		urlF = document.location.href;
		xend = urlF.lastIndexOf("/") + 1;
		var base_url = urlF.substring(0, xend);
        //Inizia l'url con http?
        if (url.substring(0, 4) != 'http') {
                url = base_url + url;
        }

        // Crea un nuovo elemento JS
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;

        //Appende l'elemento JS e quindi esegue la 'chiamata AJAX')
        document.body.appendChild (jsel);
}