function ValidoContacto()
{
	if (document.formX.apellido.value=='')
	{
		alert("Debe ingresar su apellido para continuar.");
		document.formX.apellido.focus();
		return;
	}
	if (document.formX.nombre.value=='')
	{
		alert("Debe ingresar su nombre para continuar.");
		document.formX.nombre.focus();
		return;
	}
	if (document.formX.email.value=='')
	{
		alert("Debe ingresar su email para continuar.");
		document.formX.email.focus();
		return;
	}
	if (!FormatoEmail(document.formX.email))
	{
		alert("Su Email debe tener formato válido para continuar.");
		document.formX.email.focus();
		return;
	}
	if (document.formX.codigo.value=='')
	{
		alert("Debe ingresar su código de área para continuar.");
		document.formX.codigo.focus();
		return;
	}
	if (document.formX.telefono.value=='')
	{
		alert("Debe ingresar su teléfono para continuar.");
		document.formX.telefono.focus();
		return;
	}
	document.formX.submit();
}

function ValidoRegistro()
{
	form_valido=true;
	if (document.formX.alias.value=='' && form_valido)
	{
		alert("Debe ingresar su nombre de Usuario para continuar.");
		document.formX.alias.focus();
		form_valido=false;
	}
	if (document.formX.email.value=='' && form_valido)
	{
		alert("Debe ingresar su Email para continuar.");
		document.formX.email.focus();
		form_valido=false;
	}
	if (!FormatoEmail(document.formX.email) && form_valido)
	{
		alert("Su Email debe tener formato válido para continuar.");
		document.formX.email.focus();
		form_valido=false;
	}
	if (document.formX.apellido.value=='' && form_valido)
	{
		alert("Debe ingresar su Apellido para continuar.");
		document.formX.apellido.focus();
		form_valido=false;
	}
	if (document.formX.nombre.value=='' && form_valido)
	{
		alert("Debe ingresar su Nombre para continuar.");
		document.formX.nombre.focus();
		form_valido=false;
	}
	if (document.formX.codigo.value=='' && form_valido)
	{
		alert("Debe ingresar código de área del teléfono para continuar.");
		document.formX.codigo.focus();
		form_valido=false;
	}
	if (document.formX.telefono.value=='' && form_valido)
	{
		alert("Debe ingresar su teléfono para continuar.");
		document.formX.telefono.focus();
		form_valido=false;
	}

	/*if(getSelectedRadio(document.formX.idcompra)==-1 && form_valido)
	{
		alert("Debe selecionar la opción de suscripción para continuar.");
		form_valido=false;
	}*/
	if(getSelectedRadio(document.formX.idmedio)==-1 && form_valido)
	{
		alert("Debe selecionar la forma de pago para continuar.");
		form_valido=false;
	}

	if (document.formX.user_code.value=='' && form_valido)
	{
		alert("Debe ingresar el código de verificación para continuar.");
		document.formX.user_code.focus();
		form_valido=false;
	}
	
	if (form_valido)
	{
		document.formX.submit();
	}
}


function ValidoNewsletter()
{
	form_valido=true;
	if (document.formX.apellido.value=='' && form_valido)
	{
		alert("Debe ingresar su Apellido para continuar.");
		document.formX.apellido.focus();
		form_valido=false;
	}
	if (document.formX.nombre.value=='' && form_valido)
	{
		alert("Debe ingresar su Nombre para continuar.");
		document.formX.nombre.focus();
		form_valido=false;
	}
	if (document.formX.email.value=='' && form_valido)
	{
		alert("Debe ingresar su Email para continuar.");
		document.formX.email.focus();
		form_valido=false;
	}
	if (!FormatoEmail(document.formX.email) && form_valido)
	{
		alert("Su Email debe tener formato válido para continuar.");
		document.formX.email.focus();
		form_valido=false;
	}
	if (document.formX.codigo.value=='' && form_valido)
	{
		alert("Debe ingresar código de área del teléfono para continuar.");
		document.formX.codigo.focus();
		form_valido=false;
	}
	if (document.formX.telefono.value=='' && form_valido)
	{
		alert("Debe ingresar su teléfono para continuar.");
		document.formX.telefono.focus();
		form_valido=false;
	}

	if (form_valido)
	{
		document.formX.submit();
	}
}

function ValidoBusqueda()
{
	form_valido=true;
	switch (document.formX.busqueda.value){ 
		case "2":
			if (document.formX.palabra.value=='' && $('#voces_display').html()=="<BR><FONT color=gray>No se han seleccionado voces</FONT>" 
			&& document.formX.autos.value=='' && document.formX.f_fecha_ingreso1.value=='' && document.formX.cita.value=='') {
				alert("Debe ingresar algún filtro de búsqueda para realizar la misma.");
				return;
			}
		break;
		case "1":
			if (document.formX.nro_norma.value=='' && document.formX.titulo_norma.value=='' && document.formX.palabra.value=='' 
			&& document.formX.f_fecha_ingreso1.value=='' && document.formX.f_fecha_ingreso3.value=='') {
				alert("Debe ingresar algún filtro de búsqueda para realizar la misma.");
				return;
			}
		break;
		case "3":
			if ($('#voces_display').html()=="<BR><FONT color=gray>No se han seleccionado voces</FONT>" && document.formX.titulo.value=='' && document.formX.autor.value=='' 
			&& document.formX.palabra.value=='' && document.formX.cita.value=='' && document.formX.idpublicacion.value==0) {
				alert("Debe ingresar algún filtro de búsqueda para realizar la misma.");
				return;
			}
		break;
		case "4":
			if (document.formX.palabra.value=='' && document.formX.idclase.value==0 && document.formX.idtipo.value==0 && document.formX.idsubtipo.value==0) {
				alert("Debe ingresar algún filtro de búsqueda para realizar la misma.");
				return;
			}
		break;
	}

	if (document.getElementById('palabra')) {
	if (document.formX.palabra.value!='' && document.formX.palabra.value.length<4)
	{
		alert("Debe ingresar por lo menos 4 letras para hacer una búsqueda por Palábra Libre.");
		document.formX.palabra.focus();
		form_valido=false;
	}
	}

	if (document.getElementById('f_fecha_ingreso1'))
	{
		if (document.formX.f_fecha_ingreso1.value!='')
		{
			if (isDate(document.formX.f_fecha_ingreso1.value)==false)
			{
				//alert("Formato de fecha inválido.");
				document.formX.f_fecha_ingreso1.focus();
				form_valido=false;
			}
		}
	}
	/*if (document.formX.f_fecha_ingreso2.value!='')
	{
		if (isDate(document.formX.f_fecha_ingreso2.value)==false)
		{
			//alert("Formato de fecha inválido.");
			document.formX.f_fecha_ingreso2.focus();
			form_valido=false;
		}
	}*/
	if (document.getElementById('f_fecha_ingreso3'))
	{
		if (document.formX.f_fecha_ingreso3.value!='')
		{
			if (isDate(document.formX.f_fecha_ingreso3.value)==false)
			{
				//alert("Formato de fecha inválido.");
				document.formX.f_fecha_ingreso3.focus();
				form_valido=false;
			}
		}
	}

	if (form_valido)
	{
		document.formX.submit();
	}
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "-";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)

	//var strMonth=dtStr.substring(0,pos1)
	//var strDay=dtStr.substring(pos1+1,pos2)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(0,pos2)

	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("El formato de fecha debe ser : dd-mm-yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Formato de Fecha : Mes inválido")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Formato de Fecha : Día inválido")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Formato de Fecha : El año debe ser entre "+minYear+" y "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Formato de Fecha inválido")
		return false
	}
return true
}

function ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }


