function ValidateTextReq (ptxtText, psName, piLongMin, piLongMax)
{
	if (ptxtText.value.length<=0)
	{
		alert('El campo \'' + psName + '\' es obligatorio.');
		try { ptxtText.focus() } catch(err){ }

		return(false);
	}
	else if ((ptxtText.value.length<piLongMin) || (ptxtText.value.length>piLongMax))
	{
		alert('El formato para el campo  \'' + psName + '\' debe ser una cadena de ' + piLongMin + ' a ' + piLongMax + ' caracteres.');
		try { ptxtText.focus() } catch(err){ }
		return(false);
	}
	else
	{
		return(true);
	}	
}


function ValidateNumberReq (ptxtText, psName, piMin, piMax)
{
	if (ptxtText.value.length<=0)
	{
		alert('El campo \'' + psName + '\' es obligatorio.');
		try { ptxtText.focus() } catch(err){ }
		return(false);
	}
	else if ((isNaN(ptxtText.value)) || (ptxtText.value<piMin) || (ptxtText.value>piMax))
	{
		alert('El formato para el campo  \'' + psName + '\' debe ser un número entre ' + piMin + ' y ' + piMax + '.');
		try { ptxtText.focus() } catch(err){ }
		return(false);
	}
	else
	{
		return(true);
	}
}


function ValidateEmailReq (ptxtText, psName, piLongMax)
{
	if (ptxtText.value.length<=0)
	{
		alert('El campo \'' + psName + '\' es obligatorio.');
		try { ptxtText.focus() } catch(err){ }
		return(false);
	}
	else if ((ptxtText.value.length<6) || (ptxtText.value.indexOf('@', 0)<0) || (ptxtText.value.indexOf('.', 0)<0))
	{
		alert('El formato para el campo  \'' + psName + '\' debe ser un email válido.');
		try { ptxtText.focus() } catch(err){ }
		return(false);	
	}
	else
	{
		return(true);
	}
}


function ValidateDateReq (ptxtText, psName)
{
	if ((ptxtText.value.length!=10) && (ptxtText.value.length!=16) && (ptxtText.value.length!=18) && (ptxtText.value.length!=19))
	{
		alert('El formato para el campo  \'' + psName + '\' debe ser una fecha válida.');
		try { ptxtText.focus() } catch(err){ }
		return(false);
	}
	//10/10/2000
	else if (ptxtText.value.length==10)
	{
		var dteDate=new Date(ptxtText.value.substr(6, 4), (ptxtText.value.substr(3, 2)-1), ptxtText.value.substr(0, 2));
		if ((dteDate.getDate()==ptxtText.value.substr(0, 2)) && 
			(dteDate.getMonth()==(ptxtText.value.substr(3, 2))-1) && 
			(dteDate.getFullYear()==ptxtText.value.substr(6, 4)))
		{
			return(true);
		}
		else
		{
			alert('El formato para el campo  \'' + psName + '\' debe ser una fecha válida.');
			try { ptxtText.focus() } catch(err){ }
			return(false);
		}
	}
	//10/10/2000 00:00
	else if (ptxtText.value.length==16)
	{
		var dteDate=new Date(ptxtText.value.substr(6, 4), (ptxtText.value.substr(3, 2)-1), ptxtText.value.substr(0, 2));
		if ((dteDate.getDate()==ptxtText.value.substr(0, 2)) && 
			(dteDate.getMonth()==(ptxtText.value.substr(3, 2))-1) && 
			(dteDate.getFullYear()==ptxtText.value.substr(6, 4)) &&
			(parseInt(ptxtText.value.substr(11, 2), 10)>=0) && (parseInt(ptxtText.value.substr(11, 2), 10)<24) &&
			(parseInt(ptxtText.value.substr(14, 2), 10)>=0) && (parseInt(ptxtText.value.substr(14, 2), 10)<60))
		{
			return(true);
		}
		else
		{
			alert('El formato para el campo  \'' + psName + '\' debe ser una fecha válida.');
			try { ptxtText.focus() } catch(err){ }
			return(false);
		}
	}
	//10/10/2000 0:00:00
	else if (ptxtText.value.length==18)
	{
		var dteDate=new Date(ptxtText.value.substr(6, 4), (ptxtText.value.substr(3, 2)-1), ptxtText.value.substr(0, 2));
		if ((dteDate.getDate()==ptxtText.value.substr(0, 2)) && 
			(dteDate.getMonth()==(ptxtText.value.substr(3, 2))-1) && 
			(dteDate.getFullYear()==ptxtText.value.substr(6, 4)) &&
			(parseInt(ptxtText.value.substr(11, 1), 10)>=0) && (parseInt(ptxtText.value.substr(11, 1), 10)<24) &&
			(parseInt(ptxtText.value.substr(13, 2), 10)>=0) && (parseInt(ptxtText.value.substr(13, 2), 10)<60) &&
			(parseInt(ptxtText.value.substr(16, 2), 10)>=0) && (parseInt(ptxtText.value.substr(16, 2), 10)<60))
		{
			return(true);
		}
		else
		{
			alert('El formato para el campo  \'' + psName + '\' debe ser una fecha válida.');
			try { ptxtText.focus() } catch(err){ }
			return(false);
		}
	}
	//10/10/2000 00:00:00
	else if (ptxtText.value.length==19)
	{
		var dteDate=new Date(ptxtText.value.substr(6, 4), (ptxtText.value.substr(3, 2)-1), ptxtText.value.substr(0, 2));
		if ((dteDate.getDate()==ptxtText.value.substr(0, 2)) && 
			(dteDate.getMonth()==(ptxtText.value.substr(3, 2))-1) && 
			(dteDate.getFullYear()==ptxtText.value.substr(6, 4)) &&
			(parseInt(ptxtText.value.substr(11, 2), 10)>=0) && (parseInt(ptxtText.value.substr(11, 2), 10)<24) &&
			(parseInt(ptxtText.value.substr(14, 2), 10)>=0) && (parseInt(ptxtText.value.substr(14, 2), 10)<60) &&
			(parseInt(ptxtText.value.substr(17, 2), 10)>=0) && (parseInt(ptxtText.value.substr(17, 2), 10)<60))
		{
			return(true);
		}
		else
		{
			alert('El formato para el campo  \'' + psName + '\' debe ser una fecha válida.');
			try { ptxtText.focus() } catch(err){ }
			
			return(false);
		}
	}
}


function ValidateComboReq (pcboCombo, psName)
{
	if (pcboCombo.selectedIndex<=0)
	{
		alert('El campo \'' + psName + '\' es obligatorio.');
		
			try { pcboCombo.focus(); } catch(err){ }
		
		return(false);
	}
	else if (pcboCombo.options[pcboCombo.selectedIndex].value.length<1)
	{
		alert('El campo \'' + psName + '\' es obligatorio.');
		try { pcboCombo.focus(); } catch(err){ }
		return(false);	
	}
	else
	{
		return(true);
	}
}


function ValidateText (ptxtText, psName, piLongMin, piLongMax)
{
	if (ptxtText.value.length>0)
	{
		return(ValidateTextReq(ptxtText, psName, piLongMin, piLongMax));	
	}
	else
	{
		return(true);
	}
}



function ValidateNumber (ptxtText, psName, piMin, piMax)
{
	if (ptxtText.value.length>0)
	{
		return(ValidateNumberReq(ptxtText, psName, piMin, piMax));	
	}
	else
	{
		return(true);
	}
}


function ValidateEmail (ptxtText, psName, piLongMax)
{
	if (ptxtText.value.length>0)
	{
		return(ValidateEmailReq(ptxtText, psName, piLongMax));	
	}
	else
	{
		return(true);
	}
}



function ValidateDate (ptxtText, psName)
{
	if (ptxtText.value.length>0)
	{
		return(ValidateDateReq(ptxtText, psName));
	}
	else
	{
		return(true);
	}
}


function ValidarBusqueda (pfrmFormulario)
{
	if (!ValidateTextReq(pfrmFormulario.b, 'Búsqueda', 3, 50))
	{
		return(false);
	}
	else
	{
		return(true);
	}
}
