// JavaScript Document
function menuprincipal()
{	
	document.frmdatos.action='../administrador/menu.php';
	document.frmdatos.submit();	
}


function popupeditarnoticias(Identificador_Xmod_Noticias)
{
	var cadena="";
	cadena="editarnoticias.php?idnoticias="+Identificador_Xmod_Noticias;
	secondwindow=open(cadena,'Editar','height=800,width=580,scrollbars=yes,directories=NO,location=NO,alwaysRaised');
    secondwindow.moveTo(150,120);
}

function popupvernoticias(Identificador_Xmod_Noticias)
{
	var cadena="";
	cadena="vernoticias.php?idnoticias="+Identificador_Xmod_Noticias;
	secondwindow=open(cadena,'Editar','height=220,width=680,scrollbars=no,directories=NO,location=NO,alwaysRaised');
    secondwindow.moveTo(150,120);
}
function popupvernoticiasvermas(Identificador_Xmod_Noticias)
{
	var cadena="";
	cadena="vernoticiasvermas.php?idnoticias="+Identificador_Xmod_Noticias;
	secondwindow=open(cadena,'Editar','height=620,width=680,scrollbars=yes,directories=NO,location=NO,alwaysRaised');
    secondwindow.moveTo(150,120);
}


function editarnoticias(valor)
{
	if(valor==0){cargar();setTimeout("salir()",4500);}	
}

function cargar(){
document.getElementById('qq').innerHTML="<table border='0' align='center'><tr><td>&nbsp;</td><td><strong>--------------Guardando-------------</strong></td><td>&nbsp;</td></tr><tr><td>0%</td><td><dl><dd><span><em style='left:200px'>100%</em></span></dd></dl></td><td>100%</td></tr></table>";
}
function salir(){
window.opener.location.reload();
window.close();
}

function eliminarnoticias(Identificador_Xmod_Noticias)
{
	if(confirm("Realmente desea eliminar esta noticia"))
	{
		document.frmdatos.action='eliminarnoticias.php';
		document.getElementById('Identificador_Xmod_Noticias').value=Identificador_Xmod_Noticias;
		document.frmdatos.submit();			
	}	
}

function mensajes()
{		
	document.getElementById('noticias').style.display ="none";
	document.getElementById('mens').style.display ="";
/*	document.frmdatos.action='registromensajesnoticias.php';
	document.frmdatos.submit();		
	*/
}

function guardamensajes()
{
	$(document).ready(
				function()
				{				
					$.post("ajaxmensajesnoticias.php",{mensajebda:$("#mensajebda").val(),descripcionbda:$("#descripcionbda").val(),mensajedda:$("#mensajedda").val(),descripciondda:$("#descripciondda").val(),mensajebdaing:$("#mensajebdaing").val(),descripcionbdaing:$("#descripcionbdaing").val(),mensajeddaing:$("#mensajeddaing").val(),descripcionddaing:$("#descripcionddaing").val()},
								function(data)
								{ 																			
									alert("Los Mensajes se guardaron satisfactoriamente");
									//$('form')[0].reset();								
								}
							);						
				}
	);	
}
function buscador(Idioma)
{
	
//	palabra=document.getElementById('busqueda').value;
//	alert(palabra);
	$(document).ready(
				function()
				{				
					$.post("xmod_noticias/ajaxbuscarnoticias.php",{palabras:$("#busqueda").val(),Idioma:Idioma},
								function(data)
								{ 	
									$("#subseccion").html(data);
								}
							);						
				}
	);	
	
	
}
function buscadorcliente(Idioma)
{
	
//	palabra=document.getElementById('busqueda').value;
//	alert(palabra);
	$(document).ready(
				function()
				{				
					$.post("xmod_noticias/ajaxbuscarnoticiascliente.php",{palabras:$("#busqueda").val(),Idioma:Idioma},
								function(data)
								{ 	
									$("#subseccion").html(data);
								}
							);						
				}
	);	
	
	
}
function buscadoratras(palabras,Idioma)
{
	
//	palabra=document.getElementById('busqueda').value;
//	alert(palabra);
	$(document).ready(
				function()
				{				
					$.post("xmod_noticias/ajaxbuscarnoticias.php",{palabras:palabras,Idioma:Idioma},
								function(data)
								{ 	
									$("#subseccion").html(data);
								}
							);						
				}
	);	
	
	
}
function buscadoratrascliente(palabras,Idioma)
{
	
//	palabra=document.getElementById('busqueda').value;
//	alert(palabra);
	$(document).ready(
				function()
				{				
					$.post("xmod_noticias/ajaxbuscarnoticiascliente.php",{palabras:palabras,Idioma:Idioma},
								function(data)
								{ 	
									$("#subseccion").html(data);
								}
							);						
				}
	);	
	
	
}
function vermas(Identificador_Xmod_Noticias,palabras,Idioma)
{

//	alert(Identificador_Xmod_Noticias);
//	alert(palabras);
	$(document).ready(
				function()
				{				
					$.post("xmod_noticias/ajaxbuscarnoticiasvermas.php",{Identificador_Xmod_Noticias:Identificador_Xmod_Noticias,palabras:palabras,Idioma:Idioma},
								function(data)
								{ 																			
									$("#subseccion").html(data);
								}
							);						
				}
	);	
}
function vermascliente(Identificador_Xmod_Noticias,palabras,Idioma)
{

//	alert(Identificador_Xmod_Noticias);
//	alert(palabras);
	$(document).ready(
				function()
				{				
					$.post("xmod_noticias/ajaxbuscarnoticiasvermascliente.php",{Identificador_Xmod_Noticias:Identificador_Xmod_Noticias,palabras:palabras,Idioma:Idioma},
								function(data)
								{ 																			
									$("#subseccion").html(data);
								}
							);						
				}
	);	
}
function creareventogaleriafotos(Identificador_Xmod_Eventos_Galeria)
{	
	document.getElementById('Identificador_Xmod_Eventos_Galeria').value=Identificador_Xmod_Eventos_Galeria;
	document.frmdatos.action='creaeventogaleriafotos.php';
	document.frmdatos.submit();	
}

function vereventosatras()
{
$(document).ready(
				function()
				{				
					$.post("xmod_eventos/ajaxeventosatras.php",{},
								function(data)
								{ 																			
									$("#subseccion").html(data);
								}
							);						
				}
	);	


}
function creanoticias()
{
	document.getElementById('noticias').style.display ="";
	document.getElementById('mens').style.display ="none";
	document.frmdatos.action='creanoticias.php	';
	document.frmdatos.submit();	
}


function actualizar(id)
{
	if(id!=0)
	{
		$(document).ready(
					function()
					{				
						$.post("xmod_noticias/ajaxnoticias.php",{id:id},
									function(data)
									{ 	//alert(data);																		
										$("#noticia").html(data);
									}
								);						
					}
		);
	}
}

function actualizarvermas(id)
{

document.getElementById('DIV6-7').style.display ="none";	
	if(id!=0)
	{
		$(document).ready(
						function()
						{				
							$.post("xmod_noticias/ajaxnoticiasfrontvermas.php",{id:id},
										function(data)
										{ 	//alert(data);																		
										
											$("#subseccion").html(data);
										}
									);						
						}
			);	
	}
}

function desechek(j)
{
	for (i=0;i<document.frmdatos.acceso.length;i++)
	{
		if(j==0 )
		{	
			if(i!=0)
			{
			 	document.frmdatos.acceso[i].checked=false;  
			}
		}
		else
		{
			document.frmdatos.acceso[0].checked=false;  
		}
	}		
}
function verificaenlace()
{
	var cad="";
	for (i=0;i<document.frmdatos.acceso.length;i++)
	{
	  if(document.frmdatos.acceso[i].checked)
	  {
		  cad=cad+document.frmdatos.acceso[i].value+"-";
	  }
	}
	cad=cad.substring(0,cad.length-1)
	if(cad=="")
	{
		document.getElementById('cadenachk').value="0";				
	}
	else
	{
		document.getElementById('cadenachk').value=cad;		
	}	
	
	if(document.getElementById('tipo_1').checked ==true)	
	{
		cadena="enlace";
		if(verificarcampos2(cadena)==1)
		{
			document.frmdatos.submit();		
		}
		else
		{
			alert("Por favor llene los campos de color rojo");	
		}
	}
	else
	{		
		document.frmdatos.submit();		
	}
}

function verificarcampos2(cadena)
{	
	vec=cadena.split(',');
	cont=vec.length;
	cont2=vec.length;
	
	for (i=0;i<vec.length;i++)
	{
		if(vec[i]!="correo")
		{
			if(Trim(document.getElementById(vec[i]).value) =="")
			{
				document.getElementById(vec[i]).style.background="red";
				document.getElementById(vec[i]).value =Trim(document.getElementById(vec[i]).value);
				cont=cont-1;
			}
			else
			{
				document.getElementById(vec[i]).style.background="";
				document.getElementById(vec[i]).value =Trim(document.getElementById(vec[i]).value);
			}			
		}
		else
		{
			if( Trim(document.getElementById('correo').value) =="" ||  valEmail(document.getElementById('correo').value)==false)
			{
				document.getElementById(vec[i]).style.background="red";
				document.getElementById(vec[i]).value =Trim(document.getElementById(vec[i]).value);
				cont=cont-1;		
			}
			else
			{
				document.getElementById(vec[i]).style.background="";	
				document.getElementById(vec[i]).value =Trim(document.getElementById(vec[i]).value);
			}						
		}
	}

	if(cont==cont2)
	{
		return 1;
	}
	else
	{
		return 0;
	}	
}

//funcion para validar espacios 
function Trim( str )
{
	var resultStr = "";
	
	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);
	
	return resultStr;
}
//funcion para validar espacios por izquierda
function TrimLeft( str )
{
	var resultStr = "";
	var i = len = 0;
	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;
	// Make sure the argument is a string
	str += "";
	if (str.length == 0) 
		resultStr = "";
	else {	
  		// Loop through string starting at the beginning as long as there
  		// are spaces.
//	  	len = str.length - 1;
		len = str.length;
		
  		while ((i <= len) && (str.charAt(i) == " "))
			i++;
   	// When the loop is done, we're sitting at the first non-space char,
 		// so return that char plus the remaining chars of the string.
  		resultStr = str.substring(i, len);
  	}
  	return resultStr;
}
//funcion para validar espacios por derecha
function TrimRight( str )
{
	var resultStr = "";
	var i = 0;
	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;
	// Make sure the argument is a string
	str += "";
	
	if (str.length == 0) 
		resultStr = "";
	else {
  		// Loop through string starting at the end as long as there
  		// are spaces.
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 			i--;
 			
 		// When the loop is done, we're sitting at the last non-space char,
 		// so return that char plus all previous chars of the string.
  		resultStr = str.substring(0, i + 1);
  	}  	
  	return resultStr;  	
}
function valEmail(valor)
{
	re  = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/; 
    if(!re.exec(valor))
	{
        return false;
    }else
	{
        return true;
    }
}


function NoticiasFrontVermasEnlace(id,idioma)
{
	scrollBy(0,-500);	
	document.getElementById("front1").style.display ="none";
	document.getElementById("front2").style.display ="";
	if(id!=0)
	{
		$(document).ready(
						function()
						{				
							$.post("xmod_noticias/ajaxnoticiasfrontenlacevermas.php",{id:id,idioma:idioma},
										function(data)
										{ 																																								
											$("#subseccion").html(data);
										}
									);						
						}
			);	
	}
}

function vermasacceso(id,opcion,idioma)
{
	scrollBy(0,-500);	
	if(id!=0)
	{
		$(document).ready(
						function()
						{				
							$.post("xmod_noticias/ajaxvermasacceso.php",{id:id,idioma:idioma,opcion:opcion},
										function(data)
										{ 																																								
											$("#subseccion").html(data);
										}
									);						
						}
			);	
	}
}
function vermasacceso2(Id_Master,Id_Division,Id_Seccion,Id_Subseccion,opcion,idioma)
{
	scrollBy(0,-500);	
	if(Id_Master!=0)
	{
		$(document).ready(
						function()
						{				
							$.post("xmod_noticias/ajaxvermasacceso2.php",{Id_Master:Id_Master,Id_Division:Id_Division,Id_Seccion:Id_Seccion,Id_Subseccion:Id_Subseccion,idioma:idioma,opcion:opcion},
										function(data)
										{ 																																								
											$("#subseccion").html(data);
										}
									);						
						}
			);	
	}
}
function frontalenlace()
{
	document.getElementById('front1').style.display ="";	
	document.getElementById('front2').style.display ="none";		
}

function cabiarnoticia(id,cadid,jj,actual)
{
	Cadenaid=cadid.split(',');				
	for (i=0;i<Cadenaid.length;i++)
	{
		if(Cadenaid[i]==id)
		{ 
			document.getElementById('idnf'+Cadenaid[i]).style.display ="";				
		}
		else
		{
			document.getElementById('idnf'+Cadenaid[i]).style.display ="none";		
		}	
		j=i+1;
	}
	document.getElementById('id'+id+'_'+jj+'_0').style.display ="";	
	document.getElementById('id'+id+'_'+jj+'_1').style.display ="none";	
		
}

