//**************** 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(); // We create the HTTP Object

// ********************************************************************************
//*********************************************************************************


//********************* INDEX *****************************************************
//*********************************************************************************
function handleHttpResponseNavegacion() {
	if (http.readyState == 4) {    	
		//Cargamos el contenido en la capa
		document.getElementById("contenido").innerHTML = http.responseText;	
	}    
}

function navegacion(seccion){

	//Segun la seccion seleccionamos una url para cargar su contenido
	
	//EMPRESA
	if (seccion=='empresa'){
		url='empresa-historia-electromed.htm';
		sectionPictureTitle = 'title-empresa.jpg';
	}
	
	if (seccion=='futuro') {
		url='empresa-futuro-electromed.htm';
		sectionPictureTitle = 'title-futuroelectromed.jpg';
	}
	
	if (seccion=='nuevas-tecnologias'){
		url='empresa-nuevas-tecnologias-electromed.htm';
		sectionPictureTitle = 'title-nuevastecnologias.jpg';
	}

	//INSTALACIONES
	if (seccion=='instalaciones'){
		url='instalaciones-delegacion-central-electromed.htm';
		sectionPictureTitle = 'title-delegaciones.jpg';
	}
		/*DELEGACIONES*/
		if (seccion=='delegacion-castellon'){
		url='instalaciones-delegacion-castellon-electromed.htm';
		sectionPictureTitle = 'title-instalaciones.jpg';
		}
		/*DELEGACIONES*/
		if (seccion=='delegacion-central'){
		url='instalaciones-delegacion-central-electromed.htm';
		sectionPictureTitle = 'title-instalaciones.jpg';
		}
		/*DELEGACIONES*/
		if (seccion=='delegacion-Elena-Berti'){
		url='instalaciones-delegacion-Elena-Berti-electromed.htm';
		sectionPictureTitle = 'title-instalaciones.jpg';
		}
		/*DELEGACIONES*/
		if (seccion=='delegacion-gandia'){
		url='instalaciones-delegacion-gandia-electromed.htm';
		sectionPictureTitle = 'title-instalaciones.jpg';
		}
		/*DELEGACIONES*/
		if (seccion=='delegacion-murcia'){
		url='instalaciones-delegacion-murcia-electromed.htm';
		sectionPictureTitle = 'title-instalaciones.jpg';
		}
		/*DELEGACIONES*/
		if (seccion=='delegacion-valencia-puerto'){
		url='instalaciones-delegacion-valencia-puerto-electromed.htm';
		sectionPictureTitle = 'title-instalaciones.jpg';
		}
	
		/*if (seccion=='localizacion'){
			url='instalaciones-localizacion-electromed.htm';
			sectionPictureTitle = 'title-localizacionelectromed.jpg';
			
		}
		
		if (seccion=='delegaciones'){
			url='instalaciones-delegaciones-electromed.htm';
			sectionPictureTitle = 'title-delegaciones.jpg';
		}*/
	
	//CATALOGO	
	if (seccion=='catalogo'){
		url='catalogo-electromed.asp';
		sectionPictureTitle = 'title-catalogo.jpg';
	}
	
	//OFERTAS
	if (seccion=='ofertas'){
		url='ofertas-electromed.asp';
		sectionPictureTitle = 'title-ofertas.jpg';
	}
	
	//PROVEEDORES
	if (seccion=='proveedores'){
		url='proveedores-electromed.htm';
		sectionPictureTitle = 'title-proveedores.jpg';
	}
	//DESCARGAS
	if (seccion=='descargas'){
		url='descargas-electromed.asp';
		sectionPictureTitle = 'title-descargas.jpg';
	}
	
	//FORO
	if (seccion=='foro'){
		url='foro.asp';
		sectionPictureTitle = 'title-foro.jpg';
	}
	
	//BOLSA DE TRABAJO
	if (seccion=='bolsa'){
		url='bolsa-de-trabajo-electromed.asp';
		sectionPictureTitle = 'title-empleo.jpg';
	}
	
	//ACTIVIDADES
	if (seccion=='actividades'){
		url='actividades-electromed.asp';
		sectionPictureTitle = 'title-actividades.jpg';
	}
	
	//CONTACTO
	if (seccion=='contacto'){
		url='contacto-electromed.htm';
		sectionPictureTitle = 'title-contacto.jpg';
	}
	
	//Cambia la imagen de titulo de seccion
	with(document.getElementById("seccionTitle")){
		src = 'images/' + sectionPictureTitle;
		alt = seccion + " ElectroMED.";
	}	
	
	//Ocultamos la imagen de novedades de producto
	with(document.getElementById("novedades")){
		src='images/background-title-red-part2-electromed.jpg';
		alt ='';
	}
		
	//Ahora realizamos la carga del contenido
	http.open("GET", url , true);
	http.onreadystatechange = handleHttpResponseNavegacion;
	http.send(null);	
}

//*********************************************************************************
//********************* FIN DE INDEX **********************************************

//*********************** FUNCION PARA EL MANEJO DE LOS MENUS DESPLEGABLES ********
//*********************************************************************************

function despliegaTema(tema){
//funcion para desplegar u ocultar el menu que muestras las familias y subfamilias de productos
//Se utiliza tambien para la seccion del foro
	if(document.getElementById("familia" + tema).style.display=='block'){
		document.getElementById("familia" + tema).style.display='none';
	}else{
		document.getElementById("familia" + tema).style.display='block';
	}
}

//*********************************************************************************
//*********************************************************************************

//**************** SECCION CATALOGO ***********************************************
//*********************************************************************************
function handleHttpResponseCatalogo() {
	if (http.readyState == 4) {    	
		//Cargamos el contenido en la capa
		document.getElementById("catalogo-productos").innerHTML = http.responseText;	
	}    
}

function masInformacion(producto){
	//nos lleva a la seccion de catalogo pero cargando la galeria del producto que esta en portada
	http.open("GET", "catalogo-electromed.asp?producto=" + producto , true);
	http.onreadystatechange = handleHttpResponseNavegacion;
	http.send(null);
}

function muestraGaleria(galeria){
	http.open("GET","includes/getCatalogo.asp?galeria=" + galeria , true);
	http.onreadystatechange = handleHttpResponseCatalogo;
	http.send(null);	
}

function paginacion(galeria,numeroPagina){
//funcion para la paginacion del catalogo
    http.open("GET", "includes/getCatalogo.asp?galeria="+ galeria + "&numeroPagina=" + numeroPagina, true);    
	http.onreadystatechange = handleHttpResponseCatalogo;
	http.send(null);  
}

function ampliaProducto(producto,pagina){
//funcion para mostrar la ampliacion de un producto
	http.open("GET", "includes/getCatalogoFicha.asp?producto="+ producto + "&numeroPagina=" + pagina, true);    
	http.onreadystatechange = handleHttpResponseCatalogo;
	http.send(null);
}

//**********************************************************************************
//******************* FIN DE CATALOGO **********************************************


//************************ SECCION DESCARGAS **************************************
//*********************************************************************************
function handleHttpResponseDescargas() {
	if (http.readyState == 4) {    	
		//Cargamos el contenido en la capa
		document.getElementById("contenido-descargas").innerHTML = http.responseText;	
	}    
}

function muestraDescargas(numero){
	http.open("GET","includes/getDescargas.asp?numero=" + numero , true);
	http.onreadystatechange = handleHttpResponseDescargas;
	http.send(null);
}


//*********************************************************************************
//*********************************************************************************


//************************ SECCION ACTIVIDADES **************************************
//*********************************************************************************

function handleHttpResponseActividades() {
	if (http.readyState == 4) {    	
		//Cargamos el contenido en la capa
		document.getElementById("contenido-actividades").innerHTML = http.responseText;	
	}    
}

function muestraActividades(numero){
	http.open("GET","includes/getActividades.asp?numero=" + numero , true);
	http.onreadystatechange = handleHttpResponseActividades;
	http.send(null);
}


//*********************************************************************************
//*********************************************************************************

//********************** SECCION FORO *********************************************
//*********************************************************************************

function muestraMensaje(numeroMensaje,padreMensaje){
//Funcion para ver el contenido de un mensaje
	http.open("GET","includes/getForo.asp?numeroMensaje=" + numeroMensaje + "&padreMensaje=" + padreMensaje , true);
	http.onreadystatechange = handleHttpResponseForo;
	http.send(null);
}

function nuevoMensaje(numeroMensaje,padreMensaje){
//Funcion para cargar el formulario de insertar una nueva discusion en el tema
	http.open("GET","includes/getForo.asp?numeroMensaje=" + numeroMensaje + "&padreMensaje=" + padreMensaje , true);
	http.onreadystatechange = handleHttpResponseForo;
	http.send(null);
}

function handleHttpResponseForo() {
	if (http.readyState == 4) {    	
		//Cargamos el contenido en la capa
		document.getElementById("contenido-foro").innerHTML = http.responseText;	
	}    
}

function handleHttpResponseRespuestaForo() {
	if (http.readyState == 4) {    	
		//Cargamos el contenido en la capa
		document.getElementById("mensaje-respuesta").innerHTML = http.responseText;	
		document.getElementById("enviarMensaje").reset();
	}    
}

function validarMensaje(){
//Funcion para validar el formulario de insertar un mensaje
	var texto=""
	var cadenaEnvio=""
	
	if ( document.getElementById("enviarMensaje").usuario.value=="" ){
		texto+=" - Debe poner su nombre.\n";
	}else{
		cadenaEnvio+="usuario=" + document.getElementById("enviarMensaje").usuario.value;
	}
	
	if ( document.getElementById("enviarMensaje").resumen.value=="" ){
		texto+=" - Debe poner un titulo.\n";
	}else{
		cadenaEnvio+="&resumen=" + document.getElementById("enviarMensaje").resumen.value;
	}
	
	if ( document.getElementById("enviarMensaje").mensaje.value=="" ){
		texto+=" - Debe poner el mensaje.\n";
	}else{
		cadenaEnvio+="&mensaje=" + document.getElementById("enviarMensaje").mensaje.value;
	}
	
	
	if ( texto!="" ){
		alert(texto);
	}else{
		//aņado los ultimos parametros que necesito
		cadenaEnvio+="&numeroMensaje=" + document.getElementById("enviarMensaje").numeroMensaje.value;
		cadenaEnvio+="&padreMensaje=" + document.getElementById("enviarMensaje").padreMensaje.value;
		http.open("GET","includes/insertar-en-foro.asp?" + cadenaEnvio , true);
		http.onreadystatechange = handleHttpResponseRespuestaForo;
		http.send(null);
	}
}

//*********************************************************************************
//*********************************************************************************

//****************** SECCION CONTACTO *********************************************
//*********************************************************************************

function validarEmail(valor){
//funcion para validar el formato del email
	return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor));
	
}

function validarSuscripcion(){
	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("formularioSuscripcion").nombre.value == "" ) {
		texto+=" - Debe indicar su nombre.\n";
	}else{
		cadenaEnvio="nombre=" + document.getElementById("formularioSuscripcion").nombre.value;
	}
	
	if ( document.getElementById("formularioSuscripcion").apellidos.value == "" ) {
		texto+=" - Debe indicar sus apellidos.\n";
	}else{
		cadenaEnvio+="&apellidos=" + document.getElementById("formularioSuscripcion").apellidos.value;
	}
	
	if ( document.getElementById("formularioSuscripcion").email.value == "" ) {
		texto+=" - Debe indicar su email.\n";
	}
	
	if(document.getElementById("formularioSuscripcion").email.value!=""){
		if(!validarEmail(document.getElementById("formularioSuscripcion").email.value)){
				texto+=" - Formato de E-mail incorrecto.\n";
		}else{
			cadenaEnvio+="&email=" + document.getElementById("formularioSuscripcion").email.value;
		}
	}
	
	if ( texto != "" ){
		alert(texto);
	}else{
		//alert(cadenaEnvio);
		http.open("GET", "actualizer/ap4ns/suscripcion/suscripcion.asp?" + cadenaEnvio, true);
		http.onreadystatechange = handleHttpResponseSuscripcion;
		http.send(null);
	}
	
}

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.\n";
	}else{
		cadenaEnvio="nombre=" + document.getElementById("formularioContacto").nombre.value;
	}
	
	if ( document.getElementById("formularioContacto").apellidos.value == "" ) {
		texto+=" - Debe indicar sus apellidos.\n";
	}else{
		cadenaEnvio+="&apellidos=" + document.getElementById("formularioContacto").apellidos.value;
	}
	
	if ( document.getElementById("formularioContacto").email.value == "" ) {
		texto+=" - Debe indicar su email.\n";
	}
	
	if(document.getElementById("formularioContacto").email.value!=""){
		if(!validarEmail(document.getElementById("formularioContacto").email.value)){
				texto+=" - Formato de E-mail incorrecto.\n";
		}else{
			cadenaEnvio+="&email=" + document.getElementById("email").value;
		}
	}	
	
	if ( document.getElementById("formularioContacto").comentarios.value == "" ){
		texto+=" - Debe incluir el motivo de su consulta.\n";
	}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").telefono.value != "" ){
		cadenaEnvio+="&telefono=" + document.getElementById("formularioContacto").telefono.value;
	}
	
	if ( document.getElementById("formularioContacto").asunto.value != "" ){
		cadenaEnvio+="&asunto=" + document.getElementById("formularioContacto").asunto.value;
	}
	
	
	//Si falta algun campo obligatorio o el email no tiene un formato correcto
	//mostramos un mensaje de avios
	
	if ( texto != "" ){
		alert(texto);
	}else{
		//alert(cadenaEnvio);
		http.open("GET", "actualizer/formcorreosMultiple/envio.asp?" + cadenaEnvio, true);
		http.onreadystatechange = handleHttpResponseContacto;
		http.send(null);
	}
	
}

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 handleHttpResponseSuscripcion() {
	if (http.readyState == 4) {    	
		//Aqui va el nombre de la capa donde queramos cargar el contenido
		document.getElementById("mensaje-respuesta-suscripcion").innerHTML = http.responseText;	
		document.getElementById("formularioSuscripcion").reset();
	}    
}
//*********************************************************************************
//*********************************************************************************

//******************SECCION BOLSA DE TRABAJO***************************************
//*********************************************************************************
function validarTrabajo(){
	//Funcion para la validar los datos enviados desde el formulario de bolsa de trabajo
	var texto;
	texto = "";
	
	//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.\n";
	}
	
	if ( document.getElementById("formularioContacto").apellidos.value == "" ) {
		texto+=" - Debe indicar sus apellidos.\n";
	}
	
	if ( document.getElementById("formularioContacto").email.value == "" ) {
		texto+=" - Debe indicar su email.\n";
	}
	
	if(document.getElementById("formularioContacto").email.value!=""){
		if(!validarEmail(document.getElementById("formularioContacto").email.value)){
				texto+=" - Formato de E-mail incorrecto.\n";
		}
	}	
	
	if ( document.getElementById("formularioContacto").comentarios.value == "" ){
		texto+=" - Debe incluir el motivo de su consulta.\n";
	}
	
	if ( document.getElementById("formularioContacto").curriculum.value == "" ){
		texto+=" - Debe incluir su curriculum.\n";
	} 
	
	//Si falta algun campo obligatorio o el email no tiene un formato correcto
	//mostramos un mensaje de avios
	
	if ( texto != "" ){
		alert(texto);
	}else{
		document.getElementById("formularioContacto").submit();
	}

}

function volverBolsaTrabajo(mensaje){
	sectionPictureTitle = 'title-bolsadeTrabajo.jpg';
	
	//Cambia la imagen de titulo de seccion
	with(document.getElementById("seccionTitle")){
		src = 'images/' + sectionPictureTitle;
		alt = "bolsa ElectroMED.";
	}	
	
	//Ocultamos la imagen de novedades de producto
	with(document.getElementById("novedades")){
		src='images/background-title-red-part2-electromed.jpg';
		alt ='';
	}
	
	http.open("GET", "bolsa-de-trabajo-electromed.asp?mensaje=" + mensaje , true);
	http.onreadystatechange = handleHttpResponseNavegacion;
	http.send(null);	
}
//*******************************************************************************************************
//*******************************************************************************************************
//--
function paginarOfertas(pagina)
{
	url='ofertas-electromed.asp?pagina='+pagina;
	http.open("GET", url , true);
	http.onreadystatechange = handleHttpResponseNavegacion;
	http.send(null);	
}

