function centrar_ventana(nombre, x, y)
{
	try{
		if(typeof(objeto)=="object" || typeof(objeto)=="boolean")
		{
			t					= nombre;
		}
		else
		{
			t					= $(nombre);
		}
		left_temporal		= (x=="centro")? ( (tama_width()-t.offsetWidth) /2) : (scroll_leftX()+parseInt(x));
		top_temporal		= (y=="centro")? ( (tama_height()-t.offsetHeight) /2) : (scroll_topX()+parseInt(y));
	
		if(left_temporal<0)
		{
			left_temporal	= 0;
		}
	
		if(top_temporal<0)
		{
			top_temporal	= 0;
		}
	
		t.style.left		= left_temporal + "px";
		t.style.top			= top_temporal + "px";
	}catch(ex)
	{
		alert("centrar_ventana::" + ex);
	}
}
function tama_width()
{
	try{
		return (scroll_leftX()+docwidthX());
	}catch(ex)
	{
		alert("tama_width::" + ex);
	}
}
function tama_height()
{
	try{
		return (scroll_topX()+docheightX());
	}catch(ex)
	{
		alert("tama_height::" + ex);
	}
}
function abajo_de(objeto,destino)
{
	try{
		if(typeof(objeto)=="object" || typeof(objeto)=="boolean")
		{
			left					= cordenadas_objeto(objeto, 'left');
			top						= cordenadas_objeto(objeto, 'top');
			obj_with				= objeto.offsetHeight;
		}
		else
		{
			left					= cordenadas_objeto($(objeto), 'left');
			top						= cordenadas_objeto($(objeto), 'top');
			obj_with				= $(objeto).offsetHeight;
		}
		$(destino).style.top		= top+obj_with  + "px";
		$(destino).style.left		= left+ "px";
	}catch(ex)
	{
		alert("abajo_de::" + ex);
	}
}
function domclientWidthX()
{
	try{
		return (document.documentElement && parseInt(document.documentElement.clientWidth) || 100000);
	}catch(ex)
	{
		alert("domclientWidthX::" + ex);
	}
}
function standardbodyX()
{
	try{
		return ((document.compatMode=="CSS1Compat")? document.documentElement : document.body);
	}catch(ex)
	{
		alert("standardbodyX::" + ex);
	}
}
function scroll_topX()
{
	try{
		x_standardbody=standardbodyX();
		return ((ieX())? x_standardbody.scrollTop : window.pageYOffset);
	}catch(ex)
	{
		alert("scroll_topX::" + ex);
	}
}
function ieX()
{
	try{
		return (document.all && !window.opera);
	}catch(ex)
	{
		alert("ieX::" + ex);
	}
}
function scroll_leftX()
{
	try{
		x_standardbody=standardbodyX();
		return ((ieX())? x_standardbody.scrollLeft : window.pageXOffset);
	}catch(ex)
	{
		alert("scroll_leftX::" + ex);
	}
}
function docwidthX()
{
	x_standardbody=standardbodyX();
	return ((ieX())? x_standardbody.clientWidth : (/Safari/i.test(navigator.userAgent))? window.innerWidth : Math.min(domclientWidthX(), window.innerWidth-16));
}
function docheightX()
{
	var x_standardbody	=standardbodyX();
	return ((ieX())? x_standardbody.clientHeight: window.innerHeight);
}
function nuevo_div(ID_ORIGEN,ID_DESTINO)
{
	var NEW_DIV = document.createElement("div");
	NEW_DIV.id = ID_DESTINO;
	if($(ID_ORIGEN) || $(ID_DESTINO))
	{
		$(ID_ORIGEN).appendChild(NEW_DIV);
	}
	else
	{
		debug('k7c1_utilerias no se encuentra (origen:  ' +ID_ORIGEN +',destino:  '+ID_DESTINO+')');
	}
}
function nuevo_img(ID_ORIGEN,ID_DESTINO)
{
	var NEW_IMG = document.createElement("img");
	NEW_IMG.id = ID_DESTINO;
	if($(ID_ORIGEN) || $(ID_DESTINO))
	{
		$(ID_ORIGEN).appendChild(NEW_IMG);
	}
	else
	{
		debug('k7c1_utilerias no se encuentra (origen:  ' +ID_ORIGEN +',destino:  '+ID_DESTINO+')');
	}
}
function debug_r(texto)
{
//	new Insertion.After($('k7c1_debug'), '<br>'+js_print_r(texto,'<br/>')+'<br>');
//	debugv(js_print_r(texto,'<br/>'));
	return js_print_r(texto,'<br/>');
}
function debugv(contenido)
{
	if(!$('k7c1_ventana_debug'))
	{
		new Insertion.After($('body'), nueva_caja('k7c1_ventana_debug'));
		Element.addClassName($('k7c1_ventana_debug_superior'), 'k7c1_dinamic_list_principal');
		Element.addClassName($('k7c1_ventana_debug_superior'), 'k7c1_dinamic_list_opaco90porciento');
		new Insertion.After($('k7c1_ventana_debug_caja'),'<div><INPUT type="button" id="k7c1_ventana_debug_boton" value="Cerrar"></div>');
		centrar_ventana('k7c1_ventana_debug_superior', 'centro', 'centro');
		funcion_onclick		= 'function(){$("k7c1_ventana_debug_superior").style.display="none";}';
		Event.observe('k7c1_ventana_debug_boton','click', eval(funcion_onclick)	, false);
	}
	$('k7c1_ventana_debug_superior').style.display		='';
	new Insertion.After($('k7c1_ventana_debug_caja'),'<div class="k7c1_dinamic_list_error">'+contenido+'</div>');
}
function js_print_r88(ELEMENT, TABULAR)
{
	return js_print_r(ELEMENT, TABULAR);
}

function js_print_r(ELEMENT, TABULAR)
{
    var TAB=(typeof(TABULAR)=='string') ? TABULAR + '\t' : '\t';
    var PARENT_TAB=(typeof(TABULAR)=='string') ? TABULAR : '';
	if(ELEMENT != null)
	{
    if(typeof(ELEMENT) == 'string')
	{
        var OUTPUT = "'" + ELEMENT + "'\n"
    }
	else if(typeof(ELEMENT) == 'boolean')
	{
        var OUTPUT=(ELEMENT ? 'true' : 'false') +"\n"
    }
	else if(typeof(ELEMENT) == 'object')
	{
        var OUTPUT = ((ELEMENT.reverse) ? 'Array' : 'Object') + "\n";
        OUTPUT += PARENT_TAB + "(\n";
        for(var i in ELEMENT)
		{
            OUTPUT += TAB + "[" + i + "] => " + js_print_r88(ELEMENT[i], TAB)
        }
        OUTPUT += PARENT_TAB + ")\n"
    }
	}
    return OUTPUT
}
function debug(texto)
{
//	new Insertion.After($('k7c1_debug'), '<br>'+texto+'<br>');
	if(typeof(texto)=="object" || typeof(texto)=="boolean")
	{
		try{
			return js_print_r(texto, '\n');
		}catch(ex)
		{
			return 'Error: ' + ex + '<br>' + texto;
		}
	}
	else
		return texto;
}
function nueva_caja(ID)
{
	 salida		= '<div id="' + ID + '_superior" class="sobretodo">';
	 salida		+= '<div class="caja-tl"><div class="caja-tr"><div class="caja-tc"></div></div></div>';
	 salida		+= '<div class="caja-ml"><div class="caja-mr"><div class="caja-mc">';
	 salida		+= '<div id="' + ID + '"></div>';
	 salida		+= '<div id="' + ID + '_caja"></div>';
	 salida		+= '</div></div></div>';
	 salida		+= '<div class="caja-bl"><div class="caja-br"><div class="caja-bc"></div></div></div>';
	 salida		+= '</div>';
	return salida;
}
function IsNumber(number)
{
	if ((number >= 0)||(number < 0)) return true;
	else return false;
}
function select_option(id,nombre,valor)
{
	if(!$(id))
	{
		alert('No existe el select indicado:'+id);
		return false;
	}
	if(id && (nombre || valor))
	{
		$$("#" + id + " option").each( function(option) {
			if(valor!='' && option.value == valor)
			{
				option.selected="selected";
			}
			else if (nombre!='' && option.innerHTML == nombre)
			{
				option.selected="selected";
			}
			else
			{
				option.selected="";
			}
		});
	}
}
function select_checkbox(id,valor)
{
	if(valor)
	{
		$(id).checked = true;
	}
	else if($(id))
	{
		$(id).checked = false;
	}
}
function select_checkbox_condicion(id,valor,condicion)
{
	if(valor==condicion)
	{
		$(id).checked = true;
	}
	else if($(id))
	{
		$(id).checked = false;
	}
}
function disable_condicion(id,condicion)
{
	if($(id) && condicion)
	{
		$(id).disabled = true;
	}
	else if($(id))
	{
		$(id).disabled = false;
	}
}
function mostrar_por_class(id,clase,tag)
{
	if(id && clase)
	{
		eval('$$("#' + id + ' ' + tag + '.' + clase + '").each(function(' + clase + '){' + clase + '.show();});');
	}
}
function ocultar_por_class(id,clase,tag)
{
	if(id && clase)
	{
		eval('$$("#' + id + ' ' + tag + '.' + clase + '").each(function(' + clase + '){' + clase + '.hide();});');
	}
}
/***************** NO ESTAN BIEN PROBADAS **************************/
	function valida_rfc(v)
	{
		var valida_rfc_regex = /^[a-zA-Z]{3,4}(\d{6})((\D|\d){3})*$/;
		var valida_rfc_respuesta = v.match(valida_rfc_regex);
		return (valida_rfc_respuesta) ? true : false;
	}
	function calcular_edad(fecha)
	{
		hoy=new Date()
		var array_fecha = fecha.split("/")
		if (array_fecha.length!=3)return false
		var ano
		ano = parseInt(array_fecha[2]);
		if (isNaN(ano))return false
		var mes
		mes = parseInt(array_fecha[1]);
		if (isNaN(mes))return false
		var dia
		dia = parseInt(array_fecha[0]);
		if (isNaN(dia))return false
		if (ano<=99)ano +=1900
		edad=hoy.getYear()- ano - 1;
		if (hoy.getMonth() + 1 - mes < 0)return edad
		if (hoy.getMonth() + 1 - mes > 0)return edad+1
		if (hoy.getUTCDate() - dia >= 0)return edad + 1
		return edad
	}
/***************** NO ESTAN BIEN PROBADAS **************************/
function refrescar_objetos_ajax_por_id(id)
{
	if(typeof(no_enter) == 'object')
	{
		no_enter.refrescar_id(id);
	}
	if(typeof(Tooltip) == 'object')
	{
		$$(id + " input.tooltip_js").each( function(input) {new Tooltip(input, {backgroundColor: "#FC9", borderColor: "#C96", textColor: "#000", textShadowColor: "#FFF"});});
		$$(id + " img.tooltip_js").each( function(img) {new Tooltip(img, {backgroundColor: "#FC9", borderColor: "#C96", textColor: "#000", textShadowColor: "#FFF"});});
	}
}
function desabilitar_contenido(id)
{
	if(typeof(Tooltip) == 'object')
	{
		$(id).disable();
	}
}
function scape_post_prototype(text)
{
	try{
		if(typeof(text)!='string')
		{
			return text;
		}
		text = text.sub('&aacute;', 'à', 999);
		text = text.sub('&eacute;', 'è', 999);
		text = text.sub('&iacute;', 'ì', 999);
		text = text.sub('&oacute;', 'ò', 999);
		text = text.sub('&uacute;', 'ù', 999);
		text = text.sub('&ntilde;', 'ñ', 999);
		text = text.sub('&Ntilde;', 'Ñ', 999);
		text = text.sub('{','', 999);
		text = text.sub('}','', 999);
		//text = text.sub('[','', 999);
		//text = text.sub(']','', 999);
		text = text.sub('=','', 999);
		text = text.sub('&nbsp;', ' ', 999);
		text = text.sub('&', '-', 999);
		return text;
	}catch(ex)
	{
		alert("scape_post_prototype::" + ex);
	}
}

/************ VALIDACION CON CSS ************/
var validacion_json ='';
try{
	validacion_json	= {css_error:"system_contenedor_error_validacion",css_ok:"system_contenedor_ok_validacion"};
}catch(ex)
{
	alert("validacion_json::" + ex);
}

function mostrar_validacion(json,id,valor)
{
	try{
		if(typeof(json) == 'object')
		{
			var mostrar_validacion_json_inicial = json;
		}
		else
		{
			eval("var mostrar_validacion_json_inicial = " + json);
		}
		
		if($(id))
		{
			if(valor==1)
			{
				$(id).removeClassName(mostrar_validacion_json_inicial.css_error);
				$(id).addClassName(mostrar_validacion_json_inicial.css_ok);
			}
			else
			{
				$(id).removeClassName(mostrar_validacion_json_inicial.css_ok);
				$(id).addClassName(mostrar_validacion_json_inicial.css_error);				
			}
		}
		else
		{
			alert("No existe el objeto: " + id);
		}
	}catch(ex)
	{
		alert("mostrar_validacion::" + ex);
	}
}
/************ VALIDACION CON CSS ************/
//		$$("body #Depto020a").each( function(input) {alert("repetir:" + input.innerHTML);});
//		datagrid_select_linea.poblar();
//		datagrid_select_Sublinea.poblar();
//		datagrid_select_Sublinea.poblar();
