function valida_login(){
	if (document.form_login.usuario.value == ''){
		alert ("Por favor, Rellene el campo login.");
	} else {
		if (document.form_login.contrasenia.value == ''){
			alert ("Por favor, Rellene el campo password.");
		} else {
			document.form_login.submit();
			document.form_login.usuario.value = '';
			document.form_login.contrasenia.value = '';
		}
	}
}

var myConn_carga_destacados = new XHConn();
var fin_carga_destacados = function (oXML) { document.getElementById('div_destacados').innerHTML = oXML.responseText;};
function carga_destacados(){
	cargando_destacados = '<table width="794" height="240" border="0" align="center" cellpadding="0" cellspacing="0"><tr>';
	cargando_destacados += '<td><div align="center"><img src="img/preload-grande.gif" width="32" height="32"></div></td></tr></table>';
	document.getElementById('div_destacados').innerHTML = cargando_destacados;
	window.setTimeout("myConn_carga_destacados.connect('dinamic/destacados.php', 'GET', 'ididioma=', fin_carga_destacados)", 1000);

}

var myConn_carga_buscador = new XHConn();
var fin_carga_buscador = function (oXML) { document.getElementById('div_buscador').innerHTML = oXML.responseText;};
function carga_buscador(){
	cargando_buscador = '<table width="204" height="242" border="0" align="center" cellpadding="0" cellspacing="0"><tr>';
	cargando_buscador += '<td><div align="center"><img src="img/preload-grande.gif" width="32" height="32"></div></td></tr></table>';
	document.getElementById('div_buscador').innerHTML = cargando_buscador;
	window.setTimeout("myConn_carga_buscador.connect('catalogo/buscador.php', 'GET', 'idtipo_g="+idtipo_global+"&idsubtipo_g="+idsubtipo_global+"&estado_g="+estado_global+"', fin_carga_buscador)", 1000);

}

var myConn_selec_tipo_producto = new XHConn();
var fin_selec_tipo_producto = function (oXML) { document.getElementById('div_selec_subtipo').innerHTML = oXML.responseText;};
function selec_tipo_producto(idtipo){
	if (idtipo == 0){
		if (subtipo_activo != 0){
			desaciva_subtipo();
		}
		if (estado_activo != 0){
			desaciva_estado();
		}
	} else {
		if (estado_activo != 0){
			desaciva_estado();
		}
		document.getElementById('div_selec_subtipo').innerHTML = '<img src="img/preload-campos.gif" width="56" height="21">';
		window.setTimeout("myConn_selec_tipo_producto.connect('catalogo/selec_subtipo.php', 'GET', 'idtipo="+idtipo+"&estado_activo="+estado_activo+"&subtipo_activo="+subtipo_activo+"', fin_selec_tipo_producto)", 1000);
		boton_buscar();
	}
}

var myConn_selec_subtipo_producto = new XHConn();
var fin_selec_subtipo_producto = function (oXML) { document.getElementById('div_selec_estado').innerHTML = oXML.responseText;};
function selec_subtipo_producto(idsubtipo,idtipo){
	if (idsubtipo == 0){
		if (estado_activo != 0){
			desaciva_estado();
		}
	} else {
		boton_buscar();
		document.getElementById('div_selec_estado').innerHTML = '<img src="img/preload-campos.gif" width="56" height="21">';
		window.setTimeout("myConn_selec_subtipo_producto.connect('catalogo/selec_estado.php', 'GET', 'idtipo="+idtipo+"&idsubtipo="+idsubtipo+"', fin_selec_subtipo_producto)", 1000);
	}
}

function desaciva_subtipo(){
	desplegable_desactivado = '<select name="subtipo" class="list_catalogo" id="subtipo" disabled="disabled">';
	desplegable_desactivado += '<option value="0" selected="selected">Cualquier</option>';
	desplegable_desactivado += '</select>';
	document.getElementById('div_selec_subtipo').innerHTML = desplegable_desactivado;
}

function desaciva_estado(){
	desplegable_desactivado = '<select name="estado" class="list_catalogo" id="estado" disabled="disabled">';
	desplegable_desactivado += '<option value="0" selected="selected">Cualquier</option>';
	desplegable_desactivado += '</select>';
	document.getElementById('div_selec_estado').innerHTML = desplegable_desactivado;
}

var myConn_boton_buscar = new XHConn();
var fin_boton_buscar = function (oXML) { document.getElementById('div_boton_buscar').innerHTML = oXML.responseText;};
function boton_buscar(){
	document.getElementById('div_boton_buscar').innerHTML = '<img src="img/preload-campos.gif" width="56" height="21">';
	window.setTimeout("myConn_boton_buscar.connect('catalogo/boton_buscar.php', 'GET', 'idtipo=', fin_boton_buscar)", 1000);
}

function activar_boton_buscar(){
	buscar_descativado = '<a href="javascript:buscar();" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'buscar\',\'\',\'img/boto_buscar02.jpg\',1)"><img src="img/boto_buscar01.jpg" name="buscar" width="60" height="19" border="0" id="buscar" /></a>';
	document.getElementById('div_boton_buscar').innerHTML = buscar_descativado;
}

function buscar(){
	idtipo_global = document.getElementById('tipo').value;
	if (subtipo_activo != 0){
		idsubtipo_global = document.getElementById('subtipo').value;
	} else {
		idsubtipo_global = 0;
	}
	if (estado_activo != 0){
		estado_global = document.getElementById('estado').value;
	} else {
		estado_global = 0;
	}
	listado_productos();
}

var myConn_listado_productos = new XHConn();
var fin_listado_productos = function (oXML) { document.getElementById('div_listado_productos').innerHTML = oXML.responseText;};
function listado_productos(pagina,num_pags){
		cargando_lista = '<table width="587" height="246" border="0" align="center" cellpadding="0" cellspacing="0"><tr>';
		cargando_lista += '<td><div align="center"><img src="img/preload-grande.gif" width="32" height="32"></div></td></tr></table>';
		document.getElementById('div_listado_productos').innerHTML = cargando_lista;
		window.setTimeout("myConn_listado_productos.connect('catalogo/listado.php', 'GET', 'idtipo="+idtipo_global+"&idsubtipo="+idsubtipo_global+"&estado="+estado_global+"&pagina="+pagina+"&num_pags="+num_pags+"', fin_listado_productos)", 1000);
}

var myConn_carga_ficha = new XHConn();
var fin_carga_ficha = function (oXML) { document.getElementById('div_ficha_producto').innerHTML = oXML.responseText;};
function carga_ficha(idproducto,pagina,productos_x_pag){
		cargando_ficha = '<table width="587" height="246" border="0" align="center" cellpadding="0" cellspacing="0"><tr>';
		cargando_ficha += '<td><div align="center"><img src="img/preload-grande.gif" width="32" height="32"></div></td></tr></table>';
		document.getElementById('div_ficha_producto').innerHTML = cargando_ficha;
		window.setTimeout("myConn_carga_ficha.connect('catalogo/ficha.php', 'GET', 'idproducto="+idproducto+"&pagina="+pagina+"&prod_x_pag="+productos_x_pag+"', fin_carga_ficha)", 1000);
}

var myConn_carga_imagen = new XHConn();
var fin_carga_imagen = function (oXML) { document.getElementById('div_foto_principal').innerHTML = oXML.responseText;};
function carga_imagen(foto){
		cargando_imagen = '<table width="253" height="247" border="0" align="center" cellpadding="0" cellspacing="0"><tr>';
		cargando_imagen += '<td><div align="center"><img src="img/preload-grande.gif" width="32" height="32"></div></td></tr></table>';
		document.getElementById('div_foto_principal').innerHTML = cargando_imagen;
		window.setTimeout("myConn_carga_imagen.connect('catalogo/ver_foto.php', 'GET', 'foto="+foto+"', fin_carga_imagen)", 1000);
}

var myConn_carga_noticias_portada = new XHConn();
var fin_carga_noticias_portada = function (oXML) { document.getElementById('div_noticias_portada').innerHTML = oXML.responseText;};
function carga_noticias_portada(){
		cargando_noticias = '<table width="810" height="215" border="0" align="center" cellpadding="0" cellspacing="0"><tr>';
		cargando_noticias += '<td><div align="center"><img src="img/preload-grande.gif" width="32" height="32"></div></td></tr></table>';
		document.getElementById('div_noticias_portada').innerHTML = cargando_noticias;
		window.setTimeout("myConn_carga_noticias_portada.connect('dinamic/noticias_portada.php', 'GET', '', fin_carga_noticias_portada)", 1000);
}

var myConn_carga_listado_noticias = new XHConn();
var fin_carga_listado_noticias = function (oXML) { document.getElementById('div_lista_noticias').innerHTML = oXML.responseText;};
function carga_listado_noticias(pagina){
		cargando_noticias = '<table width="205" height="242" border="0" align="center" cellpadding="0" cellspacing="0"><tr>';
		cargando_noticias += '<td><div align="center"><img src="img/preload-grande.gif" width="32" height="32"></div></td></tr></table>';
		document.getElementById('div_lista_noticias').innerHTML = cargando_noticias;
		window.setTimeout("myConn_carga_listado_noticias.connect('dinamic/listado_noticias.php', 'GET', 'pagina="+pagina+"', fin_carga_listado_noticias)", 1000);
}

var myConn_carga_noticia = new XHConn();
var fin_carga_noticia = function (oXML) { document.getElementById('div_carga_noticia').innerHTML = oXML.responseText;};
function carga_noticia(idnoticia){
		cargando_noticia = '<table width="205" height="242" border="0" align="center" cellpadding="0" cellspacing="0"><tr>';
		cargando_noticia += '<td><div align="center"><img src="img/preload-grande.gif" width="32" height="32"></div></td></tr></table>';
		document.getElementById('div_carga_noticia').innerHTML = cargando_noticia;
		window.setTimeout("myConn_carga_noticia.connect('dinamic/carga_noticia.php', 'GET', 'idnoticia="+idnoticia+"', fin_carga_noticia)", 1000);
}

function carga_ficha_destacado(idproducto,idtipo,idsubtipo,idestado){
	location.href = "./catalogo.php?idtipo="+idtipo+"&idsubtipo="+idsubtipo+"&idestado="+idestado+"&idproducto="+idproducto+"";
}


function valida_contacto(){
	if (document.contacto.nombre.value == ''){
		alert ("Por favor, Rellene el campo nombre.");
	} else {
		if ((document.contacto.telf.value == '') && (document.contacto.mail.value == '')){
			alert ("Por favor, especifica tu número de teléfono o tu dirección de e-mail para que podamos contactar contigo");
		} else {
			document.contacto.submit();
		}
	}
}

function borra_formulario(){
	document.contacto.nombre.value = '';
	document.contacto.telf.value = '';
	document.contacto.mail.value = '';
	document.contacto.coments.value = '';
}



//---------------MAPA SITUACIÓN---------------------------------------------------

var map_tienda; //hacemos global la variable para poder interactuar con otras funciones
function mapa_tienda() {

			latitud_centro = "41.53009";
			longitud_centro = "2.428193";
			inicia_mapa_tienda(longitud_centro,latitud_centro);
	
function inicia_mapa_tienda(longitud_centro,latitud_centro){

	document.getElementById('div_mapa_tienda').style.width = '566px';
	document.getElementById('div_mapa_tienda').style.height = '218px';

	var icon = new GIcon();
icon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
//icon.shadow = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png"; 
	icon.iconSize = new GSize(22, 23);
	//icon.shadowSize = new GSize(37, 34);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);

	map_tienda = new GMap2(document.getElementById("div_mapa_tienda"));
	map_tienda.addControl(new GSmallMapControl());
	map_tienda.setCenter(new GLatLng(latitud_centro, longitud_centro), 15);
	map_tienda.setMapType(G_NORMAL_MAP);
	
	//function createInfoMarker(point, address) {
	//var marker = new GMarker(point, icon);
	//return marker;
	//}
	
	var point = new GPoint(longitud_centro, latitud_centro);
	//var address = 'prueba';
	//var marker = createInfoMarker(point, address);
	var marker = new GMarker(point, icon);
	map_tienda.addOverlay(marker);
	
} // fin funcion inicia mapa

} // fin carga_mapa
