//alert('Complete El Path en el archivo "Includes\\jsfunctions.js"');
Path = 'http://www.mundoseco.com.ar/' //Path Absoluto

/*
	DESCRIPCION
		Verifica que solo se presionen números. Actualmente no funciona en netscape
*/
function SoloNumeros()
{
	if ((event.keyCode < 48) || (event.keyCode > 57))
	{
		event.keyCode = 0
	}	
}
/*
	DESCRIPCION
		Verifica que una fecha sea valida.
	PARAMETROS
		dateStr(str) = fecha en formato string
		nomFecha = texto para decir que fecha es (por si hay mas en una pagina)
*/
function isValidDate(dateStr,nomFecha) {

        var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
        var matchArray = dateStr.match(datePat);
        if (!nomFecha) 
                nomFecha = '' 
        else 
                nomFecha = ' ' + nomFecha
        if (matchArray == null) {
                alert('La fecha' + nomFecha + ' es incorrecta.')
                return false;
        }
        month = matchArray[3];
        day = matchArray[1];
        year = matchArray[4];   
        if (month < 1 || month > 12) {
                alert("El mes de la fecha" + nomFecha + " debe ser entre 1 y 12");
                return false;
        }
        if (day < 1 || day > 31) {
                alert("El dia de la fecha" + nomFecha + " debe ser entre 1 y 31");
                return false;
        }
        if ((month==4 || month==6 || month==9 || month==11) && day==31) {
                alert("El mes "+month+" de la fecha" + nomFecha + " no tiene 31 dias!")
                return false
        }
        if (month == 2) {
                var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
                if (day>29 || (day==29 && !isleap)) {
                        alert("Febrero del " + year + " no tiene " + day + " dias!");
                        return false;
                }
        }
        if ((year < 1900) || (year > 2078))
        {
                alert("Debe ingresar un año mayor a 1900 y menor a 2078 para la fecha" + nomFecha);
                return false;           
        }
return true;
}

/*
	DESCRIPCION
		Abre una ventana nueva.
	PARAMETROS
		sURK(str) = URL destino
		iAncho(int) = Ancho de la Ventana a abrir
		iAlto(int) = Alto de la Ventana a abrir
		sScrollbars(str) = Si tiene o no scrollbars ('yes'/'no')
		sResize(str) = si se podrá modificar el tamaño de la ventana  ('yes'/'no')
		sDirectories(str) =  ('yes'/'no')
		sMenuBar(str) = si tendra la barra de menu ('yes'/'no')
		sStatus(str) = si tendra la barra de Status ('yes'/'no')
		sVentana(str) = nombre de la ventana
		sLocation(str) = ('yes'/'no')
*/
function PopUpWindow(sURL,iAncho,iAlto,sScrollbars,sResize,sToolbar,sDirectories,sMenuBar,sStatus,sVentana,sLocation,sFullScreen){
	if (!sURL) sURL = Path;
	if (!iAncho) iAncho = 500
	if (!iAlto) iAlto = 400
	if (!sScrollbars) sScrollbars = 'no'
	if (!sResize) sResize = 'yes'
	if (!sToolbar) sToolbar = 'no'
	if (!sDirectories) sDirectories = 'no'
	if (!sMenuBar) sMenuBar = 'no'
	if (!sStatus) sStatus = 'no'
	if (!sVentana) sVentana = ''
	if (!sLocation) sLocation = 'no'
	if (!sFullScreen) sFullScreen = 'no'
	return window.open(sURL,sVentana,'width=' + iAncho + ',height=' + iAlto + ',toolbar=' + sToolbar + ',directories=' + sDirectories + ',menubar=' + sMenuBar + ',status=' + sStatus + ',scrollbars=' + sScrollbars + ',resizable=' + sResize + ',top='+ ((screen.width/2)-(iAncho/2)) +',left='+ ((screen.height/2)-(iAlto/2)) +',location=' + sLocation + ',fullscreen=' + sFullScreen + '');		
}

/*
' NOMBRE:
'	HeadTable
' DESCRIPCION:
'	Arma el encabezado de una tabla con el borde redondeado.
' PARAMETROS:
'	Titulo(str) = Texto a mostrar en el centro de la tabla.
'	Width(int) = Ancho que tendrá la tabla.
'	TituloAlign(str) = Alineamiento del Titulo dentro de la celda.
*/
function HeadTable(Titulo, Width, TituloAlign)
{
	var Str = '';
	Str = Str + '<table width=' + Width + ' cellspacing=0 cellpadding=0 border=0>' + String.fromCharCode(13);
	Str = Str + '<tr>' + String.fromCharCode(13);
	Str = Str + '	<td width=10 class=TituloTabla><img src="' + Path + 'imagenes/TablaIzqUp.gif" border=0 width=10></td>' + String.fromCharCode(13);
	Str = Str + '	<td align=' + TituloAlign + ' class=TituloTabla width=' + (Width - 20) + '>' + Titulo + '</td>' + String.fromCharCode(13);
	Str = Str + '	<td width=10 class=TituloTabla align=right><img src="' + Path + 'imagenes/TablaDerUp.gif" border=0 width=10></td>' + String.fromCharCode(13);
	Str = Str + '</tr>' + String.fromCharCode(13);
	Str = Str + '</table>' + String.fromCharCode(13);
	return Str;
}


/*
' NOMBRE:
'	TopMiddleTable
' DESCRIPCION:
'	Arma el encabezado de una tabla que supuestamente ira debajo de una 
'	HeadTable dejando un espacio a la derecha.
' PARAMETROS:
'	Width(int) = Ancho que tendrá la tabla.
'	space)}(int) = Ancho que tendrá el espacio a dejar a la derecha.
*/
function TopMiddleTable(width, space)
{
	var Str = '';
	Str = Str + '<table width=' + width + ' cellspacing=0 cellpadding=0 border=0>' + String.fromCharCode(13);
	Str = Str + '<tr>' + String.fromCharCode(13);
	Str = Str + '		<td width=1 class=TituloTabla><img src="' + Path + 'imagenes/pix_trans.gif" width=1 height=1></td>' + String.fromCharCode(13);
	Str = Str + '		<td width='+ space + '><img src="' + Path + 'imagenes/pix_trans.gif" width=1 height=1></td>' + String.fromCharCode(13);
	Str = Str + '		<td width=' + (width - (space *2) - 2) + '>' + String.fromCharCode(13);
	return Str;
}	

/*
' NOMBRE:
'	BottomMiddleTable
' DESCRIPCION:
'	Arma el pie de una tabla que supuestamente ira debajo de una 
'	Tabla que tuvo un TopMiddleTable dejando un espacio a la izquierda.
' PARAMETROS:
'	Space(int) = Alto que tendrá el espacio a dejar a la izquierda.
*/
function BottomMiddleTable(space)
{
	var Str = '';
	Str = Str + '	</td>' + String.fromCharCode(13);
	Str = Str + '	<td width=' + space + '><img src="' + Path + 'imagenes/pix_trans.gif" width=1 height=1></td>' + String.fromCharCode(13);
	Str = Str + '	<td width=1 class=TituloTabla><img src="' + Path + 'imagenes/pix_trans.gif" width=1 height=1></td>' + String.fromCharCode(13);
	Str = Str + '</tr>' + String.fromCharCode(13);
	Str = Str + '</table>' + String.fromCharCode(13);
	return Str;
}

/*
' NOMBRE:
'	BottomTable
' DESCRIPCION:
'	Arma el pie de una tabla con el borde redondeado.
' PARAMETROS:
'	Width(int) = Ancho de la tabla.
*/
function BottomTable(width)
{
	var Str = '';
	Str = Str + '<table width=' + width + ' cellspacing=0 cellpadding=0 border=0>' + String.fromCharCode(13);
	Str = Str + '<tr>' + String.fromCharCode(13);
	Str = Str + '	<td width=10 class=TituloTabla><img src="' + Path + 'imagenes/TablaizqDown.gif" width=10 height=11></td>' + String.fromCharCode(13);
	Str = Str + '	<td width=' + (width -20) + ' class=TituloTabla><img src="' + Path + 'imagenes/pix_trans.gif" width=10 height=11></td>' + String.fromCharCode(13);
	Str = Str + '	<td width=10 class=TituloTabla><img src="' + Path + 'imagenes/TablaDerDown.gif" width=10 height=11></td>' + String.fromCharCode(13);
	Str = Str + '</tr>' + String.fromCharCode(13);
	Str = Str + '</table>' + String.fromCharCode(13);
	return Str;
}
/*
ejemplo de div para las proximas 3 funciones (hide, show, SwitchVisibility)
<div style="POSITION: relative; visibility: visible;" name=lsalidas id=lsalidas>
<p>CACA
<hr>
<IMG alt="" src="imagen.gif" >
</div>
*/

/*
' NOMBRE:
'	hide
' DESCRIPCION:
'	Oculta un div.
'   (el div debe tener nombre e id =)
' PARAMETROS:
'	hi(str) = Nombre o id del div.
*/
function hide(hi){
	if(document.all) {
		eval("document.all." + hi + ".style.visibility = 'hidden'");
	} else if(document.layers) {
		eval("document.layers." + hi + ".visibility = 'hide'");
	} else {
	    eval("document.getElementById('" + hi + "')").style.visibility = 'hidden';
	}
	
}
/*
' NOMBRE:
'	show
' DESCRIPCION:
'	Muestra un div.
'   (el div debe tener nombre e id =)
' PARAMETROS:
'	sho(str) = Nombre o id del div.
*/
function show(sho){
	if(document.all) {
		eval("document.all." + sho + ".style.visibility = 'visible'");
	} else if(document.layers) {
		eval("document.layers['" + sho + "'].visibility = 'visible'");
	} else {
	    eval("document.getElementById('" + sho + "')").style.visibility = 'visible';
	}
}

/*
' NOMBRE:
'	SwitchVisibility
' DESCRIPCION:
'	Cambia la visibilidad de un div utilizando las funciones hide y show.
'   (el div debe tener nombre e id =)
' PARAMETROS:
'	obj(str) = Nombre o id del div.
*/
function SwitchVisibility(obj)
{
	if(document.all) 
	{
		if (eval("document.all." + obj + ".style.visibility") == 'hidden') {
			show(obj);
		} else {
			hide(obj);
		}
	}
	else
	{
		if (eval("document.layers." + obj + ".visibility") == 'hide') {
			show(obj);
		}else {
			hide(obj);
		}
	}
}

function DisplayOn(obj) {
    if(document.all) 
	{
		eval("document.all." + obj + ".style.display = 'inline'");
	} else {
	    obj = eval("document.getElementById('" + obj + "')")
		obj.style.display = '';
	}
}

function DisplayOff(obj) {
    if(document.all) 
	{
		eval("document.all." + obj + ".style.display = 'none'");
	} else {
	    obj = eval("document.getElementById('" + obj + "')")
		obj.style.display = 'none';
	}
}

/*
' NOMBRE:
'	SwitchDisplay
' DESCRIPCION:
'	Cambia la visibilidad de un div utilizando las funciones hide y show.
'   (el div debe tener nombre e id =)
' PARAMETROS:
'	obj(str) = Nombre o id del div.
*/


function SwitchDisplay(obj)
{
	if(document.all) 
	{
		if (eval("document.all." + obj + ".style.display") == 'none') {
			eval("document.all." + obj + ".style.display = 'inline'");
		} else {
			eval("document.all." + obj + ".style.display = 'none'");
		}
	} else {
	    obj = eval("document.getElementById('" + obj + "')")
	    if (obj.style.display == 'none') {
			obj.style.display = '';
		} else {
			obj.style.display = 'none';
		}
	}
}


/******************************************************************
NOMBRE:
	CheckAll
DESCRIPCION:
	Chequea todos los checkbox al hacer click en el CheckAll
PARAMETROS:
	chk(object) = Nombre del conjunto de CheckBox's a chequear
	chkAll(object) = Nombre del CheckBox que chequea y deschequea
RETORNO: void
******************************************************************/
function CheckAll(chk,chkAll) {
	if (!chk)
		return
	if (chk.length)
		for (i = 0; i < chk.length; i++)
			chk[i].checked = chkAll.checked
	else
		chk.checked = chkAll.checked								
}
/******************************************************************
NOMBRE:
	CheckFather
DESCRIPCION:
	Chequea el padre en caso que alguno de los hijos esten seleccionados
PARAMETROS:
	chk(object) = Nombre del conjunto de CheckBox's a verificar
	chkFather(object) = Nombre del CheckBox "Padre" que chequea y deschequea
RETORNO: void
******************************************************************/
function CheckFather(chk,chkFather) {
	if (!chkFather)
		return
	if (chk.length)	{
		var bCheck = true;
		for (i = 0; i < chk.length; i++) {
			if (!chk[i].checked) {
				bCheck = false;
				break;
			}
		}
		chkFather.checked = bCheck;
	}
	else
		chkFather.checked = chk.checked;							
}

/******************************************************************
NOMBRE:
	DoAction
DESCRIPCION:
	Submite un formulario llamado frmAcciones para realizar alguna accion
	a una nueva ventana
PARAMETROS:
	sAction(str) = Accion a Realizar
	ofrm(Objeto Form) = [OPCIONAL] formulario a utilizar, si no se pasa se utiliza document.frmAcciones
RETORNO: void
******************************************************************/
function DoAction(sAction,ofrm) {
	var bOK = false;
	
	if (!ofrm)
		ofrm = document.frmAcciones;
		
	var chks = ofrm.iId;
	if (chks) {
		if (chks.length) {
			for (var i=0;i < chks.length; i++)
				if (chks[i].checked) {
					bOK = true;
					break;
				}
		}
		else
			bOK = ofrm.iId.checked;
	}
	else 
		bOK = false
		
	if (!bOK) {
		alert('Debe Seleccionar un item');
		return;
	}
	vent = PopUpWindow('about:blank',350,150,'no','no','no','no','no','no','Action');
	ofrm.target = 'Action';
	ofrm.sAccion.value = sAction;
	ofrm.action = Path + 'Acciones.asp';
	ofrm.submit();
	vent.focus();
}

/******************************************************************
NOMBRE:
	SendForm
DESCRIPCION:
	Submite un formulario a una nueva ventana
PARAMETROS:
	oFrm(Form Object) = Formulario a submitir
RETORNO: void
******************************************************************/
function SendForm(oFrm) {
	vent = PopUpWindow('about:blank',350,150,'no','no','no','no','no','no','Form');
	oFrm.target = vent.name;
	setTimeout(oFrm.name + '.submit();vent.focus();',200);
}

/*
' NOMBRE:
'	printPage
' DESCRIPCION:
'	Imprime la Pagina Actual
*/
var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage()
{
	if (pr) // NS4, IE5
		window.print();
	else if (da && !mac) // IE4 (Windows)
		alert('Su exlporador no soporta esta caracteristica.\n\Imprima manualmente desde el menu o presionando Ctrl-P.');
	else // other browsers
		alert('Su exlporador no soporta esta caracteristica.\n\Imprima manualmente desde el menu o presionando Ctrl-P.');
	return;
}

/*
' NOMBRE:
'	Str2Date
' DESCRIPCION:
'	Transfroma una fecha en formato dd/mm/YYYY en Date
*/
function Str2Date(strFecha) {
	var dFecha = new Date();
	var sFecha = new String(strFecha);
	var arrFecha = sFecha.split(new RegExp('/'));
	
	dFecha.setFullYear(arrFecha[2],arrFecha[1]-1,arrFecha[0])
	return dFecha;
}
