function asociarOficina(){
	//IDENTIFICAMOS LOS USUARIOS RESPONSABLES SELECCIONADOS
	content=document.getElementById('oficinassistema'); 
	var cadResp="";
	var op=content.getElementsByTagName("input");	
	var pos=0; var sw=false;
	for(i=0;i<op.length;i++){
		id=op[i].getAttribute("id");
		if(op[i].checked)cadResp+=op[i].value+",";
	}
	document.getElementById('IdsMaster').value=cadResp;
	document.getElementById('formenoticias').submit();
}

// JavaScript Document
function menuprincipal()
{	
	document.frmdatos.action='../administrador/menu.php';
	document.frmdatos.submit();	
}


function popupeditarnoticias(Identificador_Xmod_Noticias)
{	
	var cadena="";
	IdMaster=document.getElementById('master').value;
	cadena="editarnoticias.php?idnoticias="+Identificador_Xmod_Noticias+"&IdMaster="+IdMaster;
	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="";
	IdMaster=document.getElementById('master').value;
	cadena="vernoticias.php?idnoticias="+Identificador_Xmod_Noticias+"&IdMaster="+IdMaster;
	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="";
	IdMaster=document.getElementById('master').value;
	cadena="vernoticiasvermas.php?idnoticias="+Identificador_Xmod_Noticias+"&IdMaster="+IdMaster;
	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,Id_Master:$("#IdMaster").val()},
								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,Id_Master:$("#IdMaster").val()},
								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,Id_Master:$("#IdMaster").val()},
								function(data)
								{ 					
									//alert(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 verificaenlace()
{
	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_Seccion,Ids_Master,idioma,id1)
{
/*	document.getElementById('subseccionnoticias').style.display ="";	
	document.getElementById('frontnoticias').style.display ="none";

	if(id!=0)
	{
		$(document).ready(
						function()
						{				
							$.post("xmod_noticias/ajaxnoticiasfrontenlacevermas.php",{id:id,idioma:idioma,Id_Master:idmaster},
										function(data)
										{ 	//alert(data);																		
											//document.getElementById('subseccionnoticias').style.display ="";										
											$("#subseccionnoticias").html(data);
										}
									);						
						}
			);	
	}
*/	
/*	alert(id);
	alert(idmaster);
	alert(idioma);
	*/
	if(Ids_Master!=1)
	{
		document.frmdatospagina.target="_self";
		document.frmdatospagina.action="index2.php?Id_Master="+Ids_Master+"&Id_Seccions="+Id_Seccion+"&OpciVerm=0"+"&modulos=1"+"&Id="+id1;
		document.frmdatospagina.submit();		
	}
}
function NoticiasFrontVermasEnlaceOficina(Id_Seccion,Ids_Master,idioma)
{
	
	document.getElementById('frontvermas').style.display ="";
	document.getElementById('front').style.display ="none";	

	if(Id_Seccion!=0)
	{
		$(document).ready(
						function()
						{		
							$.post("xmod_noticias/ajaxnoticiasfrontenlacevermas.php",{id:Id_Seccion,idioma:idioma,Id_Master:Ids_Master},
										function(data)
										{ 																	
											//document.getElementById('subseccionnoticias').style.display ="";										
											$("#subseccionfrontvermas").html(data);
										}
									);						
						}
			);	
	}
}
function frontalenlace()
{
	document.getElementById('frontvermas').style.display ="none";	
	document.getElementById('front').style.display ="";
}


function crearnoticias(IdMaster)
{
	document.getElementById('IdMaster').value=IdMaster;
	document.frmdatos.action='creanoticias.php';
	document.frmdatos.submit();		
}
function recargarmasternoticias()
{	
	IdMaster=document.getElementById('master').value;
	document.frmdatos.method='get';
	document.frmdatos.action='listanoticias.php?IdMaster='+IdMaster;
	document.frmdatos.submit();	
}
