function AJAX(){
		var ajaxs = ["Msxml2.XMLHTTP","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.3.0","Microsoft.XMLHTTP"];
		var ajax = false;
		for(var i=0 ; !ajax && i<ajaxs.length ; i++){
			try{ ajax = new ActiveXObject(ajaxs[i]); }
			catch(e) { ajax = false; }
		}
		if(!ajax && typeof XMLHttpRequest!='undefined') {
			ajax = new XMLHttpRequest();
		}
		return ajax;
	}
	
		
function cagardatos(pagina, capa, parametros){
		var ajax = AJAX();		
	
		if(!ajax){
			alert("Imposible Grabar Mensaje");
			return false;
		}		        
		
		document.getElementById(capa).innerHTML = "<b> ..:: Cargando ::..<br /> Espere por favor... <br /></b>";
	
 		ajax.open("POST",pagina,true);
		ajax.onreadystatechange = function() {
				if (ajax.readyState == 4)
				{
					if (ajax.status == 200)
					{
						document.getElementById(capa).innerHTML=ajax.responseText;						
					}
					else 
					{
					//	alert('Se detecto problemas en su conexion a internet o el servidor esta saturado, por favor pulse aceptar y luego Actualize la web pulsado la tecla F5');
					//	document.getElementById(capa).innerHTML='Se detecto problemas en su conexion a internet o el servidor esta saturado, por favor pulse aceptar y luego Actualize la web pulsado la tecla F5';
					}
					
					document.getElementById(capa).innerHTML=ajax.responseText;					
				}
			}			
			
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(parametros);
	}


function votar(obj)
{
  	idencuesta=obj.idencuesta.value;
	nropreguntas=obj.nropreguntas.value; OP=new Array();

	 ok=0;
	for (j=1; j<=nropreguntas; j++)
	 {   
		 for (i=0;i<eval("obj.opcion"+j+".length");i++) {
				if (eval("obj.opcion"+j+"[i].checked")) {
					
					OP[ok]=eval("obj.opcion"+j+"[i].value"); ok++; 
				}
		  }		 
	 }
	 
	 if (ok!=nropreguntas){ alert("Seleccione su alternativa"); return 0;}
	 
	 cagardatos("ajax_grabar_voto.php", "capaencuesta", "votos="+OP+"&idencuesta="+idencuesta);
	 
}

function suscribir(obj)
{
	if (trim(obj.email.value)==""){ alert("Ingrese su email"); obj.email.focus(); return 0; }
	
	if ((obj.email.value.indexOf("@")==-1) || (obj.email.value.indexOf(".")==-1))
		{	
		  alert ("Ingrese correctamente su email");
		  obj.email.focus();
		  return;
		}		

	e=obj.email.value;
	email=obj.email.value;
	if(!(e.match('@')))
	   {window.alert("Email Incorrecto"); obj.email.focus(); return 0;} 	
	   
	cagardatos("ajax_suscribir.php", "capasuscripcion", "email="+email);

}

function inscribir_convocatoria(obj)//Inscribe a la convocatoria o evento
{
	if (trim(obj.email.value)==""){ alert("Ingrese su email"); obj.email.focus(); return 0; }
	
	if ((obj.email.value.indexOf("@")==-1) || (obj.email.value.indexOf(".")==-1))
		{	
		  alert ("Ingrese correctamente su email");
		  obj.email.focus();
		  return;
		}		

	e=obj.email.value;
	email=obj.email.value;
	if(!(e.match('@')))
	   {window.alert("Email Incorrecto"); obj.email.focus(); return 0;} 	
	   
	cagardatos("ajax_inscribir_convocatoria.php", "capainscripcion", "email="+email+"&idpublicacion="+obj.idpublicacion.value);	
}


function trim(S)
{
	var A = S;
	var i;
	var P1 = 1;
	var P2 = A.length;
	 
	for (i=1; i <= A.length; i++)
	{
	  if (A.charAt(i) != ' ')
	   {
		P1 = i;
		break;
	   }
	}
	 
	for (i = A.length; i >= 1; i--)
	{
	   if (A.charAt(i) != ' ')
	   {
		P2 = i;
		break;
	   }
	}
	 
	A = A.substring(P1, P2);
	 
	return A;
}

function insertar_combo(objeto) // Muestra el objeto textbox
{
  	document.getElementById("capaobj"+objeto).style.display='';
	document.getElementById("descripcion"+objeto).focus();    
}

function deshacer_insertar_combo(objeto) // Muestra el objeto textbox
{
  	document.getElementById("capaobj"+objeto).style.display='none';    
}

function grabar_inserta_combo(objeto, tabla)
{
   if(trim(document.getElementById("descripcion"+objeto).value)=="")
     { alert("Ingrese texto"); document.getElementById("descripcion"+objeto).focus(); return 0; }
   
  
  if (confirm("Esta seguro que desea grabar?"))
  {
   cagardatos("/librerias/llenar_combo.php", "capa"+objeto, "objeto="+objeto+"&tabla="+tabla+"&descripcion="+escape(document.getElementById("descripcion"+objeto).value));	 
   document.getElementById("capaobj"+objeto).style.display='none';   
   document.getElementById("descripcion"+objeto).value='';   
  }
}

// Combo en AJAX
function cagar_combo_hijo(hijo, nieto, condicion)
{
   cagardatos("/librerias/mostrar_combo_ajax.php", "capa"+hijo, "condicion="+escape(condicion)+"&tablahijo="+hijo+"&tablanieto="+nieto);	    
}


function mostrar_portada(pagina)
{
   document.getElementById("portada_direcciones").innerHTML=document.getElementById("portada_direcciones_"+pagina).innerHTML;
}


function ficha_funcionario(cod)
{
   window.open("ficha_funcionarioo.php?cod="+cod,"Ficha de Funcionario "+cod,"width=450px; height=450px");
}

function cagar_combo_provincias(coddep,nivel)
{
   cagardatos("/librerias/ajax_combo_provincias.php", "capaprovincia", "coddep="+coddep+"&nivel="+nivel);	    
}

function cagar_combo_distritos(codprov,coddep,nivel)
{
   cagardatos("/librerias/cagar_combo_distritos.php", "capadistrito", "codprov="+codprov+"&coddep="+coddep+"&nivel="+nivel);	    
}

function cagar_combo_localidad(coddep,codprov,coddist)
{
   
   cagardatos("/librerias/cagar_combo_localidad.php", "capalocalidad", "codprov="+codprov+"&coddep="+coddep+"&coddist="+coddist);	    
}

function genera_idubigeo(coddep,codprov,coddist,codccpp)
{
  cagardatos("/librerias/ajax_genera_idubigeo.php", "capaidubigeo", "codprov="+codprov+"&coddep="+coddep+"&coddist="+coddist+"&codccpp="+codccpp); 
}

function registrar_ciudadano(obj)
{
	if (trim(obj.nombres.value)==""){ alert("Ingrese su nombre completo"); obj.nombres.focus(); return 0;}
	
	if ((obj.email.value.indexOf("@")==-1) || (obj.email.value.indexOf(".")==-1))
		{	
		  alert ("Ingrese correctamente su email");
		  obj.email.focus();
		  return;
		}		

	e=obj.email.value;
	email=obj.email.value;
	if(!(e.match('@')))
	   {window.alert("Email Incorrecto"); obj.email.focus(); return 0;} 	
	   
	   
	if (trim(obj.dni.value)==""){ alert("Ingrese su DNI"); obj.dni.focus(); return 0;}
	
	if (obj.dni.value.length!=8){ alert("Ingrese su DNI correctamente"); obj.dni.focus(); return 0;}
	
	if (trim(obj.coddep.value)==""){ alert("Seleccione su Departamento"); obj.coddep.focus(); return 0;}	
	if (trim(obj.codprov.value)==""){ alert("Seleccione su Provincia"); obj.codprov.focus(); return 0;}	
	if (trim(obj.coddist.value)==""){ alert("Seleccione su Distrito"); obj.coddist.focus(); return 0;}	
	
    if (obj.codccpp.value==""){ alert("Seleccione su Centro Localidad"); obj.codccpp.focus();  return 0;}	
	
    cagardatos("grabar_ciudadano.php", "registro", "nombres="+escape(obj.nombres.value)+"&email="+obj.email.value+"&dni="+obj.dni.value+"&idubigeo="+obj.idubigeo.value);	
}


// Slider de Noticias

//$(document).ready(function() {		
//	slideShow();
//});

//function slideShow() {
//
//	//Set the opacity of all images to 0
//
//	$('#gallery a').css({opacity: 0.0});
//	//Get the first image and display it (set it to full opacity)
//
//	$('#gallery a:first').css({opacity: 1.0});
//	//Set the caption background to semi-transparent
//
//	$('#gallery .caption').css({opacity: 0.8});
//	//Resize the width of the caption according to the image width
//
//	$('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
//
//	//Get the caption of the first image from REL attribute and display it
//
//	$('#gallery .content').html($('#gallery a:first').find('img').attr('rel'))
//	.animate({opacity: 0.8}, 400);
//	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
//	setInterval('gallery()',4000);
//}



//function gallery() {
//
//	//if no IMGs have the show class, grab the first image
//	var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));
//	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
//	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));	
//	//Get next image caption
//	var caption = next.find('img').attr('rel');	
//	//Set the fade in effect for the next image, show class has higher z-index
//	next.css({opacity: 0.0})
//	.addClass('show')
//	.animate({opacity: 1.0}, 1000);
//	//Hide the current image
//	current.animate({opacity: 0.0}, 1000)
//
//	.removeClass('show');
//	//Set the opacity to 0 and height to 1px
//
//	$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
//	
//	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
//	$('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '60px'},500 );
//	
//	//Display the content
//	$('#gallery .content').html(caption);
//
//}



