/*********************************************
NECESITA JQUERY
**********************************************/
function xajax_myFunction(var_){
	return null;	
}

//Parsea el JSON devuelvo por search_autoCompleter.php para localidades
function parseLocalidades(data){
	var map = $.map(eval(data), function(row) {
									return { data: row, value: row.id, result: row.localidad }
								}
					);
	return map;
 }

//Formatea el item de una localidad de modo que queda
//el nombre de la localidad en el 1er renglon, 
//y el partido y provincia en el 2do.
 function formatItemLocalidad(data, i, total) {
	var depto = data.depto;
	if (depto == data.localidad)
		depto = "";
	else depto += ", ";
	
	return  data.localidad + "<br>" + 
		"<small>" + depto + data.provincia + "</small>";
 }
 
 function hideUnhideCategories(visible,invi01,invi02)
 { 
 	document.getElementById("categoria-"+visible).style.display=""; 
 	document.getElementById("categoria-"+invi01).style.display="none";
 	document.getElementById("categoria-"+invi02).style.display="none";
 }
 
 function hideUnhideElementById(Id)
 { 
 	var elem = document.getElementById(Id);
 	if (elem.style.display == "none")
	{
			elem.style.display = "";
	}
	else
	{
			elem.style.display = "none";
	}		
 	
 }
 
 function changeHeightById(id_ol)
 {
	var elem = document.getElementById(id_ol);
	var number = id_ol.substring(id_ol.length-1,id_ol.length);
	
	var intHeight =  600;
	if(number==2){		
		intHeight = 300;
	}else if(number==3){		
		intHeight = 320;
	}	
	elem.style.height = intHeight+'px';
	var liitems=document.getElementById(id_ol).childNodes;
	for (var i=0; i<liitems.length; i++)
	{
		 if (liitems[i].nodeType === 1) {			
	 		liitems[i].style.height = intHeight+'px';
	 	 }
	 }	
	reajustFooter2();		

 }
 
 function reajustFooter2()
 {	 	 
	 var imch = $('#main_col').height();
	 var extraSpace = 200;
	 var j = $(".iner_containertable").height();	 
	 $(".iner_containertable").css("margin-bottom",Math.abs(imch-j+extraSpace)+"px");
 } 
 function reajustFooter()
 {
	 var h = $(document).height();
	 var j = $(".iner_containertable").height();
	 $(".iner_containertable").css("margin-bottom",Math.abs(h-j+10)+"px");
 }
 /*
  * Esta funcion de javascript sirve para los paquetes de avisos que dinamicamente pueden setear la cantidad a comprar
  * */
 function addAviso(addCant,subfijo)
 {
 	var currentPrice = document.getElementById('price_'+subfijo).value;
 	var currentCant = document.getElementById('cantidad_'+subfijo).value;
 	var moneda = document.getElementById('currenci_'+subfijo).value;
 	currentCant = parseInt(currentCant)+parseInt(addCant);
 	if(parseInt(currentCant)==0) return;
 	currentPrice = parseFloat(parseFloat(currentPrice)*parseInt(currentCant));

 	document.getElementById('displayPrice_'+subfijo).innerHTML = moneda+' '+currentPrice+'.00';
 	document.getElementById('cantidad_'+subfijo).value=currentCant;

 }

 function suscribeToNewsletter(){
		
		var trans = 0;
		var agro =  0;
		var vial =  0;
		var grua =  0;
		var serv =  0;
		if($('#nw_trans').attr("checked")) trans = 1;
		if($('#nw_agro').attr("checked"))  agro =  1;
		if($('#nw_vial').attr("checked"))  vial =  1;
		if($('#nw_grua').attr("checked"))  grua =  1;
		if($('#nw_serv').attr("checked"))  serv =  1;
		
		var email = $('#nw_email').val();
		
		var params = '?email='+email+'&trans='+trans+'&agro='+agro+'&vial='+vial+'&grua='+grua+'&serv='+serv;		
		jQuery.get("newsletter_subscribe.php"+params,{},function(data){
				alert(data);		
		});
}
 
 function unsuscribeToNewsletter(){
	 
	 	var email = $('#nw_des_email').val();		
		var params = '?email='+email+'&des=1';		
		jQuery.get("newsletter_subscribe.php"+params,{},function(data){
				alert(data);		
		});
 }
 /******* funciones Javascript para el formulario de contacto a un vendedor *********/
 
 function closePopUpContactoVendedor(){
		$("#popup_contacto_vendedor").fadeOut('slow'); 
		 if($.browser.msie && $.browser.version=="6.0"){
				showAllForms();
		 }
		 $("#popup_contacto_vendedor").css("height","285px");
	}
 
 //"promotion_id": Campo optativo, si es distintio de 0 o null indica que se cargue un archivo de constantes: promocion.php
 //de donde se sacaran datos especificos para el formulario de contacto. Textos distintos para el email, etc..
 function showPopUpContactoVendedor(ad_id,user_id,promotion_id){
	 	
	 	var w = $(this).width(); 
	 	var h = $(this).height();
	 	var extraParameter_url = ''; 
	 	w = (w/2) - 360; 
	 	h = 520;
	  	$("#popup_contacto_vendedor").css("left",w + "px"); 
	  	//$("#popup_contacto_vendedor").css("top",h + "px");
	 
	  	
		 if($.browser.msie && $.browser.version=="6.0"){
				hideAllForms();
		 }
		 if(promotion_id != null && promotion_id != '' && promotion_id != 0){
			 extraParameter_url = '&promotion_id='+promotion_id;
		 }
		 jQuery.get("formulario_contacto.php?ad_id="+ad_id+"&user_id="+user_id+"&step=1"+extraParameter_url,{},function(data){
				jQuery("#inner_contacto_vendedor").html(data);			
		 });
		 window.scroll(0,0);
		 $("#popup_contacto_vendedor").fadeIn('slow');
}
 

function sendDataContactoVendedor(){
	 	
	 var p_name 	  =  jQuery("#contacto_vendedor_name").val();
	 var p_email      =  jQuery("#contacto_vendedor_email").val();
	 var p_phone 	  =  jQuery("#contacto_vendedor_name_tel_car").val()+' '+jQuery("#contacto_vendedor_name_tel_num").val();
	 var p_comments   =  jQuery("#contacto_vendedor_comments").val();
	 var p_code 	  = '';
	 var p_mainType   =  jQuery("#contacto_vendedor_mainType").val();
	 var p_user_id    =  jQuery("#contacto_vendedor_user_id").val();
	 var p_ad_id      =  jQuery("#contacto_vendedor_ad_id").val();
	 var p_promotion_id        =	 jQuery("#promotion_id").val();

	 $.ajax({
		    type: "POST",
		    url: "formulario_contacto.php",
		    data: {'name': p_name, 'email': p_email, 'phone': p_phone, 'comments': p_comments, 'code': p_code, 'user_id': p_user_id, 'step': '2', 'ad_id': p_ad_id, 'mainType': p_mainType, 'promotion_id': p_promotion_id},
		    success: function(info) {
		 		jQuery("#inner_contacto_vendedor").html(info);
		    },
		    error: function (XMLHttpRequest, textStatus, errorThrown) {
		        alert("No fue posible recuperar los datos del vendedor");
		    }
		});
}

