/*---------------------------------------------
 Libreria di base.

 Mall4Net E-Solution?? un prodotto realizzato
 da Valerio Maurizio - www.icio.it
 Tutti i diritti riservati?.

----------------------------------------------*/

var NS;
var OP;
var IE4;
var IE5;
var SOWIN;
var IE5WIN;
getAgent();

function getAgent() {
SOWIN = (navigator.userAgent.toLowerCase().indexOf("win") > -1) ? 1 : 0; 
OP = (window.opera) ? 1:0; 
IE4 = (document.all && !OP) ? 1:0; 
IE5 = (IE4 && document.getElementById) ? 1:0; 
IE5WIN = ((IE5) && SOWIN);
NS = (IE4 || IE5 || OP) ? 0:1;
}

function apriWin(sName,sTop,sLeft,sWidth,sHeight,sUrl) {
	wf =  "top="+ sTop + ",left=" + sLeft + ",width=" + sWidth + ",height=" + sHeight +",resizable=yes,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=no";
	window.open(sUrl,sName,wf);
}

function chiudiWin() {
	self.opener = self;
	self.close();
}

function CheckForm() { //v3.1
  var i,p,p1,q,nm,test,num,min,max,errors='',args=CheckForm.arguments,theForm=args[0];
  for (i=1; i<(args.length-2); i+=3) { test=args[i+2]; val=theForm.elements[args[i]];
    if (val) { nm=args[i+1]; if (nm=='') nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isCheck')!=-1) { if (!theForm.elements[args[i]].checked) errors+='- '+nm+' obbligatorio.\n';
      } else if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');p1=val.lastIndexOf('.');
        if (p<2 || p==(val.length-1) || p1<p || p<0) errors+='- '+nm+' deve essere un indirizzo e-mail.\n';
      } else if (test.indexOf('isNum') != -1) { (NS) ? val = val.replace(",","."):val = val.replace("\.","").replace(",","");
 	for(x=0;x<val.length;x++) { if (val.substring(x,1)!="0") {val=val.substring(x); break;} }
        num = parseFloat(val);  if (val!=''+num) errors+='- '+nm+' deve essere un numero. (' + val + ')\n';  
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' deve essere un numero compreso tra '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' obbligatorio.\n'; }
  } if (errors) {alert('Attenzione:\n'+errors);return false} else {return true}
}

function DocFindElement(n) {
	var elem = document.getElementById(n);
	if (!elem) elem = document.all(n,0);
	if (!elem) elem = document[n];
	return elem;
}
function CheckNumeric(sNum)
{
	var num;
	if (!NS) sNum = sNum.replace("\.","");
	sNum = sNum.replace(",",".");
	try {	num = parseFloat(sNum);}
	catch (err) {num=0;}
	return num;
}
var theElem=null;
function over(element) {
if (element.className!="LinkOn")
	element.className="LinkOver";
element.style.cursor = "hand";
}
function hilight(element) {
if (theElem!=null) 
	theElem.className="LinkOut";
element.className="LinkOn";
element.style.cursor = "hand";
theElem=element;
}
function out(element) {
if (element.className!="LinkOn")
	element.className = "LinkOut";
element.style.cursor = "default";
}
function MenuClick(Elem,Sel) {
	var thisMenu = DocFindElement(Sel);
	if (thisMenu) {
		if (thisMenu.style.display == "block") {
			thisMenu.style.display = "none";
			Elem.className="MenuOff";
		}
		else {
			thisMenu.style.display = "block";
			Elem.className="MenuOn";
		}
		return false;
	}
	else {
		return true;
	}
}

function DoZoom(Tpl,id,w,h,scroll) {
  pagina="Default.aspx?Template="+ Tpl + "&F=ID&V=" + id ;
  base=w;
  altezza=h;
  Sx = (screen.width) ? (screen.width-base)/2 : 0;
  Top = (screen.height) ? (screen.height-altezza)/2 - 26: 0;
  parametri ='height='+altezza+',width='+base+',top='+Top+',left='+Sx+',scrollbars='+scroll+',status=0,titlebar=0,toolbar=0'
  window.open(pagina,"zoom",parametri)
}
function DoZoomStr(Tpl,id,w,h,scroll) {
  DoZoom(Tpl,"'"+id+"'",w,h,scroll);
}
//**** new for new site
var theItem=new Array();
function btn_over(sName,id) {
	element=DocFindElement(sName+id);
	if (element) {
		if (element.className!=sName+"on")
			element.className=sName+"over";
	}
}
function btn_hilight(sName,id,sTpl,sGN, sGV,sCk) {
	if (theItem[sName]) 
		theItem[sName].className=sName;
	element=DocFindElement(sName+id);
	if (element) {
		element.className=sName+"on";
		theItem[sName]=element;
		if (sTpl!='') {
			if (sTpl.substring(0,2)=="..")
				parent.frames[1].location=sTpl;
			else
				window.location="Default.aspx?SubTemplate="+sTpl+"&GN="+sGN+"&GV="+sGV+"&ck="+sCk;
		}
	}
}
function btn_out(sName,id) {
	element=DocFindElement(sName+id);
	if (element) {
		if (element.className!=sName+"on")
			element.className = sName;
	}
}
function DoDelMaillist(sck)
{
	if (CheckForm(document.forms['frmMailingList'],'FullName','Cognome e Nome','R','Email','Indirizzo E-mail','RisEmail'))
	{
		sEmail = DocFindElement('Email').value;
		window.location = "http://www.filepoint.it/Catalog/Language0/Default.aspx?Action=del&Template=CancellatoSI.html&F=Email&V='"+ sEmail +"'&ck="+sck;
		return true;
	}
	else { return false; }
}

function PrintDate() {
	dt = new Date(); //Gets today's date right now (to the millisecond).
	month = dt.getMonth();
	day = dt.getDate();
	year = dt.getFullYear();
	m = new Array()
	m[0]='gennaio';m[1]='febbraio';m[2]='marzo';m[3]='aprile';m[4]='maggio';m[5]='giugno';m[6]='luglio';m[7]='agosto';m[8]='settembre';m[9]='ottobre';m[10]='novembre';m[11]='dicembre';
	document.write(day + ' ' + m[month] + ' ' + year);
}

function setToday(elem){
	dt = new Date(); //Gets today's date right now (to the millisecond).
	month = dt.getMonth()+1;
	day = dt.getDate();
	year = dt.getFullYear();
	elem.value = day + '/' + month + '/' + year;
}

function CenterWindow(Base,Altezza)
{
	var Top = (screen.height) ? (screen.height-Altezza)/2 - 26: 0;
	Top = (Top<0) ? 0 : Top;
	var Left = (screen.width) ? (screen.width-Base)/2 : 0;
	Left = (Left<0) ? 0 : Left;
	window.moveTo(Left,Top);
	window.resizeTo(Base,Altezza);
}

function ResizeWin(elem) {
	var Base = window.offsetWidth;
	var Altezza = window.offsetHeight;
	if (elem) {
		Base = elem.width + 100;
		Altezza = window.document.body.scrollHeight + 35;
	} else {
		Base = window.document.body.scrollWidth + 100;
		Altezza = window.document.body.scrollHeight + 35;
	}
	Base = (Base>screen.width) ? screen.width : Base;
	Altezza = (Altezza>screen.height) ? screen.height : Altezza;
	CenterWindow(Base,Altezza)
	self.focus();
}
/**************************************
	Controllo del Codice Fiscale
	Linguaggio: JavaScript
***************************************/

function ControllaCF(cf)
{
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return '';
	cf = cf.toUpperCase();
	if( cf.length != 16 )
		return "Lunghezza del codice fiscale non\n"
		+"corretta: il codice fiscale dovrebbe essere lungo\n"
		+"esattamente 16 caratteri.\n";
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
			return "Il codice fiscale contiene un carattere non valido `" +
				cf.charAt(i) +
				"'.\nI caratteri validi sono le lettere e le cifre.\n";
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
		return "Codice fiscale non corretto:\n"+
			"il codice di controllo non corrisponde.\n";
	return "";
}
/*****************************************
	Controllo della Partita I.V.A.
	Linguaggio: JavaScript
******************************************/

function ControllaPIVA(pi)
{
	if( pi == '' )  return '';
	if( pi.length != 11 )
		return "Lunghezza della partita IVA non\n" +
			"corretta: la partita IVA dovrebbe essere lunga\n" +
			"esattamente 11 caratteri.\n";
	validi = "0123456789";
	for( i = 0; i < 11; i++ ){
		if( validi.indexOf( pi.charAt(i) ) == -1 )
			return "La partita IVA contiene un carattere non valido `" +
				pi.charAt(i) + "'.\nI caratteri validi sono le cifre.\n";
	}
	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) )
		return "Partita IVA non valida:\n" +
			"il codice di controllo non corrisponde.\n";
	return '';
}


// funzione per assegnare l'oggetto XMLHttpRequest
// compatibile con i browsers più recenti e diffusi
function getXMLHttpRequest() {

 var XHR = null;
 
 var browserUtente = navigator.userAgent.toUpperCase();


 // browser standard con supporto nativo
 // non importa il tipo di browser
 if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
  XHR = new XMLHttpRequest();

 // browser Internet Explorer
 // è necessario filtrare la versione 4
 else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) {
 
  // la versione 6 di IE ha un nome differente
  // per il tipo di oggetto ActiveX
  if(browserUtente.indexOf("MSIE 5") < 0)
   XHR = new ActiveXObject("Msxml2.XMLHTTP");

  // le versioni 5 e 5.5 invece sfruttano lo stesso nome
  else
   XHR = new ActiveXObject("Microsoft.XMLHTTP");
 }

 return XHR;
} 
function ValidAjax(Tpl,fld,val,ck) {
	var ajax = getXMLHttpRequest();
	if (ajax) { // syncrona !!
		ajax.open("get","Default.aspx?ck="+ck+"&Template="+Tpl+"&VN=STRWHERE&VV="+fld+"='"+val+"'", false);
		ajax.send(null);
		if(ajax.readyState == 4) {
			if(ajax.status == 200) {
				var resp = ajax.responseText;
				var p = resp.indexOf(" -->");
				if (p>=0) resp=resp.substring(p+4,resp.length);
				try { if (eval(resp)) return true; }
				catch (err) {alert(resp);}
			} else
				alert("Operazione fallita, errore numero " + ajax.status);
		}
	} else 
		alert ('Funzione AJAX non abilitata!');

	return false
}

