// mostra riquadro di anteprima
function anteprima(textarea,w,h) {
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;	
	//var inf = document.form.testo.value;
	var inf = document.getElementById(textarea).value;
	inf = inf.split(/\n/).join("<br />");
	var win = window.open(", ", "popup", "width="+w+",height="+h+",top="+TopPosition+",left="+LeftPosition+",scrollbars=yes");
	win.document.open();	
	win.document.writeln("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
	win.document.writeln("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>");
	win.document.writeln("<head><title>Anteprima</title>");	
	win.document.writeln("<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />");
	win.document.writeln("<link href='../inc/inc/style.css' rel='stylesheet' type='text/css' />");
	win.document.writeln("</head><body>");
	win.document.writeln("<div style='text-align:right; margin-bottom:20px;'><a href='javascript:window.close()'>Chiudi</A></div>");
	win.document.writeln("" + inf + "");
	win.document.writeln('</body></html>');
	win.document.close();
}

// data
function controllo_data(stringa){
	var espressione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
	if (!espressione.test(stringa))
	{
		return false;
	}else{
		anno = parseInt(stringa.substr(6),10);
		mese = parseInt(stringa.substr(3, 2),10);
		giorno = parseInt(stringa.substr(0, 2),10);
		
		// alert('anno ' + ' mese' + ' giorno');
		
		var data=new Date(anno, mese-1, giorno);
		if(data.getFullYear()==anno && data.getMonth()+1==mese && data.getDate()==giorno){
			return true;
		}else{
			return false;
		}
	}
}

//popup
var win = null;
function popup(mypage,w,h){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	h = h + 10;
	w = w + 10;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,resizable'
	winName =  'winName'+w+h;
	window.open(mypage,winName,settings);
}


//toggle
function toggle(obj,tipo) {
	var el = document.getElementById(obj);
	if (!tipo) {
		if ( el.style.display != 'none' ) {
			el.style.display = 'none';
		}	else {
			el.style.display = 'block';
		}
	} else if (tipo == 'mostra') { el.style.display = 'block';
	} else if (tipo == 'nascondi') { el.style.display = 'none';}
}

function cambiaClass(obj,classe) {
	var el = document.getElementById(obj);
		if (el.className == classe) {
				el.className = '';
		} else {
				el.className = classe;
		}
}

/*V*/
function controllaMail(EmailAddr){
 Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
 if (Filtro.test(EmailAddr))
    return true;
 else
    return false;
}

/************************************************
//	Funzioni per la gestione del campo testo SMS
*************************************************/
/*
function restrictinput(maxlength,e,placeholder){
	if (window.event&&event.srcElement.value.length>=maxlength)
	return false
	else if
	(e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){ var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
	if (pressedkey.test(String.fromCharCode(e.which)))
		e.stopPropagation();
	}
} 

function countlimit(maxlength,e,placeholder){
	var theform = eval(placeholder);
	var lengthleft = maxlength-theform.value.length;
	var placeholderobj = document.all? document.all[placeholder] :
	document.getElementById(placeholder);
	if (window.event||e.target&&e.target==eval(placeholder)){
	if (lengthleft<0)
		theform.value=theform.value.substring(0,maxlength);placeholderobj.innerHTML=lengthleft;
	}
} 

function displaylimit(thename, theid, thelimit){
	var theform = theid!=""? document.getElementById(theid) : thename;
	var limit_text='<strong>Caratteri rimanenti: <span id="char_rimanenti">'+thelimit+'</span> caratteri</strong>';
	alert('x: ' + limit_text);
	if (document.all||ns6){
		document.write(limit_text);
		//	alert('n6 NON vuoto');
	}
	if (document.all){
		eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform);}
		eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform);}
	}
	else if (ns6){
		alert('n6 NON vuoto');
		document.body.addEventListener('keypress', function(event) {
		restrictinput(thelimit,event,theform) }, true);
		document.body.addEventListener('keyup', function(event) {
		countlimit(thelimit,event,theform) }, true);
	}
}
*/