// JavaScript Document
function EnviarForm2(x){
	x.submit();
}

function EnviarForm(x){
	
	
	// Variables
	var total_unidades = 0;

	// Verifica nombre
	if(!x.nombre.value){
		x.nombre.focus();
		alert(msn[2]);
		return false;
	}
	
	// Verifica apellido
	//if(!x.apellido.value){
	//	x.apellido.focus();
	//	alert(msn[12]);
	//	return false;
	//}
	
	// Verifica direccion
	if(!x.direccion.value){
		x.direccion.focus();
		alert(msn[3]);
		return false;
	}


	// Verifica pais
	if(x.pais.value=='Select country'){
		x.pais.focus();
		alert(msn[6]);
		return false;
	}
	// Verifica ciudad
	if(!x.ciudad.value){
		x.ciudad.focus();
		alert(msn[5]);
		return false;
	}
	// Verifica codigo postal
	if(!x.cp.value){
		x.cp.focus();
		alert(msn[4]);
		return false;
	}
	// Verifica email vacio
	if(!x.email.value){
		x.email.focus();
		alert(msn[7]);
		return false;
	}
	// Verifica email valido
	if(!verifica_email(x.email.value)){
		x.email.focus();
		return false;
	}
	// Verifica telefono
		if(!x.telefono.value){
		x.telefono.focus();
		alert(msn[8]);
		return false;
	}
	// Verifica si fue selecionado algún producto
	for(aux = 0; aux < producto.length; aux++){
		var unidades = parseFloat(document.getElementById("unidad["+aux+"]").value);
		total_unidades = total_unidades + unidades;
	}
	if(total_unidades ==0){
		alert(msn[9]);
		return false;
	}
	

	x.submit();
}

function verifica_email(x){
	var s = x;

	var filter=/^[A-Za-z]+(\.?)[A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;

    if (filter.test(s)){
		return true;
	}else{
		alert(msn[1]);
		return false;
	}
}

function LimpiarForm(x){
	if(confirm(msn[0])){
		// Limpia form
		x.reset();
		// Limpia total
		document.getElementById("total").innerHTML = "0";
		document.getElementById("cost").innerHTML = "0";
	}
}


function totalTransporte(pais){

arts=leePedido();
totalt=0.0;
totalp=0.0;
for (elem in tienda)
	if (tienda[elem].cant >0){
	totalp=totalp+tienda[elem].valor*tienda[elem].cant;
	if (pais!='Select country')
	{
	if (elem=='articulo1')
		{
		if (tienda[elem].cant==1)
			totalt=totalt+cost_transp1_1[pais];
		if (tienda[elem].cant==2)
			totalt=totalt+cost_transp1_2[pais];
		if (tienda[elem].cant==3)
			totalt=totalt+cost_transp1_3[pais];
		}

	if (elem=='articulo2')
		{
		if (tienda[elem].cant==1)
			totalt=totalt+cost_transp2_1[pais];
		if (tienda[elem].cant==2)
			totalt=totalt+cost_transp2_2[pais];
		if (tienda[elem].cant==3)
			totalt=totalt+cost_transp2_3[pais];
		}


	if (elem=='articulo3')
		{
		if (tienda[elem].cant==1)
			totalt=totalt+cost_transp3_1[pais];
		if (tienda[elem].cant==2)
			totalt=totalt+cost_transp3_2[pais];
		if (tienda[elem].cant==3)
			totalt=totalt+cost_transp3_3[pais];
		}


	if ((elem=='articulo4') || (elem=='articulo5') || (elem=='articulo6'))
		{
		if (tienda[elem].cant==1)
			totalt=totalt+cost_transp4_1[pais];
		if (tienda[elem].cant==2)
			totalt=totalt+cost_transp4_2[pais];
		if (tienda[elem].cant==3)
			totalt=totalt+cost_transp4_3[pais];
		}
	}

document.getElementById("cost").innerHTML = totalt;
document.getElementById("cost_b").value = totalt;
document.getElementById("total").innerHTML =totalp+totalt;
}


}




function CommaFormatted(amount)
{
	var delimiter = "."; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}
// end of function CommaFormatted()
