/*var url = "/eurocovering/";
var url_web='http://www.qualtoprojects.com/eurocovering/es/';*/

var url = "/";
var url_web='http://www.eurocovering.com/es/';

function goTo(url_){
    window.location=url_;
}

function muestraBurbuja(idBurbuja,timeOut){
    document.getElementById(idBurbuja).style.display="block";
    
    if(timeOut==true) setTimeout('escondeBurbuja(\''+idBurbuja+'\')',10000);
}

function escondeBurbuja(idBurbuja){
    document.getElementById(idBurbuja).style.display="none";
}

/*******************************************************
		Funciones AJAX
****************************************************/

function addToPedido(){
    alert("Producto a"+'\u00f1'+"adido al pedido");
}
var searching=false;
var toFind="";
var id;
function busquedaDinamica(){
    toFind=document.getElementById('inputBuscarHeader').value;
    if(toFind.length>0){
	if(searching==false){
	    id=setTimeout('searchLater(1)',300);
	    searching=true;
	}
    }else{
	if(searching){
	    clearInterval(id);
	    searching=false;
	}
	document.getElementById('matchesHolder1').innerHTML="";
    }
}
function busquedaDinamica2(){
    toFind=document.getElementById('inputBuscarPort').value;
    if(toFind.length>0){
	if(searching==false){
	    id=setTimeout('searchLater(2)',300);
	    searching=true;
	}
    }else{
	if(searching){
	    clearInterval(id);
	    searching=false;
	}
	document.getElementById('matchesHolder2').innerHTML="";
    }
}

function searchLater(num){
    searching=false;
    //alert("searching");
	$.ajax({
		url: url + "ajax.php",
		type: "GET",
		data: "pagina=busquedaDinamica&txt="+toFind,
		error: function(objeto, quepaso, otroobj){
		    alert("Error");
		},
		success: function(datos){
	    
		    document.getElementById('matchesHolder'+num).innerHTML=datos;
		    
		}
	    });
}

/*******************************************************
		Funciones AJAX Galeria Productos
****************************************************/
function seleccionaMarca(id){
    $.ajax({
	url: url + "ajax.php",
	type: "GET",
	data: "pagina=galeria_productos&action=selectMarca&id="+id,
	error: function(objeto, quepaso, otroobj){
	    alert("Error");
	},
	success: function(datos){
	    var a=datos.split('|');
	    if(a[0]!="-1") document.getElementById("marca_"+id).style.border="solid 3px #E5C7DF";
	    else document.getElementById("marca_"+id).style.border="3px solid white";
	    
	    if(a[1]!="-1" && a[1]!="") document.getElementById("marca_"+a[1]).style.border="medium none";
	    
	    document.getElementById('holderProductos').innerHTML=a[2];
	    
	    if(a[3]!="") document.getElementById('holderTags').innerHTML=a[3];
	    
	    document.getElementById("tagsSeleccionados").innerHTML="";
	    
	},
	timeout: 3000
    });
}

function seleccionaTono(id,nombre){
    
    $.ajax({
	url: url + "ajax.php",
	type: "GET",
	data: "pagina=galeria_productos&action=selectTono&id="+id,
	error: function(objeto, quepaso, otroobj){
	    alert("Error");
	},
	success: function(datos){
	    var a=datos.split('|');
	    if(a[0]!="-1") document.getElementById("tono_"+id).className="miniaturaTonoFiltro selectedTono";
	    else document.getElementById("tono_"+id).className="miniaturaTonoFiltro";
	    
	    if(a[1]!="-1" && a[1]!="") document.getElementById("tono_"+a[1]).className="miniaturaTonoFiltro";
	    
	    document.getElementById('holderProductos').innerHTML=a[2];
	    
	    if(a[3]!="") document.getElementById('holderTags').innerHTML=a[3];
	    animatedcollapse.show('holderProductos');
	    
	    document.getElementById("tagsSeleccionados").innerHTML="";
	},
	timeout: 3000
    });
}

function seleccionaTipo(id,nombre){
    
    $.ajax({
	url: url + "ajax.php",
	type: "GET",
	data: "pagina=galeria_productos&action=selectTipo&id="+id,
	error: function(objeto, quepaso, otroobj){
	    alert("Error");
	},
	success: function(datos){
	    var a=datos.split('|');
	    if(a[0]!="-1") document.getElementById("tipo_"+id).className="tipoProduct selectedProducto";
	    else document.getElementById("tipo_"+id).className="tipoProduct";
	    
	    if(a[1]!="-1" && a[1]!="") document.getElementById("tipo_"+a[1]).className="tipoProduct";
	    
	    document.getElementById('holderProductos').innerHTML=a[2];
	    
	    if(a[3]!="") document.getElementById('holderTags').innerHTML=a[3];
	    animatedcollapse.show('holderProductos');
	    
	    document.getElementById("tagsSeleccionados").innerHTML="";
	},
	timeout: 3000
    });
}

function seleccionaTag(id,nombre){
   
    $.ajax({
	url: url + "ajax.php",
	type: "GET",
	data: "pagina=galeria_productos&action=addTag&id="+id+"&nombre="+nombre,
	error: function(objeto, quepaso, otroobj){
	    alert("Error");
	},
	success: function(datos){
	   
	    document.getElementById("tagsSeleccionados").innerHTML+="<div class=\"imgSelectedTagLeft\"></div><div id=\"tagD_"+id+"\" onmouseout=\"escondeBurbuja('tE"+id+"')\" onmouseover=\"muestraBurbuja('tE"+id+"',false)\" onclick=\"eliminaTag("+id+",'"+nombre+"')\" class=\"tagSeleccionado\">"+nombre+"<div class=\"burbujaTag\" style=\"margin-top:-40px\" id=\"tE"+id+"\">Quitar Filtro</div></div><div class=\"imgSelectedTagRight\"></div>";
	    var a=datos.split('|');
	    
	    document.getElementById('holderProductos').innerHTML=a[0];
	    
	     document.getElementById('holderTags').innerHTML=a[1];
	     animatedcollapse.show('holderProductos');
	},
	timeout: 3000
    });
}

function eliminaTag(id,nombre){
    $.ajax({
	url: url + "ajax.php",
	type: "GET",
	data: "pagina=galeria_productos&action=removeTag&id="+id+"&nombre="+nombre,
	error: function(objeto, quepaso, otroobj){
	    alert("Error");
	},
	success: function(datos){
	    var a=datos.split('|');
	    document.getElementById("tagsSeleccionados").innerHTML=a[0];
	    
	    document.getElementById('holderProductos').innerHTML=a[1];
	    
	    if(a[2]!="") document.getElementById('holderTags').innerHTML=a[2];
	    
	},
	timeout: 3000
    });
}

function descolapsaFiltros(){
    $.ajax({
	url: url + "ajax.php",
	type: "GET",
	data: "pagina=galeria_productos&action=clearFilters",
	error: function(objeto, quepaso, otroobj){
	    alert("Error");
	},
	success: function(datos){
	    var a=datos.split('|');
	    document.getElementById("tagsSeleccionados").innerHTML="";
	    document.getElementById('holderProductos').innerHTML="";
	    document.getElementById('holderTags').innerHTML=a[0];
	    
	    if(a[1]!='-1') document.getElementById("marca_"+a[1]).style.background="#E5E5E5";
	    if(a[2]!='-1') document.getElementById("tipo_"+a[2]).className="tipoProduct";
	    if(a[3]!='-1') document.getElementById("tono_"+a[3]).className="miniaturaTonoFiltro";
	    
	    
	},
	timeout: 3000
    });
}

/*******************************************************
		Funciones AJAX Galeria Marcas
****************************************************/


function seleccionaTonoMarcas(id,nombre){
    
    $.ajax({
	url: url + "ajax.php",
	type: "GET",
	data: "pagina=galeria_marcas&action=selectTono&id="+id,
	error: function(objeto, quepaso, otroobj){
	    alert("Error");
	},
	success: function(datos){
	    var a=datos.split('|');
	    if(a[0]!="-1") document.getElementById("tono_"+id).className="miniaturaTonoFiltro selectedTono";
	    else document.getElementById("tono_"+id).className="miniaturaTonoFiltro";
	    
	    if(a[1]!="-1" && a[1]!="") document.getElementById("tono_"+a[1]).className="miniaturaTonoFiltro";
	    
	    document.getElementById('holderProductos').innerHTML=a[2];
	    
	    if(a[3]!="") document.getElementById('holderTags').innerHTML=a[3];
	    
	    document.getElementById("tagsSeleccionados").innerHTML="";
	    
	},
	timeout: 3000
    });
}

function seleccionaTipoMarcas(id,nombre){
    
    $.ajax({
	url: url + "ajax.php",
	type: "GET",
	data: "pagina=galeria_marcas&action=selectTipo&id="+id,
	error: function(objeto, quepaso, otroobj){
	    alert("Error");
	},
	success: function(datos){
	    var a=datos.split('|');
	    if(a[0]!="-1") document.getElementById("tipo_"+id).className="tipoProduct selectedProducto";
	    else document.getElementById("tipo_"+id).className="tipoProduct";
	    
	    if(a[1]!="-1" && a[1]!="") document.getElementById("tipo_"+a[1]).className="tipoProduct";
	    
	    document.getElementById('holderProductos').innerHTML=a[2];
	    
	    if(a[3]!="") document.getElementById('holderTags').innerHTML=a[3];
	    
	    document.getElementById("tagsSeleccionados").innerHTML="";
	    
	},
	timeout: 3000
    });
}

function seleccionaTagMarcas(id,nombre){
   
    $.ajax({
	url: url + "ajax.php",
	type: "GET",
	data: "pagina=galeria_marcas&action=addTag&id="+id+"&nombre="+nombre,
	error: function(objeto, quepaso, otroobj){
	    alert("Error");
	},
	success: function(datos){
	   
	    document.getElementById("tagsSeleccionados").innerHTML+="<div class=\"imgSelectedTagLeft\"></div><div id=\"tagD_"+id+"\" onmouseout=\"escondeBurbuja('tE"+id+"')\" onmouseover=\"muestraBurbuja('tE"+id+"',false)\" onclick=\"eliminaTag("+id+",'"+nombre+"')\" class=\"tagSeleccionado\">"+nombre+"</div><div class=\"imgSelectedTagRight\"></div><div class=\"burbujaTag\" id=\"tE"+id+"\">Quitar Filtro</div>";
	    var a=datos.split('|');
	    
	    document.getElementById('holderProductos').innerHTML=a[0];
	    
	     document.getElementById('holderTags').innerHTML=a[1];
	    
	},
	timeout: 3000
    });
}

function eliminaTagMarcas(id,nombre){
    $.ajax({
	url: url + "ajax.php",
	type: "GET",
	data: "pagina=galeria_marcas&action=removeTag&id="+id+"&nombre="+nombre,
	error: function(objeto, quepaso, otroobj){
	    alert("Error");
	},
	success: function(datos){
	    var a=datos.split('|');
	    document.getElementById("tagsSeleccionados").innerHTML=a[0];
	    
	    document.getElementById('holderProductos').innerHTML=a[1];
	    
	    if(a[2]!="") document.getElementById('holderTags').innerHTML=a[2];
	    
	},
	timeout: 3000
    });
}

/****************pagina codigo postal**********/
function submitMarca(id){
    var cp=document.getElementById('cntBody_TextBox1').value;
   
	if(cp!="" && cp.length==5 ){
	$.ajax({
	    url: url + "ajax.php",
	    type: "GET",
	    data: "pagina=distribuidores&cp="+cp,
	    error: function(objeto, quepaso, otroobj){
		alert("Error");
	    },
	    success: function(datos){
		window.location=url_web +"mapa_distribuidores-"+id+".html";
		
	    }
	});
    }else{
	alert("Debes introducir un codigo postal valido para continuar");
	
    }
}

function submitMarca2(id,num){
    var cp=document.getElementById('cntBody_TextBox'+num).value;
	if(cp!="" && cp.length==5 ){
	$.ajax({
	    url: url + "ajax.php",
	    type: "GET",
	    data: "pagina=distribuidores&cp="+cp,
	    error: function(objeto, quepaso, otroobj){
		alert("Error");
	    },
	    success: function(datos){
		window.location=url_web +"mapa_distribuidores-"+id+".html";
		
	    }
	});
    }else{
	alert("Debes introducir un codigo postal valido para continuar");
	
    }
}
/*********************Aņadir a favoritos***************/

var added=new Array();
function addToFav(idProducto){
    var ok=true;
    for (var x=0; x<added.length; x++){
	if(added[x]==idProducto) ok=false;
    }
    if(ok){
	$.ajax({
		url: url + "ajax.php",
		type: "GET",
		data: "pagina=addToFav&id="+idProducto,
		error: function(objeto, quepaso, otroobj){
		    alert("Error");
		},
		success: function(datos){
		    
		    alert("Producto a"+'\u00f1'+"adido a Favoritos");
		    document.getElementById('numFavoritosHead').innerHTML=datos;
		    document.getElementById('favIcon_'+idProducto).className="favNovRecActive";
		    added[added.length]=idProducto;
		
		    muestraBurbuja('burbujaFav',true);
		}
	});
    }else{
	//alert("ande vas");
    }
}
/*********************Paginacion*********************/
function goToPage(page){
    var divs=document.getElementById('numPags').value;
    //alert('paging_'+divs);
    for(var i=0;i<divs;i++){
	if(i==page-1){
	    
	    document.getElementById('p_'+i).style.display="block";
	   
	    document.getElementById('pButton1_'+(i+1)).style.cssText = "background:#E5C7DF;font-weight:bold;margin-top: -5px;padding-top: 10px";
	    document.getElementById('pButton2_'+(i+1)).style.cssText = "background:#E5C7DF;font-weight:bold;margin-top: -5px;padding-top: 10px";
	    
	    
	    
	    
	}
	else{
	    document.getElementById('p_'+i).style.display="none";
	    
	    document.getElementById('pButton1_'+(i+1)).style.cssText = "";
	    document.getElementById('pButton2_'+(i+1)).style.cssText="";
	    
	}
    }
}

function nextPage(num_paginas){
    var divs=document.getElementById('numPags').value;
    
    for(var i=0;i<divs;i++){
	if(document.getElementById('p_'+i).style.display=="block"){
	    document.getElementById('p_'+i).style.display="none";
	    document.getElementById('p_'+(i+1)).style.display="block";
	    document.getElementById('pButton1_'+(i+1)).style.cssText = "";
	    document.getElementById('pButton2_'+(i+1)).style.cssText="";
	    document.getElementById('pButton1_'+(i+2)).style.cssText = "background:#E5C7DF;font-weight:bold;margin-top: -5px;padding-top: 10px";
	    document.getElementById('pButton2_'+(i+2)).style.cssText = "background:#E5C7DF;font-weight:bold;margin-top: -5px;padding-top: 10px";
	    
	    return;
	}
	
    }
}


