/*---------------------------------------------
 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.2
  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) { if (theForm.elements[args[i]]!=null) if (!theForm.elements[args[i]].disabled) { 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 CheckForm1() { //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+' required.\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('Warning:\n'+errors);return false} else {return true}
}

var bookmarkurl="http://www.deltaforex.it"
var bookmarktitle="Delta Forex S.r.l." 

function addbookmark(){
if (document.all)
window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

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);
}

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,ck) {
	if (frm.name!="frmDatiUtente" && !ValidAjax("ValidUtente.html",'ID',frm.elements['ID'].value,ck)) {
		return false;
	} else {																																																																								
		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','RisEmail','Password','Password','R','RememberQuestion','Domanda Recupero Password','R','RememberAnswer','Risposta Recupero Password','R','FullName','Cognome e Nome','R','Telephone','Telefono','R','Organization','Azienda','R','Piva','Partita IVA','R','OrgCF','Cod.Fiscale','R','acconsento','Privacy','RisCheck');
			} else {
				return CheckForm(frm,'Email','Email','RisEmail','Password','Password','R','RememberQuestion','Domanda Recupero Password','R','RememberAnswer','Risposta Recupero Password','R','FullName','Cognome e Nome','R','Telephone','Telefono','R','CodCF','Cod. Fiscale','R','acconsento','Privacy','RisCheck');
			}
		}
	}
}

function controllaFormCarrello(frm,ck) {
	controllaFormEmail(frm,ck)	
	var ele = DocFindElement('DatiAz');
	if (ele.style.visibility=="visible") {
		return CheckForm(frm,'Email','Email','RisEmail','FullName','Cognome e Nome','R','Address','Indirizzo','R','Address1','Localita','R','Zip','CAP','R','Country','Provincia','R','State','Nazione','R','Telephone','Telefono','R','Organization','Azienda','R','OrgAddress','Indirizzo Azienda','R','OrgAddress1','Localita Azienda','R','OrgZip','CAP Azienda','R','OrgCountry','Provincia Azienda','R','Piva','Partita IVA','R','OrgCF','Cod.Fiscale','R','acconsento','Privacy','RisCheck');
	} else {
		return CheckForm(frm,'Email','Email','RisEmail','FullName','Cognome e Nome','R','Address','Indirizzo','R','Address1','Localita','R','Zip','CAP','R','Country','Provincia','R','State','Nazione','R','Telephone','Telefono','R','CodCF','Cod. Fiscale','R','acconsento','Privacy','RisCheck');
	}
}

function controllaFormAbbonamenti(frm,ck) {
		controllaFormEmail(frm,ck)
		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','RisEmail','Password','Password','R','RememberQuestion','Domanda Recupero Password','R','RememberAnswer','Risposta Recupero Password','R','FullName','Cognome e Nome','R','Telephone','Telefono','R','Organization','Azienda','R','Piva','Partita IVA','R','OrgCF','Cod.Fiscale','R','acconsento','Privacy','RisCheck');
			} else {
				return CheckForm(frm,'Email','Email','RisEmail','Password','Password','R','RememberQuestion','Domanda Recupero Password','R','RememberAnswer','Risposta Recupero Password','R','FullName','Cognome e Nome','R','Telephone','Telefono','R','CodCF','Cod. Fiscale','R','acconsento','Privacy','RisCheck');
			}
		}
}

function controllaFormCorsi(frm,ck) {
		controllaFormEmail2(frm,ck)
		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','RisEmail','Password','Password','R','RememberQuestion','Domanda Recupero Password','R','RememberAnswer','Risposta Recupero Password','R','FullName','Cognome e Nome','R','Telephone','Telefono','R','Organization','Azienda','R','Piva','Partita IVA','R','OrgCF','Cod.Fiscale','R','acconsento','Privacy','RisCheck');
			} else {
				return CheckForm(frm,'Email','Email','RisEmail','Password','Password','R','RememberQuestion','Domanda Recupero Password','R','RememberAnswer','Risposta Recupero Password','R','FullName','Cognome e Nome','R','Telephone','Telefono','R','CodCF','Cod. Fiscale','R','acconsento','Privacy','RisCheck');
			}
		}
}

function controllaFormEmail(frm,ck) {
    frm.elements['ID'].value=frm.elements['Email'].value;
	ValidAjax("ValidUtenteRegistrato.html",'ID',frm.elements['ID'].value,ck)
	var sTp = frm.elements['Money'].value;
	if (sTp=="Az") {
		ele = DocFindElement('DatiAz');
		if (ele.style.visibility!="visible") {
			ShowHide(true,'DatiAz');
			ShowHide(false,'DatiPr');
		}
	} else {
		ele = DocFindElement('DatiPr');
		if (ele.style.visibility!="visible") {
			ShowHide(false,'DatiAz');
			ShowHide(true,'DatiPr');
		}
	}
}

function controllaFormEmail2(frm,ck) {
	ValidAjax("ValidUtenteRegistratoC.html",'Email',frm.elements['Email'].value,ck)
	var sTp = frm.elements['Money'].value;
	if (sTp=="Az") {
		ele = DocFindElement('DatiAz');
		if (ele.style.visibility!="visible") {
			ShowHide(true,'DatiAz');
			ShowHide(false,'DatiPr');
		}
	} else {
		ele = DocFindElement('DatiPr');
		if (ele.style.visibility!="visible") {
			ShowHide(false,'DatiAz');
			ShowHide(true,'DatiPr');
		}
	}
}
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";
		}
	}
}

// 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 SetPaymentAjax(sID,ck) {
	var ajax = getXMLHttpRequest();
	if (ajax) { // syncrona !!
		ajax.open("get","Default.aspx?Action=SetPayment&Payment=" + sID + "&Template=SetPayment.html&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
}


//Manual Scroller- © Dynamic Drive 2001
//For full source code, visit http://www.dynamicdrive.com
var speed = new Array();
var crossobj = new Array();
var contentheight = new Array();
var movedownvar = new Array();
var moveupvar = new Array();
var iens6=document.all||document.getElementById;
var ns4=document.layers;

function movedown(x){
	if (moveupvar[x]) clearTimeout(moveupvar[x])
	if (iens6&&parseInt(crossobj[x].style.top)>=(contentheight[x]*(-1)))
	crossobj[x].style.top=parseInt(crossobj[x].style.top)-speed[x]
	else if (ns4&&crossobj[x].top>=(contentheight[x]*(-1)))
	crossobj[x].top-=speed[x]
	else crossobj[x].style.top=0
	movedownvar[x]=setTimeout("movedown("+x+")",100)
}

function moveup(x){
	if (movedownvar[x]) clearTimeout(movedownvar[x])
	if (iens6&&parseInt(crossobj[x].style.top)<=0)
	crossob[x].style.top=parseInt(crossobj[x].style.top)+speed[x]
	else if (ns4&&crossobj[x].top<=0)
	crossobj[x].top+=speed[x]
	moveupvar[x]=setTimeout("moveup("+x+")",100)
}

function stopscroll(x){
	if (moveupvar[x]) clearTimeout(moveupvar[x]);
	if (movedownvar[x]) clearTimeout(movedownvar[x]);
}

function movetop(x){
	stopscroll(x);
	if (iens6)
	crossobj[x].style.top=0;
	else if (ns4)
	crossobj[x].top=0;
}


function getcontent_height(x){
	if (iens6)
	contentheight[x]=(crossobj[x].offsetHeight / 2) - 5
	else if (ns4)
	eval("document.nscontainer"+x+".document.nscontent"+x+".visibility='show'")
}

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 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 loadXMLIL(url,tipo,ck)
{
	xmlhttp=getXMLHttpRequest();
	if (xmlhttp) {
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		if(xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
				writeResponseIL(xmlhttp,tipo,ck);
			}
		}
  	}
	else
	{
		alert("Your browser does not support XMLHTTP.");
	}
}

function writeResponseIL(oxml,tipo,ck)
{
  var response = oxml.responseXML.documentElement;
  var txi = "";
  txi = txi + "<table width='100%' border='0' cellspacing='1' cellpadding='2' style='width: 100%'><tr><td class='TitoloBianco' bgcolor='#9fa8af'>DESCRIZIONE<\/td><td class='TitoloBianco' bgcolor='#9fa8af'>DATA<\/td><td class='TitoloBianco' align='right' bgcolor='#9fa8af'>PREZZO<\/td><td class='TitoloBianco' align='right' bgcolor='#9fa8af'>VARIAZIONE<\/td><\/tr>";
  var x=response.getElementsByTagName(tipo);
  for (var i=0;i<x.length;i++)
    {
		txi = txi + "<tr> <td valign='top'><span class='titoletto'>"+ x[i].getElementsByTagName("descrizione")[0].firstChild.data+"<\/span><\/td>";
		txi = txi + "<td valign='top'>" + x[i].getElementsByTagName("data")[0].firstChild.data +"<\/td>";
		txi = txi + "<td valign='top' align='right'>"+x[i].getElementsByTagName("prezzp")[0].firstChild.data+"&euro;<\/td><td align='right' valign='top'>"+x[i].getElementsByTagName("var")[0].firstChild.data+"<\/td> <\/tr>";
	}
  txi=txi + "<\/table>";
  document.getElementById(tipo).innerHTML = txi;
}

/*==============================================================================

    Routines written by John Gardner - 2003 - 2005

    See www.braemoor.co.uk/software for information about more freeware
    available.

================================================================================

Routine to write a session cookie

    Parameters:
        cookieName        Cookie name
        cookieValue       Cookie Value
    
    Return value:
        true              Session cookie written successfullly
        false             Failed - persistent cookies are not enabled

   e.g. if (writeSessionCookie("pans","drizzle") then
           alert ("Session cookie written");
        else
           alert ("Sorry - Session cookies not enabled");
*/

function writeSessionCookie (cookieName, cookieValue) {
  if (testSessionCookie()) {
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
    return true;
  }
  else return false;
}

/*==============================================================================

Routine to get the current value of a cookie

    Parameters:
        cookieName        Cookie name
    
    Return value:
        false             Failed - no such cookie
        value             Value of the retrieved cookie

   e.g. if (!getCookieValue("pans") then  {
           cookieValue = getCoookieValue ("pans2);
        }
*/

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;
}

/*==============================================================================

Routine to see if session cookies are enabled

    Parameters:
        None
    
    Return value:
        true              Session cookies are enabled
        false             Session cookies are not enabled

   e.g. if (testSessionCookie())
           alert ("Session coookies are enabled");
        else
           alert ("Session coookies are not enabled");
*/

function testSessionCookie () {
  document.cookie ="testSessionCookie=Enabled";
  if (getCookieValue ("testSessionCookie")=="Enabled")
    return true 
  else
    return false;
}

/*==============================================================================

Routine to see of persistent cookies are allowed:

    Parameters:
        None
    
    Return value:
        true              Session cookies are enabled
        false             Session cookies are not enabled

   e.g. if (testPersistentCookie()) then
           alert ("Persistent coookies are enabled");
        else
           alert ("Persistent coookies are not enabled");
*/

function testPersistentCookie () {
  writePersistentCookie ("testPersistentCookie", "Enabled", "minutes", 1);
  if (getCookieValue ("testPersistentCookie")=="Enabled")
    return true  
  else 
    return false;
}

/*==============================================================================

Routine to write a persistent cookie

    Parameters:
        CookieName        Cookie name
        CookieValue       Cookie Value
        periodType        "years","months","days","hours", "minutes"
        offset            Number of units specified in periodType
    
    Return value:
        true              Persistent cookie written successfullly
        false             Failed - persistent cookies are not enabled
    
    e.g. writePersistentCookie ("Session", id, "years", 1);
*/       

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=/";
}  

/*==============================================================================

Routine to delete a persistent cookie

    Parameters:
        CookieName        Cookie name
    
    Return value:
        true              Persistent cookie marked for deletion
    
    e.g. deleteCookie ("Session");
*/    

function deleteCookie (cookieName) {

  if (getCookieValue (cookieName)) writePersistentCookie (cookieName,"Pending delete","years", -1);  
  return true;     
}
