/************************************************
/* FILENAME: COMMON.JS
/* AUTHOR: CRISTIANO MOTTA
/* LIBRERIE JAVASCRIPT PER LOGICA LATO CLIENT
/***********************************************/


/*************************************
/*	 ELENCO MESSAGGI D'ERRORE 
/*************************************/
var ERRMSG = new Array();

ERRMSG[0] = "Attenzione, inserire LOGIN e PASSWORD per accedere all'area riservata.";
ERRMSG[1] = "Attenzione, inserire la data nel formato corretto.";
ERRMSG[2] = "Attenzione, compilare tutti i campi prima di proseguire.";
ERRMSG[3] = "Attenzione, il messaggio di avviso non può superare i 350 caratteri.";
ERRMSG[4] = "Attenzione, ci sono alcuni caratteri non ammessi nel campo di testo.";
ERRMSG[5] = "Attenzione, l'indirizzo email non è valido.";
ERRMSG[6] = "Attenzione, si è verificato un errore nell'invio del messaggio. Riprova più tardi, grazie.";
ERRMSG[7] = "Attenzione, inserire la password per procedere.";


function CheckFormAvviso()
{	  	
	if (!CheckMandatoryField(document.getElementById("titolo_avviso").value))
	{
		alert(ERRMSG[2]);
		return false;
	}

	if (!CheckMandatoryField(document.getElementById("testo_avviso").value))
	{
		alert(ERRMSG[2]);
		return false;
	}
	return true;
}


function CheckMandatoryField(szTxt)
{
	if (szTxt.length == 0)
		return false;
	else
		return true;
}

function _regexEmail(szEmail)
{

	var regex = /^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/
	if (regex.test(szEmail))
		return true
	else
		return false

}

function _regexEuroDate(szDate)
{
	 var regex = /^(?:(?:0?[1-9]|1\d|2[0-8])(\/|-)(?:0?[1-9]|1[0-2]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:31(\/|-)(?:0?[13578]|1[02]))|(?:(?:29|30)(\/|-)(?:0?[1,3-9]|1[0-2])))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(29(\/|-)0?2)(\/|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$/  			
	 //alert(regex.test(data_avviso));

	 if (regex.test(szDate))	 
		 return true;
	 else
		 return false;
}


/******************************************/
/* Controlla il tasto premuto dall'utente */
/******************************************/
function CheckDigit(e,tipo)
{
	var cod = null;
	// browser sniffer
	if(window.event) {  // for IE, e.keyCode or window.event.keyCode can be used
		cod = e.keyCode;
	}
	else if(e.which) { // netscape or Firefox
		cod = e.which;
	}
		
	//alert(cod);
	if (cod == 13 && e.which) {//Firefox
		e.preventDefault();
		return false;
	}
	else if (cod == 13 && window.event) {//IE
		e.returnValue = false;
		return false;
	}
}

function showf2() {
	document.getElementById("secondtd").innerHTML = "Testo del Programma";
}


function Freccia(idObj) {
	idObj.style.cursor = 'pointer';
}


function ReplacePage(URLpage) {
	location.replace(URLpage);
}

//tolgo i caratteri < > dall'xml	(non utilizzata)
function cleanTextBox(szText)  {
	var regEx = new RegExp ('<|>', 'gi') ;
	szText = szText.replace(regEx, '')
	return szText; 
}

function CheckFormInfo()
{	  	
	if (!CheckMandatoryField(document.getElementById("email_info").value)) {
		alert(ERRMSG[2]);
		return false;
	}

	if (!CheckMandatoryField(document.getElementById("testo_info").value)) {
		alert(ERRMSG[2]);
		return false;
	}
	
	if (!_regexEmail(document.getElementById("email_info").value)) {
		alert(ERRMSG[5]);
		return false;
	}
	return true;
}

function popitup(url) {
	newwindow=window.open(url,'name','height=600,width=750,resizable=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}



/**************************************
* http://vertical-scroller.vbarsan.com/
*    This notice may not be removed 
**************************************/

//-- Begin Scroller's Parameters and messages -->
//scroller's width
var swidth=135;

//scroller's height
var sheight=180;


//scroller's speed 
var sspeed=2;
var restart=sspeed;
var rspeed=sspeed;

//scroller's pause 
var spause=2000;

//scroller's background
var sbcolor="#FFFFFF";

//singletext[1]='<div class=tan><b>On Windows/Linux:</b><br>ie4+ firefox1+ ns6+ opera7+ ns4+.<br><br><b>On Mac OS X</b>:<br>Safari, ie5+ firefox1+ opera7+.<br><br>Any message may be <b><i>as large as desired.</i></B><br>===<br><br><font color="olive">Any wider row will automatically be adjusted into as many rows as to fit the width you set for the scrolling area.</font><br><br>===<br>One may use <b><i>any basic HTML code.</i><br><br>===</B></div>';
//singletext[...]='...';
//-- end Parameters and message -->

//-- begin: Scroller's Algorithm -->
var ii=0;
function goup(){if(sspeed!=rspeed*16){sspeed=sspeed*2;restart=sspeed;}}

function start(){
	
if(document.getElementById){ns6div=document.getElementById('iens6div');ns6div.style.top=sheight+"px";ns6div.innerHTML=singletext[0];sizeup=ns6div.offsetHeight;ns6scroll();}
else 
if(document.layers){ns4layer=document.ns4div.document.ns4div1;ns4layer.top=sheight;ns4layer.document.write(singletext[0]);ns4layer.document.close();sizeup=ns4layer.document.height;ns4scroll();}
else 
if(document.all){iediv=iens6div;iediv.style.pixelTop=sheight+"px";iediv.innerHTML=singletext[0];sizeup=iediv.offsetHeight;iescroll();}}
function iescroll(){if(iediv.style.pixelTop>0&&iediv.style.pixelTop<=sspeed){iediv.style.pixelTop=0;setTimeout("iescroll()",spause);}else 
if(iediv.style.pixelTop>=sizeup*-1){iediv.style.pixelTop-=sspeed+"px";setTimeout("iescroll()",100);}else{if(ii==singletext.length-1)ii=0;else ii++;iediv.style.pixelTop=sheight+"px";iediv.innerHTML=singletext[ii];sizeup=iediv.offsetHeight;iescroll();}}
function ns4scroll(){if(ns4layer.top>0&&ns4layer.top<=sspeed){ns4layer.top=0;setTimeout("ns4scroll()",spause);}else 
if(ns4layer.top>=sizeup*-1){ns4layer.top-=sspeed;setTimeout("ns4scroll()",100);}else{if(ii==singletext.length-1)ii=0;else ii++;ns4layer.top=sheight;ns4layer.document.write(singletext[ii]);ns4layer.document.close();sizeup=ns4layer.document.height;ns4scroll();}}
function ns6scroll(){if(parseInt(ns6div.style.top)>0&&parseInt(ns6div.style.top)<=sspeed){ns6div.style.top=0;setTimeout("ns6scroll()",spause);}else 
if(parseInt(ns6div.style.top)>=sizeup*-1){ns6div.style.top=parseInt(ns6div.style.top)-sspeed+"px";setTimeout("ns6scroll()",100);}
else{if(ii==singletext.length-1)ii=0;else ii++;
ns6div.style.top=sheight+"px";ns6div.innerHTML=singletext[ii];sizeup=ns6div.offsetHeight;ns6scroll();}}


function DrawScrollingNews() {
	if (document.layers) {
		document.write('<ilayer id="ns4div" width="'+swidth+'" height="'+sheight+'" bgcolor='+sbcolor+'><layer id="ns4div1" width="'+swidth+'" height="'+sheight+'" onmouseover="sspeed=0;" onmouseout="sspeed=rspeed"></layer></ilayer>')
	}						
	
	if(document.getElementById||document.all) {
		document.write('<div style="position:relative;overflow:hidden;width:'+swidth+'px;height:'+sheight+'px;clip:rect(0 '+swidth+'px '+sheight+'px 0);background-color:'+sbcolor+';" onmouseover="sspeed=0" onmouseout="sspeed=rspeed"><div id="iens6div" style="position:relative;width:'+swidth+'px;"></div></div>');						
	}
}



