/*
Created By: Raul Morales <raulemofe@hotmail.com>
Copyright 2008
*/

function LoadOptions(Type)
{
	var AjaxField="../ajax/AjaxClient.php?Type="+Type;
	switch(Type)
	{
		case "LoadSearchFormLocalitys":
			var IdValue=document.getElementById("IdCity").value; 
			ComboB=document.getElementById("Locality"); ComboB.length=0; var NewOption=document.createElement("option"); NewOption.value=0; 
			if(IdValue) { NewOption.innerHTML="Cargando..."; ComboB.appendChild(NewOption); ComboB.disabled=true; }
			else { NewOption.innerHTML="Todas las colonias"; ComboB.appendChild(NewOption); }
		break;
		case "LoadCitys":
			var IdValue=document.getElementById("ESTADO_ID").value; 
			ComboB=document.getElementById("CIUDAD_ID"); ComboB.length=0; var NewOption=document.createElement("option"); NewOption.value=0; 
			if(IdValue) { NewOption.innerHTML="Cargando..."; ComboB.appendChild(NewOption); ComboB.disabled=true; }
			else { NewOption.innerHTML="Selecciona..."; ComboB.appendChild(NewOption); }
		break;
	}
	if(IdValue) 
	{
		var ajax=funcionnuevoAjax();
		ajax.open("POST", AjaxField, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		switch(Type)
		{
			case "LoadSearchFormLocalitys": ajax.send("IdValue="+IdValue); break;
			case "LoadCitys": ajax.send("IdValue="+IdValue); break;
		}
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==1) { }
			if (ajax.readyState==4)
			{
				//alert(ajax.responseText);
				if(!ajax.responseText) { }
				else 
				{
					switch(Type)
					{
						case "LoadSearchFormLocalitys": 
							var Request=new Array(); Request=ajax.responseText.split("*&*"); 
							document.getElementById("RowLocality").innerHTML=Request[1]; 
						break;
						case "LoadCitys": 
							var Request=new Array(); Request=ajax.responseText.split("*&*"); 
							document.getElementById("RowCIUDAD_ID").innerHTML=Request[1]; 
						break;
					}
				}
			}
		}
	}
}

function BigImg(Img) 
{ 
	var Str="";
	Str=Str + '<br /><a href="../sitio/PopupFile.php?file=' + Img + '&type=image&path=../images/products/">'; 
		Str=Str + '<img src="../images/products/' + Img + '" width="280" border="0" alt="" />'; 
	Str=Str + '</a>';
	Str=Str + '<br /><img src="../images/space.gif" width="1" height="5" border="0" alt="" /><br />';
	Str=Str + '<a href="../sitio/PopupFile.php?file=' + Img + '&type=image&path=../images/products/">'; 
	Str=Str + '<img src="../images/MainDetailsButtonView.jpg" srcover="../images/MainDetailsButtonViewOver.jpg" border="0" alt="Ver imagen..." title="Ver imagen..." /></a>';
	Str=Str + '<br /><br />';
	document.getElementById("RowBigImage").innerHTML=Str;
}

function GenericDeleteCurrentImage(ImgName, Table, Id, Key)
{
	if(confirm("Realmente desea eliminar esta imagen? \nSi pulsa aceptar no podrá recuperarla!"))
	{
		var Type='GenericDeleteImage';
		var archivo_ajax="../ajax/AjaxClient.php?Type="+Type;
		if((ImgName) && (Table) && (Key) && (Id))
		{
			var ajax=funcionnuevoAjax();
			ajax.open("POST", archivo_ajax, true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("ImgName="+ImgName+"&Table="+Table+"&Key="+Key+"&Id="+Id);
			ajax.onreadystatechange=function()
			{
				if (ajax.readyState==1) { } 
				if (ajax.readyState==4)
				{
					//alert(ajax.responseText);
					if(ajax.responseText==1) { document.location=location.href; }
				}
			}
		}
	}
}

function ir_a(url) { document.location=url; }

function cambia_clase(clase, id) { document.getElementById(id).className=clase; }

function validarEmail(valor) { if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)) { return true; } else { return false; } }

function validar_formulario(type)
{
	switch(type)
	{
		case "contacto":
			var mensaje=document.getElementById("mensaje").value; 	if(!mensaje){ alert("Debes llenar el campo Mensaje!");				document.getElementById('mensaje').focus(); return false; }
			var email=document.getElementById("email").value; 		if(!email) 	{ alert("Escibe una direccion de correo electronico!");	document.getElementById('email').focus(); 	return false; }
			else { 								if(validarEmail(email)==false) 	{ alert("Direccion de correo electronico incorrecta!");	document.getElementById('email').focus(); 	return false; } }
		break;
		case "registro":
			var type=document.getElementById("type").value; 
			if(!type) { alert("Debes seleccionar un tipo!"); document.getElementById('type').focus(); return false; }
			var email=document.getElementById("email").value; 
			if(!email) { alert("Escibe una direccion de correo electronico!"); document.getElementById('email').focus(); return false; }
			else { if(validarEmail(email)==false) { alert("Direccion de correo electronico incorrecta!"); document.getElementById('email').focus(); return false; } }
			var password=document.getElementById("password").value; if(!password) { alert("Debes escribir una contraseña!"); document.getElementById('password').focus(); return false; }
			var passwordb=document.getElementById("passwordb").value; 
			if(password!=passwordb)
			{ 
				alert("Los campos de contraseña no coinciden!");
				document.getElementById('password').value=""; 
				document.getElementById('passwordb').value="";
				document.getElementById('password').focus();
				return false; 
			}
			var nombre=document.getElementById("nombre").value;
			if(!nombre) { alert("Debes escribir tu nombre!"); document.getElementById('nombre').focus(); return false; }
		break;
	}
}

