// Javascript Document
/*******************************************************/
function ToggleMenu(id)
{
	if (document.all("Menu_"+id))
	{ 
		if (document.all("Menu_"+id).style.display == "none")
		{
			//document.all("imgidcat"+id).src=img_down.src;
			document.all("Menu_"+id).style.display = "";
		}
		else
		{
			//document.all("imgidcat"+id).src=img_der.src;
			document.all("Menu_"+id).style.display = "none";
		}
	}
}
/*******************************************************/
function Show_obj(obj,estado)
{	
	if(estado)
	{
		obj.style.visibility= "";
	}
	else
	{
		obj.style.visibility = "hidden";
	}
}	
/*******************************************************/
function DivSetVisible(state)
{
	var DivRef = document.getElementById("loading");	
	if(state)
	{
		DivRef.style.display = "block";
	}
	else
	{
		DivRef.style.display = "none";
	}	
}	
/*******************************************************/
function IsEmail(email)
{
	if(email=="")
		return false;
	else if (!(email.indexOf(' ')==-1  && email.indexOf('@')>0 && email.indexOf('.')>0 && email.indexOf('@')+1 < email.length))
		 return false;		
	else
		 return true;		
}
/*******************************************************/
function getRadioButtonSelectedValue(obj)
{
    for(i=0;i<obj.length;i++)
        if(obj[i].checked) return obj[i].value;
}
/*******************************************************/
function getComboSelectedValue(obj)
{
	return obj.options[obj.selectedIndex].value;
}
/*******************************************************/
function getElementsByName(name,element,tagname)
{
	if(tagname==undefined)tagname="*";

	if(element===undefined)
		var todos=document.getElementsByTagName(tagname);
	else
		var todos=element.getElementsByTagName(tagname);
	
	for(var i=0,t=todos.length;i<t;i++)
	{
		if(todos[i].name==name)
		{
				salida=todos[i];
				break;
		}
	}
	return salida;
}
/*******************************************************/
function solo_numeros()
{
	var key=window.event.keyCode;//codigo de tecla.	
	if (key!=46 && (key < 48 || key > 57))//si no es numero		
	window.event.keyCode=0;//anula la entrada de texto.
}
/*******************************************************/
function anula_enter()
{
	var key=window.event.keyCode;//codigo de tecla.	
	if(key==13)	window.event.keyCode=0;//anula la entrada de texto.
		//alert(window.event.keyCode);	
}
/*******************************************************/
function solo_float()
{
	var key=window.event.keyCode;//codigo de tecla.	
	if (key!=46 && (key < 48 || key > 57))//si no es numero		
	{
		if(key!=13)	window.event.keyCode=0;//anula la entrada de texto.
		//alert(window.event.keyCode);
	}
}
/*******************************************************/
function solo_text()
{
	var key=window.event.keyCode;//codigo de tecla.	
	if(!(key < 48 || key > 57))
	window.event.keyCode=0;//anula la entrada de texto.
}
/*******************************************************/
function FormatObj(obj)
{	
	numero=	new oNumero(obj.value);
	obj.value=numero.formato(2, false);
}
/*******************************************************/
function Format(valor,deci)
{
	numero=	new oNumero(valor);
	if(deci==undefined)deci=2;
	numero=numero.formato(deci, true);
	return numero;
}
/*******************************************************/
function GetFormat(valor)
{
	do
	{
		valor=valor.replace(",","");
	}while(valor.indexOf(",")>0);
	return parseFloat(valor);
}
function oNumero(numero)
{
	//Propiedades 
	this.valor = numero || 0
	this.dec = -1;
	//Métodos 
	this.formato = numFormat;
	this.ponValor = ponValor;
	//Definición de los métodos 
	function ponValor(cad)
	{
		if (cad =='-' || cad=='+') return
		if (cad.length ==0) return
		if (cad.indexOf('.') >=0)
			this.valor = parseFloat(cad);
		else 
			this.valor = parseInt(cad);
		//alert(this.valor);
	} 
	function numFormat(dec, miles)
	{
		var num = this.valor, signo=3, expr;
		var cad = ""+this.valor;
		var ceros = "", pos, pdec, i;
		for (i=0; i < dec; i++)
		ceros += '0';
		pos = cad.indexOf('.');
		if (pos < 0)
		cad = cad+"."+ceros;
		else
		{
			pdec = cad.length - pos -1;
			if (pdec <= dec)
			{
				for (i=0; i< (dec-pdec); i++)
					cad += '0';
			}
			else
			{
				num = num*Math.pow(10, dec);//alert(num);
				num+=0.01;
				num = Math.round(num);
				num = num/Math.pow(10, dec);
				num = new String(num);
				
				pos1 = num.indexOf('.')
				if(pos1==-1)//numero entero sin coma
				{
					cad=num+"."+ceros;
				}
				else
				{					
					pdec = num.length - pos1 -1;
					cad1="";
					for (i=0; i< (dec-pdec); i++)
						cad1+='0';
					
					cad=num+cad1;
				}				
		}
	 }
		pos = cad.indexOf('.')
		if (pos < 0) pos = cad.length
		if (cad.substr(0,1)=='-' || cad.substr(0,1) == '+') 
		 signo = 4;
		if (miles && pos > signo)
		do
		{
			expr = /([+-]?\d)(\d{3}[\.\,]\d*)/;
			cad.match(expr)
			cad=cad.replace(expr, RegExp.$1+','+RegExp.$2)
		}
		while (cad.indexOf(',') > signo)
		if (dec<0) cad = cad.replace(/\./,'')
		return cad;
	}
}//Fin del objeto oNumero:
/************************************************************/
function Format_ceros(valor,num_ceros)
{
	cad="";
	cifras=valor.length;
	for(i=0;i<(num_ceros-cifras);i++)
		cad+="0";
	valor=cad+valor;	
	return valor;
}
/*******************************************************/
function num_aleatorio(inferior,superior)
{ 
	numPosibilidades = superior - inferior 
	aleat = Math.random() * numPosibilidades 
	aleat = Math.round(aleat) 
	return parseInt(inferior) + aleat; 
} 
/*******************************************************/
//con esta función recuperamos una instancia del objeto que disparo el evento
rObj = function (evt)
{
	return evt.srcElement ?  evt.srcElement : evt.target;
}
/*******************************************************/
evento = function (evt)
{ 
//esta funcion nos devuelve el tipo de evento disparado   
	return (!evt) ? event : evt;
}
/********************************************************/
function td_front(opt,k,idtipo,id)
{
	switch(opt)
	{
		case "onmouseover":
			document.all("td_front_"+k).style.background="#B6D7FE";
			//document.all("a_categoria_"+idtipo).style.color=document.all("td_front_"+k).style.background;
			document.all("a_categoria_"+idtipo).style.color="#B6D7FE";			
			break;
		case "onmouseout":
			document.all("td_front_"+k).style.background="#FFFFFF";
			document.all("a_categoria_"+idtipo).style.color="#434880";
			break;
	}
	if(document.all("a_subcategoria_"+id))document.all("a_subcategoria_"+id).style.color=document.all("a_categoria_"+idtipo).style.color;
}
/********************************************************/
function texto_rtf()
{
	tinyMCE.init({
		mode : "textareas",
		plugins : "contextmenu, directionality, media, paste, preview, safari",
		theme : "advanced",
		language : "es",
		elements : "nourlconvert",
		convert_urls : false,
		theme_advanced_buttons1 : "bold, italic, underline, fontselect, fontsizeselect",
		theme_advanced_buttons2 : "forecolor, backcolor, separator, justifyleft, justifycenter, justifyright, justifyfull, separator, bullist, numlist, separator, undo, redo, separator, link, unlink, separator, code",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_buttons3_add : "ltr,rtl,pastetext,pasteword,selectall",
		theme_advanced_buttons1_add : "media,preview",
		paste_create_paragraphs : false,
		paste_create_linebreaks : false,
		paste_use_dialog : true,
		paste_auto_cleanup_on_paste : true,
		paste_convert_middot_lists : false,
		paste_unindented_list_class : "unindentedList",
		paste_convert_headers_to_strong : true,
		plugin_preview_width : "600",
		plugin_preview_height : "700",
		extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]"
	});	
}
/********************************************************/
function Open_modal(img,titulo,k)
{
	pindex=k;//alert(pindex);
	var i=new Image();i.src=document.getElementById('img_show_modal').src=img;
	document.getElementById('titulo_image').innerHTML="<strong>"+titulo+"</strong>";
	document.getElementById('light').style.top="0px";
	document.getElementById('light').style.left=(screen.width-i.width-20)/2;
	document.getElementById('light').style.display='block';
	document.getElementById('fade').style.display='block';
}
/********************************************************/
function Close_modal()
{
	document.getElementById('light').style.display='none';
	document.getElementById('fade').style.display='none';
}
/********************************************************/

