var peticions = false; 
var  testPasados = false; 
try { 
  peticions = new XMLHttpRequest(); 
  } catch (trymicrosoft) { 
  try { 
  peticions = new ActiveXObject("Msxml2.XMLHTTP"); 
  } catch (othermicrosoft) { 
  try { 
  peticions = new ActiveXObject("Microsoft.XMLHTTP"); 
  } catch (failed) { 
  peticions = false; 
  } 
  } 
} 
if (!peticions) 
alert("¡ERROR AL INICIALIZAR AJAX!"); 

function abrirventana(ruta, ancho, alto, barras){
	var posicion_x; 
	var posicion_y; 
	posicion_x=(screen.width/2)-(ancho/2); 
	posicion_y=(screen.height/2)-(alto/2);
	var parametros = "width="+ancho+",height="+alto+",scrollbars="+barras+",status=no,location=no,toolbar=0,left="+posicion_x+"top="+posicion_y;
	window.open(ruta,'ventana',parametros,'');
}

function cargayoutube(id, divdatos){
	var fragment_url = '/includes/ajax/apic.asp?clase=youtube&id='+id; 
	//abrimos la url 
	peticions.open("GET", fragment_url); 
	peticions.onreadystatechange = function() { 
		if (peticions.readyState == 4) { 
		//escribimos la respuesta 
		//alert(unescape(peticions.responseText)); 
			if(unescape(peticions.responseText)!=""){
				document.getElementById(divdatos).value = unescape(peticions.responseText); 
			} else {
				document.getElementById(divdatos).value = "";
			}
		} 
	} 
   peticions.send(null);
}

// Comprobamos los atributos encadenados
function compruebaplus(valor, seccion){
	if(valor!="{0};0"){
		// Comenzamos el cálculo de atributos encadenados
		var fragment_url = '/includes/ajax/apic.asp?clase=atributosplus&id='+valor; 
		//abrimos la url 
		peticions.open("GET", fragment_url); 
		peticions.onreadystatechange = function() { 
			if (peticions.readyState == 4) { 
			//escribimos la respuesta 
			//alert(unescape(peticions.responseText)); 
				if(unescape(peticions.responseText)!=""){
					document.getElementById(seccion).innerHTML = unescape(peticions.responseText); 
				} else {
					document.getElementById(seccion).innerHTML = "";
				}
			} 
		} 
	   peticions.send(null);
	} else {
		document.getElementById(seccion).innerHTML = "";
	}
}

// Esta función comprueba que se hayan seleccionado todos los atributos
function compruebatipos(errormsg){
	seleccionados = 0;
	formcomprar1 = document.getElementById("formcomprarid");
	for(i=0;i<formcomprar1.elements.length;i++) {
		var elemento = formcomprar1.elements[i];
		if(elemento.type == "radio") {
			if(elemento.checked) {
				if(elemento.value == "{0};0") {
					seleccionados += 1;
				}
			}
		}
		if(elemento.type == "select-one") {
			if(elemento.value == "{0};0") {
				seleccionados += 1;
			}
		}
	}
	
	if(seleccionados > 0) {
		alert(errormsg);
		return false;
	} else {
		return true;
	}
}

function busqueda_ajax_web(campo, idioma, tarifa){
	//Obtenemos el contenido del div 
	//donde se cargaran los resultados 
	var resultados =  document.getElementById('muestra_search_ajax'); 
	resultados.innerHTML = "<table width='400' style='background-color:#FFFFFF; border: 1px solid #999999; z-index:1;'><tr><td style='padding:8px;'><img src='/img/general/loading.gif' align='absmiddle' /> <strong>Buscando, espere...</strong></td></tr></table>"; 
	var valorsearch = document.getElementById(campo).value;
	var x = valorsearch;
	var fragment_url = '/includes/ajax/busqueda_inteligente.asp?id='+x+'&idioma='+idioma+'&tarifa='+tarifa; 
	//resultados.innerHTML = '<img src="/img/general/loading.gif" /> Cargando, espere...'; 
	//abrimos la url 
	peticions.open("GET", fragment_url); 
	peticions.onreadystatechange = function() { 
		if (peticions.readyState == 4) { 
		//escribimos la respuesta 
		resultados.innerHTML = unescape(peticions.responseText); 
		document.getElementById('muestra_search_ajax').style.display="block";
		} 
	} 
   peticions.send(null);
}

function copiarcampos()
{
	document.formregistro.flogin_contacto.value=document.formregistro.flogin_nombre.value + ' ' + document.formregistro.flogin_apellidos.value;
	document.formregistro.flogin_direccionenvio.value=document.formregistro.flogin_direccion.value;
	document.formregistro.flogin_poblacionenvio.value=document.formregistro.flogin_poblacion.value;
	document.formregistro.flogin_provinciaenvio.value=document.formregistro.flogin_provincia.value;
	document.formregistro.flogin_cpenvio.value=document.formregistro.flogin_cp.value;
	document.formregistro.flogin_telefonoenvio.value=document.formregistro.flogin_telefono.value;
	document.formregistro.flogin_paisenvio.value=document.formregistro.flogin_pais.value;
}

function validanuevadireccion(mensaje){
	if (document.formregistro.nombredireccion.value == '' || document.formregistro.flogin_contacto.value == '' || document.formregistro.flogin_direccionenvio.value == '' || document.formregistro.flogin_poblacionenvio.value == '' || document.formregistro.flogin_provinciaenvio.value == '' || document.formregistro.flogin_cpenvio.value == '' || document.formregistro.flogin_telefonoenvio.value == '' || document.formregistro.flogin_pais.value == '(0)') {
		alert(mensaje);
		return false;
	}
}

function ValidaCamposR(valores, msgerror){
	//Realiamos el bucle
	var validador = true;
	valores = valores.split("|");
	for(var i=0;i<valores.length;i++){
		if(document.getElementById(valores[i]).value==""){
			validador = false;
		}
	}
	if(validador==true){
		return true;
	} else {
		alert(msgerror);
		return false;
	}
}













