$(document).ready(function(){
	
	$("img#restrange_right_side").click(function(){
			$("div#content_fara_pub").hide("slow");
			$("div#content_cu_pub").show("slow");
		});

	$("img#expandeaza_right_side").click(function(){
			$("div#content_cu_pub").hide("slow");
			$("div#content_fara_pub").show("slow");
		});


	$(".bifa_pt_compara").click(function(){
			value=this.value;
			stare=(this.checked==true)?"checked":"";
			$(".bpc_"+value).attr("checked",stare);//le atribui la ambele inputuri(cele din restrans si cele din expandat)
			if(stare=="checked"){
				nr=0;de_scos='';
				$("div.masini_selectate_restranse input").each(function(){
						if(this.value!=value){
							//alert(de_scos);
							if(this.checked==true) nr++;

							if(nr>=3){
								stare='';
								$(".bpc_"+this.value).attr("checked",stare);
							}
						}
					});
			}
		});

	$("#compara_msini_cos, #compara_masinile_selectate_restrans").click(function(){
			nr=0;
			str=base_url+'cos_masini/goto_c/comparator/index/';
			$("div.masini_selectate_restranse input").each(function(){
					if(this.checked==true) {str+='varianta/'+this.value+'/';}
				});
			window.location=str;
	});
		
});



function debifeaza(id_bifa)
{
			$("#added_"+id_bifa).attr("checked","");
			if(base_url!='')
			{
				$.post(base_url+"cos_masini/scoate_var_din_cos", //adresa la care trimit
				{ func: id_bifa},//aici pun date ce vreau sa trimit
				  function(data)
				  {
				    if(data.ok==1)
				    {
				    	p=$("#added_"+id_bifa).parent();
			    		$(p).removeClass("btn_ac_1");
			    		$(p).addClass("btn_ac_0");
				    	$("#insert_html_mare").html(data.html_mare);
				    	$("#insert_html_mic").html(data.html_mic);
				    	$("#insert_text_masini_ramase").html(data.text_masini_ramase);
				    }else alert("Nu pot sterge varianta !");
				  },
				  "json");
			}else { alert("Trebuie definit base_url !!!!!!");}
}

	function bifeaza(id,cod_pag)
	{
		$("#added_"+id).attr("checked","checked");
		if(base_url!='')
		{
			$.post(base_url+"cos_masini/add_in_cos_var",
			{ func: id, page_code: cod_pag},
			  function(data)
			  {
			    if(data.ok==1)
			    {
			    	p=$("#added_"+id).parent();
			    	if($(p).hasClass("btn_ac_0")==true)
			    	{
			    		$(p).removeClass("btn_ac_0");
			    		$(p).addClass("btn_ac_1");
			    	}else{
			    			$(p).removeClass("btn_ac_1");
			    			$(p).addClass("btn_ac_0");
			    		}

			    	$("#insert_html_mare").html(data.html_mare);
				    $("#insert_html_mic").html(data.html_mic);
			    	$("#insert_text_masini_ramase").html(data.text_masini_ramase);
			    }else alert(data.eroare);
			  },
			  "json");
		}
	}






