/*// Funcion para identificar en el 
menu en que seccion nos encontramos//*/

/*function activeLink(seccion) 
{
	var finalUrl = "";
	var url = document.URL;
	var splitUrl = url.split('/');
	
	
	if(url == server) 
	{ 
		$("#divHome").css("background","none");
	}
	
	//var child = splitUrl[4].match(/[_]/);
	
	if(splitUrl[4].match(/[_]/) != null) 
	{
		finalUrl = splitUrl[4].split('_')[0];
	}
	else if(splitUrl[4].match(/[&]/) != null) 
	{
		finalUrl = splitUrl[4].split('&')[0];
	}
	else 
	{
		finalUrl = splitUrl[4];
	}
	
	var secc = document.getElementById(seccion);
	var a = secc.getElementsByTagName("a");
	
	for(var i=0; i < a.length; i++) 
	{
		if(a[i].getAttribute("href") == finalUrl)
		{
			if(seccion == "maiNav") 
			{
				$('#' + a[i].id.replace("btn", "div")).css("background","none");
			}
		}
	}
}

window.onload = activeLink("maiNav");*/

function activeLink(seccion) 
{
	var finalUrl = "";
	var url = document.URL;
	var splitUrl = url.split('/');
	
	
	if(url == server) 
	{ 
		document.getElementById("divHome").style.background = "none";
	}
	
	/*if(splitUrl[3].match(/[_]/) != null) 
	{
 		finalUrl = splitUrl[3].split('_')[0];
	}
	else*/
	if(splitUrl[3].match(/[&]/) != null) 
	{
		finalUrl = splitUrl[3].split('&')[0];
	}
	else 
	{
		finalUrl = splitUrl[3];
	}
		
	var secc = document.getElementById(seccion);
	var a = secc.getElementsByTagName("a");
	
	for(var i=0; i < a.length; i++) 
	{
		if(a[i].getAttribute("href") == finalUrl || a[i].getAttribute("href") == (server + finalUrl))
		{
			if(seccion == "maiNav") 
			{
				document.getElementById(a[i].id.replace("btn", "div")).style.background = "none";
			}
		}
	}
	if(document.location.href.indexOf("-c-")>-1) // This doesn't work, any suggestions.
	{
		 document.getElementById("divTienda").style.background = "none";
	}
}

/*// Funcion que valida y envia la informacion
formulario de contacto //*/
function sendInfo() 
{
	var nombre = document.getElementById("nombre").value;
	var email = document.getElementById("email").value;
	var email2 =  document.getElementById("email2").value;
	var compania = document.getElementById("compania").value;
	var pais = document.getElementById("pais").value;
	var apellido = document.getElementById("apellido").value;
	var telefono = document.getElementById("telefono").value;
	var sitioweb = document.getElementById("sitioweb").value;
	var selct = document.getElementById("select").value;
	var Comentarios = document.getElementById("Comentarios").value;
	
	if(validate(nombre, "El nombre es obligatorio")) 
	{
		if(validarMail(email, "El email es obligatorio")) 
		{
			if(validate(apellido, "El apellido es obligatorio")) 
			{
				if(email != email2) 
				{
					alert("Los correos electronicos deben coincidir");
				}
				else
				{
					var query_string = "nombre=" + encodeURIComponent(nombre) +
							"&email=" + encodeURIComponent(email) +
							"&compania=" + encodeURIComponent(compania) +
							"&pais=" + encodeURIComponent(pais) +
							"&apellido=" + encodeURIComponent(apellido) +
							"&telefono=" + encodeURIComponent(telefono) +
							"&sitioweb=" + encodeURIComponent(sitioweb) +
							"&select=" + encodeURIComponent(selct) +
							"&comentarios=" + encodeURIComponent(Comentarios);
							
					var cargador = new netp.CargadorContenidos(server+"contact.php?action=send", "POST", query_string, "application/x-www-form-urlencoded", showCiudad);
				}
			}
		}
	}
}

function showCiudad() 
{
	$("#message").hide();
	document.getElementById("message").innerHTML = this.req.responseText;
	
	$("#inputWrapper").animate({"height" : 0}, "normal", function() { 
		$(this).css("display", "none");
		$("#message").fadeIn("normal");
	});
}

function subscribeNews() 
{
	var email = document.getElementById("newsletter_email").value;
	
	var radio = document.getElementsByName("newsletter_invite");
	var radioValue = "";
	
	for(var i=0; i<radio.length;i++) 
	{
		if(radio[i].checked) { radioValue = radio[i].value; }
	}
	
	if(email == "" || email == "E-mail") 
	{ 
		document.getElementById("mess").innerHTML = "<span>Error:</span> Ingrese un email valido <br /> Please verify the email";
	}
	else
	{
		var query_string = "newsletter_email=" + encodeURIComponent(email) +
			"&newsletter_invite=" + encodeURIComponent(radioValue);
			
		var cargador = new netp.CargadorContenidos(server+"inscription_newsletter.php?action=process", "POST", query_string, "application/x-www-form-urlencoded", subscribe, newsError);
	}
}

function subscribe() 
{
	setInnerHtml(this.req.responseText, 'blank', 411, 50); 
	loadP('pop');
}

function newsError() 
{
	setInnerHtml(this.req.responseText, 'blank', 411, 50); 
	loadP('pop');
}

function clearText(field)
{
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}



