function in_array (needle, haystack, argStrict) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // +   input by: Billy
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true
    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false

    var key = '', strict = !!argStrict;

    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }

    return false;
}
	function actualizable(obj,color,fuente){
		obj.style.background=color;
		obj.style.fontWeight=fuente;
	}
	//Calcula el dc correcto para los datos introducidos
	//Ver porque deja pasar
	function CalculoCC(IentOfi,InumCta){
		var APesos = new Array(1,2,4,8,5,10,9,7,3,6); // Array de "pesos"
		DC1=0;
		DC2=0;
		x=8;
		while(x>0) {
			//digito=IentOfi[x-1]; 
			digito=IentOfi.charAt(x-1); //Enrique: Modificado para ie
			DC1=DC1+(APesos[x+2-1]*(digito));
			x = x - 1;
		}
		Resto = DC1%11;
		DC1=11-Resto;
		if (DC1==10) DC1=1;
		if (DC1==11) DC1=0;              // Dï¿½gito control Entidad-Oficina
		x=10;
		while(x>0) {
			//digito=InumCta[x-1];
			digito=InumCta.charAt(x-1); //Enrique: Modificado para ie
			DC2=DC2+(APesos[x-1]*(digito));
			x = x - 1;
		}
		Resto = DC2%11;
		DC2=11-Resto;
		if (DC2==10) DC2=1;
		if (DC2==11) DC2=0;         // Dï¿½gito Control C/C
		DigControl=DC1+""+DC2;   // los 2 nï¿½meros del D.C.
		return DigControl;
	}

	//compara el dc introducido con el calculado
	function numeros(){
		var num1=document.getElementById('codigo').value+document.getElementById('sucursal').value;
		var num2=document.getElementById('cuenta').value;
		var dc=document.getElementById('dc').value;
		var enviar=true;
		var dcc=CalculoCC(num1,num2);
		var mostrar='none';
		if(dcc!=dc){
			mostrar='block';
			enviar=false;
		}
		document.getElementById('ccc').style.display=mostrar;
		if (document.getElementById('tarjeta').checked==true) {
			enviar=true;
		}
		return enviar;
	}
	//funciï¿½n para crear un objeto ajax crossbrowser
	function nuevoAjax(){
		var xmlhttp=false;
 		try {
 			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 	} catch (e) {
 			try {
 				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	 		} catch (E) {
 				xmlhttp = false;
 			}
	  	}
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 			xmlhttp = new XMLHttpRequest();
		}
		return xmlhttp;
	}
	//funciï¿½n para rotar las ï¿½ltimas 5 noticias de rss cada 10 segundos mostrando los primeros 150 caracteres
	function rotarNoticias(id,idDestino){
		var contenedor = document.getElementById(idDestino);
		ajax=nuevoAjax();
		ajax.open("POST","cgi/privado/rss.php",true);
		ajax.send(null);
		ajax.onreadystatechange=function(){
			if (ajax.readyState==4){
				var xml = ajax.responseXML;
				var limite = xml.getElementsByTagName('item').length;
				var titulo = xml.getElementsByTagName('item')[limite-id].getElementsByTagName('title')[0].firstChild.nodeValue;
				var url = xml.getElementsByTagName('item')[limite-id].getElementsByTagName('link')[0].firstChild.nodeValue;
				var descripcion = xml.getElementsByTagName('item')[limite-id].getElementsByTagName('description')[0].firstChild.nodeValue;
				//contenedor.innerHTML = "<p class='titnoticias'>NOTICIAS</p>\n<p class='textnoticias'><span class='textnoticias'>"+titulo+"</span>"+descripcion.substr(0,150)+"...</p>\n<p class='mas'><a class='compra' href='"+url+"' onfocus='blur()' target='_self'>mï¿½s informaciï¿½n</a></p>\n";
				contenedor.innerHTML = "<p class='titnoticias'>NOTICIAS</p>\n<p class='textnoticias'><span class='textnoticias'>"+titulo+"</span>"+descripcion.substr(0,150)+"...</p>\n<p class='mas'><a class='compra' href='http://www.ada.es/publico/noticias.php?id="+(id-1)+"' onfocus='blur()' target='_self'>m&aacute;s informaci&oacute;n</a></p>\n";
				id++;
				if(id>5)
					id=1;
				setTimeout("rotarNoticias("+id+",'"+idDestino+"')",10000);
			}
		}
	}

	//funciï¿½n para cargar el html de ofertas
	function cargarOfertas(pagina,idDestino){
		ajax2=nuevoAjax();
		ajax2.open("POST",pagina,true);
		ajax2.send(null);
		ajax2.onreadystatechange=function(){
			if (ajax2.readyState==4){
				document.getElementById(idDestino).innerHTML = ajax2.responseText;
			}
		}
	}

//-----------------------------------------------
//Funciones ajax para solicitud de productos
//-----------------------------------------------	
	function cargarContenido(idOrigen,idDestino){
	var x,productos, contenedor;
	x=document.getElementById(idOrigen);
	productos = x.value;
	var prod = [1162];//Array solo tarifa
	var prod2 = [1291];//Array matricula + tarifa
	document.getElementById('nombproducto').value=x.options[x.selectedIndex].text;
	//meter un array con los productos que no necesitan datos. Hay productos con diferentes datos a mostrar. Dos tipos Usar función in_array en javascript
	if(in_array(productos,prod) == true){//oculto datos vehiculo para los productos que no lo necesitan
		ocultar('marcas');
		ocultar('modelos');
		ocultar('matriculas');
	//}else if(in_array(productos,prod2) == true){
		//ocultar('marcas');
		//ocultar('modelos');
		//mostrar('matriculas');
	}else{
		mostrar('marcas');
		mostrar('modelos');
		mostrar('matriculas');
	}
	contenedor = document.getElementById(idDestino);
	ajax=nuevoAjax();
	ajax.open("POST", "../cgi/privado/marcas.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState!=4) {
			limpiar();
			//ocultar('matriculas');
			contenedor.innerHTML = '<img src="../img/ajax-loader-peque.gif" />';
	 	}else{
			contenedor.innerHTML = ajax.responseText;
			cargarTarifa('tarifa');
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("productos="+productos);
	}
	
	function cargarContenido2(idOrigen,idDestino){
	var x,productos,marcas,contenedor;
	x=document.getElementById(idOrigen);
	marcas = x.value;
	document.getElementById('nombmarca').value=x.options[x.selectedIndex].text;
	productos = document.getElementById('producto').value;
	contenedor = document.getElementById(idDestino);
	ajax=nuevoAjax();
	ajax.open("POST", "../cgi/privado/modelos.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState!=4) {
			limpiar();
			contenedor.innerHTML = '<img src="../img/ajax-loader-peque.gif" />';
	 	}else{
			contenedor.innerHTML = ajax.responseText;
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("productos="+productos+"&marcas="+marcas);
	}
	
	function cargarContenido3(idDestino){
	var x,productos,marcas,modelos,contenedor;
	x=document.getElementById('modelo');
	productos = document.getElementById('producto').value;
	marcas = document.getElementById('marca').value;
	modelos = x.value;
	document.getElementById('nombmodelo').value=x.options[x.selectedIndex].text;;
	contenedor = document.getElementById(idDestino);
	ajax=nuevoAjax();
	ajax.open("POST", "../cgi/privado/productos.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState!=4) {
			contenedor.innerHTML = '<img src="../img/ajax-loader-peque.gif" />';
	 	}else{
			contenedor.innerHTML = ajax.responseText;
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("productos="+productos+"&marcas="+marcas+"&modelos="+modelos);
	}
	
	function cargarContenido4(idDestino){
	var contenedor;
	contenedor = document.getElementById(idDestino);
	ajax=nuevoAjax();
	ajax.open("POST", "../cgi/privado/provincias.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState!=4) {
			limpiar2();
			contenedor.innerHTML = '<img src="../img/ajax-loader-peque.gif" />';
	 	}else{
			contenedor.innerHTML = ajax.responseText;
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(null);
	}
	
	function cargarContenido5(idOrigen,idDestino){
	var x,provincias,contenedor;
	x=document.getElementById(idOrigen);
	provincias = x.value;
	document.getElementById('nombprovincia').value=x.options[x.selectedIndex].text;
	contenedor = document.getElementById(idDestino);
	ajax=nuevoAjax();
	ajax.open("POST", "../cgi/privado/poblaciones.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState!=4) {
			limpiar2();
			contenedor.innerHTML = '<img src="../img/ajax-loader-peque.gif" />';
	 	}else{
			contenedor.innerHTML = ajax.responseText;
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("provincias="+provincias);
	}
	
	function cargarContenido6(idOrigen){
		x=document.getElementById(idOrigen);
		document.getElementById('nombpoblacion').value=x.options[x.selectedIndex].text;
	}
	
	function cargarTarifa(idDestino){
	var productos,marcas,contenedor;
	productos = document.getElementById('producto').value;
	marcas = '';
	contenedor = document.getElementById(idDestino);
	ajax=nuevoAjax();
	ajax.open("POST", "../cgi/privado/productos.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState!=4) {
			contenedor.innerHTML = '<img src="../img/ajax-loader-peque.gif" />';
	 	}else{
			contenedor.innerHTML = ajax.responseText;
			cargarContenido4('provincias');
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("productos="+productos+"&marcas="+marcas);
	}


	function limpiar(){
		//document.getElementById('modelos').innerHTML='';
		//document.getElementById('matricula').value='';
		document.getElementById('modelos').innerHTML="Modelos<br /><select class='required' id='modelo' name='modelo' tabindex='3' onchange='cargarContenido3('tarifa')'><option value='' selected='selected'>Seleccione un modelo</option></select>";
		document.getElementById('tarifa').innerHTML="<span class='tarifa'>Tarifa Anual</span>";
	}
	function limpiar2(){
//		document.getElementById('poblacion').value='';
		document.getElementById('poblaciones').innerHTML="Localidad<br /><select class='required' id='poblacion' name='poblacion' tabindex='13' onchange='cargarContenido6(this.id)'><option value='' selected='selected'>Seleccione una localidad</option></select>";
		document.getElementById('cp').value='';
	}

	function ocultar(capa){
		document.getElementById(capa).style.display="none";
		//document.getElementById(capa).style.visibility="hidden";
	}
	
	function mostrar(capa){
		document.getElementById(capa).style.display="block";
		//document.getElementById(capa).style.visibility="visible";
	}
	function mostrarocultar(sw,id){
		if(sw==id)
			mostrar(id);
		else
			ocultar(id);
	}
//-------------------------------------
//-------------------------------------
//mapa ADA
	function cambiar(img,id){
		document.getElementById(img).src="../img/mapa"+id+".gif";
	}
	function cargaCentros(prov){
		var provincia, contenedor;
		contenedor = document.getElementById('centrosada');
		ajax=nuevoAjax();
		ajax.open("POST", "../cgi/privado/mapa.php",true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState!=4) {
				contenedor.innerHTML = '<img src="../img/ajax-loader-peque.gif" />';
		 	}else{
				contenedor.innerHTML = ajax.responseText;
				document.getElementById('centrosada').disabled='';
				cargaEstablecimientos(prov);
			}
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("provincia="+prov+"&tipo=1");
	}
	function cargaEstablecimientos(prov){
		var provincia, contenedor;
		contenedor = document.getElementById('centrosestablecimientos');
		ajax=nuevoAjax();
		ajax.open("POST", "../cgi/privado/mapa.php",true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState!=4) {
				contenedor.innerHTML = '<img src="../img/ajax-loader-peque.gif" />';
		 	}else{
				contenedor.innerHTML = ajax.responseText;
				document.getElementById('centrosestablecimientos').disabled='';
				cargaAutoescuelas(prov);
			}
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("provincia="+prov+"&tipo=2");
	}
	function cargaAutoescuelas(prov){
		var provincia, contenedor;
		contenedor = document.getElementById('centrosautoescuelas');
		ajax=nuevoAjax();
		ajax.open("POST", "../cgi/privado/mapa.php",true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState!=4) {
				contenedor.innerHTML = '<img src="../img/ajax-loader-peque.gif" />';
		 	}else{
				contenedor.innerHTML = ajax.responseText;
				document.getElementById('centrosautoescuelas').disabled='';
			}
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("provincia="+prov+"&tipo=3");
	}
	function cargaMapa(prov){
		document.getElementById('contieneficha').innerHTML = '';
		document.getElementById('titcentros').innerHTML = prov;
		cargaCentros(prov);
	}
	function cargarFicha(idOrigen,id){
		var provincia, contenedor;
		contenedor = document.getElementById('contieneficha');
		ajax=nuevoAjax();
		ajax.open("POST", "../cgi/privado/ficha.php",true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState!=4) {
				contenedor.innerHTML = '<img src="../img/ajax-loader-peque.gif" />';
		 	}else{
				contenedor.innerHTML = ajax.responseText;
			}
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("id="+id+"&tipo="+idOrigen);
	}
	
	function cargarContenido7(idOrigen,idDestino){
	var provincias,contenedor;
	provincias=document.getElementById(idOrigen).value;
	contenedor = document.getElementById(idDestino);
	ajax=nuevoAjax();
	ajax.open("POST", "../cgi/privado/poblaciones2.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState!=4) {
			contenedor.innerHTML = '<img src="../img/ajax-loader-peque.gif" />';
	 	}else{
			contenedor.innerHTML = ajax.responseText;
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("provincias="+provincias);
	}
	
	function cargarContenido8(idOrigen,idDestino){
	var marcas,contenedor;
	marcas = document.getElementById(idOrigen).value;
	contenedor = document.getElementById(idDestino);
	ajax=nuevoAjax();
	ajax.open("POST", "../cgi/privado/modelos2.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState!=4) {
			contenedor.innerHTML = '<img src="../img/ajax-loader-peque.gif" />';
	 	}else{
			contenedor.innerHTML = ajax.responseText;
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("&marcas="+marcas);
	}
	
	function copiar(idOrigen,idDestino){
		x=document.getElementById(idOrigen);
		document.getElementById(idDestino).value=x.options[x.selectedIndex].text;
	}
	//----------------------------------------------
	//funciones ajax para modificar en parte privada
	//----------------------------------------------
	function cargarPoblaciones(valor_prov_ant,valor_local_ant,obj,idDestino,numsocio,id){
	var contenedor;
	contenedor = document.getElementById(idDestino);
	ajax=nuevoAjax();
	ajax.open("POST", "poblacion.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState!=4) {
			contenedor.innerHTML = '<img class="ajax" src="../../img/ajax-loader-peque.gif" />';
	 	}else{
			contenedor.innerHTML = ajax.responseText;
			modificar(valor_prov_ant,obj,numsocio,id);
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("id="+obj.value+"&numsocio="+numsocio+"&valor_local_ant="+valor_local_ant);
	}
	
	function cargarModelos(valor_marc_ant,valor_mod_ant,obj,idDestino,numsocio,id){
	var contenedor;
	contenedor = document.getElementById(idDestino);
	ajax=nuevoAjax();
	ajax.open("POST", "modelo.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState!=4) {
			contenedor.innerHTML = '<img class="ajax" src="../../img/ajax-loader-peque.gif" />';
	 	}else{
			contenedor.innerHTML = ajax.responseText;
			modificar(valor_marc_ant,obj,numsocio,id);
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("id="+obj.value+"&numsocio="+numsocio+"&valor_mod_ant="+valor_mod_ant);
	}

	function modificar(valor_ant,obj,numsocio,id){
	var campo,valor,contenedor;
	contenedor=document.getElementById(id);
	contenedor.style.display='block';
	campo=obj.id;
	if(campo=='fecha_nacimiento')
		valor=obj.value+" 0:00:00";
	else
		valor=obj.value;
	ajax=nuevoAjax();
	ajax.open("POST", "modificar.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState!=4) {
			contenedor.innerHTML = '<img class="ajax" src="../../img/ajax-loader-peque.gif" />';
	 	}else{
			actualizable(obj,'#02CE53','bold');
			contenedor.innerHTML='datos actualizados';
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("campo="+campo+"&valor="+valor+"&numsocio="+numsocio+"&valor_ant="+valor_ant);
	}
	
	function modificarcc(campo,valor,numsocio,contenedor){
	ajax=nuevoAjax();
	ajax.open("POST", "modificar.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState!=4) {
			contenedor.innerHTML = '<img class="ajax" src="../../img/ajax-loader-peque.gif" />';
	 	}else{
			actualizable(contenedor,'transparent','bold');
			contenedor.innerHTML='Número de cuenta actualizado';
			contenedor.style.display='block';
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("campo="+campo+"&valor="+valor+"&numsocio="+numsocio);
	}
	
	//compara el dc introducido con el calculado
	function comparardc(numsocio,id){
		var contenedor=document.getElementById(id);
		var num1=document.getElementById('cod_banco');
		var num2=document.getElementById('cod_sucursal');
		var num3=document.getElementById('dig_control');
		var num4=document.getElementById('num_cuenta');
		var suma=num1.value+num2.value;
		var dcc=CalculoCC(suma,num4.value);
		var mostrar='none';
		if(dcc!=num3.value){
			contenedor.innerHTML='N&uacute;mero de cuenta inv&aacute;lido.';
			mostrar='block';
		}else{
			for(i=1;i<5;i++){
				modificarcc(eval('num'+i+'.id'),eval('num'+i+'.value'),numsocio,contenedor);
			}
		}
			contenedor.style.display=mostrar;
	}
	//-----------------------------
	//-----------------------------
	//------------------------------------------
	//Funciones ajax para tarificador de seguros
	//------------------------------------------
	function cargarMarcasSoap(id){
	var contenedor,cadena,xml;
	contenedor=document.getElementById(id);
	ajax=nuevoAjax();
	ajax.open("POST", "../cgi/privado/classes/xml/serviautos.php",true);
	ajax.onreadystatechange=function(){
		if (ajax.readyState!=4) {
			contenedor.innerHTML = '<img class="ajax" src="../../img/ajax-loader-peque.gif" />';
	 	}else{
			cadena="Marca<br />\n<select id='MARCA' name='MARCA' tabindex='36' onchange='cargarModelosSoap(this.value,\"modelos\")'>\n<option value='' selected='selected'>Seleccione una marca</option>\n";
			xml=ajax.responseXML;
			var root=xml.getElementsByTagName("MARCA");
			for(i=0;i<root.length;i++){
				cadena+="<option value='"+root[i].firstChild.nodeValue+"'>"+root[i].firstChild.nodeValue+"</option>\n";
			}
			cadena+="\n</select>";
			contenedor.innerHTML=cadena;
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("peticion=M");
	}
	
	function cargarModelosSoap(valor,id){
	var contenedor,cadena,xml;
	contenedor=document.getElementById(id);
	ajax=nuevoAjax();
	ajax.open("POST", "../cgi/privado/classes/xml/serviautos.php",true);
	ajax.onreadystatechange=function(){
		if (ajax.readyState!=4) {
			contenedor.innerHTML = '<img class="ajax" src="../../img/ajax-loader-peque.gif" />';
	 	}else{
			cadena="Modelo<br />\n<select id='MODELO' name='MODELO' tabindex='37' onchange='cargarVersionesSoap(this.value,\"MARCA\",\"versiones\")'>\n<option value='' selected='selected'>Seleccione un modelo</option>\n";
			xml=ajax.responseXML;
			var root=xml.getElementsByTagName("MODELO");
			for(i=0;i<root.length;i++){
				cadena+="<option value='"+root[i].firstChild.nodeValue+"'>"+root[i].firstChild.nodeValue+"</option>\n";
			}
			cadena+="\n</select>";
			contenedor.innerHTML=cadena;
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("peticion=MO&marca="+valor);
	}
	
	function cargarVersionesSoap(valor1,id_valor2,id){
	var contenedor,cadena,xml;
	valor2=document.getElementById(id_valor2).value;
	contenedor=document.getElementById(id);
	ajax=nuevoAjax();
	ajax.open("POST", "../cgi/privado/classes/xml/serviautos.php",true);
	ajax.onreadystatechange=function(){
		if (ajax.readyState!=4) {
			contenedor.innerHTML = '<img class="ajax" src="../../img/ajax-loader-peque.gif" />';
	 	}else{
			cadena="Versiones<br />\n<select id='BASE7' name='BASE7' tabindex='38' onchange='cargarAccesoriosSoap(this.value,\"accesorios\")'>\n<option value='' selected='selected'>Seleccione una versi&oacute;n</option>\n";
			xml=ajax.responseXML;
			var raiz=xml.getElementsByTagName("VERSION");
			for(i=0;i<raiz.length;i++){
				base7=raiz[i].getElementsByTagName("CLAVE")[0].firstChild.nodeValue;
				tipo=raiz[i].getElementsByTagName("TIPO")[0].firstChild.nodeValue;
				if(raiz[i].childNodes[3].hasChildNodes()){//Si el NOMBRE no está vacío
					nom_version=raiz[i].getElementsByTagName("NOMBRE")[0].firstChild.nodeValue;
				}else{
					nom_version=raiz[i].getElementsByTagName("POTENCIA")[0].firstChild.nodeValue+" CV";
				}
				cadena+="<option value='"+base7+"#"+tipo+"'>"+nom_version+"</option>\n";
			}
			cadena+="\n</select>";
			contenedor.innerHTML=cadena;
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("peticion=V&modelo="+valor1+"&marca="+valor2);
	}
	
	function cargarAccesoriosSoap(valor,id){
	var contenedor,cadena,xml;
	contenedor=document.getElementById(id);
	ajax=nuevoAjax();
	ajax.open("POST", "../cgi/privado/classes/xml/serviautos.php",true);
	ajax.onreadystatechange=function(){
		if (ajax.readyState!=4) {
			contenedor.innerHTML = '<img class="ajax" src="../../img/ajax-loader-peque.gif" />';
	 	}else{
			cadena="Accesorios<br />\n<select id=\"accesorio\" name=\"accesorio\" tabindex=\"39\" onchange=\"anadir(this.value,'accesoriosselect')\">\n<option value='' selected='selected'>Seleccione los accesorios</option>\n";
			xml=ajax.responseXML;
			var raiz=xml.getElementsByTagName("ACCESORIO");
			for(i=0;i<raiz.length;i++){
				if(raiz.length > 1){//Si devuelve accesorios
					oppack=raiz[i].getElementsByTagName("OPPACK")[0].firstChild.nodeValue;
					descripcion=raiz[i].getElementsByTagName("DESCRIP")[0].firstChild.nodeValue;
					precio=raiz[i].getElementsByTagName("PVP")[0].firstChild.nodeValue;
					cadena+="<option value='"+oppack+"#"+descripcion+"#"+precio+"'>"+descripcion+"</option>\n";
				}
			}
			cadena+="\n</select>";
			contenedor.innerHTML=cadena;
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("peticion=AC&base7="+valor.substr(0,11));
	}
	var contador=0;
	function anadir(valor,id){
		var valores,contenedor,cont;
		valores=valor.split("#");
		contenedor=document.getElementById(id);
		cont=contador+1;
		contador=cont;
		newDIV = contenedor.appendChild(document.createElement("div"));
        newDIV.setAttribute("class","fila");
        newDIV.setAttribute("id","fila"+cont);
		newINPUT = newDIV.appendChild(document.createElement("input"));
        newINPUT.setAttribute("type","text");
        //newINPUT.setAttribute("class","accesor");
        newINPUT.setAttribute("id","DESCRIPCION"+cont);
        newINPUT.setAttribute("name","DESCRIPCION"+cont);
        newINPUT.setAttribute("value",valores[1]);
        document.getElementById('DESCRIPCION'+cont+'').className='accesor';
		newINPUT = newDIV.appendChild(document.createElement("a"));
        newINPUT.setAttribute("href","#accesoriosselect");
        newINPUT.setAttribute('id','a'+cont+'');
        document.getElementById('a'+cont+'').onclick = function(){borrar("accesoriosselect",'fila'+cont+''); };
        //newINPUT.setAttribute("onclick","borrar('accesoriosselect','fila"+cont+"')");
		newIMG = newINPUT.appendChild(document.createElement("img"));
        newIMG.setAttribute("src","../img/borrar.jpg");
        newIMG.setAttribute("alt","borrar");
        newIMG.setAttribute("title","borrar");
		newINPUT = newDIV.appendChild(document.createElement("input"));
        newINPUT.setAttribute("type","text");
        newINPUT.setAttribute("id","CODIGOACCESORIO"+cont);
        newINPUT.setAttribute("name","CODIGOACCESORIO"+cont);
        newINPUT.setAttribute("value",valores[0]);
        document.getElementById('CODIGOACCESORIO'+cont+'').style.visibility = 'hidden';
		newINPUT = newDIV.appendChild(document.createElement("input"));
        newINPUT.setAttribute("type","text");
        newINPUT.setAttribute("id","VALOR"+cont);
        newINPUT.setAttribute("name","VALOR"+cont);
        newINPUT.setAttribute("value",valores[2]);
        document.getElementById('VALOR'+cont+'').style.visibility = 'hidden';	
	}
	
	function borrar(padre,id){
		var nodo=document.getElementById(id);
		document.getElementById(padre).removeChild(nodo);
	}
