//**************** FUNCIONES PARA EL MANEJO DEL AJAX **********************************
//*************************************************************************************

//--
function getHTTPObject() {
	var xmlhttp;      
  
  /*@cc_on
  @if (@_jscript_version >= 5)
	try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
		xmlhttp = false;
	  }
	}
  @else
  xmlhttp = false;
  @end @*/
  
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {  
		try {
		  xmlhttp = new XMLHttpRequest();
		} catch (e) {
		  xmlhttp = false;
		}
	}
	return xmlhttp;
}
    
//--
var http = getHTTPObject(); 

// ********************************************************************************
//*********************************************************************************


//************ SECCION PRODCUTOS **************************************************
//*********************************************************************************
function ampliaProducto(pagina,id,tipo,galeria){
	if (tipo == 1){
//		alert(tipo);
		var ref = document.getElementById("pk_info"+id).value;
		if (ref != ""){
			document.getElementById("formularioAmplia" + id).action = document.getElementById("formularioAmplia" + id).action + "&ref="+ref;
		}
	}
	document.getElementById("formularioAmplia" + id).numPagina.value=pagina
	document.getElementById("formularioAmplia" + id).numGaleria.value=galeria
	document.getElementById("formularioAmplia" + id).submit();
}


function paginacion(pagina){
//funcion para realizar la paginacion de los productos
	document.getElementById("formularioPaginacion").numPagina.value=pagina;
	document.getElementById("formularioPaginacion").producto.value=0;
	document.getElementById("formularioPaginacion").submit();
}

function volverCatalogo(pagina){
	document.getElementById("formularioVolver").numPagina.value=pagina
	document.getElementById("formularioVolver").submit();
}

function cambiaFondo(familia){
	//alert(familia);
	var fondo;
	fondo="";
	
	if (familia==1){
		fondo="fondo1";
	}
	
	//if (familia==2){
	//	fondo="fondo2";
	//}
	
	//if (familia==3){
	//	fondo="fondo3";
	//}
	
	if (familia==4){
		fondo="fondo4";
	}
	
	if (familia==5){
		fondo="fondo5";
	}
	
	if (familia==6){
		fondo="fondo6";
	}
	
	if (familia==7){
		fondo="fondo7";
	}
	
	if (familia==8){
		fondo="fondo8";
	}
	
	if (familia==9){
		fondo="fondo9";
	}
	
	if (familia==11){
		fondo="fondo11";
	}
	
	if (familia==12){
		fondo="fondo12";
	}
	
	if (familia==13){
		fondo="fondo13";
	}
	
	document.getElementById("actualizable").className=fondo;

}

function cambiaClaseFamilia(familia){
	
	if (familia==1){
		clase="cajas-y-estuches-marcado";
	}
	
	//if (familia==2){
	//	fondo="fondo2";
	//}
	
	//if (familia==3){
	//	fondo="fondo3";
	//}
	
	if (familia==4){
		clase="tubos-estandar-marcado";
	}
	
	if (familia==5){
		clase="expositores-bandejas-marcado";
	}
	
	if (familia==6){
		clase="blisters-a-medida-marcado";
	}
	
	if (familia==7){
		clase="packaging-embotellados-marcado";
	}
	
	if (familia==8){
		clase="carpetas-muestrarios-marcado";
	}
	
	if (familia==9){
		clase="blisters-expositores-marcado";
	}
	
	if (familia==11){
		clase="cajas-maravillosas-marcado";
	}
	
	if (familia==12){
		clase="packaging-flores-plantas-marcado";
	}
	
	if (familia==13){
		clase="piezas-tecnicas-marcado";
	}
	
	document.getElementById("familia" + familia).className=clase;
}

function quitaClaseFamilia(familia,marcado){
	
	if (familia==1 && marcado==0){
		clase="cajas-y-estuches";
	}
	
	//if (familia==2){
	//	fondo="fondo2";
	//}
	
	//if (familia==3){
	//	fondo="fondo3";
	//}
	
	if (familia==4 && marcado==0){
		clase="tubos-estandar";
	}
	
	if (familia==5 && marcado==0){
		clase="expositores-bandejas";
	}
	
	if (familia==6 && marcado==0){
		clase="blisters-a-medida";
	}
	
	if (familia==7 && marcado==0){
		clase="packaging-embotellados";
	}
	
	if (familia==8 && marcado==0){
		clase="carpetas-muestrarios";
	}
	
	if (familia==9 && marcado==0){
		clase="blisters-expositores";
	}
	
	if (familia==11 && marcado==0){
		clase="cajas-maravillosas";
	}
	
	if (familia==12 && marcado==0){
		clase="packaging-flores-plantas";
	}
	
	if (familia==13 && marcado==0){
		clase="piezas-tecnicas";
	}
	
	document.getElementById("familia" + familia).className=clase;
}
//*********************************************************************************
//********************************************************************************

//****************** SECCION CONTACTO *********************************************
//*********************************************************************************

function validarEmail(valor){
//funcion para validar el formato del email
	return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor));
	
}

function validar(){
//Funcion para la validar los datos enviados desde el formulario de contacto
	var texto;
	texto = "";

	var cadenaEnvio;
	cadenaEnvio = "";
	
	//Aqui validamos que los campos obligatorios tengan valor y se añaden a la cadena de envio
	
	if ( document.getElementById("formularioContacto").nombre.value == "" ) {
		texto+=" * Debe indicar su nombre.<br>";
	}else{
		cadenaEnvio="nombre=" + document.getElementById("formularioContacto").nombre.value;
	}
	
	if ( document.getElementById("formularioContacto").email.value == "" ) {
		texto+=" * Debe indicar su e-mail.<br>";
	}
	
	if(document.getElementById("formularioContacto").email.value!=""){
		if(!validarEmail(document.getElementById("formularioContacto").email.value)){
				texto+=" * Formato de E-mail incorrecto.<br>";
		}else{
			cadenaEnvio+="&email=" + document.getElementById("formularioContacto").email.value;
		}
	}
	if ( document.getElementById("formularioContacto").comentarios.value == "" ){
		texto+=" * Debe incluir el motivo de su consulta.<br>";
	}else{
		cadenaEnvio+="&comentarios=" + document.getElementById("formularioContacto").comentarios.value;
	}	
	
	//Aqui vamos añadiendo los demas campos sino estan vacion
	
	
	if ( document.getElementById("formularioContacto").poblacion.value != "" ){
		cadenaEnvio+="&poblacion=" + document.getElementById("formularioContacto").poblacion.value;
	}
	
	
	if ( document.getElementById("formularioContacto").telefono.value != "" ){
		cadenaEnvio+="&telefono=" + document.getElementById("formularioContacto").telefono.value;
	}
	
	
	//Si falta algun campo obligatorio o el email no tiene un formato correcto
	//mostramos un mensaje de avios
	
	if ( texto != "" ){
		document.getElementById("mensajeError").innerHTML=texto;
		document.getElementById("capaError").style.display='block';
		
	}else{
		//alert(cadenaEnvio);
		document.getElementById("mensaje-respuesta").innerHTML="";
		document.getElementById("mensajeError").innerHTML="";
		document.getElementById("capaError").style.display='none';
		http.open("GET", "actualizer/formcorreosMultiple/envioSinBd.asp?" + cadenaEnvio, true);
		http.onreadystatechange = handleHttpResponseContacto;
		http.send(null);
	}
	
}

function cerrarAviso(){
	document.getElementById("mensajeError").innerHTML="";
	document.getElementById("capaError").style.display='none';
}

function handleHttpResponseContacto() {
	if (http.readyState == 4) {    	
		//Aqui va el nombre de la capa donde queramos cargar el contenido
		document.getElementById("mensaje-respuesta").innerHTML = http.responseText;	
		document.getElementById("formularioContacto").reset();
	}    
}
//*********************************************************************************
//*********************************************************************************
function mostrarReferencia(id){
		if (document.getElementById("pk_info"+id).value == ""){
			document.getElementById("referencia").innerHTML = "";
			document.getElementById("referencia").style.display = "block";	
			return false;
		}
		var idReferencia = document.getElementById("pk_info"+id).value;
		http.open("GET", "./includes/getReferencia.asp?id=" + idReferencia, true);
		http.onreadystatechange = handleHttpResponseReferencia;
		http.send(null);
	
}

function handleHttpResponseReferencia() {
	if (http.readyState == 4) {    	
		//Aqui va el nombre de la capa donde queramos cargar el contenido
		document.getElementById("referencia").innerHTML = "<p class='descripcion'>-&nbsp;" + http.responseText + "</p>";	
		document.getElementById("referencia").style.display = "block";	
	}    
}

//ABRE UN POPUP
	function openWindow(theURL,winName,features){
 		window.open(theURL,winName,features);
		return
	}
	
//***************************************************************************
// Funcion que muestra los temas
//***************************************************************************
function muestraTema(id,numero) {
	for (i=1;i<=numero;i++){
		if (id != i){
			if (document.getElementById("filaContenidoTema"+ i).style.display == "block"){
				document.getElementById("filaContenidoTema"+ i).style.display = "none";
			}
				document.getElementById("enlaceTema"+ i).className = "desmarcado";
		}
	}
	if (document.getElementById("filaContenidoTema"+ id).style.display == "block") { 
		document.getElementById("filaContenidoTema"+ id).style.display = "none"; }
	else { 
		document.getElementById("filaContenidoTema"+ id).style.display = "block";
		document.getElementById("enlaceTema"+ id).className = "marcado";
		}
}

function capaPosition(layer, position){
		element = document.getElementById(layer);
		screenCenterX = document.body.clientWidth / 2;
		element.style.left = screenCenterX + position;
		element.style.display = 'inline';
	}

function setSound(modo){
//	alert(modo)	
		http.open("GET", "./includes/setSound.asp?estado=" + modo, true);
		http.onreadystatechange = handleHttpResponseSound;
		http.send(null);
}

function handleHttpResponseSound() {
	if (http.readyState == 4) {    	
		//Aqui va el nombre de la capa donde queramos cargar el contenido
//		alert('ok');
//		document.getElementById("referencia").innerHTML = "<p class='descripcion'>-&nbsp;" + http.responseText + "</p>";	
//		document.getElementById("referencia").style.display = "block";	
	}    
}

/****************************************************************************************
/ Nombre: ampliaImagen
/ Implentacion: PACO
/ Revision:
/ Descripcion: Muestra el PopUp de ampliacion de las imagenes y lo redimensiona
'***************************************************************************************/
function ampliaImagen(url){
	document.getElementById('imagenAmpliada').src = "actualizer/catalogoSinReferencias/fotos/" + url;
	}

function redimensionarImagen(img){
	var anchoImagen,altoImagen,anchoPantalla,altoPantalla;
	img1 = new Image(); 
	img1.src = img.src;
	anchoImagen = 550;
//	anchoImagen = img1.width;
	altoImagen = img1.height + 80;
//	anchoPantalla = window.screen.width;
	anchoPantalla = 930
	altoPantalla = window.screen.height - 240;
	posicionx = (anchoPantalla/2) - (anchoImagen/2);
	posiciony = (altoPantalla/2) - (altoImagen/2);
	
	// coloca la capa de la imagen y la redimensiona
//	document.getElementById('capaImagenAmpliada').style.top = posiciony + 'px';
//	document.getElementById('capaImagenAmpliada').style.left = posicionx + 'px';
	document.getElementById('capaImagenAmpliada').style.top = 101 + 'px';
	document.getElementById('capaImagenAmpliada').style.left = 174 + 'px';
	document.getElementById('capaImagenAmpliada').style.width = anchoImagen + 'px';
	document.getElementById('capaImagenAmpliada').style.height = altoImagen + 'px';
	// coloca un poco más arriba la capa del enlace para cerrar
	posicionCerrar = posiciony - 19;
	document.getElementById('cerrarImagenAmpliada').style.top = 82 + 'px';
	document.getElementById('cerrarImagenAmpliada').style.left = 174 + 'px';

	document.getElementById('capaImagenAmpliada').style.display = 'block';
	document.getElementById('cerrarImagenAmpliada').style.display = 'block';
	// en caso del formulario de contacto, ocultamos el combo
//	document.getElementById('pais').style.visibility = 'hidden';
}

function cerrarImagenAmpliada(){
	document.getElementById('imagenAmpliada').src = "";
	document.getElementById('capaImagenAmpliada').style.display = 'none';
	document.getElementById('cerrarImagenAmpliada').style.display = 'none';
//	document.getElementById('pais').style.visibility = 'visible';
}
//***************************************************************************
//***************************************************************************
