                function CheckForm() {
                  var error = '';
                  Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
                  if (document.form._name.value.length == 0 ||
                    document.form._name.value == 'il tuo nome') {
                    error += "Il campo NOME e' obbligatorio\n";
                  }
                  if (document.form._mail.value.length != 0) {
                    if ((document.form._mail.value == 'la tua email')
                            || !Filtro.test(document.form._mail.value)) {
                      error += "La tua EMAIL non e' valida\n";
                    }
                  }
                  if (document.form._commnt.value.length == 0 ||
                    document.form._commnt.value=='inserisci commento') {
                        error += "Non e' possibile inviare un messaggio vuoto\n";
                  }
                  if (error) {
                    alert(error);
                    return(false);
                  }
                  return(true);
                }


function regionestatocs(cmp){

var url = 'http://www.sardegnamigranti.it/index.php?xsl=729&s=25&v=9&c=5237&campo='+cmp.options[cmp.options.selectedIndex].value;
/*
var el1 = document.getElementById("circoli");
            if (el1) {
            el1.style.display = '';
            }
*/
	liveReq = false;
	
	if (window.XMLHttpRequest) {
		liveReq = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		liveReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (liveReq && liveReq.readyState < 4) {
		liveReq.abort();
	}
	liveReq.onreadystatechange = function () {
		if (liveReq.readyState == 4) {
			if (liveReq.status == 200) {

				document.getElementById("circoli").innerHTML = liveReq.responseText;

			} else {
				alert('Si verificato un problema con la richiesta');
			}
			document.body.style.cursor = 'default';
		}
	}
	document.body.style.cursor = 'wait';

        //alert(url);
	liveReq.open("GET", url);
	liveReq.send(null);
	return false;


}





function sendmail2(subject,linkhref){
	window.location.href = "mailto:?subject="+escape(subject)+"&body="+escape(linkhref);
	return false;
}
function sendmail(subject){
	window.location.href = "mailto:?subject="+escape(subject)+"&body="+escape(window.location);
	return false;
}
function intercetta() {
    for (var i=0; i<document.links.length; i++) {
        if (document.links[i].rel=="blank") {
            document.links[i].target="_blank";
			document.links[i].title = document.links[i].title+" (apertura in nuova finestra)";
        }
        else if (document.links[i].rel=="blankcc") {
            document.links[i].target="_blank";
			document.links[i].rel="license";
			document.links[i].title = document.links[i].title+" (apertura in nuova finestra)";
        }
	}
}
addEvent(window,'load',intercetta);
/*window.onload = intercetta;*/
function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
/**
 * Determine whether a node's text content is entirely whitespace.
 *
 * @param nod  A node implementing the |CharacterData| interface (i.e.,
 *             a |Text|, |Comment|, or |CDATASection| node
 * @return     True if all of the text content of |nod| is whitespace,
 *             otherwise false.
 */
function is_all_ws( nod )
{
  // Use ECMA-262 Edition 3 String and RegExp features
  return !(/[^\t\n\r ]/.test(nod.data));
}


/**
 * Determine if a node should be ignored by the iterator functions.
 *
 * @param nod  An object implementing the DOM1 |Node| interface.
 * @return     true if the node is:
 *                1) A |Text| node that is all whitespace
 *                2) A |Comment| node
 *             and otherwise false.
 */

function is_ignorable( nod )
{
  return ( nod.nodeType == 8) || // A comment node
         ( (nod.nodeType == 3) && is_all_ws(nod) ); // a text node, all ws
}

/**
 * Version of |previousSibling| that skips nodes that are entirely
 * whitespace or comments.  (Normally |previousSibling| is a property
 * of all DOM nodes that gives the sibling node, the node that is
 * a child of the same parent, that occurs immediately before the
 * reference node.)
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The closest previous sibling to |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function node_before( sib )
{
	while ((sib = sib.previousSibling)) {
		if (!is_ignorable(sib))
			return sib;
	}
	return null;
}

/**
 * Version of |nextSibling| that skips nodes that are entirely
 * whitespace or comments.
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The closest next sibling to |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function node_after( sib )
{
	while ((sib = sib.nextSibling)) {
		if (!is_ignorable(sib))
			return sib;
	}

	return null;
}

function closeAll(){
	var hurray=document.getElementsByTagName('ul');
	if (hurray) {
		for (i=0;i<hurray.length;i++){
			if(hurray[i].className=='tab-open2'){
				hurray[i].style.display='none';
			}
		}
	}
	hurray=document.getElementsByTagName('div');
	if (hurray) {
		for (i=0;i<hurray.length;i++){
			if(hurray[i].className=='tab-open2'){
				hurray[i].style.display='none';
			}
		}
	}
}

function showSublinks(me,cat)
{
	if(me.src){
		if(me.src.substring(me.src.lastIndexOf('/')+1)=="minus.gif"){
			me.src="/img/plus.gif";
			me.alt="Espandi categoria "+cat;
			me.title="Espandi categoria "+cat;
			node_after(me.parentNode).style.display='none';
		}
		else{
			closeAll();
			me.src="/img/minus.gif";
			me.alt="Comprimi categoria "+cat;
			me.title="Comprimi categoria "+cat;
			node_after(me.parentNode).style.display='inline';
		}
	}
	else{
		closeAll();
		if(node_after(me.parentNode).style.display == 'inline'){
			node_after(me.parentNode).style.display='none';
		}
		else{
			node_after(me.parentNode).style.display='inline';
		}
	}
}

function openPopUp(url, larghezza, altezza){
	var location=url;
	if (location!=''){
		var DispWin;
		DispWin=window.open(location, '','toolbar=no, "NewWin", status=yes,resizable=yes,,scrollbars=yes, width='+larghezza+', height='+altezza+',  top=1, left=1');
		DispWin.focus();
	}
	return false;
}

function stoperror(){return true;}

window.onerror=stoperror
	
function validate_RecomendForm() {  
	var validity = true;
	if (!check_empty(document.inviaLink.senderName.value)) {
		validity = false;
		alert('Campo NOME MITTENTE obbligatorio!');
		document.inviaLink.senderName.focus();
	}		
	if (!check_email(document.inviaLink.senderEmail)) {
		if (validity == true)
			document.inviaLink.senderEmail.focus();
		validity = false;
	} 
	if (!check_email(document.inviaLink.receiverEmail)) {
		if (validity == true)
			document.inviaLink.receiverEmail.focus();
		validity = false;
	}
	return validity;
}

function check_empty(text) {
	return (text.length > 0); 
}

function check_email(address)
{
	var status = false;
	if (address.value.length > 0) {
		var regEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
		status = regEmail.test(address.value);
		if (status == false) {
			alert('Il campo \"Email\" non e\' valido');
		}
	}
	else
		alert('Campo \"Email\" obbligatorio!'); 
	return status;
}

function aprippinvio(url) {
	var location=url;
	if (location!=''){
		var DispWin;
		DispWin=window.open(location, '','toolbar=no, "NewWin", status=yes,resizable=no,,scrollbars=no, width=560px, height=600px,  top=1, left=1');
		DispWin.focus();
	}
	return false;
}


function galleriaimg(idc,c1,n,pagina,nn,w,h) {
	window.open("http://www.sardegnadigitallibrary.it/index.php?xsl=625&slide=1&s=17&v=9&c="+idc+"&c1="+c1+"&pagina="+pagina+"&nn="+nn+"&n="+n,"","width="+w+",height="+h+",top=60,left=60,status=no,menubar=no,toolbar=no,scrollbar=no");
	return false;
}

function temporizza(idc,pictemp,c1,numnews){
	window.location.href = "http://www.sardegnadigitallibrary.it/index.php?xsl=625&s=17&v=9&c="+idc+"&slide=1&na=1&pic="+pictemp+"&c1="+c1+"&n="+numnews;
}


function controllaform(f) {
 var msg = '';
 if ((f.email.value == '') || (f.emaildest.value == '')){
  if (f.email.value == '') {
   msg = '\nla tua email';
  }
  if (f.emaildest.value == '') {
   msg += '\nl\'email del destinatario 1';
  }
  alert('ATTENZIONE\ncampi mancanti:'+msg);
  return false;
 }

 if ((f.email.value != '') && (f.emaildest.value != '')){
  return true;
 }

}

function autoSelect(el) {
    if(el && (el.tagName === "TEXTAREA" || (el.tagName === "INPUT" && el.type === "text"))) {
        el.select();
        return;
    }
    
    if (el && window.getSelection) { // FF, Safari, Opera
        var sel = window.getSelection();
        var range = document.createRange();
        range.selectNodeContents(el);
        sel.removeAllRanges();
        sel.addRange(range);
    } else if (el) { // IE
        document.selection.empty();
        var range = document.body.createTextRange();
        range.moveToElementText(el);
        range.select();
    }
}

