/**
* Archivo js creado EVO I.T.
* 
* Este archivo contiene funciones generales de JavaScript que pueden utilizar las
* clases creadas con O-creator
*
* @package EVOIT
* @author {@link http://www.evoit.com/ EVO I.T.}
* @version 05-06-2008
* @copyright {@link http://www.evoit.com/ EVO I.T.}
*/

/**
* Funcion para mostrar y ocultar una capa
* 
* Estas funciones se utilizan para cambiar el estilo (CSS) de una capa, haciendola invisible o visible segun sea el caso
* 
* @param object id_ob Id del objeto que se quiere ocultar o mostrar
*/
function viewlayer(id_ob)
{
	var ob_layer = document.getElementById(id_ob);
	if (ob_layer.style.display == 'none')
	{
		ob_layer.style.display = '';
	}
	else
	{
		ob_layer.style.display = 'none';
	}
}

/**
* Funcion para mostrar y ocultar el formulario de busqueda
* 
* Esta funcion se utiliza para mostrar u ocultar el formulario de buqueda y setear una variable de $_SESSION
* mediante AJAX para mantener el estado del formulario (abierto o cerrado)
* 
* @param object id_ob Id del objeto que se quiere ocultar o mostrar
*/
function showhide_menu(id_ob)
{
	var ob_layer = document.getElementById('menu_' + id_ob);
	var ob_btn   = document.getElementById('btn_menu_' + id_ob);
	
	if (ob_layer.style.display == 'none')
	{
		ob_layer.style.display = '';
		ob_btn.className = 'btn_menu_open';		
		loadPage('btnmenu.php', '', 's=' + id_ob + '&v=open');
	}
	else
	{
		ob_layer.style.display = 'none';
		ob_btn.className = 'btn_menu_closed';
		loadPage('btnmenu.php', '', 's=' + id_ob + '&v=closed');
	}	
}

/**
* Funcion para mostrar y ocultar el formulario de busqueda
* 
* Esta funcion se utiliza para mostrar u ocultar el formulario de buqueda y setear una variable de $_SESSION
* mediante AJAX para mantener el estado del formulario (abierto o cerrado)
* 
* @param object id_ob Id del objeto que se quiere ocultar o mostrar
*/
function showhide_search(id_ob)
{
	var ob_layer = document.getElementById('main_tr_search_' + id_ob);
	var ob_btn   = document.getElementById('btn_search_' + id_ob);
	
	if (ob_layer.style.display == 'none')
	{
		ob_layer.style.display = '';
		ob_btn.className = 'btn_search_open';		
		loadPage('btnsearch.php', '', 's=' + id_ob + '&v=open');
	}
	else
	{
		ob_layer.style.display = 'none';
		ob_btn.className = 'btn_search_closed';
		loadPage('btnsearch.php', '', 's=' + id_ob + '&v=closed');
	}	
}

/**
* Función para cambiar el estilo de las filas de una consulta
* 
* Estas funciones se utilizan para cambiar el estilo (CSS) de las filas de una tabla
* que se crea llamando al método show_query()
* 
* @param object _obj objeto row (tr) de una tabla en HTML
* @param string _class clase CSS de la fila
*/
function tr_over(_obj, _class)
{
	if (_obj.className == 'query_tr_' + _class + '_click')
	{
		_obj.className = 'query_tr_' + _class + '_click';
	}
	else
	{
		_obj.className = 'query_tr_' + _class + '_hover';
	}
}

/**
* Función para cambiar el estilo de las filas de una consulta
* 
* Estas funciones se utilizan para cambiar el estilo (CSS) de las filas de una tabla
* que se crea llamando al método show_query()
* 
* @param object _obj objeto row (tr) de una tabla en HTML
* @param string _class clase CSS de la fila
*/
function tr_out(_obj, _class)
{
	if (_obj.className == 'query_tr_' + _class + '_click')
	{
		_obj.className = 'query_tr_' + _class + '_click';
	}
	else
	{
		_obj.className = 'query_tr_' + _class + '';
	}
}

/**
* Función para cambiar el estilo de las filas de una consulta
* 
* Estas funciones se utilizan para cambiar el estilo (CSS) de las filas de una tabla
* que se crea llamando al método show_query()
* 
* @param object _obj objeto row (tr) de una tabla en HTML
* @param string _class clase CSS de la fila
* @param boolean _click_check indica si se debe chequear el checkbox de la fila
* @param string _id id del checkbox de la fila
* @param string _table tabla (de la clase)
*/
function tr_click(_obj, _class, _click_check, _id, _table)
{
	if (_obj.className != 'query_tr_' + _class + '_click')
	{
		_obj.className = 'query_tr_' + _class + '_click';
	}
	else
	{
		_obj.className = 'query_tr_' + _class + '';
	}
	
	if (_click_check)
	{
		var ob_chkb = document.getElementById('cb_' + _table + '_' + _id);
		if (ob_chkb.checked == true)
		{
			ob_chkb.checked = false;
		}
		else
		{
			ob_chkb.checked = true;
		}
		
		checked_select_all('form_query_' + _table, _table + '_select_all');
	}	
}

/**
* Esta función la utilizo para que el click del checkbox no interfiera con el click de la fila
*
* Esta función se utiliza em conjunto con las funciones tr_over, tr_out y tr_click
*
* @param object _obj objeto checkbox
*/
function checkbox_click(_obj)
{
	_obj.checked = ! _obj.checked;
}

/**
* Función para seleccionar o deseleccionar el checkbox de selección grupal
* 
* Esta función se utiliza para seleccionar o deseleccionar el checkbox de selección grupal cuando se seleccionan
* todos los checkbox de una consulta o se deselecciona al menos uno.
* 
* @param string _form id del formulario que contiene los checkbox
* @param string _checkbox id del checkbox que se utiliza para seleccionar todos los otros
*/
function checked_select_all(_form, _checkbox)
{
	var ob_form = document.getElementById(_form);
	var ob_chkb = document.getElementById(_checkbox);
	
	cantidad = ob_form.elements.length;
	checked_all = true;
	
	for (i = 0; i < cantidad; i++)
	{ 
		if (ob_form.elements[i].type == 'checkbox')
		{
			if (ob_form.elements[i].value)
			{			
				if (!ob_form.elements[i].checked)
				{
					checked_all = false;	
				}
			}
		}
	}
	
	ob_chkb.checked = checked_all;
}

/**
* Función para seleccionar o deseleccionar todos los checkbox de un formulario
* 
* Esta función se utiliza para seleccionar o deseleccionar todos los checkbox de las filas de una tabla
* que se crea llamando al método show_query()
* 
* @param string _table tabla (de la clase)
*/
function query_select_all(_table)
{
	var ob_form = document.getElementById('form_query_' + _table);
	var ob_chkb = document.getElementById(_table + '_select_all');
	
	cantidad = ob_form.elements.length;
		
	for (i = 0; i < cantidad; i++)
	{ 
		if (ob_form.elements[i].type == 'checkbox')
		{
			ob_form.elements[i].checked = ob_chkb.checked;
			
			if (ob_form.elements[i].value)
			{
				var ob_tr = document.getElementById(_table + '_tr_' + ob_form.elements[i].value);
				
				/**
				* determino si es clase 1 o clase 2 (query_tr_1, query_tr_1_click o query_tr_2, query_tr_2_click)
				*/
				aux_class = ob_tr.className.substr(9, 1);
				
				if (ob_chkb.checked)
				{
					ob_tr.className = 'query_tr_' + aux_class + '_click';	
				}
				else
				{
					ob_tr.className = 'query_tr_' + aux_class;
				}
			}
		}
	}
}

/**
* Función para realizar el submit del formulario de las acciones grupales
* 
* Esta función se utiliza para realizar el submit del formulario para realizar las acciones grupales
* que se crean llamando al método show_query()
* 
* @param string _form id del formulario
* @param string _action archivo al que redirecciona el formulario
* @param string _params parámetros que se envían
* @param boolean _confirm indica si la acción necesita confirmación antes de ser realizada
* @param string _msg mensaje de la confirmación
*/
function form_query_submit(_form, _action, _params, _confirm, _msg)
{
	var ob_form = document.getElementById(_form);
	
	ob_form.action = _action;
	ob_form.p.value = _params;
	if (_confirm)
	{
		if (confirm(_msg))
		{
			ob_form.submit();
		}
	}
	else
	{
		ob_form.submit();
	}
}

/**
* Función para abrir un popup con la imagen seleccionada
* 
* @param string myimage URL de la imagen
*/
function display(myimage, alt)
{
	if (alt)
	{
		html = '<html><head><title>' + alt + ' - C&oacute;rdoba, Argentina - Conci Carpinella<\/title> ';
	}
	else
	{
		html = '<html><head><title>Conci Carpinella - Diagn&oacute;stico por Im&aacute;genes - C&oacute;rdoba, Argentina<\/title> ';
	}
	html+= '<script language="javascript" type="text\/javascript">';
	html+= 'var arrTemp = self.location.href.split(\'?\'); ';
	html+= 'var picUrl = (arrTemp.length > 0) ? arrTemp[1] : \'\'; ';
	html+= 'var NS = (navigator.appName == \'Netscape\') ? true : false; ';
	html+= 'function FitPic() ';
	html+= '{ ';
	html+= 'var obj_img = document.getElementById(\'image\'); ';
	html+= 'iWidth = (NS) ? window.innerWidth:document.body.clientWidth; ';
	html+= 'iHeight = (NS) ? window.innerHeight:document.body.clientHeight; ';
	html+= 'iWidth = obj_img.width - iWidth; ';
	html+= 'iHeight = obj_img.height - iHeight; ';
	html+= 'window.resizeBy(iWidth, iHeight); ';
	html+= 'var X = (screen.width - obj_img.width) / 2; ';
	html+= 'var Y = (screen.height - obj_img.height) / 4; ';	
	html+= 'window.moveTo(X, Y); ';
	html+= 'self.focus(); ';
	html+= '} ';
	html+= '<\/script> ';
	html+= '<\/head>';
	html+= '<body leftmargin="0"';
	html+= 'marginwidth="0" topmargin="0" marginheight="0"><center>';
	html+= '<a href="javascript:window.close()">';
	html+= '<img src="' + myimage + '" border="0" name="image" id="image" alt="' + alt + '" title="Cerrar" onload="FitPic()" \/>';
	html+= '<\/a><\/center>';
	html+= '<\/body><\/html>';
	
	var NS = (navigator.appName == 'Netscape') ? true : false;
	if (NS)
	{
		iWidth = screen.width;
		iHeight = screen.height;
	}
	else
	{
		iWidth = 1;
		iHeight = 1;
	}
	
	popup = window.open('', 'image', 'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1,width=' + iWidth + ',height=' + iHeight);
	popup.document.open();
	popup.document.write(html);
	popup.focus();
	popup.document.close();
}

/**
* Función para abrir popups
* 
* @param string _url url del archivo del popup
* @param string _name name
* @param string _width ancho del popup
* @param string _height alto del popup
*/
function popup(_url, _name, _width, _height)
{
	popup_window = window.open(_url, _name, 'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1,left=270,top=200,width=' + _width + ',height=' + _height);
	popup_window.focus();
}
