//menu flotante
var bandera_error_gral = false;
var menu_top = 0;
var menu_max_top = 0;
var obj_max_top = false;
var obj_mf = false;
var obj_cn = false;
var menu_left = 0;
var menu_width = 0;
var menu_height = 0;
var menu_pos_act = -1;
var sc_Top = 0;
var sc_Left = 0;
var menu_avance = 20; //velocidad al desplegar/ocultar el menu flotante
var menu_t_vista = 1; //tiempo en segundos que dura el menu flotante desplegado
var menu_min_height = 250; //altura minima del menu flotante
var cvget = ""; // contiene la variable GET para actualizar la ligas de las paginas
function scroll_pp()
{
	if(document.body && document.body.scrollTop)
	{
		sc_Top = document.body.scrollTop;
	}
	else
	{
		if(document.documentElement && document.documentElement.scrollTop)
		{
			sc_Top = document.documentElement.scrollTop;
		}
		else
		{
			sc_Top = 0;
		}
	}
	if(document.body && document.body.scrollLeft)
	{
		sc_Left = document.body.scrollLeft;
	}
	else
	{
		if(document.documentElement && document.documentElement.scrollLeft)
		{
			sc_Left = document.documentElement.scrollLeft;
		}
		else
		{
			sc_Left = 0;
		}
	}
}
function inicia_pp()
{
	//alert("ini");
	//$("div.bus_pp").show();
	scroll_pp();
	obj_mf = document.getElementById('menu_f');
	obj_cn = document.getElementById('contenedor');
	obj_max_top = document.getElementById('d_men_inf');
	/*menu_flotante*/
	if(obj_m_c = document.getElementById('menu_f_c'))
	{
		obj_m_c.style.display = "block";
		menu_height = Math.max(obj_m_c.offsetHeight, menu_min_height);
		menu_width = obj_m_c.offsetWidth;
		obj_m_c.style.display = "none";
		obj_m_c.style.width = menu_avance+"px";
		obj_m_c.style.height = menu_height+"px";
		obj_m_c.style.overflow = "hidden";
		if(obj_m_l = document.getElementById('menu_lv'))
		{
			obj_m_l.style.height = menu_height-12+"px";
		}
	}
	if(obj_mf)
	{
		obj_mf.style.visibility = "visible";
		menu_top = obj_mf.offsetTop;
	}
	menu_max_top = obj_max_top ? obj_max_top.offsetTop : 0;
	if(obj_cn)
	{
		menu_left = obj_cn.offsetLeft;
	}
	menu_pos_act = -1;
	//	mostrar los controles de scroll para imagenes
	var tabla_ = document.getElementById('t_contf');
	var controles_ = document.getElementById('ctr_fot');
	if(tabla_ && controles_ && parseInt(tabla_.style.width)>=740)
	{
		controles_.style.visibility = "visible";
	}
	mueve_menu();
	iniV();
	gV();
}
function inicia_pp_c()
{
	scroll_pp();
	menu_max_top = obj_max_top ? obj_max_top.offsetTop : 0;
	mueve_menu();
	iniV();
}
function reinicio_pp()
{
	menu_left = obj_cn ? obj_cn.offsetLeft : 0;
	menu_pos_act = -1;
	mueve_menu();
}
var mueve_menu = function ()
{
	scroll_pp();
	monV();
	//window.status=sc_Top+"-"+menu_top+"-"+menu_height+"-"+menu_max_top+"-"+menu_left;
	var p_m = calcula_mp();
	var pos_top = sc_Top;
	if(pos_top!=menu_pos_act && obj_mf)
	{
		if(((sc_Top+menu_height)<menu_top) || ((sc_Top+menu_height)>menu_max_top))
		{
			obj_mf.style.display = 'none';
			/*
			 if( (sc_Top+menu_height)>=menu_max_top )
			 setTimeout("resalt_secc('d_men_inf')", 50);
			 */
		}
		else
		{
			altura = Math.max(0, p_m["height"]);
			centro_top = (altura-menu_height)/2;
			obj_mf.style.top = (pos_top+centro_top)+"px";
			obj_mf.style.left = (menu_left-5)+"px";
			obj_mf.style.display = 'block';
			menu_pos_act = pos_top;
		}
	}
	setTimeout("mueve_menu()", 100);
}
var menu_f_act = false;
var menu_s_act = false;
var menu_s_div = false;
var menu_creciendo = false;
function menu_ver()
{
	if(menu_creciendo)
	{
		return;
	}
	if(!menu_f_act)//abre el menu
	{
		if(img_l = document.getElementById('sp_mn_flt'))
		{
			img_l.innerHTML = txt_sh;
		}
		if(img_b = document.getElementById('menu_img_bv'))
		{
			img_b.src = "/pr/imagenes/menu_fo.jpg";
		}
		if(men_c = document.getElementById('menu_f_c'))
		{
			men_c.style.display = "block";
			crece_menu();
		}
		menu_f_act = true;
		menu_s_act = true;
		menu_cierra();
	}
	else  //abre el menu
	{
		if(img_l = document.getElementById('sp_mn_flt'))
		{
			img_l.innerHTML = txt_hd;
		}
		if(img_b = document.getElementById('menu_img_bv'))
		{
			img_b.src = "/pr/imagenes/menu_fv.jpg";
		}
		if(men_c = document.getElementById('menu_f_c'))
		{
			//men_c.style.display="none";
			decrece_menu();
		}
		menu_f_act = false;
		menu_s_act = true;
	}
}
function menu_cierra()
{
	if(menu_s_act)
	{
		if(!menu_s_div)
		{
			menu_s_act = false;
		}
		setTimeout("menu_cierra()", (menu_t_vista*1000));
	}
	else
	{
		menu_f_act = true;
		menu_ver();
	}
}
function crece_menu()
{
	if(men_c = document.getElementById('menu_f_c'))
	{
		var wid = parseInt(men_c.style.width);
		if(wid<menu_width)
		{
			menu_creciendo = true;
			men_c.style.width = wid+menu_avance+"px";
			setTimeout("crece_menu()", 1);
		}
		else
		{
			menu_creciendo = false;
		}
	}
}
function decrece_menu()
{
	if(men_c = document.getElementById('menu_f_c'))
	{
		var wid = parseInt(men_c.style.width);
		if(wid>0)
		{
			menu_creciendo = true;
			men_c.style.width = Math.max(wid-menu_avance, 0)+"px";
			setTimeout("decrece_menu()", 1);
		}
		if(wid<=menu_avance)
		{
			menu_creciendo = false;
			men_c.style.display = "none";
		}
	}
}
//fin menu flotante
//funciones pantalla
function calcula_mp()
{
	var med = new Array();
	med["width"] = 0;
	med["height"] = 0;
	if(window.innerWidth)
	{
		med["width"] = window.innerWidth;
		med["height"] = window.innerHeight;
	}
	else
	{
		if(document.documentElement && document.documentElement.clientWidth)
		{
			med["width"] = document.documentElement.clientWidth;
			med["height"] = document.documentElement.clientHeight;
		}
		else
		{
			if(document.body && document.body.clientWidth)
			{
				med["width"] = document.body.clientWidth;
				med["height"] = document.body.clientHeight;
			}
		}
	}
	return med;
}
function setStyle(objId, style, value)
{
	if(document.getElementById(objId))
	{
		document.getElementById(objId).style[style] = value;
	}
}
function aS(div, fnt)// ~put_button2 : ampliar y disiminuir
{
	var input = fnt;
	var iner = new String(input.innerHTML);
	var obj_div = document.getElementById(div);
	var alto_real = 0;
	if(!obj_div || input.innerHTML=="&nbsp;")
	{
		return;
	}
	if(iner.indexOf('+')!=-1)// se amplia
	{
		input.innerHTML = tx_disminuir+" <font class=\"f\">&nbsp;-&nbsp;</font>";
		setStyle(div, 'height', 'auto');
		obj_div = document.getElementById(div);
		alto_real = obj_div.offsetHeight;
		if(alto_real<180)
		{
			input.innerHTML = "&nbsp;";
		}
	}
	else
	{
		input.innerHTML = tx_ampliar+" <font>&nbsp;+&nbsp;</font>";
		setStyle(div, 'height', '180px');
	}
	inicia_pp_c();
}
function ppsub(id_form)//sin uso en pp
{
	if(forma = document.getElementById(id_form))
	{
		forma.submit();
	}
}
move = false;
function der()
{
	if(!document.getElementById('dv_secc_fotos_p'))
	{
		return;
	}
	document.getElementById('dv_secc_fotos_p').scrollLeft += 10;
	setTimeout("prueba(1)", 50);
}
function izq()
{
	if(!document.getElementById('dv_secc_fotos_p'))
	{
		return;
	}
	document.getElementById('dv_secc_fotos_p').scrollLeft -= 10;
	setTimeout("prueba(2)", 50);
}
function prueba(c)
{
	if(move)
	{
		if(c==1)
		{
			der();
		}
		if(c==2)
		{
			izq();
		}
	}
}
var dv_comm_act = 0;
function sh_comm(id_apo, scc)//sin uso en pp
{
	if(dv_comm_act)
	{
		dv_comm_act.style.visibility = "hidden";
		dv_comm_act.style.display = "none";
	}
	dv_comm_act = document.getElementById('dv_com_'+scc+'_ap_'+id_apo);
	dv_comm_act.style.visibility = "visible";
	dv_comm_act.style.display = "block";
}
function cV(cad_elemento, tipo)// ~cambiaVisibilidad
{
	var ley_txt = false;
	var div_cont;
	var imagen;
	var nvo_src = '/pr/iconos/comentario';
	var temp = '';
	var txt_si = '';
	var txt_no = '';
	div_cont = document.getElementById(cad_elemento);
	imagen = document.getElementById('img_'+cad_elemento);
	ley_txt = document.getElementById('txt_'+cad_elemento);
	if(!div_cont || !imagen)
	{
		return;
	}
	var mostrar = div_cont.style.display!="block" ? true : false;
	if(ley_txt)
	{
		temp = new String(ley_txt.innerHTML);
	}
	if(cad_elemento.indexOf('comentario')!=-1)
	{
		txt_si = tx_ver_rpts;
		txt_no = tx_no_rpts;
	}
	else
	{
		txt_si = tx_ver_cmt;
		txt_no = tx_no_cmt;
	}
	div_cont.style.display = mostrar ? "block" : "none";
	div_cont.style.visibility = mostrar ? "visible" : "hidden";
	imagen.src = !mostrar ? nvo_src+'.gif' : nvo_src+'_esc.gif';
	if(tipo==2 && temp!='')
	{
		if(!mostrar)
		{
			ley_txt.innerHTML = temp.replace(txt_no, txt_si);
		}
		else
		{
			ley_txt.innerHTML = temp.replace(txt_si, txt_no);
		}
	}
	iniV();
	if(marcado_extra)
	{
		marcado_extra.className = mostrar ? marcado_extra.className+" resalta" : marcado_extra.className.replace(" resalta", "");
	}
}
var marcado_extra = null;
var elemento_foto = null;
var div_foto = null;
function cVF(elemento)// ~cambiaVisibilidad_foto
{
	var id_ap = elemento.split("_");
	if(elemento_foto!=null) // cierra los comentarios de la foto abierta actualmente
	{
		marcado_extra = document.getElementById(div_foto);//+
		cV(elemento_foto, 1);
		marcado_extra = null;//+
	}
	if(elemento_foto==elemento)
	{
		elemento_foto = null;
		div_foto = null;//+
	}
	else
	{
		div_foto = "ap_"+id_ap[2];//+
		marcado_extra = document.getElementById(div_foto);//+
		cV(elemento, 1);
		marcado_extra = null;//+
		elemento_foto = elemento;
	}
}
var opc_sin = 0;
function lista_sinonimos(opcion, val)//sin uso en pp
{
	if(opc_sin==val)
	{
		document.getElementById('enca_s').innerHTML = "";
		document.getElementById('lista_s').style.display = "none";
		document.getElementById('lista_s').style.visibility = "hidden";
		opc_sin = 0;
	}
	else
	{
		document.getElementById('enca_s').innerHTML = opcion;
		document.getElementById('lista_s').style.display = "block";
		document.getElementById('lista_s').style.visibility = "visible";
		opc_sin = val;
	}
}
function selec_pr(id, total, pro_rel)
{
	for(inicio = 0; inicio<total; inicio++)
	{
		sinonimo = document.getElementById('pr_s_'+id+"_"+inicio);
		if(sinonimo)
		{
			sinonimo.checked = pro_rel.checked;
		}
	}
}
function selec_pr_rev(id, pro_rel)
{
	inicio = 0;
	princ = document.getElementById("pr_"+id);
	princ.checked = pro_rel.checked;
	while(true)
	{
		sinonimo = document.getElementById("pr_s_"+id+"_"+inicio);
		if(sinonimo)
		{
			if(sinonimo)
			{
				sinonimo.checked = pro_rel.checked;
				inicio++;
			}
		}
		else
		{
			return false;
			break;
		}
	}
}
// ordenamiento
var ordenF = 'ordF_vts';//primer ordenamiento
var ordInfoClase = '';
function mi_ordena_fotos(obj)
{
	ordInfoClase = 'foto_cont_ap';
	if(ordenF=="ordF_vts")// como se va a ordenar
	{
		//alert("ordenar por votos desc");
		ordInfo('t_contf', 'viapsft', 'sumVts', false);
		//'ordenar imagenes cronologicamente (descendente)';
		ordenF = 'ordF_cro';//sig ordenamiento
	}
	else	//	id
	{
		//alert("ordenar por id desc");
		ordInfo('t_contf', 'viapsft', 'viap', false);
		//'ordenar imagenes por votos (descendente)';
		ordenF = 'ordF_vts';//sig ordenamiento
	}
	try
	{
		obj.value = leyenda[ordenF];
		document.getElementById('ley_ord_f').innerHTML = ordenF=="ordF_vts" ? leyenda['orden_fechas'] : leyenda['orden_votos'];
	}
	catch(weg)
	{
		obj.value = ordenF;
	}
}
/*busqueda en esta pagina*/
var NS4 = (document.layers);
var IE4 = (document.all);
var win = window;
var n = 0;
function BuscarPalabras(str)
{
	var txt, i, found;
	if(str=="")
	{
		return false;
	}
	if(NS4)
	{
		if(!win.find(str))
		{
			while(win.find(str, false, true))
			{
				n++;
			}
		}
		else
		{
			n++;
		}
		if(n==0)
		{
			alert(leyenda['no_encontrado']);
		}
	}
	if(IE4)
	{
		txt = win.document.body.createTextRange();
		for(i = 0; i<=n && (found = txt.findText(str))!=false; i++)
		{
			txt.moveStart("character", 1);
			txt.moveEnd("textedit");
		}
	}
	if(found)
	{
		txt.moveStart("character", -1);
		txt.findText(str);
		txt.select();
		txt.scrollIntoView();
		n++;
	}
	else
	{
		if(n>0)
		{
			n = 0;
			BuscarPalabras(str);
		}
		else
		{
			alert(leyenda['no_encontrado']);
		}
	}
	//}
	return false;
}
/*busqueda en esta pagina*/
/*conversiones*/
function set_ajax()
{
	var regresa_p;
	if(window.XMLHttpRequest)
	{
		// Si es Mozilla, Safari etc
		regresa_p = new XMLHttpRequest();
	}
	else
	{
		if(window.ActiveXObject)
		{
			// pero si es IE
			try
			{
				regresa_p = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{ // en caso que sea una versión antigua
				try
				{
					regresa_p = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
				}
			}
		}
		else
		{
			return false
		}
	}
	return regresa_p;
}
function convierte_prop(p, flag, value, ap)
{
	url = "/pr/im/ticcsrv.php";
	id_contenedor = "cont_"+flag+"_apo_"+p;
	var pagina_requerida = false;
	pagina_requerida = set_ajax();
	pagina_requerida.onreadystatechange = function()
	{
		if(pagina_requerida.readyState==1)
		{
			document.getElementById(id_contenedor).innerHTML = "<img src='/pr/imagenes/wait.gif' align='center' />";
		}
		if(pagina_requerida.readyState==4)
		{
			if(pagina_requerida.status==200)
			{
				document.getElementById(id_contenedor).innerHTML = pagina_requerida.responseText;
			}
			else
			{
				id_contenedor.innerHTML = leyenda['error_ajax'];
			}
		}
	}
	if(flag=='p')
	{
		name_f = "pide_val";
	}
	else
	{
		name_f = "pide_val_c";
	}
	valorpost = "func="+name_f+"&propiedad="+p+"&nw_conv="+value;
	pagina_requerida.open('POST', url, true);
	pagina_requerida.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	pagina_requerida.send(valorpost);
}
/*conversiones*/
//--noticias
var popUpWin = 0;
function popUpWindow(URLStr, left, top, width, height)
{
	if(popUpWin && !popUpWin.closed)
	{
		popUpWin.close();
	}
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=yes,menub ar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	popUpWin.focus();
}
//noticias--
function now()
{
	var Stamp = new Date();
	var tm_tmp = '';
	var Hours;
	var Mins;
	var Segs;
	var Time;
	Hours = Stamp.getHours();
	if(Hours>=12)
	{
		Time = " P.M.";
	}
	else
	{
		Time = " A.M.";
	}
	if(Hours>12)
	{
		Hours -= 12;
	}
	if(Hours==0)
	{
		Hours = 12;
	}
	Mins = Stamp.getMinutes();
	if(Mins<10)
	{
		Mins = "0"+Mins;
	}
	Segs = Stamp.getSeconds();
	if(Segs<10)
	{
		Segs = "0"+Segs;
	}
	tm_tmp += Hours+":"+Mins+":"+Segs+Time;
	return tm_tmp;
}
//--ajx
var cont_din_ini = '<div class="contenido limpio"><div class="centro_pp">';
var cont_din_fin = '</div></div>';
var sign_act = ''; //cont_din_ini+'<p><h1>ACTUALIZADO!!</h1></p>'+cont_din_fin;
function upSeccPP(secc)
{
	//alert("upSeccPP("+secc+")");
	if(secc!=0 && secc!='seccion-0' && secc!="")
	{
		return getSeccPP(secc);
	}
	return false;
}
var muestra_mensaje = true;
function getSeccPP(secc)
{
	//alert('getSeccPP('+secc+')');
	var dc = document.getElementById(secc);
	if(!dc)
	{
		return false;
	}
	url_ = '/pr/ap/r.php';
	var manejador = set_ajax();
	manejador.onreadystatechange = function()
	{
		if(manejador.readyState==4)
		{
			if(manejador.status==200)
			{
				html_extra = "";
				/*html_extra= '<div class="secc_actualizada centro_pp" id="'+secc+'_ia">'+leyenda['secc_actualizada']+'&nbsp;'+now()+'&nbsp;<a href="#" onclick="setStyle(\''+secc+'_ia\', \'display\', \'none\'); return false;">'+leyenda['cerrar']+'</a></div><div class="limpia"></div>';*/
				//alert(html_extra);
				dc.innerHTML = html_extra+manejador.responseText+sign_act;
				//iniResSecc(secc);
				setTimeout('abrir_secciones()', 3000);
				cambia_ligas();
			}
			else
			{
				dc.innerHTML = leyenda['error_ajax'];
			}
			getMenPP();
		}
	}
	//alert("ya mero pide el ajx:"+url_);
	manejador.open('POST', url_, true);
	manejador.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	if(typeof otro_pRef!='undefined')
	{
		pRef = otro_pRef;
	}
	manejador.send("qn="+pRef+seP+ipRef+seP+secc);
	//alert("ajx:\n\n"+"qn="+pRef+seP+ipRef+seP+secc);
	return true;
}
var ctr_res = 0;
var secc_res = '';
function iniResSecc(secc)
{
	if(secc_res!=secc && secc_res!='')
	{
		ctr_res = 0;
		setStyle(secc_res, 'border', '');
	}
	secc_res = secc;
	resSecc();
}
function resSecc()
{
	if(ctr_res<=3 && secc_res!='')
	{
		if(ctr_res%2==0)
		{
			setStyle(secc_res, 'border', '2px dashed RED');
		}
		else
		{
			setStyle(secc_res, 'border', '');
		}
		if(ctr_res<=2)
		{
			ctr_res++;
			setTimeout('resSecc()', 2000);
			return;
		}
	}
	ctr_res = 0;
	secc_res = '';
}
function getMenPP()
{
	var menu_top = document.getElementById('d_men_sup');
	var menu_bottom = document.getElementById('d_men_inf');
	if(!menu_top || !menu_bottom)
	{
		return;
	}
	url_ = '/pr/ap/r.php';
	var manejador = set_ajax();
	manejador.onreadystatechange = function()
	{
		if(manejador.readyState==4)
		{
			if(manejador.status==200)
			{
				var resp_ajx = manejador.responseText;
				//alert('menu regreso:\n'+resp_ajx);
				menu_top.innerHTML = resp_ajx+sign_act;
				var arr_nvo_texto = resp_ajx.split('<!-- tag_bus -->');
				if(typeof arr_nvo_texto[0]!='undefined' && typeof arr_nvo_texto[2]!='undefined')
				{
					menu_bottom.innerHTML = arr_nvo_texto[0]+arr_nvo_texto[2];
				}
				$("div.bus_pp").show();
			}
			else
			{
				menu_top.innerHTML = leyenda['error_ajax'];
			}
		}
	}
	manejador.open('POST', url_, true);
	manejador.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	manejador.send("qn="+pRef+seP+ipRef+seP+"d_men");
	//alert("ajx2_,menu:\n\n"+"qn="+pRef+seP+ipRef+seP+"d_men");
}
var leyendas_secc = new Array();
function nombre_secc(secc)
{
	return leyendas_secc[secc] ? leyendas_secc[secc] : secc;
}
$(function()
{
	inicia_pp();
});
$(window).resize(function()
{
	reinicio_pp();
});

