//
//-------------------------------------------------------------------
// Licensed Materials - Property of IBM
//
// WebSphere Commerce
//
// (c) Copyright IBM Corp. 2006
//
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
//-------------------------------------------------------------------
//

var busy = false;
//
// ***
// * This javascript function is used by the 'Add to Shopcart' button.  Since the HTML form is shared by both 'Add to Shopcart' and 'Add to Wish List' button,
// * appropriate values are set using this javascript before the form is submitted.
// * The variable 'busy' is used to avoid submitting the same forms multiple times when users click the button more than once.
// ***
//



// This javascript function is used by the 'Add to Wish List' button to set appropriate values before the form is submitted
function Add2WishList(form)
{
       if (!busy) {
              busy = true;
              form.action="InterestItemAdd"
              form.URL.value='InterestItemDisplay'
              form.submit()
       }
}




// Funzione per evidenziare il prezzo del prodotto
function updatePrice(selectbox, attrName){
	var valore1 = selectbox.value;
	var valore = selectbox.value;
	valore = valore.replace(/ /g, "_");
	valore = valore.replace('.', "_");
	var form = document.OrderItemAddForm;
	var scontoPresente = form.scontoPresente.value;	
	
	if (valore == ""){
		var prezzo = form.minPrice.value;
		var prezzoV = form.minPriceV.value;
		var Sprezzo = prezzoV * 100;
		var Dprezzo = Sprezzo / prezzo;
		var Sconto = 100 - Dprezzo;
		var Differenza = prezzo - prezzoV;
		x = Math.round(Differenza * 100) / 100;
		x=x+"";
		if((x.indexOf('.'))< 0){
			x=x+".00";
		}
		var punto = x.indexOf(".");
		var prezzodopoPunto = x.substring(punto+1,x.length);
		if(prezzodopoPunto.length == 1){
			x = x+"0";
		}
		
		
		if(scontoPresente == 2){
			//Element.update($('prezzoVisualizzato'), ("&euro; " + prezzo));
			$('#prezzoVisualizzato').text("€" + prezzo);
		}else{
			if(scontoPresente == 3){
				//Element.update($('prezzoVisualizzato'), ("&euro; <strike>" + prezzo + "</strike>"));
				$('#prezzoVisualizzato').text("€" + prezzo);
				var ScontoWeb = form.scontoPresenteWeb.value;
				var prezzoWeb = (prezzo*(100 - ScontoWeb)/100);		

				prezzoWeb=Math.round(prezzoWeb*100)/100;
				prezzoWeb = prezzoWeb+"";
				var ultimo = prezzoWeb.substring(prezzoWeb.length - 1,prezzoWeb.length);

				if(ultimo >= 3 && ultimo <=7){
					prezzoWeb = prezzoWeb.substring(0,prezzoWeb.length - 1) + "5";
				}
				if(ultimo >= 1 && ultimo <=2){
					if(prezzoWeb.length == 1){
							prezzoWeb = prezzoWeb+".00"
					}else{
						prezzoWeb = prezzoWeb.substring(0,prezzoWeb.length - 1) + "0";
					}
				}
				if(ultimo >= 8 && ultimo <=9){
					prezzoWeb = prezzoWeb.substring(0,prezzoWeb.length - 1) + "0";
				}
				
					
				//Element.update($('prezzoscontoweb'), ("&euro; " + prezzoWeb + "</strike>"));
				$('#prezzoscontoweb').text("€" + prezzoWeb);
				var diffWeb = prezzo - prezzoWeb;

				
				ScontoWeb=Math.round(ScontoWeb*100)/100;
				diffWeb=Math.round(diffWeb*100)/100;
				
				diffWeb = diffWeb+"";
				var punto = diffWeb.indexOf(".");
				var prezzodopoPunto = diffWeb.substring(punto+1,diffWeb.length);
				if(prezzodopoPunto.length == 1){
					diffWeb = diffWeb+"0";
				}
				
				//Element.update($('DifferenzaPrezzoWeb'), ("&euro; " + diffWeb + "</strike>"));
				$('#DifferenzaPrezzoWebb').text("€ " + diffWeb + "</strike>");
				//Element.update($('ScontoWeb'), ("(" + ScontoWeb + "%)"));
				$('#ScontoWeb').text(ScontoWeb);
			}else{
				//Element.update($('prezzoVisualizzato'), ("&euro; <strike>" + prezzo + "</strike>"));
				$('#prezzoVisualizzato').text("&euro; <strike>" + prezzo + "</strike>");
				//Element.update($('prezzoVisualizzatoVendita'), ("&euro; " + prezzoV + "</strike>"));
				$('#prezzoVisualizzatoVendita').text("&euro; " + prezzoV + "</strike>");
				//Element.update($('DifferenzaPrezzo'), ("&euro; " + x + "</strike>"));
				$('#DifferenzaPrezzo').text("&euro; " + x + "</strike>");
			}
			
		}
		
		if(scontoPresente == 1){
			//Element.update($('Sconto'), ("(" + Math.round(Sconto) + "%)"));
			$('#Sconto').text("(" + Math.round(Sconto) + "%)");
		}
		$('#prezzoProdottoVisualizzato_messaggio1').text('Prezzo a partire da:');
		$('#prezzoProdottoVisualizzato_messaggio2').css({visibility: 'visible'})
	}
	else{
		var prezzo = eval( "form." + valore + ".value");
		var prezzoV = eval( "form." + valore + "_V.value");
		var Sprezzo = prezzoV * 100;
		var Dprezzo = Sprezzo / prezzo;
		var Sconto = 100 - Dprezzo;
		var Differenza = prezzo - prezzoV;
		x = Math.round(Differenza * 100) / 100;
		x=x+"";
		if((x.indexOf('.'))< 0){
			x=x+".00";
		}
		var punto = x.indexOf(".");
		var prezzodopoPunto = x.substring(punto+1,x.length);
		if(prezzodopoPunto.length == 1){
			x = x+"0";
		}
		
		if(scontoPresente == 2){
			//Element.update($('prezzoVisualizzato'), ("€" + prezzo));
			$('#prezzoVisualizzato').text("€" + prezzo);
		}else{
		if(scontoPresente == 3){
				//Element.update($('prezzoVisualizzato'), ("&euro; <strike>" + prezzo + "</strike>"));
				$('#prezzoVisualizzato').text("€" + prezzo);
				var ScontoWeb = form.scontoPresenteWeb.value;
				var prezzoWeb = (prezzo*(100 - ScontoWeb)/100);			
				prezzoWeb=Math.round(prezzoWeb*100)/100;				
				ScontoWeb=Math.round(ScontoWeb*100)/100;

				prezzoWeb = prezzoWeb+"";
				var ultimo = prezzoWeb.substring(prezzoWeb.length - 1,prezzoWeb.length);

				if(ultimo >= 3 && ultimo <=7){
					prezzoWeb = prezzoWeb.substring(0,prezzoWeb.length - 1) + "5";
				}
				if(ultimo >= 1 && ultimo <=2){
					if(prezzoWeb.length == 1){
							prezzoWeb = prezzoWeb+".00"
					}else{
						prezzoWeb = prezzoWeb.substring(0,prezzoWeb.length - 1) + "0";
					}
				}
				if(ultimo >= 8 && ultimo <=9){
					prezzoWeb = prezzoWeb.substring(0,prezzoWeb.length - 1) + "0";
				}
				//Element.update($('prezzoscontoweb'), ("&euro; " + prezzoWeb + "</strike>"));
				$('#prezzoscontoweb').text("€" + prezzoWeb);
				var diffWeb = prezzo - prezzoWeb;
				

				diffWeb=Math.round(diffWeb*100)/100;
				diffWeb = diffWeb+"";
				var punto = diffWeb.indexOf(".");
				var prezzodopoPunto = diffWeb.substring(punto+1,diffWeb.length);
				if(prezzodopoPunto.length == 1){
					diffWeb = diffWeb+"0";
				}
				//Element.update($('DifferenzaPrezzoWeb'), ("&euro; " + diffWeb + "</strike>"));
				$('#DifferenzaPrezzoWeb').text("&euro; " + diffWeb + "</strike>");
				//Element.update($('ScontoWeb'), ("(" + ScontoWeb + "%)"));
				$('#ScontoWeb').text("(" + ScontoWeb + "%)");
			}else{
			//Element.update($('prezzoVisualizzato'), ("&euro; <strike>" + prezzo + "</strike>"));
			$('#prezzoVisualizzato').text("&euro; <strike>" + prezzo + "</strike>");
			//Element.update($('prezzoVisualizzatoVendita'), ("&euro; " + prezzoV + "</strike>"));
			$('#prezzoVisualizzatoVendita').text("&euro; " + prezzoV + "</strike>");
			//Element.update($('DifferenzaPrezzo'), ("&euro; " + x + "</strike>"));
			$('#DifferenzaPrezzo').text("&euro; " + x + "</strike>");
		}	
		}	
		if(scontoPresente == 1){
			//Element.update($('Sconto'), ("(" +  Math.round(Sconto) + "%)"));
			$('#Sconto').text("(" +  Math.round(Sconto) + "%)");
		}
		$('#prezzoProdottoVisualizzato_messaggio1').text(attrName + " " + valore1);
		$('#prezzoProdottoVisualizzato_messaggio2').css({visibility: 'hidden'});
		//$('prezzoProdottoVisualizzato_messaggio1').update(attrName + " " + valore1);
		//$('prezzoProdottoVisualizzato_messaggio2').setStyle({visibility: 'hidden'});
	}


	//new Effect.Highlight($('prezzoProdottoVisualizzato'), {startcolor:'#D7E0EA', endcolor:'#FFFFFF'});
	
}


