var trad = new Array();

trad["italiano"] = new Array();
trad["italiano"]["unit_price"] = "Prezzo unitario:&nbsp;";
trad["italiano"]["total"] = "Prezzo totale:&nbsp; ";
trad["italiano"]["total_discount"] = "Prezzo totale scontato:&nbsp; ";
trad["italiano"]["large"] = "Per quantitativi elevati <a href=\"contacts.html\" target=\"_self\">Contattaci</a> direttamente";
trad["italiano"]["username"] = "Username già in uso! Per favore inseriscine un'altro";
trad["italiano"]["mail"] = "E-mail già presente!Per favore prova con un altro indirizzo";
trad["italiano"]["item_deleted"] = "Il prodotto è stato cancellato";
trad["italiano"]["delete"] = "Sei sicuro di voler eliminare la tag?";
trad["italiano"]["tag_deleted"] = "la tag è stata eliminata";
trad["italiano"]["empty_cart"] = "Sei sicuro di voler svuotare il carrello?";
trad["italiano"]["empty"] ="Il carrello è vuoto";
trad["italiano"]["checkcert"] ="Il codice del Certificato di Regalo inserito non è valido o scaduto, riprova facendo attenzione alle lettere minuscole e maiuscole.";
trad["italiano"]["usedcert"] ="Il codice di questo Certificato di Regalo è già stato utilizzato! Non è possibile utilizzarlo ancora.";

trad["inglese"] = new Array();
trad["inglese"]["unit_price"] = "Unit Price:&nbsp; ";
trad["inglese"]["total"] = "Total Price:&nbsp; ";
trad["inglese"]["total_discount"] = "Discounted Price:&nbsp; ";
trad["inglese"]["large"] = "For large volume orders please <a href=\"contacts.html\" target=\"_self\">contact</a> us directly";
trad["inglese"]["username"] = "try another username please! this is already used";
trad["inglese"]["mail"] = "try another e-mail please! this is already used";
trad["inglese"]["item_deleted"] = "Your product is deleted";
trad["inglese"]["delete"] = "Are you sure you want delete tag?";
trad["inglese"]["tag_deleted"] = "Your tag is deleted";
trad["inglese"]["empty_cart"] = "Are you sure you want to empty the cart?";
trad["inglese"]["empty"] ="Your cart is empty";
trad["inglese"]["checkcert"] ="The Gift Certificate code entered is not valid or expired, please note that codes are case sensitive, then try again.";
trad["inglese"]["usedcert"] ="This Gift Certificate code has been already used! You can not use it again!";

trad["spagnolo"] = new Array();
trad["spagnolo"]["unit_price"] = "Precio por unidad:&nbsp; ";
trad["spagnolo"]["total"] = "Precio Total:&nbsp; ";
trad["spagnolo"]["total_discount"] = "Precio con descuento:&nbsp; ";
trad["spagnolo"]["large"] = "Por gran volumen de pedidos por favor póngase en <a href=\"contacts.html\" target=\"_self\">contacto</a> directamente con nosotros";
trad["spagnolo"]["username"] = "try another username please! this is already used";
trad["spagnolo"]["mail"] = "try another e-mail please! this is already used";
trad["spagnolo"]["item_deleted"] = "Your product is deleted";
trad["spagnolo"]["delete"] = "Are you sure you want delete tag?";
trad["spagnolo"]["tag_deleted"] = "Your tag is deleted";
trad["spagnolo"]["empty_cart"] = "Are you sure you want to empty the cart?";
trad["spagnolo"]["empty"] ="Your cart is empty";
trad["spagnolo"]["checkcert"] ="El código regalo que ha escrito no es válido o ha expirado, recuerde que el código distingue las letras mayúsculas de las minúsculas, inténtelo de nuevo.";
trad["spagnolo"]["usedcert"] ="Este código regalo ya ha sido usado, sólo se puede usar un vez";

 function buyProduct(kid) {
 	var p_id = $('#prod'+kid).val();
 	var p_qt = $('#qty'+kid).val();
 	var p_qt2 = 0;
 	var p_id2 = 0;
 	var lang = arguments[1];
 	
 	if(p_id != 101){
 		if( p_id < 107 && p_id > 109 ){
 			$.get('../i2cart/i2cart/_i2helper.php', { act: 'buy', pid: p_id, qty: p_qt }, function(data) { 				window.open('cart.html','_top');  });
 		} else {
 			if ($('#check_l0').is(":checked") == true){
 				$.get('../i2cart/i2cart/_i2helper.php', { act: 'buy', pid: 105, qty: 1 }, function(data) { });
 			}
 			if ($('#check_l1').is(":checked") == true){
 				$.get('../i2cart/i2cart/_i2helper.php', { act: 'buy', pid: 106, qty: 1 }, function(data) { });
 			}
 			$.get('../i2cart/i2cart/_i2helper.php', { act: 'buy', pid: p_id, qty: p_qt }, function(data) {});
 			setTimeout("go('cart.html')", 1250);
 		} 		
 	} else {
 		for(i=0;i<4;i++){
 			p_id2 = $('#prod_l'+i).val();
 			p_qt2 = $('#qty_l'+i).val();
 			if(p_qt2!=0)
 				$.get('../i2cart/i2cart/_i2helper.php', { act: 'buy', pid: p_id2, qty: p_qt2 }, function(data) {  });
 		}
 				
 		setTimeout("go('cart.html')", 1250);
 		//alert('You have to choose the model: love,mess,old bag or stop');		
 	}
 	//displayCartContents();
 }
 
 function go(url){
 	window.open(url,'_top');
 }
 
 function refreshQty_lug(kid,prez,val){
 	var add1=parseInt($('#qty101').val());
 	var add2=parseInt($('#qty_l'+kid).val());
 	if(isNaN(add1))
 		add1 = 0;
 	if(isNaN(add2))
 		add2 = 0;	
 	var somma = (add1 + add2);

 	$('#qty101').val(somma);
 	refreshQty(101,101,prez,val,arguments[3]);
 }
 
 function checkusername(){
 	var users = $('#uid*').val();
 	var lang = arguments[0];
 	$.get('../i2cart/i2cart/_i2helper.php', { act: 'checkuser', user: users }, function(data) {
 		if(data==1){
 			alert(trad[lang]["username"]);
 			$('#uid*').val("");
 		}
 	});
 }
 
  function checkmail(){
 	var mails = $('#mailcheck*').val();
 	var lang = arguments[0];
 	$.get('../i2cart/i2cart/_i2helper.php', { act: 'checkmail', mail: mails }, function(data) {
 		if(data==1){
 			alert(trad[lang]["mail"]);
 			$('#mailcheck*').val("");
 		}
 	});
 }
 
 function refreshQty(pid,kid,prez,val) {
 
 	var p_id = $('#prod'+kid).val();
 	var p_qt = $('#qty'+kid).val();
 	var prezz = $('#price'+kid).val();
 	var lang = arguments[4];
 	
 	$.get('../i2cart/i2cart/_i2helper.php', { act: 'refreshPrice', pid: p_id, qty: p_qt, price: prez }, 
 		function(data) {
 			$('#message_error').html('');
 			if ( data != 0 ) 
 			{
 				if( data != 2)
 				{
 					//if( kid < 107 || kid > 109 ){
 					if((data != (p_qt*prez))){
 						$('#price').html( trad[lang]["unit_price"] + prezz + ' ' + val + ' - ' +  trad[lang]["total_discount"]  + data + ' ' + val + ' *' );
 					} else {
 						$('#price').html( trad[lang]["unit_price"] + prezz + ' ' + val + ' - ' +  trad[lang]["total"] + data + ' ' + val + ' *');
 					}
 				} else {
 					$.get('../i2cart/i2cart/_i2helper.php', { act: 'changeQty', qty: p_qt }, 
 					function(data) { 
 						$('#qty'+kid).val(data);
 						$('#price').html(trad[lang]["large"]);
 					}); 					
 				} 				
 			} else {
 				
 				$.get('../i2cart/i2cart/_i2helper.php', { act: 'changeQty', qty: p_qt }, 
 				function(data) { 					
 					$('#qty'+kid).val(data);
 					p_qt = data;
 					$.get('../i2cart/i2cart/_i2helper.php', { act: 'refreshPrice', pid: p_id, qty: p_qt, price: prez }, 
 					function(data) { 
 						if( (kid < 105 || kid > 109) && (kid < 125 || kid > 130)){
 							$('#price').html( trad[lang]["unit_price"] + prezz + ' ' + val + ' - ' + trad[lang]["total_discount"] + data + ' ' + val + ' *' );
	 					} else {
	 						$('#price').html( trad[lang]["unit_price"] + prezz + ' ' + val + ' - ' + trad[lang]["total"] + data + ' ' + val + ' *');
	 					} });
 					//$('#message_error').html('for orders of 40 or more items, available in multiples of 20 only').css('color','red');
 				}); 				
 			}
 		});
 }
  
 function DeleteItem(pid){
 	var lang = arguments[1];
 	var conf = confirm(trad[lang]["delete"]);
 	if ( conf == true ) {
 
	 	$.get('../i2cart/i2cart/_i2helper.php', { act: 'deleteItem', pid: pid }, 
	 	function(data) { 	});
	 	
	 alert(trad[lang]["item_deleted"]);
	 setTimeout("go('cart.html')", 1250);
 	} 
 }
 
 function displayCartContents() {
 	$.get('../i2cart/i2cart/_i2helper.php', { act: 'discnt' }, 
 		function(data) {
 			$('#cart').html(data);
 	});
 }
 
 function delete_tag(tag_id){
  var lang = arguments[1];
 	var conf = confirm(trad[lang]["delete"]);
 	if ( conf == true ) {
	 	$.get('../i2cart/i2cart/_i2helper.php', { act: 'delete_tag', id_tag: tag_id }, 
	 		function(data) {
	 			if ( data == 'delete' ) {
	 				alert(trad[lang]["tag_deleted"]);
	 			} else {
	 				alert(data);
	 			}
	 		});
 	}
 	}
 
 
 function updateItem(kid) {
 	var p_id = $('#prod'+kid).val();
 	var p_qt = $('#qty'+kid).val();
 	
 	$.get('../i2cart/i2cart/_i2helper.php', { act: 'update', pid: p_id, qty: p_qt }, 
 		function(data) {
 			window.location.reload(true);
 		});

 }
 
  
 function emptyCart() {
 	var lang = arguments[0];
 	var conf = confirm(trad[lang]["empty_cart"]);
 	
 	if ( conf == true ) {
 	$.get('../i2cart/i2cart/_i2helper.php', { act: 'empty' }, 
 		function(data) {
 			if ( data == 'empty' ) {
 				alert(trad[lang]["empty"]);
 				continueShopping();
 			} else {
 				alert(data);
 				window.location.reload(true);	
 			}		
 	});
 	} else {
 		return false;	
 	}	
 }
 
 
 function continueShopping() {
 	/*window.location = 'buy.html';	*/
 	window.open('buy.html','_top');
 }

 
 
 function setCurrency(cur,id) {
 	$.get('../i2cart/i2cart/_i2helper.php', { act: 'setcur', currency: cur }, 
 			function(data) { 
 				if ( data == 1 ) {
 					//alert('Currency set');
 					window.location = '?pid=' + id;
 					return true;
 				} else {
 					alert(data);
 				} 
 			});	
 }
  
 function setCur(id) {
 	var cur = $('#cb_cur').val();
 	//alert(cur);
 	setCurrency(cur,id);
 }
  
  
 function toggleBillingAddress() {
	var chk = $('#sameaddr').is(":checked");
	
	if ( chk == false ) {
		$('#billaddrdiv').show();
	} else {
		$('#billaddrdiv').hide();
	}
 }
 
 function toggleGiftCard() {
	var chk = $('#gift_card').is(":checked");
	
	if ( chk == true ) {
		$('#giftdiv').show();
	} else {
		$('#giftdiv').hide();
	}
 }
 
 function checkgift(lang,order_code){
 	var code = $('#giftcertificate').value
 	
 	$.get('../i2cart/i2cart/_i2helper.php', { act: 'checkcertificate', certificate: code, order: order_code }, 
 			function(data) { 
 				if ( data == 1 ) { 					 					
 					//alert(trad[lang]["checkcert"]);
 					return;
 				} else {
 					$('#giftcertificate').val('');
 					alert(data);
 				} 
 			});	
 }
 
 function subaccount(frase){
 	var check = trim($('#pass').val());
 	if(check != ""){
 		if(confirm(frase)){
 			$('#form_account').submit();
 		}
 	} else { 		
 		$('#form_account').submit();
 	}
 }
 
 function changeProduct(id){
 	window.open(id+".details","_top");
 }
 
 function trim(stringa){
    while (stringa.substring(0,1) == ' '){
        stringa = stringa.substring(1, stringa.length);
    }
    while (stringa.substring(stringa.length-1, stringa.length) == ' '){
        stringa = stringa.substring(0,stringa.length-1);
    }
    return stringa;
}
