/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var cambiar_maximo = function(){
    var _variables = document.getElementById("variables").value;
    var _cambio = document.getElementById("maximo").value;
    window.location.href='busquedas.php?'+_variables+_cambio;
}
var contarSeleccion = function(){
	var cont = 0;
	if (YAHOO.util.Cookie.get("clasificado1", Number==null)){cont++;}
	if (YAHOO.util.Cookie.get("clasificado2", Number==null)){cont++;}
	if (YAHOO.util.Cookie.get("clasificado3", Number==null)){cont++;}
	if (YAHOO.util.Cookie.get("clasificado4", Number==null)){cont++;}
	if (cont>0){
		document.getElementById("btnLimpiar").src="assets/busquedas/btnLimpiar2.png"
		document.getElementById("btnComparar").src="assets/busquedas/btnComparar2.png"
	}else{
		document.getElementById("btnLimpiar").src="assets/busquedas/btnLimpiar.png"
		document.getElementById("btnComparar").src="assets/busquedas/btnComparar.png"
	}
	document.getElementById("selComparar").innerHTML = "<span>" + cont + "</span> Veh&iacute;culos Seleccionados";
}

var checarComparar = function(op){
	var cookie1 = YAHOO.util.Cookie.get("clasificado1", Number);
	var cookie2 = YAHOO.util.Cookie.get("clasificado2", Number);
	var cookie3 = YAHOO.util.Cookie.get("clasificado3", Number);
	var cookie4 = YAHOO.util.Cookie.get("clasificado4", Number);
	//alert(cookie1)
	if(document.getElementById(op).checked){
		//alert("si");
		if (cookie1==null){
			YAHOO.util.Cookie.set("clasificado1", op);
		}else{
			if (cookie2 == null){
				YAHOO.util.Cookie.set("clasificado2", op);
			}else{
				if (cookie3 == null){
					YAHOO.util.Cookie.set("clasificado3", op);
				}else{
					if (cookie4 == null){
						YAHOO.util.Cookie.set("clasificado4", op);
					}else{
						alert("No se puede seleccionar mas");
						document.getElementById(op).checked = false;
					}
				}
			}
		}
	}else{
		if (cookie1==op){
			YAHOO.util.Cookie.remove("clasificado1");
		}else{
			if (cookie2==op){
				YAHOO.util.Cookie.remove("clasificado2");
			}else{
				if (cookie3==op){
					YAHOO.util.Cookie.remove("clasificado3");
				}else{
					if (cookie4 == op) {
						YAHOO.util.Cookie.remove("clasificado4");
					}
				}
			}
		}
		//alert("no");
	}
	contarSeleccion();
}

var comparar = function(){
	var cookie1 = YAHOO.util.Cookie.get("clasificado1", Number);
	var cookie2 = YAHOO.util.Cookie.get("clasificado2", Number);
	var cookie3 = YAHOO.util.Cookie.get("clasificado3", Number);
	var cookie4 = YAHOO.util.Cookie.get("clasificado4", Number);
	var cont = 0;
	if (cookie1){cont++;}else{cookie1="";}
	if (cookie2){cont++;}else{cookie2="";}
	if (cookie3){cont++;}else{cookie3="";}
	if (cookie4){cont++;}else{cookie4="";}
	if (cont>=2){
		//alert("en mantenimiento, disculpe las molestias")
                window.location.href = "comparar.php?ide1="+cookie1+"&ide2="+cookie2+"&ide3="+cookie3+"&ide4="+cookie4;
	}else{
		alert("Debe seleccionar al menos 2 vehiculos..")
	}
}

var borrarSeleccion = function(){
	//alert("entro")
	var cookie1 = YAHOO.util.Cookie.get("clasificado1", Number);
	var cookie2 = YAHOO.util.Cookie.get("clasificado2", Number);
	var cookie3 = YAHOO.util.Cookie.get("clasificado3", Number);
	var cookie4 = YAHOO.util.Cookie.get("clasificado4", Number);
	if (cookie1 == null){

	}else{
		if (document.getElementById(cookie1)){
			document.getElementById(cookie1).checked = false;
		}
		YAHOO.util.Cookie.remove("clasificado1");
	}
	if (cookie2 == null){

	}else{
		if (document.getElementById(cookie2)){
			document.getElementById(cookie2).checked = false;
		}
		YAHOO.util.Cookie.remove("clasificado2");
	}
	if (cookie3 == null){

	}else{
		if (document.getElementById(cookie3)){
			document.getElementById(cookie3).checked = false;
		}
		YAHOO.util.Cookie.remove("clasificado3");
	}
	if (cookie4 == null){

	}else{
		if (document.getElementById(cookie4)){
			document.getElementById(cookie4).checked = false;
		}
		YAHOO.util.Cookie.remove("clasificado4");
	}
	contarSeleccion();
}
var cambiar_ano = function(opcion){
    var total_anos=new Array();
    var contador = 0;
    for (var i=opcion;i<2011;i++){
        total_anos[contador]=i;
        contador++;
    }
    var campo = document.getElementById("txt_ano2");
    campo.length = 0;
    for(var j=0;j<total_anos.length;j++){
        campo.options[j] = new Option(total_anos[j],total_anos[j]);
    }
}
var actualizar_ano = function(){
    var ano1 = document.getElementById("txt_ano1").value;
    var ano2 = document.getElementById("txt_ano2").value;
    if (ano2){
        var estilo = document.getElementById("var_estilo").value;
        var marca = document.getElementById("var_marca").value;
        var modelo = document.getElementById("var_modelo").value;
        var p1 = document.getElementById("var_p1").value;
        var p2 = document.getElementById("var_p2").value;
        var t = document.getElementById("var_t").value;
        var max = document.getElementById("var_max").value;
        var d = document.getElementById("var_d").value;
        window.location.href='busquedas.php?estilo='+estilo+'&marca='+marca+'&modelo='+modelo+'&a1='+ano1+'&a2='+ano2+'&p1='+p1+'&p2='+p2+'&t='+t+'&p=1&max='+max+'&d='+d;
    }else{
        alert("Favor de seleccionar un año, gracias")
    }
}
var actualizar_precio = function(){
    var precio1 = document.getElementById("txt_precio1").value;
    var precio2 = document.getElementById("txt_precio2").value;
    if (precio2){
        if (precio2>=precio1){
        	var estilo = document.getElementById("var_estilo").value;
            var marca = document.getElementById("var_marca").value;
            var modelo = document.getElementById("var_modelo").value;
            var a1 = document.getElementById("var_a1").value;
            var a2 = document.getElementById("var_a2").value;
            var t = document.getElementById("var_t").value;
            var max = document.getElementById("var_max").value;
            var d = document.getElementById("var_d").value;
            window.location.href='busquedas.php?estilo='+estilo+'&marca='+marca+'&modelo='+modelo+'&a1='+a1+'&a2='+a2+'&p1='+precio1+'&p2='+precio2+'&t='+t+'&p=1&max='+max+'&d='+d;
        }else{
        	alert("El segundo precio tiene que ser menor que el primero, gracias")
        }
    }else{
        alert("Favor de seleccionar un precio, gracias")
    }
}
