function muestraDIV(strIdDiv)
{
	document.getElementById(strIdDiv).style.visibility = "visible";
}

function ocultaDIV(strIdDiv)
{
	document.getElementById(strIdDiv).style.visibility = "hidden";
}

function posicionaMenu()
{
	var ancho;
	var distancia;
	
	ancho = document.documentElement.clientWidth;
	
	distancia = ((ancho - 1024) / 2);
	
	if(distancia > 0)
	{
		distancia = distancia + 80;
		distancia = distancia + 'px';
		document.getElementById('divMenu').style["left"] = distancia;
	}else
	{
		document.getElementById('divMenu').style["left"] = '80px';
	}
	
}

function posicionaTexto()
{
	var ancho;
	var distancia;
	var distanciaTexto1;
	var distanciaTexto2;
	
	ancho = document.documentElement.clientWidth;
	
	distancia = ((ancho - 1024) / 2);

	if(distancia > 0)
	{
		distanciaTexto1 = distancia + 660;
		distanciaTexto2 = distancia + 120;
		distanciaTexto1 = distanciaTexto1 + 'px';
		distanciaTexto2 = distanciaTexto2 + 'px';
		document.getElementById('divTexto1').style["left"] = distanciaTexto1;
		document.getElementById('divTexto2').style["left"] = distanciaTexto2;
	}else
	{
		document.getElementById('divTexto1').style["left"] = '660px';
		document.getElementById('divTexto2').style["left"] = '120px';		
	}
}

function posicionaTextoHome()
{
	var ancho;
	var distancia;
	var distanciaTexto;
	ancho = document.documentElement.clientWidth;
	
	distancia = ((ancho - 1024) / 2);

	if(distancia > 0)
	{
		distanciaTexto = distancia + 117;
		
		distanciaTexto = distanciaTexto + 'px';
		document.getElementById('divTextoHome').style["left"] = distanciaTexto;
	}else
	{
		document.getElementById('divTextoHome').style["left"] = '117px';
	}
}

function calculaPrecio()
{
	document.getElementById('txtPrecioTotDol').value = document.getElementById('txtPrecioUniDol').value * document.getElementById('txtQty').value;
	
	document.getElementById('txtPrecioTotDol').value = '$' + document.getElementById('txtPrecioTotDol').value;
	
	document.getElementById('txtPrecioTotEur').value = document.getElementById('txtPrecioUniEur').value * document.getElementById('txtQty').value
	
	document.getElementById('txtPrecioTotEur').value = document.getElementById('txtPrecioTotEur').value + '€';
}

function validaNumero()
{
	if (IsNumeric(document.getElementById('txtQty').value) == false)
	{
		alert('The quantity must be numeric.');
		document.getElementById('txtQty').value = '1'
	}
}

function IsNumeric(valor) 
{ 
	var log=valor.length; var sw="S"; 
	for (x=0; x<log; x++) 
	{
		v1=valor.substr(x,1); 
		v2 = parseInt(v1); 
		//Compruebo si es un valor numérico 
		if (isNaN(v2)) { sw= "N";} 
	} 
	if (sw=="S") {return true;} else {return false; } 
}

function mostrarMsg()
{
	var callingURL = document.URL; 
	if (callingURL.indexOf('?msg=') >= 0)
	{
		var msg = callingURL.substring(callingURL.indexOf('?msg=')+5,callingURL.length); 
		msg = msg.replace(/[%20]/g,' ')
		alert(msg);
	}else if(callingURL.indexOf('&msg=') >= 0)
	{
		var msg = callingURL.substring(callingURL.indexOf('&msg=')+5,callingURL.length); 
		msg = msg.replace(/[%20]/g,' ')
		alert(msg);
	}
}

function validaFormulari(strPantalla, strAccio)
{
	var bolValida;
	bolValida = true
	if (strPantalla == "espadrilles")
	{
		if (strAccio == "order")
		{
			if (IsNumeric(document.getElementById('txtQty').value) == false)
			{
				alert('The quantity must be numeric.');
				document.getElementById('txtQty').value = '1'
				bolValida = false;
			}
		}
	}else if(strPantalla == "shopping")
	{
		//Validar que los campos son obligatorios
		if (document.getElementById('email').value == "")
		{
			alert('Email is required.');
			bolValida = false;
		}else if(document.getElementById('first_name').value == "")
		{
			alert('First Name is required.');
			bolValida = false;
		}else if(document.getElementById('last_name').value == "")
		{
			alert('Last Name is required.');
			bolValida = false;
		}else if(document.getElementById('city').value == "")
		{
			alert('City is required.');
			bolValida = false;
		}else if(document.getElementById('address1').value == "")
		{
			alert('Address 1 is required.');
			bolValida = false;
		}else if(document.getElementById('zip').value == "")
		{
			alert('Postal code is required.');
			bolValida = false;
		}else if(document.getElementById('night_phone_a').value == "")
		{
			alert('Phone is required.');
			bolValida = false;
		}else if(validarEmail(document.getElementById('email').value) == false)
		{
			bolValida = false;
		}
	}
	
	return bolValida;	
}

function enviaFormulari(objEnvio, strPantalla, strAccio, idValor)
{	

	document.getElementById('pantalla').value = strPantalla;
	document.getElementById('accio').value = strAccio;
	
	if (idValor)
	{
		document.getElementById('idValor').value = idValor;
	}
	
	if (strPantalla == "espadrilles")
	{
		if (strAccio == "order")
		{
			var indice = document.getElementById('cmbColor').selectedIndex;
			document.getElementById('nomColor').value = document.getElementById('cmbColor')[indice].text;			
		}
	}
		
	if (validaFormulari(strPantalla, strAccio) == true)
	{
		document.form1.submit();
	}
}

function seleccionaPais()
{
	document.form1.action = '#';
	document.form1.submit();
}

function seleccionaProductoStock()
{
	document.form1.action = '#';
	document.form1.submit();
}

function validarEmail(valor)
{
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
  	return (true);
  } else {
   alert("The email address is incorrect.");
   return (false);
  }
}

window.onresize=function(){posicionaMenu();}
