function verificamail() {
	document.getElementById("bottoneinvio").innerHTML = resource5;
	pageTracker._trackPageview('/going_to_paypal');
	document.getElementById("paypalcart").submit();
}

function verificamailOLD() {
	if (document.getElementById('email').value === '')
	{
		alert(resource1);
		return false;
	}

	if (!echeck(document.getElementById('email').value))
	{
		alert(resource1b);
		return false;
	}
	else
	{
		document.getElementById("bottoneinvio").innerHTML = resource5;
		pageTracker._trackPageview('/going_to_paypal');
		document.getElementById("paypalcart").submit();
	}
}

function sostituisciklikk() {
	if (dimensione == 'grande')
	{
		if (color == 'nero') {
			img = "klikk_big_black_config.jpg";
		} else {
			img = "klikk_big_red_config.jpg";
		}
	}
	else
	{
		if (color == 'nero') {
			img = "klikk_small_black_config.jpg";
		} else {
			img = "klikk_small_red_config.jpg";
		}
	}

	document.getElementById('configuratore').src = 'images/' + img;

	if (color == 'nero')
	{
		document.getElementById('colorenero').src = 'images/colore_black_r.gif';
		document.getElementById('colorerosso').src = 'images/colore_red.gif';
	}
	else
	{
		document.getElementById('colorenero').src = 'images/colore_black.gif';
		document.getElementById('colorerosso').src = 'images/colore_red_r.gif';
	}

	if (dimensione == 'grande')
	{
		document.getElementById('selezionatoregrande').style.backgroundColor = '#666666';
		document.getElementById('selezionatorepiccolo').style.backgroundColor = '#c2c2c2';
	}
	else
	{
		document.getElementById('selezionatoregrande').style.backgroundColor = '#c2c2c2';
		document.getElementById('selezionatorepiccolo').style.backgroundColor = '#666666';
	}
	return true;
}

function updateqtt() {
	quantity = document.getElementById("textfield").value;
	if (quantity < 0) {
		quantity = 1;
	}
	document.getElementById("textfield").value = quantity;
	return true;
}

function updateqttbyid(id) {
	var tempqtt;
	tempqtt = document.getElementById("cartqtt" + id).value;
	if (tempqtt < 0) {
		tempqtt = 1;
	}
	document.getElementById("cartqtt" + id).value = tempqtt;
	cartqtt[id] = tempqtt;
	stampacarrello();
	return true;
}

function cartremove(id) {
	cartqtt[id] = 0;
	stampacarrello();
	return true;
}

function aggiungialcarrello() {
	cartprod[currelem] = dimensione;
	cartcolor[currelem] = color;
	cartqtt[currelem] = quantity;
	currelem = currelem + 1;
	stampacarrello();
	return true;
}

function stampacarrello() {
	totale = 0;
	tabb = '<table width="440" border="0" align="center" cellpadding="0" cellspacing="0" id="tabellacart">';
	for (i = 0; i < currelem; i++)
	{
		if (cartqtt[i] > 0)
		{
			tabb += '<tr>';
			tabb += '<td width="190" style="padding-top:10px; padding-bottom:10px;">Klikk Kit ';
			if (cartprod[i] == 'grande') {
				tabb += resource_grande;
			}
			else {
				tabb += resource_piccolo;
			}
			tabb += '</td>';
			tabb += '<td width="80" align="center"><input name="cartqtt' + i + '" type="text" class="quantita" onchange="javascript:updateqttbyid(' + i + ');" id="cartqtt' + i + '" value="' + cartqtt[i] + '">';
			tabb += '<a style="cursor:pointer;" onclick="javascript:updateqttbyid(' + i + ');"><img src="images/ico_refresh.gif" width="11" height="13" border="0" style="margin-left:4px;"></a></td>';
			tabb += '<td width="70" align="center"><img src="images/';
			if (cartcolor[i] == 'nero') {
				tabb += 'colore_black.gif';
			}
			else {
				tabb += 'colore_red.gif';
			}
			tabb += '" width="21" height="19" border="0"></td>';
			parziale = 14.99 * cartqtt[i];
			totale = totale + parziale;
			tabb += '<td width="70" align="right">' + parziale.toFixed(2) + ' &euro;</td>';
			tabb += '<td width="30" align="right"><a style="cursor:pointer;" onclick="javascript:cartremove(' + i + ');"><img src="images/ico_trash.gif" width="11" height="13" border="0"></a></td>';
			tabb += '</tr>';
		}
	}
	tabb += '</table>';
	iva = 0 * totale;
	ivato = iva + totale;
	document.getElementById('totalenetto').innerHTML = totale.toFixed(2) + ' &euro;';
	//document.getElementById('totaleiva').innerHTML = iva.toFixed(2) + ' &euro;';
	document.getElementById('totaleivato').innerHTML = '<strong>' + ivato.toFixed(2) + ' &euro;</strong>';
	document.getElementById('tabellacart').innerHTML = tabb;
	return true;
}

function confermaordine() {
	totale = 0;
	tabb = '';
	for (i = 0; i < currelem; i++)
	{
		tabb = '&';
		if (cartqtt[i] > 0)
		{
			parziale = 12.50 * cartqtt[i];
			totale = totale + parziale;
		}
	}
	iva = 0.20 * totale;
	ivato = iva + totale;
	if (totale === 0)
	{
		alert (resource4);
		return false;
	}

	totale = 0;
	pp_Carrellone = '';
	tabb2 = '<table width="440" border="0" align="center" cellpadding="0" cellspacing="0" id="ct2_tabellacart">';
	ppi = 0;
	for (i = 0; i < currelem; i++)
	{
		if (cartqtt[i] > 0)
		{
			ppi++;
			pp_Carrellone += '<input type="hidden" name="item_name_' + ppi + '" value="Klikk Kit ';
 			if (cartprod[i] == 'grande') {
				pp_Carrellone += resource_grande;
			}
			else {
				pp_Carrellone += resource_piccolo;
			}
			if (cartcolor[i] == 'nero') {
				pp_Carrellone += ' black';
			}
			else {
				pp_Carrellone += ' red';
			}
			pp_Carrellone += '" />';
			pp_Carrellone += '<input type="hidden" name="amount_' + ppi + '" value="14.99" />';
			pp_Carrellone += '<input type="hidden" name="quantity_' + ppi + '" value="' + cartqtt[i] + '" />';
			pp_Carrellone += '<input type="hidden" name="tax_' + ppi + '" value="0" />';

			tabb2 += '<tr>';
			tabb2 += '<td width="190" style="padding-top:10px; padding-bottom:10px;">Klikk Kit ';
			if (cartprod[i] == 'grande') {
				tabb2 += resource_grande;
			}
			else {
				tabb2 += resource_piccolo;
			}
			tabb2 += '</td>';
			tabb2 += '<td width="80" align="center">' + cartqtt[i] + '</td>';
			tabb2 += '<td width="70" align="center"><img src="images/';
			if (cartcolor[i] == 'nero') {
				tabb2 += 'colore_black.gif';
			}
			else {
				tabb2 += 'colore_red.gif';
			}
			tabb2 += '" width="21" height="19" border="0"></td>';
			parziale = 14.99 * cartqtt[i];
			totale = totale + parziale;
			tabb2 += '<td width="70" align="right">' + parziale.toFixed(2) + ' &euro;</td>';
			tabb2 += '<td width="30" align="right">&nbsp;</td>';
			tabb2 += '</tr>';
		}
	}
	tabb2 += '</table>';
	iva = 0 * totale;
	ivato = iva + totale;
	
	document.getElementById('ct2_tabellacart').innerHTML = tabb2;
	document.getElementById('ct2_totalenetto').innerHTML = totale.toFixed(2) + ' &euro;';
	document.getElementById('ct2_totaleivato').innerHTML = '<strong>' + ivato.toFixed(2) + ' &euro;</strong>';
	document.getElementById('pp_total_amount').value = ivato.toFixed(2);
	document.getElementById('pp_carrellone').innerHTML = pp_Carrellone;

	newSvisvoHtml = '<div id="content">' + document.getElementById('content2').innerHTML + '</div>';
	
	//document.getElementById('content').removeChild();
	document.body.removeChild(document.getElementById('content'));
	document.body.removeChild(document.getElementById('content2'));
	newSvisvoDom = document.createElement('div');
	newSvisvoDom.innerHTML = newSvisvoHtml;
	oldSvisvo = document.getElementById('filetto');
	document.body.insertBefore(newSvisvoDom, oldSvisvo);
	
	//document.getElementById('email').select();
	//document.getElementById('email').focus();

	pageTracker._trackPageview('/checkout');
	
	return true;
}

function checkEmailAddress(field)
{
  var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\..{2,2}))$)\b/gi);
  if (goodEmail) {
  	return true;
  }
  else {
  	return false;
  }
}


function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);

		if (str.indexOf(at)==-1){
			return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at) === 0 || str.indexOf(at)==lstr){
			return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot) === 0 || str.indexOf(dot)==lstr){
			return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
			return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			return false;
		 }

		 if (str.indexOf(" ")!=-1){
			return false;
		 }

 		 return true;
	}
