function sendmail(subject){
	window.location.href = "mailto:?subject="+escape(subject)+"&amp;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";
        }
	}
}
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;
}
