/*---------------------------------------------
 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 Apri(pagina,base,altezza){
	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=1,status=0,titlebar=0,toolbar=0'
	window.open(pagina,"",parametri)
}

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 openInter(id,type){

  var ele = DocFindElement("idd"+id);
  if (ele) {
	  ele.style.display = "block";
	  if(type=='on')
		ele.style.visibility = "visible";
		  else  ele.style.visibility="hidden";
  }
  return false;
}

function ResizeWin(elem) {
	var Base = window.offsetWidth;
	var Altezza = window.offsetHeight;
	if (elem) {
		Base = elem.width + 238;
		Altezza = window.document.body.scrollHeight + 100;
	} else {
		Base = window.document.body.scrollWidth + 100;
		Altezza = window.document.body.scrollHeight + 45;
	}
	Base = (Base>screen.width) ? screen.width : Base;
	Altezza = (Altezza>screen.height) ? screen.height : Altezza;
	CenterWindow(Base,Altezza)
	self.focus();
}

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 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 CheckForm1() { //v3.1
  var i,p,p1,q,nm,test,num,min,max,errors='',args=CheckForm1.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+' mandatory.\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+' must be a valid e-mail address.\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+' must be a number. (' + 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+' must be a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' mandatory.\n'; }
  } if (errors) {alert('Warning:\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;
}

var theElem=new Array();
function over(element, sclass) {
	if (element.className!=sclass+"On")
		element.className=sclass+"Over";
	element.style.cursor = "hand";
}

function hilight(element, sclass) {
	if (theElem!=null) 
		if (theElem[sclass]!=null) 
			theElem[sclass].className=sclass+"Out";
	element.className=sclass+"On";
	element.style.cursor = "hand";
	theElem[sclass]=element;
}

function out(element, sclass) {
	if (element.className!=sclass+"On")
		element.className = sclass+"Out";
	element.style.cursor = "default";
}

function ShowHide(Sel) {
	var thisMenu = DocFindElement(Sel);
	if (thisMenu) {
		if (thisMenu.style.display == "block") {
			thisMenu.style.display = "none";;
		}
		else {
			thisMenu.style.display = "block";
		}
		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],'FullName','Nome','R','Email','Indirizzo E-mail','RisEmail'))
	{
		sEmail = DocFindElement('Email').value;
		window.location = "Default.aspx?Action=del&SubTemplate=CancellatoSI.html&F=Email&V='"+ sEmail +"'&ck="+sck;
		return true;
	}
	else { return false; }
}

