/*---------------------------------------------
 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";
	return 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<3 || 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(13,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 = "default";
}
function hilight(element) {
if (theElem!=null) 
	theElem.className="LinkOut";
element.className="LinkOn";
element.style.cursor = "default";
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);
}

function DoDelMaillist(sck)
{
	if (CheckForm(document.forms[0],'Nom','Nome','R','Email','Indirizzo E-mail','RisEmail'))
	{
		sEmail = DocFindElement('Email').value;
		window.location = "Default.aspx?Action=del&Template=CancellatoSI.html&F=Email&V='"+ sEmail +"'&ck="+sck;
		return true;
	}
	else { return false; }
}

function controllaForm(frm) {
    frm.elements['ID'].value=frm.elements['Email'].value;
	if (frm.elements['Password'].value!=frm.elements['Rpassword'].value) {
		alert ("La Password inserita non corrisponde alla Verifica.\nControllare i dati inseriti");
		return false;
	} else {
		var ele = DocFindElement('DatiAz');
		if (ele.style.visibility=="visible") {
			return CheckForm(frm,'Email','Email','R','FullName','Cognome e Nome','R','Address','Indirizzo','R','Zip','CAP','R','Address1','Localita','R','Country','Provincia','R','State','Nazione','R','Telephone','Telefono','R','Organization','Azienda','R','Piva','Partita IVA','R','OrgCF','Cod.Fiscale','R','acconsento','Privacy','RisCheck');
		} else {
			return CheckForm(frm,'Email','Email','R','FullName','Cognome e Nome','R','Address','Indirizzo','R','Zip','CAP','R','Address1','Localita','R','Country','Provincia','R','State','Nazione','R','Telephone','Telefono','R','acconsento','Privacy','RisCheck');
		}
	}
}
function MenuClick(Sel) {
	var thisMenu = DocFindElement('cat'+Sel);
	if (thisMenu) {
		if (thisMenu.style.display == "block") {
			thisMenu.style.display = "none";
			DocFindElement('Freccia'+Sel).src='images/frecciachiusa.gif';
		}
		else {
			thisMenu.style.display = "block";
			DocFindElement('Freccia'+Sel).src='images/frecciaAPERTA.gif';		
		     }
		return false;
	}
	else {
		return true;
	}
}

function ShowHide(show,id) {
	var ele = DocFindElement(id);
	if (ele) {
		if (show) {
			ele.style.visibility="visible";
			ele.style.display="block";
		} else {
			ele.style.visibility="hidden";
			ele.style.display="none";
		}
	}
}