function validar_frm(frm, submi,arreglofun)
{
	if ( typeof submi == 'undefined' || submi == '' ) { submi = true; }

	var tform  = eval('window.document.' + frm);




	if(typeof campos != 'undefined'){

		for (i=0 ; i<campos.length;i++)
		{


			var camp 				= campos[i];
			var msj					= dic[i];
			var tipocampo			= tipo[i];

			var valorcampo 			= eval('tform.' + camp);
			
			if(typeof valorcampo == 'undefined'){
			
				alert('NO existe el campo  ' + camp + '  Informe al administrador');
				return false;
			}

			if (valorcampo.value == '' || valorcampo.value == 0)
			{
				alert('El campo' + ' '+ msj +  ' debe tener información');
				valorcampo.focus();
				return false;
			}

			if (tipocampo == 'numeric')
			{					
			
	

				var numstring	= is_numeric(valorcampo.value);

				if (!numstring)
				{

					alert ('El campo' + ' '+ msj +  ' debe ser numerico');

					return false;
				}

			}


			if(tipocampo == 'correo'){

				if(valorcampo.value!= ''){

					var Email= /^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/

					if (!Email.test(valorcampo.value )){
						alert("Debe ingresar un Email valido");
						valorcampo.focus();
						return (false);
					}//Validar que el campo email tenga un formato de mail valido
				}


			}


			
			
			
			

		}

	}
	if(submi)
	{
		/*esto no hace falta si el tipo de input es button*/

		//tform.submit();

	}
	if (submi == 'false')
	{
		if(arreglofun)
		{

			for (x=0 ; x<arreglofun.length ; x++){

				eval( arreglofun[x] );
				//alert(eval(arreglofun[x] + '()'));
			}

		}
		return true;
	}

	return true;
}


function is_numeric(n)
{
	var PNum = new String(n);
	var regex = /[^0-9]/;
	return !regex.test(PNum);
}
function  numerico(evento)
{
	var iKeyCode;
	iKeyCode = (evento.which) ? evento.which : evento.keyCode

	if (iKeyCode > 31 && (iKeyCode < 46 || iKeyCode > 57 )
		&& iKeyCode != 44 && iKeyCode != 37
		&& iKeyCode != 39 ){
		return false;
	}
	return true;


}

function esconder_tabla( fid, add ){
	saved = new Array();
	clean = new Array();

	if ( add ){
		my_show_div( my_getbyid( 'fc_'+fid  ) );
		my_hide_div( my_getbyid( 'fo_'+fid  ) );
		my_hide_div( my_getbyid( 'foc_'+fid  ) );
	}else{
		my_show_div( my_getbyid( 'fo_'+fid  ) );
		my_hide_div( my_getbyid( 'fc_'+fid  ) );
		my_show_div( my_getbyid( 'foc_'+fid  ) );
	}
}

function my_hide_div(itm){
	if ( ! itm ) return;
	itm.style.display = "none";
}

function my_show_div(itm){
	if ( ! itm ) return;
	itm.style.display = "";
}

function my_getbyid(id){
	itm = null;

	if (document.getElementById){
		itm = document.getElementById(id);
	}else if (document.all){
		itm = document.all[id];
	}else if (document.layers){
		itm = document.layers[id];
	}

	return itm;
}

function abrirVentana(url, c)
{
	if (! c)
	{
		c = 'width=790,height=500,resizable,scrollbars=yes,menubar=yes';
	}

	window.open( url,'', c )

	return false;
}

var oldLink = null;

var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;
var WEEK = 7 * DAY;
function selected(cal, date)
{
	cal.sel.value = date; // just update the date in the input field.

	/*
	if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "fechacorrespondencia"))
	// if we add this call we close the calendar on single-click.
	// just to exemplify both cases, we are using this only for the 1st
	// and the 3rd field, while 2nd and 4th will still require double-click.
	*/

	cal.callCloseHandler();
}


// And this gets called when the end-user clicks on the _selected_ date,
// or clicks on the "Close" button.  It just hides the calendar without
// destroying it.
function closeHandler(cal)
{
	 cal.hide();	// hide the calendar
		//cal.destroy();

	_dynarch_popupCalendar = null;
}



function setActiveStyleSheet(link, title)
{
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
		{
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}

	if (oldLink) oldLink.style.fontWeight = 'normal';

	oldLink = link;

	link.style.fontWeight = 'bold';

	return false;
}

function showCalendar(id, format, showsTime, showsOtherMonths)
{


	var el = document.getElementById(id);
	if (_dynarch_popupCalendar != null)
	{
		// we already have some calendar created
		_dynarch_popupCalendar.hide();                 // so we hide it first.
	}
	else
	{
		// first-time call, create the calendar.
		var cal = new Calendar(1, null, selected, closeHandler);
		// uncomment the following line to hide the week numbers
		// cal.weekNumbers = false;
		if (typeof showsTime == "string")
		{
			cal.showsTime = true;
			cal.time24 = (showsTime == "24");
		}

		if (showsOtherMonths)
		{
			cal.showsOtherMonths = true;
		}

		_dynarch_popupCalendar = cal;	// remember it in the global var
		cal.setRange(1900, 2070);	// min/max year allowed.
		cal.cache = true;		// se usa el chace para el calendario
		cal.weekNumbers = true;		// mostramos el dia de la semana
		cal.showOthers = true;

		cal.create();
	}

	_dynarch_popupCalendar.setDateFormat(format);    // set the specified date format
	_dynarch_popupCalendar.parseDate(el.value);      // try to parse the text in field
	_dynarch_popupCalendar.sel = el;                 // inform it what input field we use

	// the reference element that we pass to showAtElement is the button that
	// triggers the calendar.  In this example we align the calendar bottom-right
	// to the button.

	_dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");        // show the calendar

	return false;
}



//FUNCION PARA CAMBIAR COLOR DE LETRAS
function cambia_color(name,fg)
{
	name.style.color = fg;
}
//FUNCION PARA CAMBIAR FONDO DE COLOR
function cambia_fondo(name,bg)
{
	name.style.background= bg;
}
