//**************** 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).subPag.value=tipo
	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").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").empresa.value == "" ) {
		texto+=" * Debe indicar el nombre de su empresa.<br>";
	}else{
		cadenaEnvio="empresa=" + document.getElementById("formularioContacto").empresa.value;
	}
	if ( document.getElementById("formularioContacto").nombre.value == "" ) {
		texto+=" * Debe indicar una persona de contacto.<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").direccion.value != "" ){
		cadenaEnvio+="&direccion=" + document.getElementById("formularioContacto").direccion.value;
	}
	
	if ( document.getElementById("formularioContacto").poblacion.value != "" ){
		cadenaEnvio+="&poblacion=" + document.getElementById("formularioContacto").poblacion.value;
	}
	
	if ( document.getElementById("formularioContacto").provincia.value != "" ){
		cadenaEnvio+="&provincia=" + document.getElementById("formularioContacto").provincia.value;
	}
	
	if ( document.getElementById("formularioContacto").telefono.value != "" ){
		cadenaEnvio+="&telefono=" + document.getElementById("formularioContacto").telefono.value;
	}
	
	if ( document.getElementById("formularioContacto").movil.value != "" ){
		cadenaEnvio+="&movil=" + document.getElementById("formularioContacto").movil.value;
	}
	
	if ( document.getElementById("formularioContacto").cpostal.value != "" ){
		cadenaEnvio+="&cpostal=" + document.getElementById("formularioContacto").cpostal.value;
	}

	//if ( document.getElementById("formularioContacto").pais2.value != "" ){
		cadenaEnvio+="&pais=" + document.getElementById("formularioContacto").pais.options[document.getElementById("formularioContacto").pais.selectedIndex].text
		
		cadenaEnvio+="&departamento=" + document.getElementById("formularioContacto").departamento.options[document.getElementById("formularioContacto").departamento.selectedIndex].text
		
	//}
	
	//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';
		document.getElementById("formularioContacto").action = "actualizer/formcorreosMultiple/envioCV.asp";
		document.getElementById("formularioContacto").submit();
		//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 EL POPU DEL MAPA
	function abrir(){
		window.open('mapa.htm','localizacion','width=750 height=500'); 
		return
	}
	
	
	/****************************************************************
/ Nombre: muestraTema
/ Implentacion:
/ Revision:
/ Descripcion: Muestra los temas
'***************************************************************/
function muestraTema(id,numero,subpagina) {
	for (i=1;i<=numero;i++)
	{
		if (i != id)
		{
			if (document.getElementById("filaContenidoTema"+ i).style.display == "block")
			{document.getElementById("filaContenidoTema"+ i).style.display = "none";}
			
			document.getElementById("enlaceTema"+ i).className = "desmarcado"+i;			
		}
		else
		{document.getElementById("enlaceTema"+ i).className = "marcado"+i;}
	}
	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"+id;
	}
	cambiaCabecera(subpagina);
	
}


function cambiaCabecera(subpagina){	
		url = "swf/cabecera.swf?pagina=productos&subpagina=" + subpagina;
		var pelicula ="";
		
		pelicula = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="1000" height="142">';
		
        pelicula += '<param name="movie" value="' + url + '">';
		
        pelicula += '<param name="quality" value="high">';
		pelicula +='<embed src="' + url + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="1000" height="142"></embed>';
		
		pelicula += '</object>';

		document.getElementById("flash").innerHTML = pelicula;
}




