function newWindow(mypage,myname,w,h,features) {
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}

function get_radio_value(){
	for(var i=0; i < document.jump.var1.length; i++)
	{
		if(document.jump.var1[i].checked)
		{
			var rad_val = document.jump.var1[i].value;
		}
	}
	return(rad_val);
}

function  jump_radio(){
	var link=document.jump.jslink;
	var choice1=get_radio_value();
	self.location.href=link.value+"&var1="+choice1+"#a1";
}

function  jump1(){
	var link=document.form1.link;	/* forms[0] */
	var choice1=document.form1.var1;
	self.location.href=link.value+"&IDvar1="+choice1.options[choice1.selectedIndex].value+"#a1";
}

function  jump2(){
	var link=document.form1.link;
	var choice1=document.form1.var1;
	var choice2=document.form1.var2;
	self.location.href=link.value+"&IDvar1="+choice1.options[choice1.selectedIndex].value+"&IDvar2="+choice2.options[choice2.selectedIndex].value+"#a1";
}

function  jump3(){
	var link = document.form1.link;
	var choice1 = document.form1.var1;
	var choice2 = document.form1.var2;
	var choice3 = document.form1.var3;
	self.location.href=link.value+"&IDvar1="+choice1.options[choice1.selectedIndex].value+"&IDvar2="+choice2.options[choice2.selectedIndex].value+"&IDvar3="+choice3.options[choice3.selectedIndex].value+"#a1";
}

// aggiornamento select lingua
function  jump_language(){
	var sl=document.form_lng.lng;
	self.location.href="index.php?lngId="+sl.options[sl.selectedIndex].value;
}

function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
	var anchor = anchors[i];
	if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
		anchor.target = "_blank";
		if (anchor.title) anchor.title += " (Il link apre una nuova finestra)";
		if (!anchor.title) anchor.title = "Il link apre una nuova finestra";
	}
}
}
window.onload = externalLinks;

// Form

/*
window.onload=function(){
if(!document.getElementById || !document.createElement) return;
document.forms[0].onsubmit=function(){
	if(Validate())
		document.forms[0].submit();
	else{
		alert("attenzione: alcuni campi non sono stati inseriti o l\' indirizzo email fornito non è valido");
		return(false);
		}
	}
}
*/

// onsubmit=\"return confirmSubmit();\"
function confirmSubmit()
{
	var agree=confirm("Are you sure you wish to continue?");
	if (agree)
	return true ;
	else
	return false ;
}

// Funzioni di class.form.php

function validateForm(oForm)
{
	var formID = $(oForm).getProperty('id');
	oForm.onsubmit = function() // attach the function to onsubmit event
	{
		if(Validate(formID)) {
			//document.forms[formID].submit();
		}
		else {
			alert("Attenzione: alcuni campi obbligatori non sono stati inseriti o l'email inserita non valida");
			return(false);
		}
	}
}

function Validate(formID){
	
	var labels = $$('#'+formID+' label');
	var validationOK=true; 

	for(var i=0;i<labels.length;i++)
	{
		var lab=labels[i];
		if(lab.className=="req2") lab.className="req";
		if(lab.className=="req")
		{
			var form_element_id = lab.getProperty('for');
			var match_sb = /(.*?)\[\]/.exec(form_element_id);
			if(match_sb && match_sb.length>0) 
				var form_elements = $$('#'+formID+' [name^='+match_sb[1]+'[]');
			else 
				var form_elements = $$('#'+formID+' [name='+form_element_id+']');
			var form_element = form_elements[0];
			
			if(form_element.match('input')) {
				if(form_element.getProperty('type')=='text') {
					if(form_element.getProperty('value') == '' || (form_element_id=='email' && !isEmail(form_element.getProperty('value')))) {
						lab.className="req2";   //input vuoto o email non valida
						validationOK=false;
					}
				}
				else if(form_element.getProperty('type')=='checkbox') {
					var checked = false;
					for(var l=0;l<form_elements.length;l++) {
						if(form_elements[l].checked) checked = true;
					}
				       	if(!checked) {
						lab.className="req2";   //checkbox non selezionato
						validationOK=false;
					}
				}
				else if(form_element.getProperty('type')=='radio') {
					var checked = false;
					for(var iii=0;iii<form_elements.length;iii++) {
						if(form_elements[iii].checked) checked = true;
					}
				       	if(!checked) {
						lab.className="req2";   //radio non selezionato
						validationOK=false;
					}
				}
				else if(form_element.getProperty('type')=='hidden') {
					if(FCKeditorAPI.GetInstance(form_element_id).GetXHTML() == "") {
						lab.className="req2";   //input vuoto
						validationOK=false;
					}
				}

			}
			else if(form_element.match('textarea')) {
				if(form_element.getProperty('value') == '') {
					lab.className="req2";   //textarea vuoto
					validationOK=false;
				}
			}
			else if(form_element.match('select')) { 
				if(form_element.getProperty('value') == '') {
					lab.className="req2";   //select vuoto
					validationOK=false;
				}
			}
		}
	}
	return(validationOK);
}

function isEmail(str){
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}
