/*---------------------------------------------
 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;
var x;
var y;
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 DocFindElement(n) {
	var elem = document.getElementById(n);
	if (!elem) elem = document.all(n,0);
	if (!elem) elem = document[n];
	return elem;
}

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 Cambia(cosa,img,txt){
document.getElementById('img' + cosa).src=img; 
document.getElementById('desc' + cosa).innerHTML=txt; 
}

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";
		}
	}
}

function setSelElements() {
	if (loadingSel==false) {
		clearInterval(intSel);
		winSel.returnobj = elemSel;
		//winSel.iframeobj = ifrmSel;
	}
}

// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        alert(btn[i].checked);
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return false;
}
                  
function ShowHideFocus(show,id,fid) {
	var ele = DocFindElement(id);
	if (ele) {
		if (show) {
			ele.style.visibility="visible";
			ele.style.display="block";
			setTimeout("setFocus('"+fid+"')",10);
		} else {
			ele.style.visibility="hidden";
			ele.style.display="none";
		}
	}
}
function setFocus(ele) {
	var elem = DocFindElement(ele);
	try { elem.focus(); } catch	(err) { alert(err.message) }
}

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;
}


/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Robert Nyman | http://robertnyman.com/ */
function removeHTMLTags(txt){
 	
 		var strInputCode = txt;
 		/* 
  			This line is optional, it replaces escaped brackets with real ones, 
  			i.e. < is replaced with < and > is replaced with >
 		*/	
 	 	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
 		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
 		return strTagStrippedText;	

}


function openIFrame(id,img,win){
  var ele = DocFindElement(id);
  var ico = DocFindElement(img);
  var ifr = parent.DocFindElement(win);
  if (ele) {
	if (ele.className == "nascosto") {
	    ele.className = "visibile";
		if (ifr) ifr.style.height = "420px";
		if (ico) ico.src = "../imgsito/redtgiu.gif";

	} else {
	    ele.className = "nascosto";
		if (ifr) ifr.style.height = "118px";
		if (ico) ico.src = "../imgsito/redt.gif";
	}
  }
  return false;
}

function openIFrameSub(id,img,win){
  var ele = DocFindElement('pagina').contentWindow.DocFindElement(id);
  var ico = DocFindElement(img);
  var ifr = DocFindElement(win);
  if (ele) {
	if (ele.className == "nascosto") {
	    ele.className = "visibile";
		if (ifr) ifr.style.height = "420px";
		if (ico) ico.src = "../imgsito/redtgiu.gif";

	} else {
	    ele.className = "nascosto";
		if (ifr) ifr.style.height = "118px";
		if (ico) ico.src = "../imgsito/redt.gif";
	}
  }
  return false;
}
function getViewportWidth() {

	if(window.innerWidth) return window.innerWidth-16;
	if(typeof window.document.documentElement.clientWidth=="number") return window.document.documentElement.clientWidth;
	return window.document.body.clientWidth;
}

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 CheckFormLogin() { //v3.1
  var i,p,p1,q,nm,test,num,min,max,errors='',args=CheckFormLogin.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+'\n la registrazione non comporta nessun obbligo');return false} else {if (parent.DocFindElement('totbarra')!=null)parent.DocFindElement('totbarra').style.visibility='visible'; return true}
}

function controllaForm(frm) {
    frm.elements['Email'].value=frm.elements['ID'].value;
     frm.elements['Address'].value=frm.elements['Via'].value + " " + frm.elements['Nc'].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{
	return CheckForm(frm,'ID','Email','RisEmail','FullName','Cognome e Nome','R','Via','Indirizzo','R','Nc','Nr. Civico','R','Zip','CAP','R','Address1','Localita','R','Country','Provincia','R','State','Nazione','R','Telephone','Telefono','R','acconsento','Consenso Privacy','RisCheck')
	}
}

function CheckNumeric(sNum)
{
	var num;
	if(sNum=='') return 0;
	if(sNum=='--,--') return 0;
	if (!NS) sNum = sNum.replace("\.","");
	sNum = sNum.replace(",",".");
	try { num = parseFloat(sNum);}
	catch (err) {num=0;}
	if (num=="NaN") num=0
	return num;
}
function Moltiplica(Qta,Price)
{
	var sTot = (Qta*Price).toString();
	if (NS)
		return sTot;
	else
		return sTot.replace("\.",","); 
}
function Formatta(Num)
{
	var sTot = (Math.floor((Num*100)+.0001)/100).toString();
	if (Num==0) sTot="--,--";
	sTot= sTot.replace("\.",","); 
	var p = sTot.lastIndexOf(',');
	if (p==-1)	{
		sTot=sTot+",00";
	} else {
		if ((sTot.length-p)<3) sTot=sTot+"0"; 
	}
	return sTot;

}

function Formatta3Dec(Num)
{
	var sTot = (Math.floor((Num*1000)+.00001)/1000).toString();
	if (Num==0) sTot="--,---";
	sTot= sTot.replace("\.",","); 
	var p = sTot.lastIndexOf(',');
	if (p==-1)	{
		sTot=sTot+",000";
	} else {
		if ((sTot.length-p)<4) sTot=sTot+"0"; 
	}
	return sTot;

}

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);
}

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; }
}

//Routines written by John Gardner - 2003 - 2005

function writeSessionCookie (cookieName, cookieValue) {
  if (testSessionCookie()) {
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
    return true;
  }
  else return false;
}

function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}

function testSessionCookie () {
  document.cookie ="testSessionCookie=Enabled";
  if (getCookieValue ("testSessionCookie")=="Enabled")
    return true 
  else
    return false;
}

function testPersistentCookie () {
  writePersistentCookie ("testPersistentCookie", "Enabled", "minutes", 1);
  if (getCookieValue ("testPersistentCookie")=="Enabled")
    return true  
  else 
    return false;
}

function writePersistentCookie (CookieName, CookieValue, periodType, offset) {

  var expireDate = new Date ();
  offset = offset / 1;
  
  var myPeriodType = periodType;
  switch (myPeriodType.toLowerCase()) {
    case "years": 
     var year = expireDate.getYear();     
     // Note some browsers give only the years since 1900, and some since 0.
     if (year < 1000) year = year + 1900;     
     expireDate.setYear(year + offset);
     break;
    case "months":
      expireDate.setMonth(expireDate.getMonth() + offset);
      break;
    case "days":
      expireDate.setDate(expireDate.getDate() + offset);
      break;
    case "hours":
      expireDate.setHours(expireDate.getHours() + offset);
      break;
    case "minutes":
      expireDate.setMinutes(expireDate.getMinutes() + offset);
      break;
    default:
      alert ("Invalid periodType parameter for writePersistentCookie()");
      break;
  } 
  
  document.cookie = escape(CookieName ) + "=" + escape(CookieValue) + "; expires=" + expireDate.toGMTString() + "; path=/";
}  

function deleteCookie (cookieName) {

  if (getCookieValue (cookieName)) writePersistentCookie (cookieName,"Pending delete","years", -1);  
  return true;     
}

function ValidVal(Tpl,Var,Sel,descr,ck,over) {
	var ele=DocFindElement(descr);
	if (over)
		ele.src="Default.aspx?Template="+Tpl+"&overwrite=on&VN="+Var+"&VV=" + Sel + "&ck="+ck;
	else
		ele.src="Default.aspx?Template="+Tpl+"&VN="+Var+"&VV=" + Sel + "&ck="+ck;
}

// 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
}
function ValidAjaxPrz(Tpl,fld,val,qta,ck) {
	var ajax = getXMLHttpRequest();
	if (ajax) { // syncrona !!
		ajax.open("get","Default.aspx?ck="+ck+"&Template="+Tpl+"&VN=STRWHERE&VV="+fld+"='"+val+"'&VN=QTA&VV="+qta, 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
}

function ExecAjax(act,fld,val,dsc,set,tpl,ck) {
	var ajax = getXMLHttpRequest();
	if (ajax) { // syncrona !!
		ajax.open("get","Default.aspx?Action="+act+"&"+fld+"="+val+"&Descr="+dsc+"&Value="+set+"&Template="+tpl+"&ck="+ck, false);
		if ((act=='SetPayment') && (val=='002'))
		{
		ExecAjaxSped('SetSheepment','ID','004','Vettore 48 ore','6,00','13,00','ListCarrello.html',ck);
		}
		if ((act=='SetPayment') && (val=='003'))
		{
		ExecAjaxSped('SetSheepment','ID','004','Vettore 48 ore','6,00','13,00','ListCarrello.html',ck);
		}
		if ((act=='SetPayment') && (val=='GESTP'))
		{
		ExecAjaxSped('SetSheepment','ID','004','Vettore 48 ore','6,00','13,00','ListCarrello.html',ck);
		}	
		if ((act=='SetPayment') && (val=='001'))
		{
		ExecAjaxSped('SetSheepment','ID','001','Ritiro in sede','0,00','0,00','ListCarrello.html',ck);	
		}
		ajax.send(null);
		if(ajax.readyState == 4) {
			if(ajax.status == 200) {
				window.location.reload();
				return true;
			} else
				alert("Operazione fallita, errore numero " + ajax.status);
		}
	} else 
		alert ('Funzione AJAX non abilitata!');

	return false
}

function ValidAjaxLog(act,fld,val,ck) {
	var ajax = getXMLHttpRequest();
	if (ajax) { // syncrona !!
		ajax.open("get","Default.aspx?Template=vuoto.html&Action="+act+"&"+fld+"="+val+"&ck="+ck, 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
}

function ExecAjaxSped(act,fld,val,dsc,set,set2,tpl,ck) {
	var ajax = getXMLHttpRequest();
	if (ajax) { // syncrona !!
		ajax.open("get","Default.aspx?Action="+act+"&"+fld+"="+val+"&Descr="+dsc+"&Value="+set+"&Value2="+set2+"&Template="+tpl+"&ck="+ck, false);
		ajax.send(null);
		if(ajax.readyState == 4) {
			if(ajax.status == 200) {
				window.location.reload();
				return true;
			} else
				alert("Operazione fallita, errore numero " + ajax.status);
		}
	} else 
		alert ('Funzione AJAX non abilitata!');

	return false
}

function EditAjax(Tpl,id,ck,txt) {
	var ajax = getXMLHttpRequest();
	if (ajax) { // syncrona !!
		ajax.open("post","Default.aspx?Action=upd&ck="+ck+"&Template="+Tpl+"&F=ID&V="+id, false);
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		ajax.setRequestHeader("Content-length", txt.length+7);
		ajax.setRequestHeader("Connection", "close");
		ajax.send("Filename="+txt);
		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
}
function ClearOptions(OptionList) {

   // Always clear an option list from the last entry to the first
   for (x = OptionList.length; x >= 0; x--) {
      OptionList[x] = null;
   }
}

function AddToOptionList(OptionList, OptionValue, OptionText, Code, Price) {
   // Add option to the bottom of the list

   var obj = new Option(OptionText, OptionValue);
   obj.Code=Code;
   obj.Price=Price;
   OptionList[OptionList.length] = obj;
}
function accendiBtn(btn) {
btn.src=btn.src.replace(".jpg","a.jpg");
}
function spegniBtn(btn) {
btn.src=btn.src.replace("a.jpg",".jpg");
}

