function destino_costes(destino,sec){
	
	document.getElementById('siguiente_carrito').href = 'index.php?op=cm4&sec='+sec+'&destino='+destino;
	
}

function valida_destino(destino){
	
		document.location.href = document.getElementById('siguiente_carrito').href;

	
}

function valida_cliente(){
	
	var nombre = document.getElementById('nombre').value;
	var apellidos = document.getElementById('apellidos').value;
	var telefono = document.getElementById('telefono').value;
	var direccion = document.getElementById('direccion').value;
	var poblacion = document.getElementById('poblacion').value;
	var idprovincia = document.getElementById('idprovincia').value;
	var cp = document.getElementById('cp').value;
	var email = document.getElementById('email').value;
	
	var datos_entrega = document.form_datos_compra.datos_entrega[0].checked;
	
	
	if ( datos_entrega == true )
	{
		var nombre_entrega = document.getElementById('nombre').value;
		var apellidos_entrega = document.getElementById('apellidos').value;
		var telefono_entrega = document.getElementById('telefono').value;
		var direccion_entrega = document.getElementById('direccion').value;
		var poblacion_entrega = document.getElementById('poblacion').value;
		var idprovincia_entrega = document.getElementById('idprovincia').value;
		var cp_entrega = document.getElementById('cp').value;
		
	}
	else
	{
		var nombre_entrega = document.getElementById('nombre_entrega').value;
		var apellidos_entrega = document.getElementById('apellidos_entrega').value;
		var telefono_entrega = document.getElementById('telefono_entrega').value;
		var direccion_entrega = document.getElementById('direccion_entrega').value;
		var poblacion_entrega = document.getElementById('poblacion_entrega').value;
		var idprovincia_entrega = document.getElementById('idprovincia_entrega').value;
		var cp_entrega = document.getElementById('cp_entrega').value;
	}

	
	var errores_formulario = "";
	
	errores_formulario += (nombre == "") ? '- Introduce tu nombre \r\n' : '';
	errores_formulario += (apellidos == "") ? '- Introduce tus apellidos \r\n' : '';
	errores_formulario += (telefono == "") ? '- Introduce tu telefono \r\n' : '';
	errores_formulario += (direccion == "") ? '- Introduce tu dirección \r\n' : '';
	errores_formulario += (poblacion == "") ? '- Introduce tu localidad \r\n' : '';
	errores_formulario += (idprovincia == "0") ? '- Especifica tu provincia \r\n' : '';	
	errores_formulario += (cp == "") ? '- Introduce el código postal \r\n' : '';	
	errores_formulario += (email == "") ? '- Introduce tu e-mail \r\n' : '';
	
	
	if ( datos_entrega == false )
	{
		errores_formulario += (nombre_entrega == "") ? '- Introduce tu nombre de envio \r\n' : '';
		errores_formulario += (apellidos_entrega == "") ? '- Introduce tus apellidos de envío \r\n' : '';
		errores_formulario += (telefono_entrega == "") ? '- Introduce tu telefono de envío \r\n' : '';
		errores_formulario += (direccion_entrega == "") ? '- Introduce tu dirección de envío \r\n' : '';
		errores_formulario += (poblacion_entrega == "") ? '- Introduce tu localidad  de envío\r\n' : '';
		errores_formulario += (idprovincia_entrega == "0") ? '- Especifica tu provincia de envío \r\n' : '';
		errores_formulario += (cp_entrega == "") ? '- Introduce el código postal de envío \r\n' : '';
		
	}
	

	
	if (errores_formulario != ""){ 
		errores_formulario = "Para poder continuar debes rellenar los siguientes campos obligatorios:\r\n\r\n" + errores_formulario;
		alert(errores_formulario); 
	} else {
		document.form_datos_compra.submit();
				
	}



}

var con_carga_visor_imagenes = new XHConn( );
function carga_visor_imagenes ( idcategoria,idimagen )
{
	var fin_carga_visor_imagenes = function ( oXML ) { document.getElementById( 'div_carga_visor' ).innerHTML = oXML.responseText; window.setTimeout('inicia_visor();',200); };
	//debido a un problema con la función del visor de imágenes tenemos que cargar en ajax y ponemos un div con ese tamaño para solucionarlo (tambíen sirver una imagen)
	document.getElementById( 'div_carga_visor' ).innerHTML = '<div style="width:66px;height:66px;"></div>';
	window.setTimeout( 'con_carga_visor_imagenes.connect( "visor_imagenes.php", "GET", "idcategoria='+idcategoria+'&idimagen='+idimagen+'", '+fin_carga_visor_imagenes+' );', 200);
}
var con_carga_menu_index = new XHConn( );
function carga_menu_index ( )
{
	var fin_carga_menu_index = function ( oXML ) { document.getElementById( 'carga_menu' ).innerHTML = oXML.responseText; };
	window.setTimeout( 'con_carga_menu_index.connect( "menu_index.php", "GET", "", '+fin_carga_menu_index+' );', 10);
}

function carga_complementos(idcomplemento,referencia,gm,producto){
	var con_carga_complementos = new XHConn( );
	var fin_carga_complementos = function ( oXML ) { document.getElementById( 'div_carga_complementos' ).innerHTML = oXML.responseText; document.getElementById('complemento_muestra').value = referencia; window.location.href="#ancla_enviar"; };	 
	con_carga_complementos.connect( "http://www.todoriginal.com/__dinamic/muestra_complemento.php", "GET", "idcomplemento="+idcomplemento+"&gm="+gm+"&referencia="+referencia+"&producto="+producto, fin_carga_complementos );
}

function func_muestra_complementos_producto2(producto){
	var con_muestra_complementos_producto2 = new XHConn( );
	var fin_muestra_complementos_producto2 = function ( oXML ) {  document.getElementById( 'div_carga_complemento2' ).innerHTML = oXML.responseText; };	 
	
	var array_producto = producto.split("-");
	con_muestra_complementos_producto2.connect( "http://www.todoriginal.com/__dinamic/muestra_complemento_producto2.php", "GET", "idproducto="+array_producto[0], fin_muestra_complementos_producto2 );
}


function elimina_complementos(){
	document.getElementById( 'div_carga_complementos' ).innerHTML = "";
	document.getElementById('complemento_muestra').value = 0;
}

function carga_vistas(tipo, foto, sec){
	
	if(tipo == 'tras') {	
	if(document.getElementById('tras')){
	document.getElementById('tras').className ="selec";
	}
	if(document.getElementById('del')){
	document.getElementById('del').className = "noselec";	
	}
	document.getElementById('carga_imagen_producto').innerHTML = "<img src=\"http://www.todoriginal.com/img_bd/productos/ficha/"+foto+"\" class=\"bloque\" />";
	}
	if(tipo == 'del') {	
	if(document.getElementById('del')){
	document.getElementById('del').className ="selec";
	}
	if(document.getElementById('tras')){
	document.getElementById('tras').className = "noselec";
	}
		if(sec != 0){
			document.getElementById('carga_imagen_producto').innerHTML = "<img src=\"http://www.todoriginal.com/img_bd/productos/ficha"+sec+"/"+foto+"\" class=\"bloque\" />";
		}else{
			document.getElementById('carga_imagen_producto').innerHTML = "<img src=\"http://www.todoriginal.com/img_bd/productos/ficha/"+foto+"\" class=\"bloque\" />";
		}
	}
	
}
//duplicamos para las cestitas
function carga_vistas_cestitas(tipo, foto, sec, ref){
	
	if(tipo == 'tras') {	
	if(document.getElementById('tras')){
		document.getElementById('tras').className ="selec";
	}
	if(document.getElementById('del')){
		document.getElementById('del').className = "noselec";	
	}
	document.getElementById('carga_imagen_producto').innerHTML = "<a href=\"javascript:tb_show('"+ref+"', 'http://www.todoriginal.com/img_bd/productos/ficha/pers_max_"+ref+".jpg', 'false');\"><img src=\"http://www.todoriginal.com/img_bd/productos/ficha/"+foto+"\" border=\"0\" class=\"bloque\" /></a>";
	}
	if(tipo == 'del') {	
	if(document.getElementById('del')){
		document.getElementById('del').className ="selec";
	}
	if(document.getElementById('tras')){
		document.getElementById('tras').className = "noselec";
	}
	document.getElementById('carga_imagen_producto').innerHTML = "<a href=\"javascript:tb_show('"+ref+"', 'http://www.todoriginal.com/img_bd/productos/ficha/max_"+ref+".jpg', 'false');\"><img src=\"http://www.todoriginal.com/img_bd/productos/ficha/"+foto+"\" border=\"0\" class=\"bloque\" /></a>";

	}
	
}



//Envio de formularios//
function pedir_muestra(){
	var nombre = document.getElementById('nombre').value;
	var apellidos = document.getElementById('apellidos').value;
	var telefono = document.getElementById('telefono').value;
	var direccion = document.getElementById('direccion').value;
	var poblacion = document.getElementById('poblacion').value;
	var provincia = document.getElementById('provincia').value;
	var cp = document.getElementById('cp').value;
	var email = document.getElementById('email').value;
	var complemento_muestra = document.getElementById('complemento_muestra').value;
	var ref_producto = document.getElementById('ref_producto').value;
	var titulo_producto = document.getElementById('titulo_producto').value;
	
	var producto2 = document.getElementById('producto2').value;
	var complemento2 = document.getElementById('complemento2').value;
	
	var errores_formulario = "";
	
	errores_formulario += (nombre == "") ? '- Introduce tu nombre \r\n' : '';
	errores_formulario += (apellidos == "") ? '- Introduce tus apellidos \r\n' : '';
	errores_formulario += (telefono == "") ? '- Introduce tu telefono \r\n' : '';
	errores_formulario += (direccion == "") ? '- Introduce tu dirección \r\n' : '';
	errores_formulario += (poblacion == "") ? '- Introduce tu localidad \r\n' : '';
	errores_formulario += (provincia == "") ? '- Especifica tu provincia \r\n' : '';	
	errores_formulario += (cp == "") ? '- Introduce el código postal \r\n' : '';	

	
	if(nombre != "" && apellidos != "" && telefono != "" && direccion != "" &&  poblacion != "" &&  provincia != "" && cp != ""){
	var con_pedir_muestra = new XHConn( );
	document.getElementById( 'form_pedir_muestra' ).innerHTML = '<div class="div_recarga_pedir_muestra">Enviando...</div>';
	//document.getElementById( 'recarga_complementos' ).innerHTML = "";	//div que ocultará los complementos una vez enviado
	var fin_pedir_muestra = function ( oXML ) { document.getElementById( 'form_pedir_muestra' ).innerHTML = '<div class="div_recarga_pedir_muestra">Su petición de muestra ha sido enviada, en un plazo de 48h recibirá<br /><br /> el envío contrareembolso con una personalización standard.<br /><br />Este importe se reembolsará finalmente si realiza un pedido superior a 200 €</div>' };	
	con_pedir_muestra.connect( "http://www.todoriginal.com/mailform/mailform_muestras.php", "GET", "nombre="+nombre+"&apellidos="+apellidos+"&telefono="+telefono+"&direccion="+direccion+"&poblacion="+poblacion+"&provincia="+provincia+"&cp="+cp+"&email="+email+"&complemento_muestra="+complemento_muestra+"&ref_producto="+ref_producto+"&titulo_producto="+titulo_producto+"&producto2="+producto2+"&complemento2="+complemento2, fin_pedir_muestra );	
	} else {
		errores_formulario = "Para poder continuar debes rellenar los siguientes campos obligatorios:\r\n\r\n" + errores_formulario;
		alert(errores_formulario); 	
	}
	
}

function enviar_contacto(){
	var nombre = document.getElementById('nombre').value;
	var telefono = document.getElementById('telefono').value;
	var provincia = document.getElementById('provincia').value;
	var cp = document.getElementById('cp').value;
	var email = document.getElementById('email').value;
	var consulta = document.getElementById('consulta').value;
	
	var con_contacto = new XHConn( );
	document.getElementById( 'div_contacto_corporativo' ).innerHTML = '<div class="div_recarga_pedir_muestra">Enviando...</div>';
	var fin_contacto = function ( oXML ) { document.getElementById( 'div_contacto_corporativo' ).innerHTML = '<div class="div_recarga_pedir_muestra">Su petición ha sido enviada<br /><br />En breve uno de nuestros agentes contactará con usted</div>' };	
	con_contacto.connect( "mailform/mailform_corporativo.php", "GET", "nombre="+nombre+"&telefono="+telefono+"&provincia="+provincia+"&cp="+cp+"&email="+email+"&consulta="+consulta, fin_contacto );		
}

function enviar_franquicia(){
	var nombre = document.getElementById('nombre').value;
	var telefono = document.getElementById('telefono').value;
	var provincia = document.getElementById('provincia').value;
	var cp = document.getElementById('cp').value;
	var email = document.getElementById('email').value;
	var consulta = document.getElementById('consulta').value;
	
	var con_franquicia = new XHConn( );
	document.getElementById( 'div_contacto_corporativo' ).innerHTML = '<div class="div_recarga_pedir_muestra">Enviando...</div>';
	var fin_franquicia = function ( oXML ) { document.getElementById( 'div_contacto_corporativo' ).innerHTML = '<div class="div_recarga_pedir_muestra">Su petición ha sido enviada<br /><br />En breve uno de nuestros agentes contactará con usted</div>' };	
	con_franquicia.connect( "mailform/mailform_franquicia.php", "GET", "nombre="+nombre+"&telefono="+telefono+"&provincia="+provincia+"&cp="+cp+"&email="+email+"&consulta="+consulta, fin_franquicia );		
}

/*-----------------------------------funciones para el cargando fullscreen-------------------------*/
function cargando_full_screen(){
	document.getElementById('fondo_cargando').style.visibility = 'visible';
	document.getElementById('full_screen_cargando').style.visibility = 'visible';
}

function oculta_cargando_full_screen(){
	document.getElementById('fondo_cargando').style.visibility = 'hidden';
	document.getElementById('full_screen_cargando').style.visibility = 'hidden';
}

function carga_directorio_ajax(){

	var con_carga_directorio_ajax = new XHConn( );
	var fin_carga_directorio_ajax = function ( oXML ) { document.getElementById('seo').innerHTML = oXML.responseText;  };	 
	con_carga_directorio_ajax.connect( "http://www.todoriginal.com/__dinamic/directorio_ajax.php", "GET", "", fin_carga_directorio_ajax );
}
