// Funcions Reveex Site
// Isaac Roca - iroca at pragmapublicitat dot cat

function catFiltra(obj,id) {
	if(filtres[id]) {
		obj.src=imgDir+'icon'+id+'_off_out.png';
		jQuery(".filtreCheck").each(function() { if(this.value==id) { jQuery(this).removeAttr("checked"); } });
		filtres[id]=false;
		//desfiltra
	} else {
		obj.src=imgDir+'icon'+id+'_on_out.png';
		jQuery(".filtreCheck").each(function() { if(this.value==id) {  jQuery(this).attr("checked","checked"); } });
		filtres[id]=true;
		//filtra
	}
	catCerca(true);
}

function moverFiltre(obj,id) {
	if(filtres[id]) {
		obj.src=imgDir+'icon'+id+'_on_over.png';
	} else {
		obj.src=imgDir+'icon'+id+'_off_over.png';
	}
}


function moutFiltre(obj,id) {
	if(filtres[id]) {
		obj.src=imgDir+'icon'+id+'_on_out.png';
	} else {
		obj.src=imgDir+'icon'+id+'_off_out.png';
	}
} 

function setPag(pagina) {
	fB=document.catBusqueda;
	fB.pag.value=pagina;
	catCerca(false);
	return false;
}
	
function catCerca(resetPag) {
	var fB,pag,filtrar,filtre,tipusCerca,enfermedad,query,camps;
	
	jQuery('#resultadosCatalogo').html(carregant); 
	jQuery('#resultadosCatalogo').show();
	
	fB=document.catBusqueda;
	
	filtrar=jQuery("input[@name=filtrar]:checked").val();
	tipusCerca=jQuery("input[@name=tipusCerca]:checked").val();

	if (resetPag) {
		fB.pag.value=1;
	}
	if (tipusCerca=='avanzada') {
		strC='';
		jQuery(".tipusCercaCheck").each(function() { if(this.checked) { strC+=this.value+"-"; } });
		fB.camps.value=strC.substr(0,strC.length-1);
	}
	
	if (parseInt(filtrar)) {
		strC='';
		jQuery(".filtreCheck").each(function() { if(this.checked) { strC+=this.value+"-"; } });
		fB.filtre.value=strC.substr(0,strC.length-1);
	}
		  

	var a = {
		  pag: fB.pag.value,
		  filtrar: jQuery("input[@name=filtrar]:checked").val(),
		  filtre: fB.filtre.value,
		  tipusCerca: jQuery("input[@name=tipusCerca]:checked").val(),
		  enfermedad: fB.enfermedad[fB.enfermedad.selectedIndex].value,
		  query: fB.query.value,
		  camps: fB.camps.value  
	   };
	
	 jQuery("#resultadosCatalogo").load(wwwroot+'/'+resultadosFile,
	   a,
	   function() { isSetCatalogo=true;  }
	 );
	 return false;
}

function selectTipus(tipus) {
	//jQuery(".tipusCerca").value="";
	//jQuery(".tipusCercaCheck").each(function() { this.checked=false; });
	jQuery("input[@name=tipusCerca]").each(function() { if(this.value==tipus) {   jQuery(this).attr({checked: "checked"}); } else { jQuery(this).removeAttr("checked"); } });
	switch (tipus) {
		case 'todos':
			jQuery("#tEnfermedad").hide("fast");
			jQuery("#tAvanzada").hide("fast");
			 catCerca(true);
		break;
		case 'enfermedad':
			jQuery("#enfermedad").selectedIndex=0;
			jQuery("#tEnfermedad").show("fast");
			jQuery("#tAvanzada").hide("fast");
		break;
		case 'avanzada':
			jQuery("#tAvanzada").show("fast");
			jQuery("#tEnfermedad").hide("fast");
		break;
	} 	
}

function selectFiltre(filtre) {
	jQuery("input[@name=filtrar]").each(function() { if(this.value==filtre) {  jQuery(this).attr({checked: "checked"}); } else {  jQuery(this).removeAttr("checked"); } });
	if (filtre) {
		jQuery("#fEspecie").show("fast");
	} else {
		jQuery("#fEspecie").hide("fast");		
	}
	catCerca(true);
}

function getProducto(id) {
		jQuery.ajax({ 
					type: "GET", 
					url: wwwroot+'/'+detalleFile, 
					data: 'producto='+id, 
					success:  function(o) {
							jQuery("#catProd").hide();
							jQuery("#detalleProducto").html(o); 
							jQuery("#detalleProducto").show(); 
						}
					});
		 return false;
	}
function backProducto() {
		if (isSetCatalogo) {
			jQuery("#catProd").show();
			jQuery("#detalleProducto").hide();
		} else {
			document.location=backURL;
		}
		return false;
	}		
	
/* agricultura */

function catCercaAgr(resetPag) {
	var fB,pag,filtrar,filtre,tipusCerca,enfermedad,query,camps;
	
	jQuery('#resultadosCatalogo').html(carregant); 
	jQuery('#resultadosCatalogo').show();
	
	fB=document.catBusquedaAgr;
	
	tipusCerca=jQuery("input[@name=tipusCerca]:checked").val();

	if (resetPag) {
		fB.pag.value=1;
	}
	if (tipusCerca=='avanzada') {
		strC='';
		jQuery(".tipusCercaCheck").each(function() { if(this.checked) { strC+=this.value+"-"; } });
		fB.camps.value=strC.substr(0,strC.length-1);
	}		  

	var a = {
		  pag: fB.pag.value,
		  tipusCerca: jQuery("input[@name=tipusCerca]:checked").val(),
		  cultivo: fB.cultivo[fB.cultivo.selectedIndex].value,
		  query: fB.query.value,
		  camps: fB.camps.value  
	   };
	
	 jQuery("#resultadosCatalogo").load(wwwroot+resultadosFile,
	   a,
	   function() { isSetCatalogo=true;  }
	 );
	 return false;
}


function selectTipusAgr(tipus) {
	//jQuery(".tipusCerca").value="";
	//jQuery(".tipusCercaCheck").each(function() { this.checked=false; });
	jQuery("input[@name=tipusCerca]").each(function() { 
			if(this.value==tipus) {   
				jQuery(this).attr({checked: "checked"}); 
			} else { 
				jQuery(this).removeAttr("checked"); 
			}
		});
	
	switch (tipus) {
		case 'todos':
			jQuery("#tCultivo").hide("fast");
			jQuery("#tAvanzada").hide("fast");
			 catCercaAgr(true);
		break;
		case 'cultivo':
			jQuery("#cultivo").selectedIndex=0;
			jQuery("#tCultivo").show("fast");
			jQuery("#tAvanzada").hide("fast");
		break;
		case 'avanzada':
			jQuery("#tAvanzada").show("fast");
			jQuery("#tCultivo").hide("fast");
		break;
	} 	
}


var hasPrevious;

function openProdAgr(o) {
	hasPrevious=true;
	jQuery("#contingut").attr("id","contingutTemp");
	jQuery("#contingutTemp").before('<div id="contingut"></div>');
	jQuery("#contingut").html(o);
}

function closeProdAgr() {
	if (hasPrevious) {
		jQuery("#contingut").remove();
		jQuery("#contingutTemp").attr("id","contingut");
	} else {
		history.go(-1);
	}
	hasPrevious=false;
	return false;
}

function getProductoAgricola(id) {
	jQuery.ajax({ 
				type: "GET", 
				url: wwwroot+'/php/detalleAgricola.php', 
				data: 'producto='+id, 
				success:  function(o) {
						openProdAgr(o);
					}
		});
	return false;
}

function enviarInfoPremezcla(id) {
	fP=jQuery('form#'+id).get()[0];
	fP.envFrm.disabled=true;
	qs="";
	qs+='nombre='+fP.nombre.value;
	qs+='&empresa='+fP.empresa.value;
	qs+='&email='+fP.email.value;
	qs+='&telefono='+fP.telefono.value;
	qs+='&producto='+fP.producto.value;
	qs+='&comentario='+fP.comentario.value;
	jQuery.ajax({ 
				type: "POST", 
				url: wwwroot+'/php/enviarMailPremezcla.php', 
				data: qs,
				success:  function(o) {
						resp=o.split("|");
						if (resp[1].length) alert(resp[1]);
						if (parseInt(resp[0])) {
							fP.reset();	
							jQuery('form#'+id).hide();
						}
						fP.envFrm.disabled=false;
					}
	});
	
}

function afegirProducteButlleti(id,id_producto,taula) {
	var qs = "id="+id+"&id_producto="+id_producto+"&taula="+taula;	
	jQuery.ajax({ 
			type: "POST", 
			url: wwwroot+'/php/afegirProducteButlleti.php', 
			data: qs,
			success:  function(o) {
				jQuery('#taula_'+taula).html(o);
			}
	});
}

function eliminarProducteButlleti(id,id_producto,taula) {
	var qs = "id="+id+"&id_producto="+id_producto+"&taula="+taula;	
	jQuery.ajax({ 
			type: "POST", 
			url: wwwroot+'/php/eliminarProducteButlleti.php', 
			data: qs,
			success:  function(o) {
				jQuery('#taula_'+taula).html(o);
			}
	});
	
}

function obreFormPremezcla(codi) {
	jQuery(".contactarPremezcla").hide();
	jQuery("#"+codi).each(function () {
			if (jQuery(this).css("display")=="none") {
				jQuery(this).show("slow");
			} else {
				jQuery(this).hide("fast");
			}
	});
}

function altaNL(eml) {
	jQuery.ajax({
		type: "POST",
		url: wwwroot+'/php/alta_subscripcion.php',
		data: 'eml='+eml,
		success: function (o) {
			if (o.length) {
				alert(o);
			}
		}
	});
	return false;
}


FnLoad.push({ 
	sec:'localizacion',
	fn: function () {
		if (GBrowserIsCompatible()) {        
			/*var lloc = new GClientGeocoder();
			lloc.getLatLng('carrer canyelles 3, tarragona',function (punt){*/
				var map = new GMap2(document.getElementById("map"));  
				map.addControl(new GLargeMapControl());        
				map.addControl(new GMapTypeControl());
				map.setCenter(new GLatLng(10.236799, -67.619262), 17);
				//map.setCenter(punt,17);
				var marker = new GMarker(new GLatLng(10.236799, -67.619262));
				map.addOverlay(marker);
				map.setMapType(G_HYBRID_MAP);
				marker.openInfoWindowHtml("<strong>GRUPO REVEEX</strong><br>Av. Antón Phillips, cruce con calle El Canal<br>Complejo Industrial Reveex, Zona Industrial La Hamaca<br><br>Tel. +58-243-551,54,32 /64,03/68,52/69,76<br>Fax. +58-243-551,68,53");
				jQuery("a.gmnoprint").attr("target","_blank");     
			//});
			/*var map = new GMap2(document.getElementById("map"));
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
        	map.setCenter(new GLatLng(10.236799, -67.619262), 17);*/
		}
	}
	
	
});

FnLoad.push({ 
	sec:'catalogo',
	fn: function () {
		//	include('/js/catalogo.js');
		//  for (i=0;i<filtres.length;i++) filtres[i]=false;
		
	}
});

FnLoad.push({ 
	sec:'pequenos',
	fn: function () {
		//	include('/js/catalogo.js');
		//  for (i=0;i<filtres.length;i++) filtres[i]=false;
	}
});


FnLoad.push({ 
	sec:'labExportacion',
	fn: function () {
		//	include('/js/catalogo.js');
		//  for (i=0;i<filtres.length;i++) filtres[i]=false;
		   var so2 = new SWFObject("/swf/reveex_exportacion.swf", "cabecera", "600", "232", "8", "#FFFFFF");
		   so2.useExpressInstall('/swf/expressinstall.swf');
		   so2.addParam("wmode", "transparent");
		   so2.write("mapaExportacion");
	}
});

var includedGaleriaJS=false;
FnLoad.push({ 
	sec:'galeria',
	fn: function () {
		//	include('/js/catalogo.js');
		//  for (i=0;i<filtres.length;i++) filtres[i]=false;
		if (!includedGaleriaJS) {
			include('/js/jqGalViewII.js');
			includedGaleriaJS=true;
		} else {
	 		jQuery('ul#galeriaCanals').jqGalViewII();
		}
	}
});



/*	<script type="text/javascript">
	   var so = new SWFObject("/swf/reveex_exportacion.swf", "cabecera", "600", "232", "8", "#FFFFFF");
	   so.useExpressInstall('/swf/expressinstall.swf');
	   so.write("mapaExportacion");
	</script> */
	
var filtres=new Array();
var detalleFile='/php/detalleCatalogo.php';
var resultadosFile='/php/resultadosCatalogo.php';
var backURL='/laboratorios/especialidades';
var imgDir='/img/catalogo/';
var isSetCatalogo=false;


//Preload Images	
var prefix=new Array("aves","bovinos","caprinos","conejos","equinos","ovinos","porcinos");
var suffix=new Array("on","off");
var suffix2=new Array("over","out");
for(i=0;i<prefix.length;i++) for(j=0;j<suffix.length;j++) for(k=0;k<suffix2.length;k++)
	MM_preloadImages('/img/'+prefix[i]+'_'+suffix[j]+'_'+suffix2[k]+'.png');