function showdiv(idSelect){
	var num_options = document.getElementById(idSelect).options.length;
	var indice_selezionato = document.getElementById(idSelect).selectedIndex;
	var value_selezionato = document.getElementById(idSelect).options[indice_selezionato].value;
	//alert(num_options);
	

	if (idSelect == 'metodoPagamento') {
		if (indice_selezionato != 0){
			/*
			if (document.getElementById('auguri')){
				document.getElementById('auguri').style.display='block';
			}
			*/
			document.getElementById('compra').style.display='block';
		}
		else{
			/*
			if (document.getElementById('auguri')){
				document.getElementById('auguri').style.display='none';
			}
			*/
			document.getElementById('compra').style.display='none';
		}
	}

	
	for (i=1; i<num_options; i++){
		var indice_corrente = i;
		//alert(i);
		var myid = document.getElementById(idSelect).options[indice_corrente].value;
		//alert(indice_corrente + '-' + indice_selezionato);
		if (indice_corrente != indice_selezionato){
			document.getElementById(myid).style.display = 'none';
		}
		else {
			document.getElementById(myid).style.display = 'block';
		}
	}
}

function showform(idSelect, formId){
	var num_options = document.getElementById(idSelect).options.length;
	var indice_selezionato = document.getElementById(idSelect).selectedIndex;
	var value_selezionato = document.getElementById(idSelect).options[indice_selezionato].value;
	if (formId != '') {
		var form = document.getElementById(formId);
		if (indice_selezionato == 1) {
			form.submit();
		}
	}
	//alert(value_selezionato);
	for (i=2; i<num_options; i++){
		var indice_corrente = i;
		var myid = document.getElementById(idSelect).options[indice_corrente].value;
		if (indice_corrente != indice_selezionato){
			document.getElementById(myid).style.display = 'none';
		}
		else {
			document.getElementById(myid).style.display = 'block';
		}
	}
}

function showform2(idSelect){
	num_options = document.getElementById(idSelect).options.length;
	indice_selezionato = document.getElementById(idSelect).selectedIndex;
	value_selezionato = document.getElementById(idSelect).options[indice_selezionato].value;
	for (i=1; i<num_options; i++){
		var indice_corrente = i;
		var myid = document.getElementById(idSelect).options[indice_corrente].value;
		//alert(myid);
		if (indice_corrente != indice_selezionato){
			document.getElementById(myid).style.display = 'none';
		}
		else {
			document.getElementById(myid).style.display = 'block';
			//location.href='?cmd=areaRisArgenti&cmdArgenti=default&tipoProdotto='+myid;
			//alert('valueselezionato'+value_selezionato);
		}
	}
	
	urlAj='?cmd=selectAutoRefresh&tipoProdotto='+value_selezionato;
	//alert(urlAj);
	
	ajaxGetRand(urlAj,myHandler);
	function myHandler(aa){
		location.reload(true);
		//location.href='?cmd=areaRisArgenti&cmdArgenti=default&tipoProdotto='+parentID+'&'+idSelect+'='+value_selezionato;
	}
	
	
}
function pseudoSubmit(obj){
	idSelect=obj.id;
	indice_selezionato = document.getElementById(idSelect).selectedIndex;
	value_selezionato = document.getElementById(idSelect).options[indice_selezionato].value;
	parentID = obj.parentNode.id;
	urlAj='?cmd=selectAutoRefresh&tipoProdotto='+parentID+'&'+idSelect+'='+value_selezionato;
	//alert(urlAj);
	
	ajaxGetRand(urlAj,myHandler);
	function myHandler(aa){
		location.reload(true);
		//location.href='?cmd=areaRisArgenti&cmdArgenti=default&tipoProdotto='+parentID+'&'+idSelect+'='+value_selezionato;
	}
}

function ahref(id, url){
	var value = document.getElementById(id).value;
	var newUrl = url + "&quotaLibera=" + value;
	location.href = newUrl;
}
function insertImg(obj){
	medie = obj.src.replace("miniature","medie");
	medie = medie.replace("tn_","");
	document.getElementById('imgBig').src = medie;
	elem = obj.parentNode.parentNode.childNodes;
	
	for(i=0; i<elem.length; i++){
		if(elem[i].nodeName == "DIV"){
			elem[i].style.opacity = "1";
			elem[i].style.filter = "alpha(opacity=100)";
			elem[i].style.mozOpacity = "1";
		}
  }

	obj.parentNode.style.opacity = ".50";
	obj.parentNode.style.filter = "alpha(opacity=50)";
	obj.parentNode.style.mozOpacity = "0.5";

}
//
function openDiv(w,idOpen,urlAj,corrX,corrY){
	//dTop = document.body.scrollTop;
	//dTop = document.documentElement.scrollTop
	this.win = document.getElementById('win');
	xx = getPosX(document.getElementById(idOpen))+corrX;
	//xx = xx+dTop;
	yy = getPosY(document.getElementById(idOpen))+corrY;
	win.style.width = w+"px";
	win.style.overflow = "visible";
	//alert(dTop);
	viewMex("Caricamento in corso...");
	ajaxGetRand(urlAj,myHandler);
  function myHandler(aa){
    hideMex(aa,0);
    if(win.style.display !="block"){
    	win.style.top=yy+"px";
    	win.style.left=xx+"px";
    }
    //document.getElementById('container').style.display='none';
    win.innerHTML = aa;
    //
    document.body.style.background = "#532119";
    document.getElementById("container").style.opacity = ".2";
		document.getElementById("container").style.filter = "alpha(opacity=20)";
		document.getElementById("container").mozOpacity = "0.20";
    //
    win.style.display="block";
    //Drag.init(document.getElementById("handle"),document.getElementById('win'));
  }
  //document.getElementById('sel1').style.display='none';
  //document.getElementById('sel2').style.display='none';
}

function openDiv2(w,idOpen,urlAj,corrX,corrY){ // per liste
	//dTop = document.body.scrollTop;
	dTop = document.documentElement.scrollTop;
	this.win = document.getElementById('win');
	xx = getPosX(document.getElementById(idOpen))+corrX;
	yy = getPosY(document.getElementById(idOpen))+dTop;
	win.style.width = w+"px";
	win.style.overflow = "visible";
	//viewMex("Caricamento in corso...");
	ajaxGetRand(urlAj,myHandler);
  function myHandler(aa){
    //hideMex(aa,0);
    if(win.style.display !="block"){
    	win.style.top=yy+"px";
    	win.style.left=xx+"px";
    }
    //document.getElementById('container').style.display='none';
    win.innerHTML = aa;
    //
    document.body.style.background = "#F9F6EF";
    document.getElementById("container").style.opacity = ".2";
		document.getElementById("container").style.filter = "alpha(opacity=20)";
		document.getElementById("container").mozOpacity = "0.20";
    //
    win.style.display="block";
    //Drag.init(document.getElementById("handle"),document.getElementById('win'));
  }
  //document.getElementById('sel1').style.display='none';
  //document.getElementById('sel2').style.display='none';
}


function openDiv3(w,idOpen,urlAj,corrX,corrY){ // per argenti
        //dTop = document.body.scrollTop;
        dTop = document.documentElement.scrollTop;
        this.win = document.getElementById('win');
        xx = getPosX(document.getElementById(idOpen))+corrX;
        yy = getPosY(document.getElementById(idOpen))+dTop;
        win.style.width = w+"px";
        win.style.overflow = "visible";
        //viewMex("Caricamento in corso...");
        ajaxGetRand(urlAj,myHandler);
  function myHandler(aa){
    //hideMex(aa,0);
    if(win.style.display !="block"){
        win.style.top=yy+"px";
        win.style.left=xx+"px";
    }
    //document.getElementById('container').style.display='none';
    win.innerHTML = aa;
    //
    document.body.style.background = "#532119";
    document.getElementById("container").style.opacity = ".2";
                document.getElementById("container").style.filter = "alpha(opacity=20)";
                document.getElementById("container").mozOpacity = "0.20";
    //
    win.style.display="block";
    //Drag.init(document.getElementById("handle"),document.getElementById('win'));
  }
  //document.getElementById('sel1').style.display='none';
  //document.getElementById('sel2').style.display='none';
}

function chiudiDiv(){
	document.getElementById('sel1').style.display='block';
	document.getElementById('sel2').style.display='block';
	closeDiv();
}

function stampaDiv(){
	document.getElementById('container').style.display='none';
	//interval=setInterval(function() {},5);
//	document.getElementById('win').style.display='block';
	print();
//	closeDiv();
}

function getPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	curleft += obj.x;
	return curleft;
}

function getPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	curtop += obj.y;
	return curtop;
}
function viewMex(mex){
	dTop = document.body.scrollTop+200;
	document.getElementById('loader').innerHTML = mex;
	document.getElementById('loader').style.top = dTop+"px";
	document.getElementById('loader').style.display = "block";
}

function hideMex(cont,dbg){
	if(dbg){
		document.getElementById('loader').innerHTML = cont;
	}else{
		document.getElementById('loader').style.display = "none";
		//document.getElementById('loader').innerHTML = "";
	}
}

function closeDiv(){
	document.getElementById("container").style.display = "block";
	document.body.style.background = "#A88B7D";
  document.getElementById("container").style.opacity = "1";
	document.getElementById("container").style.filter = "alpha(opacity=100)";
	document.getElementById("container").mozOpacity = "1";
	document.getElementById("win").style.display="none";
}

function cambiaAz(){
	if(document.getElementById('tipo').value=="privato") {
		document.getElementById('hidAz').style.display = "none";
		document.getElementById('azienda').value = "";
		document.getElementById('part_iva').value = "";
	}
	if(document.getElementById('tipo').value=="rivenditore") {
		document.getElementById('hidAz').style.display = "block";
		document.getElementById('tdNome').innerHTML='Nome';
		document.getElementById('tdCognome').innerHTML='Cognome';
	}
}

function indirizzoEmailValido(indirizzo) {
  if (window.RegExp) {
    var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    var regnv = new RegExp(nonvalido);
    var regv = new RegExp(valido);
    if (!regnv.test(indirizzo) && regv.test(indirizzo))
      return true;
    return false;
  }else {
    if(indirizzo.indexOf("@") >= 0)
      return true;
    return false;
  }
}

///////////////////////////////////////////////////////////////

function vm_isCF(cf)	{
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == "" )  return "";
	cf = cf.toUpperCase();
	if( cf.length != 16 )
		return false;
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
			return false;
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	if( s%26 != cf.charCodeAt(15)-"A".charCodeAt(0) )
		return false;
	return true;
}
function vm_isPartitaIva(piva) {
	if (piva.length!=11) {
		return false;
	}
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	var somma = 0;
	for (i=0;i<5;i++) {
		if (i%2==0) {
			somma += parseInt(piva.charAt(i));
		} else {
			var cifra = parseInt(piva.charAt(i));
			somma += contributo[cifra];
		}
	}
	if (somma%10==0) return true;
	else return false;
}

function vm_isCap(cap) {	
	if (cap.length!=5) {
		return false;
	}
	else{
		var myRegex = /\d{5}/; //5 cifre 
		if (myRegex.test(cap)) {
		    return true;
		} else {
		    return false;
		}		
	}
}

function vm_isUser(cap) {	
	if (cap.length<6) {
		return false;
	}
	else{
		var myRegex = /\W/i; // Ogni carattere non di parola
		if (myRegex.test(cap)) {
		    return false;
		} else {
		    return true;
		}
	}
}

///////////////////////////////////////////////////////////////
function controlField(nome,id,id2,tipo){
	switch(tipo){
  case "_":       // controlla se il campo e' vuoto
  if(document.getElementById(id).value == false){
  	alert(nome+": campo mancante");
  	document.getElementById(id).focus();
  	//document.getElementById(id).style.border = "1px solid #ff6600";
  	return false;
  }else{
  	return true;
  }
  break;
  case "__":      // controlla se il campo e' vuoto con ""
  if(document.getElementById(id).value == ""){
  	alert(nome+": campo mancante");
  	document.getElementById(id).focus();
  	//document.getElementById(id).style.border = "1px solid #ff6600";
  	return false;
  }else{
    return true;
  }
  break;
  case "@":       // controlla la validita' del campo mail
  if(!indirizzoEmailValido(document.getElementById(id).value)){
    alert(nome+": campo non valido");
    //document.getElementById(id).style.border = "1px solid #ff6600";
    document.getElementById(id).focus();
    return false;
  }else{
    return true;
  }
  break;
  case "cf":       // controlla la validita' del campo codice fiscale
  if(!vm_isCF(document.getElementById(id).value)){
    alert(nome+": campo non valido");
    //document.getElementById(id).style.border = "1px solid #ff6600";
    document.getElementById(id).focus();
    return false;
  }else{
    return true;
  }
  break;
  
  case "pi":       // controlla la validita' del campo partita iva
  if(!vm_isPartitaIva(document.getElementById(id).value)){
    alert(nome+": campo non valido");
    //document.getElementById(id).style.border = "1px solid #ff6600";
    document.getElementById(id).focus();
    return false;
  }else{
    return true;
  }
  break;
  
  case "cap":       // controlla la validita' del campo partita iva
  if(!vm_isCap(document.getElementById(id).value)){
    alert(nome+": campo non valido");
    //document.getElementById(id).style.border = "1px solid #ff6600";
    document.getElementById(id).focus();
    return false;
  }else{
    return true;
  }
  break; 

  case "p":       // controlla la validita' del campo USER
  if(!vm_isUser(document.getElementById(id).value)){
    alert(nome+": campo non valido. "+nome+" deve avere un minimo di 6 caratteri e accetta solo lettere, numeri e il simbolo di underscore _");
    //document.getElementById(id).style.border = "1px solid #ff6600";
    document.getElementById(id).focus();
    return false;
  }else{
    return true;
  }
  break;

  case "=":       // confronta due campi
  if(document.getElementById(id).value != document.getElementById(id2).value){
    alert("Le password non coincidono");
    document.getElementById(id).focus();
    //document.getElementById(id).style.border = "1px solid #ff6600";
    document.getElementById(id2).value = "";
    return false;
  }else{
    return true;
  }
  break;
  case "h":       // controlla se il campo e' vuoto
  if(document.getElementById(id2).value == false){
  	alert(nome+": campo mancante");
  	document.getElementById(id).focus();
  	//document.getElementById(id).style.border = "1px solid #ff6600";
  	return false;
  }else{
  	return true;
  }
  break;
  default:
  	alert("tipo non riconosciuto");
  return false;
	}
}




function controlFieldEmailSubmit(obj){
	if(document.getElementById('tipo').value=="rivenditore"){
		if ( controlField('PARTITA IVA','part_iva','','pi') && controlField('EMAIL','email','','@') )
			obj.submit();
		else
			return false;
	}
	if ( controlField('CODICE FISCALE','cod_fisc','','cf') && controlField('EMAIL','email','','@') )
		obj.submit();
	else
		return false;
}

function buildUri(obj){
  var strUri = "";
  for(var n=0; n<obj.elements.length; n++){
    if(obj.elements[n].name!=""){
			strUri += "&"+obj.elements[n].name+"="+escape(obj.elements[n].value);
    }
  }
  return strUri;
}

function controlReg(obj){
	flag = true;
	if(document.getElementById('tipo').value!="rivenditore"){
	  flag = flag && controlField('NOME','nome','','_');
		flag = flag && controlField('COGNOME','cognome','','_');
	}
	if(document.getElementById('tipo').value=="rivenditore"){
		flag = flag && controlField('AZIENDA','azienda','','_');
		flag = flag && controlField('PARTITA IVA','part_iva','','pi');
	}
	flag = flag && controlField('CODICE FISCALE','cod_fisc','','cf');
	flag = flag && controlField('INDIRIZZO','indirizzo','','_');
	flag = flag && controlField('CITTA\'','citta','','_');
	flag = flag && controlField('CAP','cap','','cap');
	flag = flag && controlField('PROVINCIA','provincia','','_');
	flag = flag && controlField('STATO','stato','','_');
	flag = flag && controlField('EMAIL','email','','_');
	flag = flag && controlField('EMAIL','email','','@');
	flag = flag && controlField('USER','user','','p');
	flag = flag && controlField('PASSWORD','pass','','p');
	flag = flag && controlField('RISCRIVI PASSWORD','pass2','','_');
	flag = flag && controlField('PASSWORD NON COINCIDE','pass','pass2','=');


	if(flag){
		if(document.getElementById('privacySi').checked==false) alert("Per proseguire e' necessario fornire il consenso.");
		flag = document.getElementById('privacySi').checked;
	}
	if(flag){
		valAreaRegistrazione = document.getElementById('areaRegistrazione').value;
		strUri = "?cmd=registraUtente"+buildUri(obj)+"&areaRegistrazione="+valAreaRegistrazione;
		viewMex("Caricamento in corso...");
		ajaxGetRand(strUri,myHandler);
	}
	function myHandler(aa){
		//hideMex(aa,1);
		if(aa=="userExists"){
			alert("User gi&agrave; presente nel database.");
		}
		else if(aa=="codfiscExists"){
			alert("Codice fiscale gi&agrave; presente nel database.");
		}		
		else{
			location.href=aa;
		}
	}
}
function aggiornaQuantita(id1,url){
	val = document.getElementById(id1).value;
	prodotto = id1.replace("iid","");
	ajaxGetRand('?cmd=aggiornaCarrello&id='+id1+'&val='+val,myHandler);
	function myHandler(aa){
		location.href=url;
  }
}
function variaCarrello(prodotto,operazione,sezione){
	//alert(prodotto);
	ajaxGetRand('?cmd=variaCarrello&prodotto='+prodotto+'&sezione='+sezione+'&operazione='+operazione,myHandler);
	function myHandler(aa){
		location.reload(true);
  }
}

function togliDaCarrelloEAggiorna(prodotto){
	ajaxGetRand('?cmd=variaCarrello&prodotto='+prodotto+'&operazione=remAgg',myHandler);
	function myHandler(aa){
		location.reload(true);
  }
}

function pseudoSelect(w,obj1,obj2){
	dTop = document.body.scrollTop;
	content = document.getElementById('contents');
	contentXX = getPosX(content);
	contentYY = getPosY(content);
	me = document.getElementById(obj1);
	selectBox = document.getElementById(obj2);
	xx = getPosX(me)-contentXX;
	yy = getPosY(me)-contentYY;
	selectBox.style.width=w+"px";
	selectBox.style.background="#FFF";
	selectBox.style.zIndex="99";
	selectBox.style.position="absolute";
	selectBox.style.top=yy+"px";
	selectBox.style.left=xx+"px";
	selectBox.style.display = "block";
	//alert(xx+"  "+yy);
	document.onmouseup=function(){
  	document.getElementById(obj2).style.display='none';
    document.onmouseup='';
  }
}

function pseudoSelectClose(obj){
	me = document.getElementById(obj);
	me.style.display = "none";
}

function refreshProdotto(obj){
  //alert(obj.parentNode.id);
	optionId=obj.id;
	selectId=obj.parentNode.id;
	idProdotto=optionId.replace("selOption","");
	codiceGruppo=selectId.replace("selBox","");
	//alert(codiceGruppo+" - "+idProdotto);
	obj.parentNode.style.display='none';
	ajaxGetRand('?cmd=refreshProdotto&idProdotto='+idProdotto+'&codiceGruppo='+codiceGruppo,myHandler);
	function myHandler(aa){
		location.reload(true);
  }
}

function refreshProdottoWithSendByGet(obj,url){
	optionId=obj.id;
	selectId=obj.parentNode.id;
	idProdotto=optionId.replace("selOption","");
	codiceGruppo=selectId.replace("selBox","");
	//alert(codiceGruppo+" - "+idProdotto);
	obj.parentNode.style.display='none';
	ajaxGetRand('?cmd=refreshProdotto&idProdotto='+idProdotto+'&codiceGruppo='+codiceGruppo,myHandler);
	function myHandler(aa){
		location.href=url;
  }
}

function pseudoSelect2(w,obj1,obj2){
	dTop = document.body.scrollTop;
	content = document.getElementById('contents');
	contentXX = getPosX(content);
	contentYY = getPosY(content);
	me = document.getElementById(obj1);
	selectBox = document.getElementById(obj2);
	xx = getPosX(me)-contentXX;
	yy = getPosY(me)-contentYY;
	selectBox.style.width=w+"px";
	selectBox.style.background="#FFF";
	selectBox.style.zIndex="99";
	selectBox.style.position="absolute";
	selectBox.style.top=0+"px";
	selectBox.style.left=0+"px";
	selectBox.style.display = "block";
	document.onmouseup=function(){
  	document.getElementById(obj2).style.display='none';
    document.onmouseup='';
  }
}
function updatePseudoSelect(obj){
	selectId=obj.parentNode.id;
	optionId=obj.id;
	valSelectId=selectId.replace("selectBox","");
	valOptionId=optionId.replace(selectId+"Option","");
	//obj.parentNode.style.display='none';
	document.getElementById(selectId+"Selected").innerHTML=document.getElementById(optionId).innerHTML;
	idCorrente=document.getElementById(selectId+"Selected").innerHTML;
	document.getElementById("aSelSelected"+valSelectId).innerHTML=document.getElementById(optionId).getElementsByTagName("div")[0].innerHTML;
	

	document.getElementById('selectValue'+valSelectId).value=document.getElementById(optionId).getElementsByTagName("div")[0].innerHTML;
	if (document.getElementById('selectValue1').value=='0') document.getElementById('selectValue1').value='';
	
	if (document.getElementById('selectValue2').value=='') document.getElementById('selectValue2').value='0';
	if ( document.getElementById('selectValue2').value+document.getElementById('selectValue1').value==0 ) 
		document.getElementById('selectValue2').value='';
	
	if (document.getElementById('selectValue3').value=='') document.getElementById('selectValue3').value='0';
	
	if ((document.getElementById('selectValue1').value+document.getElementById('selectValue2').value+document.getElementById('selectValue3').value)==0){
		document.getElementById('selectValue1').value='';
		document.getElementById('selectValue2').value='';
		document.getElementById('selectValue3').value='';
		spiccioli='';
	}
	else {
		spiccioli='0,00';
	}
	document.getElementById('quotaLibera').value=document.getElementById('selectValue1').value+document.getElementById('selectValue2').value+document.getElementById('selectValue3').value+spiccioli;
	//alert("OptionId= "+optionId+" Valore= <"+document.getElementById('selectValue2').value+">");
}
/*
function updatePseudoSelect2(obj){
	selectId=obj.parentNode.id;
	optionId=obj.id;
	valSelectId=selectId.replace("selectBox","");
	valOptionId=optionId.replace(selectId+"Option","");
	//obj.parentNode.style.display='none';
	document.getElementById(selectId+"Selected").innerHTML=document.getElementById(optionId).innerHTML;
	idCorrente=document.getElementById(selectId+"Selected").innerHTML;
	document.getElementById("aSelSelected"+valSelectId).innerHTML=document.getElementById(optionId).getElementsByTagName("div")[0].innerHTML;
	//alert(valOptionId);
	ajaxGetRand('?cmd=cercaMarcaListe&idMarca='+valOptionId,myHandler);
	function myHandler(aa){
		location.reload(true);
		//document.getElementById('win').innerHTML=aa;
  }
}
*/
function updatePseudoSelect2(obj){
	selectId=obj.parentNode.id;
	optionId=obj.id;
	valSelectId=selectId.replace("selectBox","");
	valOptionId=optionId.replace(selectId+"Option","");
	//document.getElementById(selectId+"Selected").innerHTML=document.getElementById(optionId).innerHTML;
	//idCorrente=document.getElementById(selectId+"Selected").innerHTML;
	//alert(valOptionId);
	ajaxGetRand('?cmd=cercaMarcaListe&idMarca='+valOptionId,myHandler);
	function myHandler(aa){
		location.href=aa;
  }
}
/************************* VECCHI SCRIPT PER LO PREUDO SELECT IN ARGENTI ************************/
/*********************** FANNO RIFERIMENTO SOLO ALLE VARIABILI DI SESSIONE **********************/
/*
function pseudoSelect3(w,obj1,obj2){
	dTop = document.body.scrollTop;
	content = document.getElementById('contents');
	contentXX = getPosX(content);
	contentYY = getPosY(content);
	me = document.getElementById(obj1);
	selectBox = document.getElementById(obj2);
	xx = getPosX(me)-contentXX;
	yy = getPosY(me)-contentYY;
	selectBox.style.width=w+"px";
	selectBox.style.background="#FFF";
	selectBox.style.zIndex="99";
	selectBox.style.position="absolute";
	selectBox.style.top=yy+"px";
	selectBox.style.left=xx+"px";
	selectBox.style.display = "block";
	//alert(xx+"  "+yy);
	document.onmouseup=function(){
  	document.getElementById(obj2).style.display='none';
    document.onmouseup='';
  }
}
function updatePseudoSelect3(obj){
  //alert(obj.parentNode.id);
	optionId=obj.id;
	optionValue=document.getElementById(optionId).firstChild.innerHTML;
	selectId=obj.parentNode.id;
	idCategoria=optionId.replace("selCatprodOption","");
	obj.parentNode.style.display='none';
	ajaxGetRand('?cmd=refreshCatArgenti&idCategoria='+idCategoria,myHandler);
	function myHandler(aa){
		location.href='/vetrina_e_commerce_produzione_argenti.html';
		//location.href='/'+idCategoria+'/0/catalogo_online_produzione_argenti/';
		document.getElementById('selCatprodSelected').firstChild.innerHTML=optionValue;
		document.getElementById('firstSelectOption').innerHTML=optionValue;
  }
}
function updatePseudoSelect3_2(obj){
  //alert(obj.parentNode.id);
	optionId=obj.id;
	optionValue=document.getElementById(optionId).firstChild.innerHTML;
	selectId=obj.parentNode.id;
	idSottocategoria=optionId.replace("selSubcatprodOption","");
	obj.parentNode.style.display='none';
	ajaxGetRand('?cmd=refreshSubcatArgenti&idSottocategoria='+idSottocategoria,myHandler);
	function myHandler(aa){
		document.getElementById('selSubcatprodSelected').firstChild.innerHTML=optionValue;
		document.getElementById('firstSubcatprodSelectOption').innerHTML=optionValue;
		//document.getElementById(selectId).firstChild.firstChild.innerHTML=optionValue;
		//document.getElementById('sottoCategorie').innerHTML=aa;

		//location.href='/vetrina_e_commerce_produzione_argenti.html';		
		//location.href='/0/0/catalogo_online_produzione_argenti/';

		//location.reload(true);
  }
}
*/
/****************************************************************************************/


/************************* NUOVI SCRIPT PER LO PREUDO SELECT IN ARGENTI ************************/
/**************************** FANNO RIFERIMENTO ALLE VARIABILI IN GET **********************/
function pseudoSelect3(w,obj1,obj2){
	dTop = document.body.scrollTop;
	content = document.getElementById('contents');
	contentXX = getPosX(content);
	contentYY = getPosY(content);
	me = document.getElementById(obj1); //selCatprodSelected
	selectBox = document.getElementById(obj2); //selCatprodBox
	xx = getPosX(me)-contentXX;
	yy = getPosY(me)-contentYY;
	selectBox.style.width=w+"px";
	selectBox.style.background="#FFF";
	selectBox.style.zIndex="99";
	selectBox.style.position="absolute";
	selectBox.style.top=yy+"px";
	selectBox.style.left=xx+"px";
	selectBox.style.display = "block";
	//alert(xx+"  "+yy);
	document.onmouseup=function(){
  	document.getElementById(obj2).style.display='none';
    document.onmouseup='';
  }
}
function updatePseudoSelect3(obj){
  //alert(obj.parentNode.id);
	optionId=obj.id; //selCatprodOptionN
	optionValue=document.getElementById(optionId).firstChild.innerHTML;
	//alert(optionValue);
	selectId=obj.parentNode.id;
	//alert(selectId);
	idCategoria=optionId.replace("selCatprodOption","");
	obj.parentNode.style.display='none';
	ajaxGetRand('?cmd=refreshCatArgenti&idCategoria='+idCategoria,myHandler);
	function myHandler(aa){
		//location.href='/vetrina_e_commerce_produzione_argenti.html';
		//document.getElementById('win').style.display='block';
		//document.getElementById('win').innerHTML=aa;
		location.href=aa;
		//document.getElementById('selCatprodSelected').firstChild.innerHTML=optionValue;
		//document.getElementById('firstSelectOption').innerHTML=optionValue;
  }
}
function updatePseudoSelect3_2(obj,idCategoria){
  //alert(obj.parentNode.id);
	optionId=obj.id;
	optionValue=document.getElementById(optionId).firstChild.innerHTML;
	selectId=obj.parentNode.id;
	idSottocategoria=optionId.replace("selSubcatprodOption","");
	obj.parentNode.style.display='none';
	ajaxGetRand('?cmd=refreshSubcatArgenti&idCategoria='+idCategoria+'&idSottocategoria='+idSottocategoria,myHandler);
	function myHandler(aa){
		document.getElementById('selSubcatprodSelected').firstChild.innerHTML=optionValue;
		document.getElementById('firstSubcatprodSelectOption').innerHTML=optionValue;
		
		
		//document.getElementById('win').style.display='block';
		//document.getElementById('win').innerHTML=aa;		
		location.href=aa;
		
		//document.getElementById(selectId).firstChild.firstChild.innerHTML=optionValue;
		//document.getElementById('sottoCategorie').innerHTML=aa;

		//location.href='/vetrina_e_commerce_produzione_argenti.html';		
		//location.href='/0/0/catalogo_online_produzione_argenti/';

		//location.reload(true);
  }
}

/****************************************************************************************/














function costoTrasporto(obj1,obj2){
	idSelect=obj1.id;
	indice_selezionato = document.getElementById(idSelect).selectedIndex;
	value_selezionato = document.getElementById(idSelect).options[indice_selezionato].value;
	indirizzoSpedizioneValue=document.getElementById('indirizzoSpedizione').value;
	urlAj='?cmd=costoTrasporto&idNazione='+value_selezionato+'&peso='+obj2;
	if (indirizzoSpedizioneValue!=''){
		urlAj=urlAj+'&indSped='+indirizzoSpedizioneValue;
	}
	//alert(urlAj);
	
	ajaxGetRand(urlAj,myHandler);
	function myHandler(aa){
		//alert(aa);
		//document.getElementById('valoreSpeseTrasporto').innerHTML=aa;
		location.reload(true);
	}
}

function controlloQuota(foo){
	form = document.getElementById('formQuotaLibera');
	switch(foo){
	  case "submit":
		  if(document.getElementById('quotaLibera').value == ""){
		  	alert("Non e' stato inserito alcun valore");
		  	return false;
		  }
		  else{
		  	form.submit();
		  }
		break;
	  	case "reset":
	  	document.getElementById("aSelSelected1").innerHTML='0';
	  	document.getElementById("aSelSelected2").innerHTML='0';
	  	document.getElementById("aSelSelected3").innerHTML='0';
		  form.reset();
		break;
	}
}
function submitAcquista(obj){
	//num_options = document.getElementById('metodoPagamento').options.length;
	indice_selezionato = document.getElementById('metodoPagamento').selectedIndex;
	value_selezionato = document.getElementById('metodoPagamento').options[indice_selezionato].value;

/*	switch(value_selezionato){
		case "estremiCarta":
			indiceTipoCarta = document.getElementById('tipoCarta').selectedIndex;
			valueTipoCarta = document.getElementById('tipoCarta').options[indiceTipoCarta].value;
			
			numCarta=document.getElementById('numCarta').value;
			
			indiceScadMeseCarta=document.getElementById('scadMeseCarta').selectedIndex;
			indiceScadAnnoCarta=document.getElementById('scadAnnoCarta').selectedIndex;
			scadCarta=indiceScadMeseCarta+indiceScadAnnoCarta;
			
			if(valueTipoCarta == "--"){
		  		alert("Nessuna carta selezionata");
		  		return false;
		  	}
			if(numCarta == ""){
		  		alert("Inserire il numero di carta");
		  		return false;
		  	}
			if(scadCarta < 2){
		  		alert("Inserire scadenza carta");
		  		return false;
		  	}
		break;
		case "estremiBonifico":
		break;
		case "estremiContrassegno":
		break;
	}*/
	document.getElementById('ordineAcquisto').submit();
}

function vedi_tutta_la_vetrina_argenti(){
	urlAj="?cmd=resetSessionCatArgenti";
	ajaxGetRand(urlAj,myHandler);
	function myHandler(aa){
		location.href='/vetrina_e_commerce_produzione_argenti.html';
	}
}