var imagedx = new Array();
var linktodx= new Array();
var altstrdx= new Array();

var imagesx = new Array();
var linktosx= new Array();
var altstrsx= new Array();

var news_sett= new Array();
var news_info= new Array();
var news_link= new Array();

var news_max = 1;
var news_sequence = 1;

var maxinddx = 1;
var maxindsx = 1;

var sequencedx = 1;
var sequencesx = 1;


function Prova() {
 alert('Ciao');
}


function getCookie(NameOfCookie) {
 if (document.cookie.length > 0) { 
	begin = document.cookie.indexOf(NameOfCookie+"="); 
	if (begin != -1) { 
	 begin += NameOfCookie.length+1; 
 	 end = document.cookie.indexOf(";", begin);
	 if (end == -1) end = document.cookie.length;
	 return unescape(document.cookie.substring(begin, end)); 
        } 
 }
 return null; 
}


function TestLogin() {
	  var Stato = getCookie("API");
	  var bTest = false

 	  if ((Stato!=null) && (Stato=='000000-')) bTest = true;
	  return bTest;
}
	
function rotate() {
	    if (++sequencedx > maxinddx) sequencedx=1;
	    if (++sequencesx > maxindsx) sequencesx=1;
	    if (++news_sequence > news_max) news_sequence=1;

	     document.images['banner_sx'].src = imagesx[sequencesx];
             document.images['banner_sx'].alt = altstrsx[sequencesx];
	     document.links[3].href = linktosx[sequencesx];

	     document.images['banner_dx'].src = imagedx[sequencedx];
             document.images['banner_dx'].alt = altstrdx[sequencedx];
	     document.links[6].href = linktodx[sequencedx];

	     window.setTimeout('rotate();',3000);
}  

function rotate_testata() {
	    if (++sequencedx > maxinddx) sequencedx=1;
	    if (++news_sequence > news_max) news_sequence=1;

	     document.images[4].src = imagedx[sequencedx];
             document.images[2].alt = altstrdx[sequencedx];
	     document.links[3].href = linktodx[sequencedx];

	     window.setTimeout('rotate_testata();',3000);
}

	function GestDocNews(settore,area,email) {
	var Stato = getCookie("API");
	var Ref = '000000';
        var tpos = 0;
	if (Stato!=null) 
		Ref = Stato.substring(0,6)
	else
		Stato='000000-';
	document.write('<div align="center"><center><table border="0">');
	document.write('<tr>');
	document.write('<td valign="middle" align="center">');
	document.write('<p class="t04" align="center">');
	if (settore!='') {
	  if (settore=='Sindacale') tpos=10;
	  if (settore=='Previdenziale') tpos=11;
	  if (settore=='Fiscale') tpos=12;
	  if (settore=='Economico') tpos=13;
	  if (settore=='Finanziario') tpos=14;
	  if (settore=='Sicurezza') tpos=15;
	  if (settore=='Ambientale') tpos=16;
	  if (settore=='Qualità') tpos=17;
	  if (settore=='Formazione') tpos=18;
	  if (settore=='Informatica') tpos=19;
	  if (settore=='Export') tpos=20;
	  if (settore=='Giovani') tpos=21;
	  if (settore=='Studi') tpos=22;

         if (Stato.substring(tpos-1,tpos)=='1' || Stato.substring(44,45)=='1') {
              document.write('<a class="l02" href="/cgi-bin/CgiArea.cgi?Settore=' + settore + '&Area=' + area + '&Ref=' + Ref + '"><img border="0" src="images/navigazione/ico_doc.gif">')
	 }
         else
              document.write('<a class="l02" href="/search_doc.asp?Settore=' + settore + '"><img border="0" src="images/navigazione/ico_doc.gif"></a></p>');  
	}
	else
		document.write('<p class="t04">&nbsp;</p>')
	    
	document.write('</td>');
	document.write('</tr>');
	document.write('<tr>');
	document.write('<td width="80" valign="middle" align="center">');
	if (area!='')
		document.write('<a href="/cgi-bin/CgiNews.cgi?Settore=' + settore + '&Area=' + area + '&Ref='+ Ref + '"><img border="0" alt="Gestione News" src="images/navigazione/ico_news.gif"></a>');
	else
		document.write('<p class="t04">&nbsp;</p>');
	document.write('</td>');
	document.write('</tr>');
	document.write('<tr>');
	if (email!='')
		document.write('<td width="80" valign="middle" align="center"><a href="mailto:' + email + '"><img border="0" src="images/navigazione/ico_email.gif" alt="Scrivi a ' + email + '"></a></td>')
	else
		document.write('<td width="80" valign="middle" align="center"><p class="t04">&nbsp;</p></td>');
	document.write('</tr>');
	document.write('</table></center></div>'); 
	}

	function Ind_11_Sett() {
 	window.open("/_modulistica/studi/documenti/ind001.htm","","width=505,height=450,resizable=no");
	}
	
	function wvota(IDQuest, IDUt) {
		w=window.open("/Sondaggi.asp?ID=" + IDQuest + "&Ut=" + IDUt + "&Fai=Vedi","","width=380,height=145,resizable=no")
	}

	function wpopup(surl,tit,x,h,resize,scroll,tool) {
		var z = 0, t = 0; // default values

		z = (screen.width-x)/2

		t = (screen.height-h)/3

		// z = 2 *  (screen.width - x.valueOf()) / 3;
  		// t =  (screen.height - h.valueOf()) / 3;

 		var w=window.open(surl,tit,"width=" + x + ",height=" + h + ",resizable=" + resize + ",scrollbars=" + scroll + ",toolbar=" + tool + ",top=" + t + ",left=" + z )
		w.focus
	}

	function ViewUt() {
		var Stato = getCookie("API");
	
		if (Stato!=null && Stato.substring(44,45)=="1") {
	 		window.open("/testloguser.asp","UserLog","width=600,height=350,resizable=yes,scrollbars=yes");
		}   
	}


	
	function Re_Load() {
	var Stato = getCookie("API");
	
		if (Stato==null) 
	    		Stato='000000-'
		if (document.Log.Status.value!=Stato) 
	 	history.go(0);
	}
	
	function Modulistica(settore,area) {
	var Stato = getCookie("API");
	var Ref = '000000';
	if (Stato!=null) 
		Ref = Stato.substring(0,6)
	else
		Stato='000000-';
	document.write('<p><font face="Verdana" size="1" color="#800000"><a href="/cgi-bin/CgiArea.cgi?Settore=' + settore + '&Area=' + area + '&Ref='+ Ref + '"><img border="0" src="images/navigazione/ico_doc.gif">');
	document.write('<br><b> ' + settore + ' </b> &gt; ' + area + '</a></font></p>');
	}

	function foto(descrizione, evento, scatti) {
 	window.open("/fotoview.asp?Evento=" + evento + "&Scatti=" + scatti + "&Descr=" + descrizione,"","width=320,height=290,resizable=no");
	}

	function rassegna(evento) {
	 	window.open("/_modulistica/rassegna_stampa/" + evento + ".htm","","width=600,height=400,resizable=no,scrollbars=yes");
	}

	function euro() {
 	window.open("/euro/index.htm","EURO","width=600,height=400,resizable=no,toolbar=no,scrollbars=no");
	}

	function right(e) {
	if (navigator.appName == 'Netscape' && 	(e.which == 3 || e.which == 2)) {
	 alert("www.api.bs.it \n tasto destro disabilitato !");
         return false;
	}
	else if (navigator.appName == 'Microsoft Internet Explorer' && 
	(event.button == 2 || event.button == 3)) {
	alert("www.api.bs.it \n tasto destro disabilitato !");
	return false;
	}
	return true;
	}

/*
Funzioni per lo scrorrimento del testo
*/
function verifyCompatibleBrowser(){ 
    this.ver=navigator.appVersion 
    this.dom=document.getElementById?1:0 
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
    this.ie4=(document.all && !this.dom)?1:0; 
    this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
 
    this.ns4=(document.layers && !this.dom)?1:0; 
    this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5) 
    return this 
} 
bw=new verifyCompatibleBrowser() 
 
 
var speed=50 
 
var loop, timer 
 
function ConstructObject(obj,nest){ 
    nest=(!nest) ? '':'document.'+nest+'.' 
    this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0; 
    this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0; 
    this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight 
    this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight 
    this.up=MoveAreaUp;this.down=MoveAreaDown; 
    this.MoveArea=MoveArea; this.x; this.y; 
    this.obj = obj + "Object" 
    eval(this.obj + "=this") 
    return this 
} 

function MoveArea(x,y){ 
    this.x=x;this.y=y 
    this.css.left=this.x 
    this.css.top=this.y 
} 
 
function MoveAreaDown(move){ 
	if(this.y>-this.scrollHeight+objContainer.clipHeight){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".down("+move+")",speed) 
	} 
} 
function MoveAreaUp(move){ 
	if(this.y<0){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".up("+move+")",speed) 
	} 
} 
 
function PerformScroll(speed){ 
	if(initialised){ 
		loop=true; 
		if(speed>0) objScroller.down(speed) 
		else objScroller.up(speed) 
	} 
} 
 
function CeaseScroll(){ 
    loop=false 
    if(timer) clearTimeout(timer) 
} 
var initialised; 
function InitialiseScrollableArea(){ 
    objContainer=new ConstructObject('divContainer') 
    objScroller=new ConstructObject('divContent','divContainer') 
    objScroller.MoveArea(0,0) 
    objContainer.css.visibility='visible' 
    initialised=true; 
}


function checkNumeric(objName,minval, maxval,comma,period,hyphen)
{
	var numberfield = objName;
	if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false)
	{
		numberfield.select();
		numberfield.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function chkNumeric(objName,minval,maxval,comma,period,hyphen)
{
// only allow 0-9 be entered, plus any values passed
// (can be in any order, and don't have to be comma, period, or hyphen)
// if all numbers allow commas, periods, hyphens or whatever,
// just hard code it here and take out the passed parameters
var checkOK = "0123456789" + comma + period + hyphen;
var checkStr = objName;
var allValid = true;
var decPoints = 0;
var allNum = "";

for (i = 0;  i < checkStr.value.length;  i++)
{
ch = checkStr.value.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid)
{	
alertsay = "Possono essere usati solo valori numerici !";
alert(alertsay);
objName.value='';
return (false);
}

// set the minimum and maximum
var chkVal = allNum;
var prsVal = parseInt(allNum);
if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
{
alertsay = "Il valore deve essere compreso tra "
alertsay = alertsay + minval + " e "
alertsay = alertsay + maxval + " !"
alert(alertsay);
objName.value='';
return (false);
}
}


function CercaDoc(IDVal){ 
 if (IDVal!="") {
   document.ricrap.submit();
   document.ricrap.id.value="";
 }
 else
  alert("Inserire un codice articolo !"); 
} 

function submitenter(myfield,e) {
var keycode;

if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}

function CloseWindow()

{

window.open('','_self','');

window.close();

}


function ControllaPIVA(obj) {
var pi = obj.value;
var btest = false;

    if( pi == '' )  return;
    if( pi.length != 11 ) alert("La lunghezza della partita IVA non è corretta: la partita IVA dovrebbe essere lunga esattamente 11 caratteri.");
    validi = "0123456789";
    for( i = 0; i < 11; i++ ){
        if( validi.indexOf( pi.charAt(i) ) == -1 ) alert("La partita IVA contiene un carattere non valido `" + pi.charAt(i) + "'. I caratteri validi sono le cifre.");
    }
    s = 0;
    for( i = 0; i <= 9; i += 2 )
        s += pi.charCodeAt(i) - '0'.charCodeAt(0);
    for( i = 1; i <= 9; i += 2 ){
        c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
        if( c > 9 )  c = c - 9;
        s += c;
    }
    if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) ) 
	alert("La partita IVA non è valida: " + "il codice di controllo non corrisponde.")
    else btest=true;

    if (!btest) {
	obj.value="";
	obj.focus();
    }
}

