// ds.js

// Objeto Ajax
function ajaxObject(){
	var xmlhttp=false;
	try{ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ try{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch(E){ if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest(); } }
	return xmlhttp;
}

// selects catalogo
/*function catalogo(ca){
	capa = document.getElementById(ca);	
	switch(ca){
		case 'nav_catalogo':
			url = 'ajax/catalogo.php';
		break;
	}
	if(url!=''){
		// Inicio objeto AJAX
		if(window.XMLHttpRequest){ retorn = new XMLHttpRequest(); }else if(window.ActiveXObject){ retorn = new ActiveXObject("Microsoft.XMLHTTP"); }else{ retorn = false; }
		if(retorn){ retorn.onreadystatechange = mostrarCatalogo; retorn.open('GET',url,true); retorn.send(null); }	
	}
	// Funciones
	function mostrarCatalogo(){	
		if( retorn.readyState == 4){
			if( retorn.status == 200 ){
				capa.innerHTML = retorn.responseText;
			}else{
				capa.innerHTML = "Error: " + retorn.status;
			}
		}else{
			capa.innerHTML = '<center><img src="img/precarga.gif" alt="Loading..." title="Loading..." /></center>';
		}
	}	
}*/

// visor de imágenes
function visor(img){document.getElementById('imgActiva').src=img;}

// Foto Viewer
function fotoViewerSelect(img){document.getElementById('imgFotoViewer').src=img;}

// Validación del buscador
function validarBuscador(msg){
	if(document.getElementById('palabra').value.length < 3){
		alert(document.getElementById('msg_buscador').innerText);
		return false;
	}else{
		return true;
	}
}

// Añadir producto
function addProduct(id){
	capa = document.getElementById('cesta');
	var talla = '';
	var cantidad = '';
	
	if(document.getElementById('italla').value==1){
		// Si talla
		if(document.getElementById("talla").options[document.getElementById("talla").selectedIndex].value == 0){
			// No talla
			alert(document.getElementById("msg_t").innerText); return false;
		}else{
			// Si talla
			if(document.getElementById('icantidad').value==1){
				// Si cantidad control
				if(document.getElementById("cantidad").options[document.getElementById("cantidad").selectedIndex].value == 0){
					// No cantidad
					alert(document.getElementById("msg_c").innerText); return false;
				}else{
					// Correcto si talla si cantidad
					talla = document.getElementById("talla").options[document.getElementById("talla").selectedIndex].value;
					cantidad = document.getElementById("cantidad").options[document.getElementById("cantidad").selectedIndex].value;				
				}	
			}else{
				// No cantidad control
				alert(document.getElementById("msg_a").innerText); return false;
			}			
		}
	}else{
		// No talla
		if(document.getElementById('icantidad').value==1){
			// Si Cantidad
			if(document.getElementById("cantidad").options[document.getElementById("cantidad").selectedIndex].value == 0){
				alert(document.getElementById("msg_c").innerText); return false;
			}else{
				// Correcto no talla si cantidad.
				talla = document.getElementById("italla").value;
				cantidad = document.getElementById("cantidad").options[document.getElementById("cantidad").selectedIndex].value;
			}
		}else{
			// No cantidad
			alert(document.getElementById("msg_a").innerText); return false;
		}
		
	}
	
	url = 'ajax/minicesta.php?producto='+id+'&talla='+talla+'&cantidad='+cantidad;
	if(url!=''){
		// Inicio objeto AJAX
		if(window.XMLHttpRequest){ retorn = new XMLHttpRequest(); }else if(window.ActiveXObject){ retorn = new ActiveXObject("Microsoft.XMLHTTP"); }else{ retorn = false; }
		if(retorn){ retorn.onreadystatechange = addItem; retorn.open('GET',url,true); retorn.send(null); }	
	}
	// Funciones
	function addItem(){
		if( retorn.readyState == 4){
			if( retorn.status == 200 ){
				capa.innerHTML = retorn.responseText;
			}else{
				capa.innerHTML = "Error: " + retorn.status;
			}
		}else{
			capa.innerHTML = '<center><img src="img/precarga.gif" alt="Loading..." title="Loading..." /></center>';
		}
	}	
	
}

// Añadir producto desde el catalogo
function addProductCatalog(id){
	capa = document.getElementById('cesta');
	var talla = ''; 
	var cantidad = '';
		
	if(document.getElementById('italla'+id).value==1){
		if(document.getElementById("talla"+id).options[document.getElementById("talla"+id).selectedIndex].value == 0){
			if(document.getElementById("cantidad"+id).options[document.getElementById("cantidad"+id).selectedIndex].value == 0){ alert(document.getElementById("msg_tc").innerText); return false; }else{ alert(document.getElementById("msg_t").innerText); return false; }
		}else{
			if(document.getElementById("cantidad"+id).options[document.getElementById("cantidad"+id).selectedIndex].value == 0){ alert(document.getElementById("msg_c").innerText); return false; }
		}
				talla = document.getElementById("talla"+id).options[document.getElementById("talla"+id).selectedIndex].value;
		cantidad = document.getElementById("cantidad"+id).options[document.getElementById("cantidad"+id).selectedIndex].value;
	}else{
		if(document.getElementById("cantidad"+id).options[document.getElementById("cantidad"+id).selectedIndex].value == 0){ alert(document.getElementById("msg_c").innerText); return false; }	
		talla = document.getElementById("italla"+id).value;
		cantidad = document.getElementById("cantidad"+id).options[document.getElementById("cantidad"+id).selectedIndex].value;
	}
	
	url = 'ajax/minicesta.php?producto='+id+'&talla='+talla+'&cantidad='+cantidad;
	if(url!=''){
		// Inicio objeto AJAX
		if(window.XMLHttpRequest){ retorn = new XMLHttpRequest(); }else if(window.ActiveXObject){ retorn = new ActiveXObject("Microsoft.XMLHTTP"); }else{ retorn = false; }
		if(retorn){ retorn.onreadystatechange = addItem; retorn.open('GET',url,true); retorn.send(null); }	
	}
	// Funciones
	function addItem(){	
		if( retorn.readyState == 4){
			if( retorn.status == 200 ){
				capa.innerHTML = retorn.responseText;
			}else{
				capa.innerHTML = "Error: " + retorn.status;
			}
		}else{
			capa.innerHTML = '<center><img src="img/precarga.gif" alt="Loading..." title="Loading..." /></center>';
		}
	}	
}

// Enseñar cesta
function showCesta(){
	capa = document.getElementById('cesta');
	url = 'ajax/showminicesta.php';
	if(url!=''){
		// Inicio objeto AJAX
		if(window.XMLHttpRequest){ retorn2 = new XMLHttpRequest(); }else if(window.ActiveXObject){ retorn2 = new ActiveXObject("Microsoft.XMLHTTP"); }else{ retorn2 = false; }
		if(retorn2){ retorn2.onreadystatechange = show; retorn2.open('GET',url,true); retorn2.send(null); }	
	}
	// Funciones
	function show(){	
		if( retorn2.readyState == 4){
			if( retorn2.status == 200 ){
				capa.innerHTML = retorn2.responseText;
			}else{
				capa.innerHTML = "Error: " + retorn2.status;
			}
		}else{
			capa.innerHTML = '<center><img src="img/precarga.gif" alt="Loading..." title="Loading..." /></center>';
		}
	}	
}

// Validar compra de la cesta
function validarConfirmacion(){
	if(document.getElementById('nombre').value==''){ alert(document.getElementById("msg_c_nombre").innerText); return false; }
	if(document.getElementById('apellidos').value==''){ alert(document.getElementById("msg_c_apellidos").innerText); return false; }
	if(document.getElementById('dni').value==''){ alert(document.getElementById("msg_c_dni").innerText); return false; }
	if(document.getElementById('telefono').value==''){ alert(document.getElementById("msg_c_telefono").innerText); return false; }
	if(document.getElementById('email').value==''){ alert(document.getElementById("msg_c_email").innerText); return false; }
	if(document.getElementById('calle').value==''){ alert(document.getElementById("msg_c_calle").innerText); return false; }
	if(document.getElementById('numero').value==''){ alert(document.getElementById("msg_c_numero").innerText); return false; }
	if(document.getElementById('cp').value==''){ alert(document.getElementById("msg_c_cp").innerText); return false; }
	if(document.getElementById('municipio').value==''){ alert(document.getElementById("msg_c_municipio").innerText); return false; }
	return true;
}


// Validar filtro catalogo
function validarFormNavegador(){

	/*if(document.getElementById('pmin').value != ''){
		pmin = document.getElementById('pmin').value.replace(',','.');
		if(isNaN(pmin)){ alert(document.getElementById("msg_pmin").innerText); return false; }else{ document.getElementById('pmin').value = pmin; }
	}else{ pmin = 0; }
		
	if(document.getElementById('pmax').value!=''){
		pmax = document.getElementById('pmax').value.replace(',','.');
		if(isNaN(pmax)){ alert(document.getElementById("msg_pmax").innerText); return false; }else{ document.getElementById('pmax').value = pmax; }
	}else{ pmax = 0; }
		
	alert(pmin);
	alert(pmax);	
	if( pmin > pmax ){ alert(document.getElementById("msg_pcom").innerText); return false; }*/
	
	return true;
	
}
































