<!--
function WebDataGrid_ir(pagina, frm)
{
	frm.WebDataGrid_pagina.value = pagina;
	WebDataGrid_submit(frm);
}

function WebDataGrid_submit(frm)
{
	var validado = true;
	for (i=0;i<frm.elements.length;i++)
	{
		if (frm.elements[i].type == "text" && frm.elements[i].datatype != null)
		{
			if (!WebDataGrid_validarCampo(frm.elements[i],frm.elements[i].datatype)){
				validado = false;
				alert("Format error !");
				frm.elements[i].value = "";			
				break;
			}
		}
	}
	if (validado) frm.submit();
}

function WebDataGrid_ordenar(columna, frm)
{
	if (frm.WebDataGrid_order.value == columna)	
		frm.WebDataGrid_order.value = columna * -1;
	else
		frm.WebDataGrid_order.value = columna;
	frm.WebDataGrid_pagina.value = 1;
	WebDataGrid_submit(frm);
}

function WebDataGrid_print(type,frm)
{
	var prev_content = frm.WebDataGrid_contenttype.value;
	frm.WebDataGrid_contenttype.value = type;
	if (type == 1 || type == 2)
	{
		frm.target = "_blank";
		WebDataGrid_submit(frm);
		frm.target = "_self";
	}
	else
		WebDataGrid_submit(frm);
	frm.WebDataGrid_contenttype.value = prev_content;
}

function WebDataGrid_validarCampo(obj,datatype)
{
	switch(datatype)
	{
		case 'numeric':
			if (obj.value == "")
				return true; 
			else
				return !isNaN(obj.value);
			break;
		case 'text':
			comma = /\'/gi;
			obj.value = obj.value.replace(comma,"");
			return true;
			break;
		case 'date':
			return WebDataGrid_DateFormat(obj);
			break;
	}
}

function WebDataGrid_daysInFebruary (year) {   	
    // Febrero tiene 29 dias en cualquier año divisible por 4,
    // EXCEPTO los múltiplos de 100 no divisibles por 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

function WebDataGrid_makeArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 0
    } 
    return this
}

function WebDataGrid_checkFecha(dia,mes,anio) {
    var nDay;
    var nMonth;
    var nYear;
    
    if(isNaN(dia)) // Me llega el control, no el numero
    	nDay = parseInt(dia.value,10);
    else
    	nDay = dia;
    
    // compruebo que el dia sea correcto
    c = new String(nDay);
    if(c == "NaN") {
        return false;
    } else {
        nDay = c;
        if(nDay < 1 || nDay > 31) {
            return false;
        }
    }

    if(isNaN(mes)) // Me llega el control, no el numero
    	nMonth = parseInt(mes.value,10);
    else
    	nMonth = mes;
    	
    c = new String(nMonth);
    if(c == "NaN") {
        return false;
    } else {
        nMonth = c;
        if(nMonth < 1 || nMonth > 12) {
            return false;
        }
    }

    if(isNaN(anio)) // Me llega el control, no el numero
    	nYear = parseInt(anio.value,10);
    else
    	nYear = anio;
    	
    c = new String(nYear);
    if(c == "NaN") {
        return false;
    } else {
        nYear = c;
        if(nYear < 1850 || nYear > 2020) {
            return false;
        }
    }
		
    // compruebo que la fecha en conjunto sea correcta.
    var daysInMonth = WebDataGrid_makeArray(12);
    daysInMonth[1] = 31;
    daysInMonth[2] = 29;   // esto no es siempre cierto por lo que habrá que hacer comprobación extra.
    daysInMonth[3] = 31;
    daysInMonth[4] = 30;
    daysInMonth[5] = 31;
    daysInMonth[6] = 30;
    daysInMonth[7] = 31;
    daysInMonth[8] = 31;
    daysInMonth[9] = 30;
    daysInMonth[10] = 31;
    daysInMonth[11] = 30;
    daysInMonth[12] = 31;

    if((nDay != "") && (nMonth != "") && (nYear != "")) {
        var intYear = parseInt(nYear,10);
        var intMonth = parseInt(nMonth,10);
        var intDay = parseInt(nDay,10);

        // capturo los días inválidos, excepto para Febrero
        if (intDay > daysInMonth[intMonth]) {
            return false; 
        }

        if ((intMonth == 2) && (intDay > WebDataGrid_daysInFebruary(intYear))) {
            return false;
        }
    }

    return true;
}

function WebDataGrid_DateFormat (control)
{
	// 1.- Si es vacio, no hago nada
	// 2.- Si todos sus caracteres son digitos, formateo
	// 3.- Si tiene alguno no digito, sustituyo "/" por "blanco"
	// 4.- Si siguen sin ser digitos, mensaje de error,
	// 5.- Si no, formateo

	if (typeof control == "object")
		valor_control = control.value;
	else
		valor_control = eval(control + ".value");
	
	fecha = valor_control;
		
	if(fecha == "")
		return true;
		
	// ¿Todos sus caracteres son numeros?	
	if(!fecha.match(/^(\d)+$/))
	{
		fecha = fecha.replace(/[\/]/g,""); // Quito el caracter "/"
		// Si sigue sin ser numero, aviso al usuario para que rectifique
		if(!fecha.match(/^(\d)+$/))
		{
			//selecciono el texto 
			if (typeof control == "object") control.select();
    	   	//coloco otra vez el foco 
   			if (typeof control == "object") control.focus();		
			return;
		}
	}

	fecha = "00000000" + fecha;
	
	fecha = fecha.substring(fecha.length - 8, fecha.length);

	var dd   = fecha.substring(0,2);
	var mm   = fecha.substring(2,4);
	var aaaa = fecha.substring(4,8);
			
	fecha = dd + "/" + mm + "/" + aaaa;

	// Devuelvo el nuevo valor ya formateado
	if (typeof control == "object")
		control.value = fecha;
	else
		eval(control + ".value='" + fecha + "'");
	
	return WebDataGrid_checkFecha(dd,mm,aaaa);
}

//-->





