
function validateGetValueOf(o) {
	var value="";
	if(typeof(o)=="object") {
		switch(o.type) {
			case "select":
            var i=o.options.SelectedIndex;
            value=(i!=-1) ? o.options[i].value : "";
            break;
            
			case "checkbox":
			case "radio":
            case "input":
            case "textarea":
            case "file":
            default:
            return o.value;
		}
	}
	return value;
}

/* Quand est-ce que microsoft supportera le DOM corectement ? */
function hasAttribute(attribute) {
	var has=this.getAttribute(attribute);
    return (has==null) ? false : true;
}

function validate(hidealert) {
    var str = "";
    var min_reqs=max_reqs=null;
	if(!document.getElementsByTagName) {
        alert("Sorry! Your browser does not support the W3C HTML DOM!");
        return false;
	}

    var forms = document.getElementsByTagName('form');
	for(var f=0; f<forms.length;f++) {
		var e=forms[f].elements;
		for(var i = 0; i < e.length; i++) {
        	if(!e[i].hasAttribute) e[i].hasAttribute=hasAttribute;
            if(!e[i].hasAttribute('pattern')) continue;
            
            var pattern = new RegExp(e[i].getAttribute('pattern'));
            var value = validateGetValueOf(e[i]);
            
            if (pattern != '/null/') {
				var offendingChar = value.match(pattern);
                if(offendingChar == null) {
                	str+= (e[i].hasAttribute('errorMsg')) ?
	                	e[i].getAttribute('errorMsg') + "\n" :
	    	            "Parse error in form ! --"+e[i].name+"\n";
        	        
        	        e[i].setAttribute('class','inputError');
            	    continue;
				}
                
                min_reqs = (e[i].hasAttribute('min')) ? e[i].getAttribute('min') : "";
                max_reqs = (e[i].hasAttribute('max')) ? e[i].getAttribute('max') : "";
				if(typeof(e[min_reqs])=="object")
                	min_reqs=validateGetValueOf(e[min_reqs]);
				if(typeof(e[max_reqs])=="object")
                	min_reqs=validateGetValueOf(e[max_reqs]);
				if(min_reqs!="") min_reqs=parseFloat(min_reqs);
				if(max_reqs!="") max_reqs=parseFloat(max_reqs);
                //str+="["+min_reqs+"]["+value+"]["+max_reqs+"]\n";
				if ((min_reqs!="" && value < min_reqs) || (max_reqs!="" && value > max_reqs)) {
					str+= (e[i].hasAttribute('MinMaxerrorMsg')) ?
                    	e[i].getAttribute('MinMaxerrorMsg') + "\n" :
                        "Parse error in form : "+e[i].name +": "+min_reqs+"<="+value+"<="+max_reqs+"\n";
					
					e[i].setAttribute('class','inputError');
				}
			}
		}
    }
    if (str != "" && str!=null) {
		if (hidealert == 1) {
			return false;
		} else {
        	alert(str);
        	return false;
		}
    } else {

        return true;
    }
}


function printit(){
	window.print();
}
	
function Ver_NotaLegal(){
	var nota_legal = document.getElementById("nota_legal")
	
   	if(nota_legal.style.display == "block"){
       	nota_legal.style.display = "none";
       	
    }else{
   	    nota_legal.style.display = "block";
    }
}

function pu(){
	window.open( "", "d", "width=800 ,height=400, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, copyhistory=no, resizable=no");
	if(document.form1.id.value == "") {
		var parametros;
		parametros=document.form1.provincia.value;
		parametros=parametros + '@' + document.form1.poblacion.value;
		parametros=parametros + '@' + document.form1.concesionario.value;
		parametros=parametros + '@' + document.form1.carburante.value;
		parametros=parametros + '@' + document.form1.marca.value;
		parametros=parametros + '@' + document.form1.modelo.value;
		parametros=parametros + '@' + document.form1.version.value;
		parametros=parametros + '@' + document.form1.matriculacion.value;
		parametros=parametros + '@' + document.form1.kilometraje.value;
		parametros=parametros + '@' + document.form1.pminimo.value;
		parametros=parametros + '@' + document.form1.pmaximo.value;
		document.form1.id.value = parametros;
	}
	
	document.form1.submit();
}
	
function Cambio(sCombo,sId) {
	if (sId==""){
		return false;
	}
	else{
		if(sCombo=="pminimo"){
			if (parseInt(document.form1.pminimo.value)>parseInt(document.form1.pmaximo.value)){
				alert("El Precio mínimo no puede ser superior al precio máximo");
				return false;
			}
		}

		if(sCombo=="pmaximo"){
			if (parseInt(document.form1.pmaximo.value)<parseInt(document.form1.pminimo.value)){
				alert("El Precio máximo no puede ser inferior al precio mínimo");
				return false;
			}
		}				if (sCombo == 'marca')		{			modelSelect();		}				if (sCombo == 'modelo')		{			versionSelect();		}
			var parametros;		
		
		parametros=document.form1.provincia.value;
		parametros=parametros + '@' + document.form1.poblacion.value;
		parametros=parametros + '@' + document.form1.concesionario.value;
		parametros=parametros + '@' + document.form1.carburante.value;
		parametros=parametros + '@' + document.form1.marca.value;
		parametros=parametros + '@' + document.form1.modelo.value;
		parametros=parametros + '@' + document.form1.version.value;
		parametros=parametros + '@' + document.form1.matriculacion.value;
		parametros=parametros + '@' + document.form1.kilometraje.value;
		parametros=parametros + '@' + document.form1.pminimo.value;
		parametros=parametros + '@' + document.form1.pmaximo.value;
		document.form1.id.value = parametros;
	}
}

function  BusAvan() {
	var parametros;
		
	parametros=document.form1.provincia.value;
	parametros=parametros + '@' + document.form1.poblacion.value;
	parametros=parametros + '@' + document.form1.concesionario.value;
	parametros=parametros + '@' + document.form1.carburante.value;
	parametros=parametros + '@' + document.form1.marca.value;
	parametros=parametros + '@' + document.form1.modelo.value;
	parametros=parametros + '@' + document.form1.version.value;
	parametros=parametros + '@' + document.form1.matriculacion.value;
	parametros=parametros + '@' + document.form1.kilometraje.value;
	parametros=parametros + '@' + document.form1.pminimo.value;
	parametros=parametros + '@' + document.form1.pmaximo.value;
	document.form1.id.value = parametros;
}

function simple_hide(id_div) {
	var obj_div = document.getElementById(id_div);
	obj_div.style.display = "none";
}

function simple_show(id_div) {
	var obj_div = document.getElementById(id_div);
	obj_div.style.display = "block";
}

function show_div(id_div) {
	var default_div = document.getElementById('serv_default');
	var obj_div = document.getElementById(id_div);
	default_div.style.display = "none";
	obj_div.style.display = "block";
}

function hide_div(id_div) {
	var default_div = document.getElementById('serv_default');
	var obj_div = document.getElementById(id_div);
	default_div.style.display = "block";
	obj_div.style.display = "none";
}

function muestra_descripcion(tipo) {
	switch(tipo){
		case 0:
		capa = document.getElementById("descripcion_vn");
		capa.style.display = "none";
		capa = document.getElementById("descripcion_pr");
		capa.style.display = "none";
		capa = document.getElementById("descripcion_mr");
		capa.style.display = "block";
		break;
		case 1:
		capa = document.getElementById("descripcion_mr");
		capa.style.display = "none";
		capa = document.getElementById("descripcion_pr");
		capa.style.display = "none";
		capa = document.getElementById("descripcion_vn");
		capa.style.display = "block";
		break;
		case 2:
		capa = document.getElementById("descripcion_mr");
		capa.style.display = "none";
		capa = document.getElementById("descripcion_vn");
		capa.style.display = "none";
		capa = document.getElementById("descripcion_pr");
		capa.style.display = "block";
		break;
	}
}

function oculta_descripcion() {
	capa = document.getElementById("descripcion_vn");
	capa.style.display = "none";
	
	capa = document.getElementById("descripcion_pr");
	capa.style.display = "none";
	
	capa = document.getElementById("descripcion_mr");
	capa.style.display = "none";
}

aModeles = new Array(46);
aModeles['ALFA ROMEO'] = new Array('33','75','147','155','156','164','166','GTV','SPIDER','OTRO');
aModeles['ASTON MARTIN'] = new Array('DB7','VANQUISH','OTRO');
aModeles['AUDI'] = new Array('A2','A3','A4','A6','A8','ALLROAD','AUDI 100','AUDI 80 ','TT','OTRO');
aModeles['AUSTIN'] = new Array('METRO','OTRO');
aModeles['BENTLEY'] = new Array('ARNAGE','CONTIN.R','OTRO');
aModeles['BMW'] = new Array( '316', '318', '320','325','330','352',
								'518',
								'520',
								'525',
								'530',
								'535',
								'540',
								'730',
								'735',
								'740',
								'750',
								'760',
								'M3',
								'X5',
								'Z1',
								'Z3',
								'Z4',
								'Z8',
								'OTRO'
						);
aModeles['CADILLAC'] = new Array(
						'CTS',
								'SEVILLE',
								'OTRO'
						);
aModeles['CHEVROLET'] = new Array(
						'CORVETTE',
								'TAHOE',
								'TRAILBLAZER',
								'TRANS.SPORT',
								'OTRO'
						);
aModeles['CHRYSLER'] = new Array(
						'300M',
								'CHRYSLER SARATOGA',
								'GRAND VOYAGER',
								'LE BARON',
								'PT.CRUISER',
								'SEBRING',
								'VOYAGER',
								'OTRO'
						);
aModeles['CITROEN'] = new Array(
						'2CV',
								'AX',
								'BERLINGO',
								'BX',
								'C15',
								'C25',
								'C3',
								'C8',
								'CX',
								'DIANE',
								'EVASION',
								'GS/GSA',
								'JUMPER',
								'JUMPY',
								'PICASSO',
								'SAXO',
								'VISA',
								'XANTIA',
								'XANTIA TURBO',
								'XM',
								'XSARA',
								'ZX',
								'OTRO'
						);
aModeles['DAEWOO'] = new Array(
						'KALOS',
								'KORANDO',
								'MATIZ',
								'MUSSO',
								'REXTON',
								'REZZO',
								'OTRO'
						);
aModeles['DAIHATSU'] = new Array(
						'SIRION',
								'TERIOS',
								'YRV',
								'OTRO'
						);
aModeles['FERRARI'] = new Array(
						'360',
								'456',
								'575',
								'OTRO'
						);
aModeles['FIAT'] = new Array(
						'ARGENTA',
								'BARCHETTA',
								'BRAVA',
								'BRAVO',
								'CINQUECENTO',
								'CROMA',
								'DOBLO',
								'DUCATO',
								'MAREA W.E',
								'MULTIPLA',
								'PALIO',
								'PANDA',
								'PUNTO',
								'REGATA',
								'RITMO',
								'SEICENTO',
								'STILO',
								'TEMPRA',
								'TIPO',
								'ULYSSE',
								'UNO',
								'OTRO'
						);
aModeles['FORD'] = new Array(
						'ESCORT',
								'FIESTA',
								'FOCUS',
								'FUSION',
								'GALAXY',
								'KA',
								'MINIBUS',
								'MONDEO',
								'ORION',
								'SCORPIO',
								'SIERRA',
								'SPORTKA',
								'STREETKA',
								'TRANSIT',
								'OTRO'
						);
aModeles['HONDA'] = new Array(
						'ACCORD',
								'AERODECK',
								'CIVIC',
								'CONCERTO',
								'CR-V',
								'CRX',
								'HR-V',
								'JAZZ',
								'LEGEND',
								'PRELUDE',
								'S2000',
								'STREAM',
								'VSX',
								'OTRO'
						);
aModeles['HYUNDAI'] = new Array(
						'ACCENT',
								'ATOS.PRIME',
								'COUPE',
								'ELANTRA',
								'GETZ',
								'LANTRA',
								'MATRIX',
								'PONY',
								'SANTAFE',
								'SATELLITE',
								'SCOUPE',
								'SONATA',
								'TERRACAN',
								'TRAJET',
								'OTRO'
						);
aModeles['JAGUAR'] = new Array(
						'OTRO'
						);
aModeles['JEEP'] = new Array(
						'CHEROKEE',
								'JEEP WRANGLER',
								'OTRO'
						);
aModeles['KIA'] = new Array(
						'CARENS',
								'CARNIVAL',
								'MAGENTIS',
								'RIO',
								'SHUMA.II',
								'SORENTO',
								'SPORTAGE',
								'OTRO'
						);
aModeles['LADA'] = new Array(
						'110',
								'111',
								'112',
								'LADA 4/4',
								'LADA BREAK',
								'NIVA',
								'SAGONA',
								'SAMARA',
								'OTRO'
						);
aModeles['LANCIA'] = new Array(
						'DEDRA',
								'DELTA',
								'LYBRA',
								'PHEDRA',
								'THEMA',
								'THESIS',
								'Y',
								'Y10 EPSILON',
								'OTRO'
						);
aModeles['LAND ROVER'] = new Array(
						'DEFENDER',
								'FREELANDER',
								'RANGE',
								'DISCOVERY',
								'OTRO'
						);
aModeles['LEXUS'] = new Array(
						'OTRO'
						);
aModeles['LOTUS'] = new Array(
						'EGLISE',
								'OTRO'
						);
aModeles['MASERATI'] = new Array(
						'OTRO'
						);
aModeles['MAZDA'] = new Array(
						'2',
								'121',
								'323',
								'CLASSE 6',
								'DEMIO',
								'MPV',
								'MX3',
								'MX5',
								'MX6',
								'PREMACY',
								'TRIBUTE',
								'XEDOS',
								'OTRO'
						);
aModeles['MERCEDES'] = new Array(
						'200',
								'250',
								'280',
								'300',
								'320',
								'490',
								'500',
								'560',
								'600',
								'C',
								'CL',
								'CLASSE A',
								'CLASSE E',
								'CLK',
								'G',
								'ML',
								'S',
								'SL',
								'SLK',
								'SPRINTER',
								'V',
								'VANEO',
								'VITO',
								'OTRO'
						);
aModeles['MG'] = new Array(
						'OTRO'
						);
aModeles['MITSUBISHI'] = new Array(
						'3000 GT',
								'CARISMA',
								'COLT',
								'DISCOVERY',
								'GALANT',
								'LANCER',
								'MONTERO',
								'PAI.PININ',
								'PAJ.PININ',
								'PAJERO',
								'SPACE WAGON',
								'SPACE.STAR',
								'OTRO'
						);
aModeles['NISSAN'] = new Array(
						'200',
								'300',
								'100 NX',
								'ALMERA',
								'MAXIMA',
								'MICRA',
								'PATROL',
								'PRAIRIE',
								'PRIMERA',
								'SERENA',
								'SUNNY',
								'TERRANO',
								'X-TRAIL',
								'OTRO'
						);
aModeles['OPEL'] = new Array(
						'AGILA',
								'ASTRA',
								'COMBO',
								'CORSA',
								'FRONTERA',
								'KADETT',
								'MERIVA',
								'OMEGA',
								'SPEEDSTER',
								'TIGRA',
								'VECTRA',
								'ZAFIRA',
								'OTRO'
						);
aModeles['PEUGEOT'] = new Array(
						'106',
								'205',
								'206',
								'306',
								'307',																'308',
								'309',
								'405',
								'406',
								'505',
								'605',
								'607',
								'806',
								'807',
								'BOXER',
								'EXPERT',
								'J5',
								'PARTNER',
								'OTRO'
						);
aModeles['PORSCHE'] = new Array(
						'928',
								'930',
								'944',
								'968',
								'911 CARRERA',
								'BOXSTER',
								'CAYENNE',
								'TURBO 2',
								'OTRO'
						);
aModeles['RENAULT'] = new Array(
						'4L',
								'ALPINE',
								'AVANTIME',
								'CLIO',
								'ESPACE',
								'EXPRESS',
								'Gd ESPACE',
								'KANGOO',
								'LAGUNA',
								'MASTER',
								'MEGANE',
								'MICROBUS',
								'R11',
								'R5/SUPER5',
								'R9',
								'SAFRANE',
								'SCENIC',
								'TWINGO',
								'VELSATIS',
								'OTRO'
						);
aModeles['ROVER'] = new Array(
						'25',
								'45',
								'75',
								'111',
								'114',
								'216',
								'218',
								'414',
								'418',
								'420',
								'820',
								'825',
								'827',
								'2.0 GTD',
								'MINI',
								'MONTEGO',
								'OTRO'
						);
aModeles['SAAB'] = new Array(
						'9,3',
								'9,5',
								'900',
								'9000',
								'OTRO'
						);
aModeles['SEAT'] = new Array(
						'ALHAMBRA',
								'AROSA',
								'CORDOBA',
								'IBIZA',
								'LEON',
								'MARBELLA',
								'TERRA',
								'TOLEDO',
								'OTRO'
						);
aModeles['SKODA'] = new Array(
						'FABIA',
								'OCTAVIA',
								'SUPERB',
								'OTRO'
						);
aModeles['SMART'] = new Array(
						'SMART',
								'OTRO'
						);
aModeles['SUBARU'] = new Array(
						'FORESTER',
								'IMPREZA',
								'JUSTY',
								'LEGACY',
								'OUTBACK',
								'OTRO'
						);
aModeles['SUZUKI'] = new Array(
						'ALTO',
								'IGNIS',
								'JIMNY',
								'LIANA',
								'SAMURAI',
								'SANTANA',
								'VITARA',
								'WAGON',
								'OTRO'
						);
aModeles['TOYOTA'] = new Array(
						'AVENSIS',
								'LD CRUIS.',
								'PRIUS',
								'RAV4',
								'CARINA',
								'CELICA',
								'COROLLA',
								'COUPE MR2',
								'LITE',
								'PREVIA',
								'STARLET',
								'YARIS',
								'OTRO'
						);
aModeles['VENTURI'] = new Array(
						'VENTURI',
								'OTRO'
						);
aModeles['VOLKSWAGEN'] = new Array(
						'BEETLE',
								'BORA',
								'CADDY',
								'CARAVELLE',
								'COMBI',
								'LT28',
								'LUPO',
								'MULTIVAN',
								'PHAETON',
								'SHARAN',
								'TOUAREG',
								'TOURAN',
								'GOLF',
								'JETTA',
								'PASSAT',
								'POLO',
								'VENTO',
								'OTRO'
						);
aModeles['VOLVO'] = new Array(
						'460',
								'480',
								'850',
								'940',
								'960',
								'240/',
								'260/',
								'340/',
								'440/',
								'740/',
								'760/',
								'780/',
								'C70',
								'CROSS.COUNTRY',
								'S40',
								'S60',
								'S70',
								'S80',
								'V40',
								'V50',
								'V66',
								'V70',
								'XC.70',
								'XC.90',
								'OTRO'
						);

function fillOptions(selectedIdx, formObj, ArrayItems, SelectedValue, message1, message2)
{
	var i, j;

	// empty existing items
	for (i = formObj.options.length; i >= 0; i--)
	{
		formObj.options[i] = null;
	}

	// add new items
	if (selectedIdx != '')
	{
		formObj.options[0] = new Option(message1);
		formObj.options[0].value = '';

		j=1;
		for (i = 0; i < ArrayItems[selectedIdx].length; i++)
		{
			formObj.options[j] = new Option(ArrayItems[selectedIdx][i]);
			formObj.options[j].value = ArrayItems[selectedIdx][i];
			if ( ArrayItems[selectedIdx][i] == SelectedValue )
				formObj.options[j].selected = true;
			j++;
		}
	}else{
		formObj.options[0] = new Option(message2);
		formObj.options[0].value = '';
	}
}

 function openMap(url){
	 window.open(url,'map','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=600,height=420');
	 return false;
}

function apparition(val) {
    if (val == '1') {
        document.getElementById('contact[metodo_contacto]').style.display = 'block';
        document.getElementById('contact[email]').style.display = 'block';
        document.getElementById('contact[type]').style.display = 'none';
        document.getElementById('contact[address_1]').style.display = 'none';
        document.getElementById('contact[address_2]').style.display = 'none';
        document.getElementById('contact[address_5]').style.display = 'none';
        document.getElementById('contact[address_4]').style.display = 'none';
        document.getElementById('contact[address_3]').style.display = 'none';
        document.getElementById('contact[zip]').style.display = 'none';
		//document.getElementById('contact[country]').style.display = 'none';
        document.getElementById('contact[phone_2]').style.display = 'none';
        document.getElementById('contact[chassis]').style.display = 'none';
        document.getElementById('contact[immatriculation]').style.display = 'none';
        document.getElementById('contact[concession]').style.display = 'none';
        document.getElementById('contact_chassis').setAttribute('pattern', '');
        document.getElementById('contact_immatriculation').setAttribute('pattern', '');
        document.getElementById('contact_phone_2').setAttribute('pattern', '');
        document.getElementById('send_to').value = 'atencion.cliente2@peugeot.com';
    }
    if (val == '2') {
        document.getElementById('contact[metodo_contacto]').style.display = 'none';
        document.getElementById('contact[email]').style.display = 'block';
        document.getElementById('contact[type]').style.display = 'block';
        document.getElementById('contact[address_1]').style.display = 'block';
        document.getElementById('contact[address_2]').style.display = 'block';
        document.getElementById('contact[address_5]').style.display = 'block';
        document.getElementById('contact[address_4]').style.display = 'block';
        document.getElementById('contact[address_3]').style.display = 'block';
        document.getElementById('contact[zip]').style.display = 'block';
		//document.getElementById('contact[country]').style.display = 'block';
        document.getElementById('contact[phone_1]').style.display = 'none';
        document.getElementById('contact[phone_2]').style.display = 'block';
        document.getElementById('contact[chassis]').style.display = 'block';
        document.getElementById('contact[immatriculation]').style.display = 'block';
        document.getElementById('contact[concession]').style.display = 'block';
        document.getElementById('contact_chassis').setAttribute('pattern', '^[a-zA-Z0-9]{17}$');
        document.getElementById('contact_immatriculation').setAttribute('pattern', '^(([a-z,A-Z]{1,2}[\ ]?[0-9]{4}[\ ]?[a-z,A-Z]{1,2})|([0-9]{4}[\ ]?[a-z,A-Z]{3}))?$');
        document.getElementById('contact_phone_2').setAttribute('pattern', '^[6|9]{1}[0-9]{8}$');
        document.getElementById('send_to').value='atencion.cliente3@peugeot.com';
    }
    if (val == '') {
        document.getElementById('contact[metodo_contacto]').style.display = 'none';
        document.getElementById('contact[email]').style.display = 'none';
        document.getElementById('contact[type]').style.display = 'none';
        document.getElementById('contact[address_1]').style.display = 'none';
        document.getElementById('contact[address_2]').style.display = 'none';
        document.getElementById('contact[address_5]').style.display = 'none';
        document.getElementById('contact[address_4]').style.display = 'none';
        document.getElementById('contact[address_3]').style.display = 'none';
        document.getElementById('contact[zip]').style.display = 'none';
		//document.getElementById('contact[country]').style.display = 'none';
        document.getElementById('contact[phone_2]').style.display = 'none';
        document.getElementById('contact[chassis]').style.display = 'none';
        document.getElementById('contact[immatriculation]').style.display = 'none';
        document.getElementById('contact[concession]').style.display = 'none';
        document.getElementById('contact_chassis').setAttribute('pattern', '');
        document.getElementById('contact_immatriculation').setAttribute('pattern', '');
        document.getElementById('contact_phone_2').setAttribute('pattern', '');
    }

}

function apparition2(val) {
    if (val == '2') {
        document.getElementById('contact[phone_2]').style.display = 'block';
        document.getElementById('contact[phone_1]').style.display = 'none';
        document.getElementById('contact_phone_2').setAttribute('pattern', '^[6|9]{1}[0-9]{8}$');
    }
        else {
        document.getElementById('contact[phone_1]').style.display = 'block';
        document.getElementById('contact[phone_2]').style.display = 'none';
        document.getElementById('contact_phone_2').setAttribute('pattern', '');
    }
}
function modelSelect(){	var marca = document.getElementById('marca').options[document.getElementById('marca').selectedIndex].value;		if (marca != "")	{		while (document.getElementById('modelo').options.length > 1)			document.getElementById('modelo').options[1] = null;		if (aModeles[marca] != undefined)		{			for (i = 1; i<= aModeles[marca].length;i++)			{								document.getElementById('modelo').options[i] = new Option(aModeles[marca][i-1], aModeles[marca][i-1]);			}		} 	}}function versionSelect(){	var marca = document.getElementById('marca').options[document.getElementById('marca').selectedIndex].value;	var model = document.getElementById('modelo').options[document.getElementById('modelo').selectedIndex].value;	//alert(model);}
