function nuevoAjax()
{ 
    /* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
    lo que se puede copiar tal como esta aqui */
    var xmlhttp=false; 
    try 
    { 
        // Creacion del objeto AJAX para navegadores no IE
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
    }
    catch(e)
    { 
        try
        { 
            // Creacion del objet AJAX para IE 
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
        } 
        catch(E) { xmlhttp=false; }
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); } 

    return xmlhttp; 
}
function mostrar(div){   
var el = document.getElementById(div); //se define la variable "el" igual a nuestro div
el.style.display = (el.style.display == 'none') ? 'block' : 'none'; //damos un atributo display:none que oculta el div
}


 



function mostrarbarracategoria(div){   
	document.getElementById(div).style.display="block";
	testpopupcategoria.showPopup(div);
}
function mostrarbarraprovincia(div){   
	document.getElementById(div).style.display="block";
	testpopupprovincia.showPopup(div);
}
function mostrarbarrapais(div){   
	document.getElementById(div).style.display="block";
	testpopuppais.showPopup(div);
}

function ocultar(div){   
var el = document.getElementById(div); //se define la variable "el" igual a nuestro div
el.style.display =   'none'; //damos un atributo display:none que oculta el div
}



function buscaridpais(idpais){
 // $('#buscaridprovincia').show('fast');
 // $('#buscaridcategoria').hide('fast');
 // $('#buscaridsubcategoria').hide('fast');
	document.getElementById("buscaridcategoria").innerHTML='Categoria<br/><select name="idcategoria" id="idcategoria"  size="10" style="width:180px; font-size:11px; color:#333333;" disabled="disabled"><option value="">&laquo;&laquo; Seleccione</option></select>';
	document.getElementById("buscaridsubcategoria").innerHTML='Subcategoria<br/><select name="idsubcategoria" id="idsubcategoria"  size="10" style="width:180px; font-size:11px; color:#333333;" disabled="disabled"><option value="">&laquo;&laquo; Seleccione</option></select>';
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_buscarselectidpais.php?idpais="+idpais+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)
        	{ document.getElementById("buscaridprovincia").innerHTML=ajax.responseText; } 
    	}
    ajax.send(null); 
	}
	
function buscaridprovincia(idprovincia){
//  $('#buscaridcategoria').show('fast');
//  $('#buscaridsubcategoria').hide('fast');
	document.getElementById("buscaridsubcategoria").innerHTML='Subcategoria<br/><select name="idsubcategoria" id="idsubcategoria"  size="10" style="width:180px; font-size:11px; color:#333333;" disabled="disabled"><option value="">&laquo;&laquo; Seleccione</option></select>';
    ajax=nuevoAjax();
 
    ajax.open("GET", "/ajax_buscarselectidprovincia.php?idprovincia="+idprovincia+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)
        	{ document.getElementById("buscaridcategoria").innerHTML=ajax.responseText; } 
    	}
    ajax.send(null); 
	}
	
function buscaridcategoria(idcategoria){
 
//  $('#buscaridsubcategoria').show('fast');
    ajax=nuevoAjax();
 
    ajax.open("GET", "/ajax_buscarselectidcategoria.php?idcategoria="+idcategoria+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)
        	{ document.getElementById("buscaridsubcategoria").innerHTML=ajax.responseText; } 
    	}
    ajax.send(null); 
	}

function verprovincias(idpais){
  $('#provinciasindex').hide('fast');
  $('#provinciasindex').slideDown('fast');
//	var el = document.getElementById("provinciasindex").style.display = 'block';  
	document.getElementById("provinciasindex").innerHTML="<img src=\"/images/loading.gif\" width=\"16\" height=\"16\" />";
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_provinciaindex.php?idpais="+idpais+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)
        	{ document.getElementById("provinciasindex").innerHTML=ajax.responseText; } 
    	}
    ajax.send(null); 
	}
	
function buscarselects()
	{
	var accs=1;
	if (document.frmbuscar.idpais.value=="" & accs!=0){
		alert("Debes seleccionar un pais.");
		document.frmbuscar.idpais.focus();  
		accs=0;
		}
	 if (accs==1) { document.frmbuscar.submit(); }
	}

function vervideo(idvideo){
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_vervideo.php?idvideo="+idvideo+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)
        	{ document.getElementById("vervideo").innerHTML=ajax.responseText; } 
    	}
    ajax.send(null); 
	} 
function verimagen(idimagen){
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_verimagen.php?idimagen="+idimagen+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)
        	{ document.getElementById("verimagen").innerHTML=ajax.responseText; } 
    	}
    ajax.send(null); 
	} 
function buscasubcategoria(idcategoria){
  	document.getElementById("buscasubcategoria").innerHTML="<img src=\"/images/loading.gif\" width=\"16\" height=\"16\" />";
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_buscasubcategoria.php?idcategoria="+idcategoria+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)
        	{ document.getElementById("buscasubcategoria").innerHTML=ajax.responseText; } 
    	}
    ajax.send(null); 
	}
 
 
function buscadoridprovincia(idpais){
  	document.getElementById("buscadoridprovincia").innerHTML="<img src=\"/images/loading.gif\" width=\"16\" height=\"16\" />";
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_buscadorprovincia.php?idpais="+idpais+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)
        	{ document.getElementById("buscadoridprovincia").innerHTML=ajax.responseText; } 
    	}
    ajax.send(null); 
	}
	
function buscadoridsubcategoria(idcategoria){
	
	document.getElementById("buscadorprecio").innerHTML= "<input name=\"preciomin\" type=\"hidden\" id=\"preciomin\"><input name=\"preciomax\" type=\"hidden\" id=\"preciomax\">";
  	document.getElementById("buscadoridsubcategoria").innerHTML="<img src=\"/images/loading.gif\" width=\"16\" height=\"16\" />";
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_buscadorsubcategoria.php?idcategoria="+idcategoria+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)
        	{ document.getElementById("buscadoridsubcategoria").innerHTML=ajax.responseText; } 
    	}
    ajax.send(null); 
	}	
	
function buscadorprecio(idsubcategoria){

  	document.getElementById("buscadorprecio").innerHTML="<img src=\"/images/loading.gif\" width=\"16\" height=\"16\" />";
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_buscadorprecio.php?idsubcategoria="+idsubcategoria+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)
        	{ document.getElementById("buscadorprecio").innerHTML=ajax.responseText; } 
    	}
    ajax.send(null); 
	}	
	
function ocultarprovincias(id){
	if (document.getElementById){  
	var el = document.getElementById(id);  
	el.style.display =  'none';  
	}
}
function comprobarprecio()
{
var key=window.event.keyCode;
if (key < 48 || key > 57){
window.event.keyCode=0;
}
}
function validarbuscador(){    
var accs=1;
	if (document.formaulariobus.idpais.value=="" & accs!=0){
		alert("Debes ingresar Pais.");
		document.formaulariobus.idpais.focus();  
		accs=0;
		}
	if (document.formaulariobus.idprovincia.value=="" & accs!=0){
		alert("Debes ingresar Provincia.");
		document.formaulariobus.idprovincia.focus();  
		accs=0;
		}
	if (document.formaulariobus.idsubcategoria.value=="" & accs!=0){
		alert("Debes ingresar Subcategoria.");
		document.formaulariobus.idsubcategoria.focus();  
		accs=0;
		}
	if (document.formaulariobus.idcategoria.value=="" & accs!=0){
		alert("Debes ingresar Categoria.");
		document.formaulariobus.idcategoria.focus();  
		accs=0;
		}
	if (document.formaulariobus.idsubcategoria.value=="" & accs!=0){
		alert("Debes ingresar Subcategoria.");
		document.formaulariobus.idsubcategoria.focus();  
		accs=0;
		}
 	if (accs==1) { document.formaulariobus.submit();}
	}
	
  function popup (idanuncio,tipo,seid) {
  
var opciones="toolbar=no, statusbar=no, titlebar=no, location=no, directories=no, status=no, menubar=no,menubar=0, scrollbars=no, resizable=yes, width=670, height=400, left="+parseInt(((screen.width) / 2) - 335)+", top="+parseInt(((screen.height) / 2) - 200)+"";
var pagina= "/popup.php?idanuncio="+idanuncio+"&tipo="+tipo+"&seid="+seid+"";
  mywindows=window.open(pagina,"popup",opciones);

}

  function popupinfo (pagina) {
  
var opciones="toolbar=no, statusbar=no, titlebar=no, location=no, directories=no, status=no, menubar=no,menubar=0, scrollbars=yes, resizable=yes, width=670, height=400, left="+parseInt(((screen.width) / 2) - 335)+", top="+parseInt(((screen.height) / 2) - 200)+"";
 mywindows=window.open(pagina,"popup",opciones);

}


function popup_modificar_general () {
var opciones="toolbar=no, statusbar=no, titlebar=no, location=no, directories=no, status=no, menubar=no,menubar=0, scrollbars=no, resizable=yes, width=670, height=440, left="+parseInt(((screen.width) / 2) - 335)+", top="+parseInt(((screen.height) / 2) - 220)+"";
var pagina= "/popup_email.php";
mywindows=window.open(pagina,"popup",opciones);
}

function popup_modificar (idanuncio,seid) {
var opciones="toolbar=no, statusbar=no, titlebar=no, location=no, directories=no, status=no, menubar=no,menubar=0, scrollbars=no, resizable=yes, width=670, height=440, left="+parseInt(((screen.width) / 2) - 335)+", top="+parseInt(((screen.height) / 2) - 220)+"";
var pagina= "/popup_modificar.php?idanuncio="+idanuncio+"&seid="+seid+"";
mywindows=window.open(pagina,"popup",opciones);
}


function validateEmail(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
if(email.length <= 0)
{
return true;
}
var splitted = email.match("^(.+)@(.+)$");
if(splitted == null) return false;
if(splitted[1] != null )
{
var regexp_user=/^\"?[\w-_\.]*\"?$/;
if(splitted[1].match(regexp_user) == null) return false;
}
if(splitted[2] != null)
{
var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
if(splitted[2].match(regexp_domain) == null) 
{
var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
if(splitted[2].match(regexp_ip) == null) return false;
}// if
return true;
}
return false;
}


function cargaidprovincia(idpais)
{	
	document.getElementById("dividprovincia").innerHTML="<img src=\"/images/loading.gif\" width=\"16\" height=\"16\" />";
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_idprovincia.php?idpais="+idpais+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)
        	{ document.getElementById("dividprovincia").innerHTML=ajax.responseText; } 
    	}
    ajax.send(null); 
}
function cargaidsubcategoria(idcategoria)
{	
	document.getElementById("dividsubcategoria").innerHTML="<img src=\"/images/loading.gif\" width=\"16\" height=\"16\" />";
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_idsubcategoria.php?idcategoria="+idcategoria+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)
        	{ document.getElementById("dividsubcategoria").innerHTML=ajax.responseText; } 
    	}
    ajax.send(null);
	document.getElementById("divconprecio").innerHTML="<input name=\"precio\"   type=\"hidden\"  id=\"precio\" value=\"0\"  /><input name=\"moneda\"   type=\"hidden\"  id=\"moneda\" value=\"\"  />";

}

function cargasubcategoriaprecio(idsubcategoria)
{	
	document.getElementById("divconprecio").innerHTML="<img src=\"/images/loading.gif\" width=\"16\" height=\"16\" />";
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_cambiaprecio.php?idsubcategoria="+idsubcategoria+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)
        	{ document.getElementById("divconprecio").innerHTML=ajax.responseText; } 
    	}
    ajax.send(null);
	 

}

function comprobarprecio()
{
var key=window.event.keyCode;
if (key < 48 || key > 57){
window.event.keyCode=0;
}
    
}



function anuncio_eliminar_adm(idanuncio) {
if (confirm("Realmente desea eliminar?"))
{
	ajax=nuevoAjax();
    ajax.open("GET", "/admin/anuncio_listado.php?idanuncio="+idanuncio+"&del=yes&num_ale="+Math.random(), true);
    document.getElementById("divanuncio"+idanuncio+"").innerHTML='Eliminando...';
	ajax.onreadystatechange=function() 
    	{  
	if (ajax.readyState==4) { document.getElementById("divanuncio"+idanuncio+"").innerHTML=ajax.responseText;  }  
		}
    ajax.send(null);
	$("#divanuncio"+idanuncio+"").slideToggle("fast");
  	}
}

function imagenagregar(idanuncio,seid)
{	

var li = document.createElement("li");
// Aņadimos el valor introducido al nuevo elemento
li.innerHTML="<iframe  src=\"/iframe_imagen.php?idanuncio="+idanuncio+"&seid="+seid+"\" frameborder=\"0\" height=\"40\" width=\"500\" scrolling=\"no\"></iframe>";
var ul = document.getElementById("divlistaimagenes");
ul.appendChild(li);

 
	document.getElementById("imagencantidad").value=parseInt(document.getElementById("imagencantidad").value)+1;
}

function imageneliminar(idimagen,idanuncio,seid,mensaje)
{	
	document.getElementById("divimagen"+idimagen+"").innerHTML="<img src=\"/images/loading.gif\" width=\"16\" height=\"16\" />";
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_imageneliminar.php?idimagen="+idimagen+"&idanuncio="+idanuncio+"&seid="+seid+"&mensaje="+mensaje+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)  	{ document.getElementById("divimagen"+idimagen+"").innerHTML=ajax.responseText; } 
    	}
	if (mensaje==0) {  document.getElementById("divimagen"+idimagen+"").style.display="none"; }
    ajax.send(null); 
}

function videoagregar(idanuncio,seid)
{	

var li = document.createElement("li");
// Aņadimos el valor introducido al nuevo elemento
li.innerHTML="<iframe  src=\"/iframe_video.php?idanuncio="+idanuncio+"&seid="+seid+"\" frameborder=\"0\" height=\"40\" width=\"500\" scrolling=\"no\"></iframe>";
var ul = document.getElementById("divlistavideos");
ul.appendChild(li);

 
	document.getElementById("videocantidad").value=parseInt(document.getElementById("videocantidad").value)+1;
}


function videoeliminar(idvideo,idanuncio,seid,mensaje)
{	
	document.getElementById("divvideo"+idvideo+"").innerHTML="<img src=\"/images/loading.gif\" width=\"16\" height=\"16\" />";
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_videoeliminar.php?idvideo="+idvideo+"&idanuncio="+idanuncio+"&seid="+seid+"&mensaje="+mensaje+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)  	{ document.getElementById("divvideo"+idvideo+"").innerHTML=ajax.responseText; } 
    	}
	if (mensaje==0) {  document.getElementById("divvideo"+idvideo+"").style.display="none"; }
    ajax.send(null); 
}

 
function agregarfavorio(idanuncio)
{
	//document.getElementById("favoritoslista").style.display="block"; 
	$('#favoritoslista').slideDown('slow');
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_favorito.php?idanuncio="+idanuncio+"&add=yes&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)  	{ document.getElementById("favoritoslista").innerHTML=ajax.responseText; } 
    	}
	document.getElementById("favorito"+idanuncio+"").style.display="none"; 
	document.getElementById("favoritodel"+idanuncio+"").style.display="block"; 
	ajax.send(null); 	
}

function eliminarfavorio(idanuncio)
{
    var data=null;
	$('#favoritoslista').slideDown('slow');
	ajax=nuevoAjax();
    ajax.open("GET", "/ajax_favorito.php?idanuncio="+idanuncio+"&del=yes&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)  	{ document.getElementById("favoritoli"+idanuncio+"").innerHTML=ajax.responseText; } 
    	}
	data = document.getElementById("favorito"+idanuncio+"");
	if (data!=null)
		{ document.getElementById("favorito"+idanuncio+"").style.display="block"; }

	data = document.getElementById("favoritodel"+idanuncio+"");
	if (data !=null)		
		{ document.getElementById("favoritodel"+idanuncio+"").style.display="none"; }

	data = document.getElementById("favoritoli"+idanuncio+"");		
	if (data !=null)	
		{ document.getElementById("favoritoli"+idanuncio+"").style.display="none"; }
	ajax.send(null); 	
}



function votar(idanuncio)
	{
	document.getElementById("divvoto"+idanuncio+"").innerHTML="<img src=\"/images/loading.gif\" width=\"16\" height=\"16\" />";
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_votar.php?idanuncio="+idanuncio+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)  	{ document.getElementById("divvoto"+idanuncio+"").innerHTML=ajax.responseText; } 
    	}
	ajax.send(null); 		
	}
 
 function anuncio_eliminar(idanuncio,email,seid)
	{
	if (confirm("Realmente desea eliminar?"))
		{
		document.getElementById("divanuncio"+idanuncio+"").innerHTML="<img src=\"/images/loading.gif\" width=\"16\" height=\"16\" />";
	    ajax=nuevoAjax();
	    ajax.open("GET", "/ajax_eliminar.php?idanuncio="+idanuncio+"&email="+email+"&seid_email="+seid+"&num_ale="+Math.random(), true);
	    ajax.onreadystatechange=function() 
	    	{ 
	        if (ajax.readyState==4)  	{ document.getElementById("divanuncio"+idanuncio+"").innerHTML=ajax.responseText; } 
	    	}
		ajax.send(null); 		
	 	document.getElementById("divanuncio"+idanuncio+"").style.display="none";
		alert ('Anuncio eliminado con exito.');
		}
	}
	
 function anuncio_renovar(idanuncio,seid,email,seid_email)
	{
	if (confirm("Desea renovar su anuncio a 60 dias mas?"))
		{
		document.getElementById("divrenovar"+idanuncio+"").innerHTML="<img src=\"/images/loading.gif\" width=\"16\" height=\"16\" />";
	    ajax=nuevoAjax();
	    ajax.open("GET", "/ajax_renovar.php?idanuncio="+idanuncio+"&email="+email+"&seid="+seid+"&seid_email="+seid_email+"&num_ale="+Math.random(), true);
	    ajax.onreadystatechange=function() 
	    	{ 
	        if (ajax.readyState==4)  	{ document.getElementById("divrenovar"+idanuncio+"").innerHTML=ajax.responseText; } 
	    	}
		ajax.send(null); 		
		alert ('Anuncio renovado con exito');
		window.location.href='adm_listado.php?email='+email+'&seid_email='+seid_email+''; 
		}
	}
	
 function comentario_eliminar(idcomentario,idanuncio,seid,email,seid_email,seid_comentario)
	{
	if (confirm("Desea eliminar el mensaje seleccionado?"))
		{
		document.getElementById("divcomentario"+idcomentario+"").innerHTML="<img src=\"/images/loading.gif\" width=\"16\" height=\"16\" />";
	    ajax=nuevoAjax();
	    ajax.open("GET", "/ajax_comentario_eliminar.php?idcomentario="+idcomentario+"&idanuncio="+idanuncio+"&email="+email+"&seid="+seid+"&seid_email="+seid_email+"&seid_comentario="+seid_comentario+"&num_ale="+Math.random(), true);
	    ajax.onreadystatechange=function() 
	    	{ 
	        if (ajax.readyState==4)  	{ document.getElementById("divcomentario"+idcomentario+"").innerHTML=ajax.responseText; } 
	    	}
		ajax.send(null); 		
	 	document.getElementById("divcomentario"+idcomentario+"").style.display="none";
		}
	}
 