
function call_ajax(url,tag,formulario)
{
	
	if (formulario!=""){
		argumentos = '&'+$('#'+formulario).formSerialize(); 
	} else {
		argumentos="";
	}

	$('#'+tag).html('<p style="margin-top: 30px;margin-left:300px; text-align=center;"><img src="images/loading.gif" alt="Cargando"></p>');
	$('#'+tag).load(url+argumentos).hide().fadeIn('normal');
	
}

function recargar_foto_detalle(id_producto, detalle)
{
	
	var ruta = 'index.php?jump=foto_detalle&id='+id_producto;
	
	if (detalle!="")
		haydetalle = "&detalle="+detalle;
	else
		haydetalle = "";
	
	var idfoto = document.getElementById('otrafoto').value;
	if (idfoto!="")
		parametro = "&field="+idfoto;
	else
		parametro = "";
	
	ruta = ruta+parametro+haydetalle;
	
	$('#capa_foto').html('<p style="margin-top: 30px; text-align=center;"><img src="images/loading.gif" alt="Cargando"></p>');
	$('#capa_foto').load(ruta).hide().fadeIn('normal');

}

function add_carro(id,lang)
{

	// Obtenemos el numero de unidades			
	num_unidades = document.getElementById('unidades').value;
	color_item = document.getElementById('colores').value;
	talla_item = document.getElementById('tallas').value;

	$('#icono_resumen_carro').load('index.php?jump=addcarro&unidades='+num_unidades+'&idproducto='+id+'&color='+escape(color_item)+'&talla='+talla_item+'&lang='+lang).hide().fadeIn('normal')
	
}

function del_carro(id,pagina,lang)
{

	$('#contenido_carro').html('<p style="margin-top: 30px;margin-left:300px;"><img src="images/loading.gif" alt="Cargando"></p>');
	$('#contenido_carro').load('index.php?jump=delcarro&id='+id+'&pagina='+pagina+'&lang='+lang);
	
}

function check_field(value,regex)
{
	re = new RegExp(regex);

	r=re.exec(value);
	if (r==null) return false; else return true;
}

function check_form(form,nombreform)
{
	
	switch (nombreform) {
		case "datoscliente" :
			fields=	new Array('nombre','apellidos','direccion','codigopostal','poblacion','provincia','pais','telefono','email','clave','clave2');
			texts=	new Array("Nombre","Apellidos","Dirección","Codigo Postal","Población","Provincia","País","Teléfono","E-Mail","Password","Confirmar Password");
			types=	new Array('.+','.+','.+','.+','.+','.+','.+','.+','.+@.+','.+','.+');
			break;
		case "datoscliente_envio" :
			fields=	new Array('nombre_envio','apellidos_envio','direccion_envio','codigopostal_envio','poblacion_envio','provincia_envio','pais_envio','telefono_envio');
			texts=	new Array("Nombre","Apellidos","Dirección","Codigo Postal","Población","Provincia","País","Teléfono");
			types=	new Array('.+','.+','.+','.+','.+','.+','.+','.+');
			break;
		case "datosremember" :
			fields=	new Array('email');
			texts=	new Array("Email");
			types=	new Array('.+@.+');
			break;			
	}

	for (i=0;i<fields.length;i++) {
		v=eval("form."+fields[i]+".value");
		r=check_field(v,types[i]);
		if (r==false) {
			alert ("Por favor, compruebe campo "+texts[i]);
			return false;
		}
	}
	
	return true;
}

function check_pass() {

	pass1 = document.getElementById('clave').value;
	pass2 = document.getElementById('clave2').value;
	
	if (pass1==pass2){
		res = true;
	} else {
		alert ("Por favor, compruebe las contraseña, no coinciden.")
		res = false;
	}
	
	return res;
}

function mantener_direccion(){

	document.getElementById('nombre_envio').value = document.getElementById('nombre').value;
	document.getElementById('apellidos_envio').value = document.getElementById('apellidos').value;
	document.getElementById('direccion_envio').value = document.getElementById('direccion').value;
	document.getElementById('codigopostal_envio').value = document.getElementById('codigopostal').value;	
	document.getElementById('poblacion_envio').value = document.getElementById('poblacion').value;
	document.getElementById('provincia_envio').value = document.getElementById('provincia').value;
	document.getElementById('pais_envio').value = document.getElementById('pais').value;
	document.getElementById('telefono_envio').value = document.getElementById('telefono').value;	

}

//--------------------------------

function activar_coleccion(id)
{
	$(".top_list_colecciones").removeClass('top_list_colecciones_over');
	$(".list_colecciones").removeClass('list_colecciones_over');
	$(".bottom_list_colecciones").removeClass('bottom_list_colecciones_over');

	$("#top_coleccion_"+id).addClass('top_list_colecciones_over');
	$("#coleccion_"+id).addClass('list_colecciones_over');
	$("#bottom_coleccion_"+id).addClass('bottom_list_colecciones_over');
		
}

function coleccion_over(id)
{

	$("#top_coleccion_"+id).removeClass('top_list_colecciones');
	$("#top_coleccion_"+id).addClass('top_list_colecciones_over');
	$("#coleccion_"+id).removeClass('list_colecciones');	
	$("#coleccion_"+id).addClass('list_colecciones_over');
	$("#bottom_coleccion_"+id).removeClass('bottom_list_colecciones');	
	$("#bottom_coleccion_"+id).addClass('bottom_list_colecciones_over');
}

function coleccion_out(id)
{
	$("#top_coleccion_"+id).removeClass('top_list_colecciones_over');
	$("#top_coleccion_"+id).addClass('top_list_colecciones');
	$("#coleccion_"+id).removeClass('list_colecciones_over');	
	$("#coleccion_"+id).addClass('list_colecciones');
	$("#bottom_coleccion_"+id).removeClass('bottom_list_colecciones_over');	
	$("#bottom_coleccion_"+id).addClass('bottom_list_colecciones');
}

function newWindow(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen) {
  var int_windowLeft = (screen.width - a_int_windowWidth) / 2;
  var int_windowTop = (screen.height - a_int_windowHeight) / 2;
  var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=' + a_bool_resizable + ',menubar=' + a_bool_menubar + ',toolbar=' + a_bool_toolbar + ',location=' + a_bool_addressbar + ',statusbar=' + a_bool_statusbar + ',fullscreen=' + a_bool_fullscreen + '';
  var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties)
    if (parseInt(navigator.appVersion) >= 4) {
      obj_window.window.focus();
    }
}
