// **** Funzioni per carrello
function CarrelloAdd(MyUrl,pID,IdEl,Type,LangStr) {
 if (isNaN(document.getElementById(IdEl).value) || document.getElementById(IdEl).value < 1)
 {
   switch (LangStr)
  {
    default: { alert("Specificare un valore numerico intero positivo"); break }
    case 'eng': { alert("ENG:Specificare un valore numerico intero positivo"); break }
    case 'esp': { alert("ESP:Specificare un valore numerico intero positivo"); break }
    case 'fra': { alert("FRA:Specificare un valore numerico intero positivo"); break }
    case 'deu': { alert("DEU:Specificare un valore numerico intero positivo"); break }
  }
 }
 else
 {
  document.location.href = MyUrl+'?act=add&prod='+pID+'&qt='+document.getElementById(IdEl).value+'&ty='+Type;
  return true;
 }
}

function CarrelloAddOpz(MyUrl,pID,selIndex,IdEl,Type,LangStr) {
 if (isNaN(document.getElementById(IdEl).value) || document.getElementById(IdEl).value < 1)
 {
   switch (LangStr)
  {
    default: { alert("Specificare un valore numerico intero positivo"); break }
    case 'eng': { alert("ENG:Specificare un valore numerico intero positivo"); break }
    case 'esp': { alert("ESP:Specificare un valore numerico intero positivo"); break }
    case 'fra': { alert("FRA:Specificare un valore numerico intero positivo"); break }
    case 'deu': { alert("DEU:Specificare un valore numerico intero positivo"); break }
  }
 }
 else
 {
  document.location.href = MyUrl+'?act=add&prod='+pID+'&selIndex='+selIndex+'&qt='+document.getElementById(IdEl).value+'&ty='+Type;
  return true;
 }
}

function CarrelloDel(MyUrl,pID,selIndex,Type,LangStr) {
   var msg
   switch (LangStr)
  {
    default: { msg = "Eliminare il prodotto dal carrello?"; break }
    case 'eng': { msg = "ENG:Eliminare il prodotto dal carrello?"; break }
    case 'esp': { msg = "ESP:Eliminare il prodotto dal carrello?"; break }
    case 'fra': { msg = "FRA:Eliminare il prodotto dal carrello?"; break }
    case 'deu': { msg = "DEU:Eliminare il prodotto dal carrello?"; break }
  }

if(confirm(''+msg+''))
  document.location.href = MyUrl+'?act=del&prod='+pID+'&selIndex='+selIndex+'&ty='+Type;
  return true;
}

function IsNum(obj) {
if (isNaN(obj.value) || parseInt(obj.value)<1 )
{
alert('Specificare un valore numerico positivo (ex.10.33)');
obj.value="";
obj.focus();
}
}

// **** popup centrata
var win = null;
function aprialcentro(url,name,w,h,scroll){
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
win = window.open(url,name,'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=no')
if(win.window.focus){win.window.focus();}
}

//Popup normale
function openWindow(url, name, w, h,scroll ) {
  popupWin = window.open(url, name, 'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars='+scroll+',resizable=no,width='+ w + ',height='+ h + ',top=10,left=10')
}

var checkobj
function accetta(el){
checkobj=el
	if (document.all||document.getElementById){
		for (i=0;i<checkobj.form.length;i++){  
var tempobj=checkobj.form.elements[i]
	if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
							}
						}
					}

function disabilita(el){
	if (!document.all&&!document.getElementById){
			if (window.checkobj&&checkobj.checked)
return true
		else{
alert("Per favore accetta i termini del contratto")
return false
						}
					}
				}

 
function clearFocus() 
{ 
no_bordo = function(){this.blur()} 
for(i=0;i<document.links.length;i++) 
{ 
document.links[i].onfocus=no_bordo; 
} 
} 
onload=clearFocus; 
// --> 

function richiamaOnload() {
clearFocus();
}
onload=richiamaOnload;

// Funzione per disabilitare x select da un'altra select se selezione diversa da valore impostato
function selectDisab(selectNameAct,selectValueAb,selectStrName,campoNoDisab) {
   var valorecampoSelect = document.getElementById(selectNameAct).options[document.getElementById(selectNameAct).selectedIndex].value;
   
   if(valorecampoSelect == selectValueAb || valorecampoSelect == '') {  
		  document.getElementById(campoNoDisab).disabled = true; 
	   }
	   else if (valorecampoSelect != selectValueAb) {  
	      document.getElementById(campoNoDisab).disabled = false;
	   }
    
   var ArrSelectDisab = selectStrName.split(",");
   for(i = 0; i < ArrSelectDisab.length; i++){
	   if(valorecampoSelect != selectValueAb) {  
		  document.getElementById(ArrSelectDisab[i]).disabled = true; 
	   }
	   else if (valorecampoSelect == selectValueAb) {  
	      document.getElementById(ArrSelectDisab[i]).disabled = false;
	   }
	}
}

// Funzione per disabilitare x select da un'altra select se selezione diversa da valore impostato
function selectBoxDisab(selectNameAct,selectValueAb,idBoxStr) {
   var valorecampoSelect = document.getElementById(selectNameAct).options[document.getElementById(selectNameAct).selectedIndex].value;      
   var ArrIdBoxNoVis = idBoxStr.split(",");
   for(i = 0; i < ArrIdBoxNoVis.length; i++){
	   if(valorecampoSelect != selectValueAb) {  
		  document.getElementById(ArrIdBoxNoVis[i]).style.display = "none"; 
	   }
	   else if (valorecampoSelect == selectValueAb) {  
	      document.getElementById(ArrIdBoxNoVis[i]).style.display = "block";
	   }
	}
}

// Funzione per passare ad un campo (anche hidden) un valore preimpostato da checkbox
function setValueCkbox(campoSend, campoDatiId, valueOn, valueOff) { 
    if (campoSend.checked) { 
        document.getElementById(campoDatiId).value = valueOn; 
    } 
    else { 
        document.getElementById(campoDatiId).value = valueOff; 
    } 
}

// Inserisce automaticamente le slash in un campo data
function addSlashes(input) {
    var v = input.value;
    if (v.match(/^\d{2}$/) !== null) {
        input.value = v + '/';
    } else if (v.match(/^\d{2}\/\d{2}$/) !== null) {
        input.value = v + '/';
    }
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


