var peticion = false;
var  testPasado = false;
try {
  peticion = new XMLHttpRequest();
  } catch (trymicrosoft) {
  try {
  peticion = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
  try {
  peticion = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (failed) {
  peticion = false;
  }
  }
}

function cargar(url,element_id){
	
	var element =  document.getElementById(element_id);
	
	var fragment_url = url;
	
    peticion.open("GET", fragment_url);
    peticion.onreadystatechange = function() {

	    if (peticion.readyState == 4) {
		element.innerHTML = peticion.responseText;
	    }
   }
   peticion.send(null);
}
  
function cargarMensaje(url,element_id,email,keyword,website,frecuencia){

    var element =  document.getElementById(element_id);

    var fragment_url = url+'?email='+email+'&keyword='+keyword+'&website='+website+'&frecuencia='+frecuencia;

    element.innerHTML = '<img src="/images/carga.gif"/ style="padding-top:10px;">';

    peticion.open("GET", fragment_url);
    peticion.onreadystatechange = function() {

	    if (peticion.readyState == 4) {
		element.innerHTML = peticion.responseText;
	    }
   }
   peticion.send(null);
}

function cargarCombo (url, tipo, comboAnterior,par, element_id,cambiaheight) {
    var element =  document.getElementById(element_id);
    var valordepende = document.getElementById(comboAnterior)
    var x = valordepende.value
    if(cambiaheight){
    	document.getElementById('busca_azul_2').style.height = '80px';

    }
    var fragment_url = url+'?tipo='+tipo+'&col='+par+'&valor_col='+x+'&cargado=1';

    element.innerHTML = '<img src="/images/cargador.gif"/ style="padding-top:10px;">';

    peticion.open("GET", fragment_url);
    peticion.onreadystatechange = function() {

	    if (peticion.readyState == 4) {
		element.innerHTML = peticion.responseText;
	    }
   }
   peticion.send(null);
}

function cargarMedio (url, tipo, comboAnterior,par, element_id) {
    var element =  document.getElementById(element_id);
    var valordepende = document.getElementById(comboAnterior)
    var x = valordepende.value
    var fragment_url = url+'?tipo='+tipo+'&col='+par+'&valor_col='+x;

    element.innerHTML = '<img src="/images/cargador.gif"/ style="padding-top:10px;">';

    peticion.open("GET", fragment_url);
    peticion.onreadystatechange = function() {

	    if (peticion.readyState == 4) {
		element.innerHTML = peticion.responseText;
	    }
   }
   peticion.send(null);
}

function cargarFoto (url, tipo, comboAnterior,par, element_id) {
    var element =  document.getElementById(element_id);
    var x = valordepende.value
    var fragment_url = document.getElementById(comboAnterior);

    element.innerHTML = '<img src="/images/cargador.gif"/ style="padding-top:10px;">';

    peticion.open("FILE", url);
    peticion.onreadystatechange = function() {

	    if (peticion.readyState == 4) {
		element.innerHTML = peticion.responseText;
	    }
   }
   peticion.send(null);
}

function cargarBuscador (url, element_id,sec,subsec,microsec,q,prov,loc,min,max,id_tipo,home) {

    var element =  document.getElementById(element_id);

    element.innerHTML = 'Cargando <img src="/images/cargador.gif"/ style="padding-top:10px;">';
    
    if(!min){
    	min = "";
    }
    
    if(!max){
    	max = "";
    }
    
    if(!home){
    	home = "";
    }


    
    var fragment_url = url+'?sec='+sec+'&subsec='+subsec+'&microsec='+microsec+'&q='+q+'&prov='+prov+'&loc='+loc+'&min='+min+'&max='+max+'&id_tipo='+id_tipo+'&home='+home;

    peticion.open("GET", fragment_url);
    peticion.onreadystatechange = function() {

	    if (peticion.readyState == 4) {
		element.innerHTML = peticion.responseText;
		 document.getElementById('b').focus();
	    }
   }
   peticion.send(null);


}

function listafotos(url,id,anuncio_id,element_id,tipo){
    var element =  document.getElementById(element_id);

    element.innerHTML = 'Cargando <img src="/images/cargador.gif"/ style="padding-top:10px;">';

    var fragment_url = url+'?id='+id+'&anuncio_id='+anuncio_id+'&tipo='+tipo;

    peticion.open("GET", fragment_url);
    peticion.onreadystatechange = function() {

	    if (peticion.readyState == 4) {
		element.innerHTML = peticion.responseText;
	    }
   }
   peticion.send(null);
}

var sobre=0;
var varCapa;
var ant;
var timeOut;
var delayTime = 600;

function actualiza(orden,sentido){
	document.getElementById('orden').value = orden;
	document.getElementById('sentido').value = sentido;
	document.getElementById('frm_actualiza').submit();
}


function seguro(){
var ok = confirm("El artículo ya lo has vendido o lo quieres borrar?");
	if(ok==true){
		return true
	}else{
		return false
	}
}

function ordena(valor){

	if(valor=='precio_asc'){
		valor = 'precio';
		direccion = "asc";
	}else if(valor=='precio_desc'){
		valor = 'precio';
		direccion = "desc";
	}else if(valor=='fecha_alta'){
		valor = 'fecha_alta';
		direccion = "asc";
	}

	document.getElementById('ord_valor').value = valor;
	document.getElementById('ord_direccion').value = direccion;
	document.getElementById('frm_ordena').submit();

}

function solo_fotos(valor){

	if(valor=='precio_asc'){
		valor = 'precio';
	}else if(valor=='precio_desc'){
		valor = 'precio';
	}

	document.getElementById('ord_valor').value = valor;
	document.getElementById('frm_fotos').submit();

}

function muestraTipo(valor){

	document.getElementById('listado_tipo').value = valor;
	document.getElementById('frm_muestra').submit();

}

function anadirfav(url,nombre){
//Para internet explorer
if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
var url=url; //Cambia esta dirección por la de tu web
var titulo=nombre; //Cambia esta nombre por el de tu web
window.external.AddFavorite(url,titulo);
}
//Para Netscape y Firefox
else {
if(navigator.appName == "Netscape")
alert ("Presione Crtl+D para agregar a este sitio en sus Bookmarks");  //Puedes personalizar este mensaje
}
}