//ESTA FUNCIÓN ES PARA MANTENER ACTIVO EN AZUL BRILLANTE LA OPCIÓN DEL MENÚ PRINCIPAL SELECCIONADA
function menu(activo){
	if (activo != ""){
		document.getElementById(activo).style.color="#fda83e";	
	}
	else{
		document.getElementById('inicio').style.color="#fda83e";	
	}
}
	
	
//igual que la primera pero para activar el submenu de productos

function subMenu(activo){
	if (activo != ""){
		document.getElementById(activo).style.color="#fda83e";	
	}
	else{
		return true;
	}
}
	


// para los submenus de segundo nivel de FORMACIÓN
function subMenu1(activo){
	if (activo != ""){
		document.getElementById(activo).style.color="#990203";	
	}
	else{
		return true;
	}
}
	
	
function validarEmail() {
	
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.revista.email.value)){
	document.revista.submit();
  } else {
	alert("La dirección de EMAIL es incorrecta.");
	return (false);
  }	
}

function validaRevista(){
	//alert(document.revista.elements(3).name)
	var campos= "Los siguientes campos son obligatorios:\n";
	var errores = 0;
	for (i=0; i<=12; i++){
		if (document.revista.elements(i).value == ""){
				errores = 1;
				//campos = campos + document.revista.elements(i).name + "\n";
			}
		
		}
	if(errores == 1) {
			document.getElementById('error').style.display="";
			
			
			//alert(campos);
			
		}else{
			validarEmail();
			
			}
	
	}
	
	
function validaDistri(){
	var campos = document.distri.elements.length - 1;
	var errores = 0;
	var error;
	for (i=0; i<=campos; i++){
		if (document.distri.elements(i).value == ""){
			errores = 1;
		}
	}
	if(errores == 1) {
		posiciona();
		estadoForm(true,'distri');
		error = "Todos los campos son obligatorios."
		document.getElementById('p1').innerHTML = error;
 		document.getElementById('capaerrores').style.display = "";
 		
 		location.href = "#";
	}
	else{	
		posiciona();
		validarEmaildistri();
	}
	
	
}
	
	function errores(errortelefono, errorfax, errorcp, errormail){
		
		alert("Se han encontrado los siguientes errores:" + errortelefono + errorfax + errorcp + errormail)
		}
	
	
	function validarEmaildistri() {
	var error = 0
	var errortelefono, errorfax, errorcp, errormail;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.distri.email.value)){
document.getElementById('p4').style.display="none";

  		} else {
		 error = 1;
		errormail= "La dirección de EMAIL es incorrecta";
		document.getElementById('p4').style.display="";
		
  		}	
  
	if (isNaN(document.distri.telefono.value) == false){
			
			if (document.distri.telefono.value.length<9){
				error = 1;
				errortelefono = "El campo TELÉFONO es incorrecto"
				document.getElementById('p1').style.display="none";

			}else{
				document.getElementById('p1').style.display="none";;
				}
		}else{
			error = 1;
			errortelefono = "El campo TELÉFONO es incorrecto"
			document.getElementById('p1').style.display="";
			}
		if(isNaN (document.distri.fax.value)== false){
				if (document.distri.fax.value.length<9){
				error = 1;
				errorfax = "El campo FAX es incorrecto"
				document.getElementById('p2').style.display="";
				}else{
					document.getElementById('p2').style.display="none";
					}
		}else{
			error = 1;
			errorfax = "El campo FAX es incorrecto"
			}
									  
		 if(isNaN (document.distri.cp.value)== false){
													
				if (document.distri.cp.value.length<5){
				error = 1;
				errorcp = "El campo CÓDIGO POSTAL es incorrecto"
				document.getElementById('p3').style.display="";
				}else{
					document.getElementById('p3').style.display="none";
					}
		}else{
			error = 1;
			errorcp = "El campo CÓDIGO POSTAL es incorrecto"
			document.getElementById('p3').style.display="";
			}
 if (error == 1){

	 document.getElementById('p1').innerHTML = errortelefono;
	 document.getElementById('p2').innerHTML = errorfax;
	 document.getElementById('p3').innerHTML = errorcp;
	 document.getElementById('p4').innerHTML = errormail;
	 
	 document.getElementById('capaerrores').style.display = "";
	 location.href = "#";
	 //errores(errortelefono, errorfax, errorcp, errormail);
	 }else{
		 document.distri.submit();
		 } 
}
	
	
	
				
 function validarEmailcontacto() {
	
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.contacto.email.value)){
	document.contacto.submit();
  } else {
	alert("La dirección de EMAIL es incorrecta.");
	return (false);
  }	
}

function distri(){
	alert(document.distribuidor.estado.value);
	document.getElementById('subservicios').style.display="block";
	}
	
function cambiaImagen(){
	document.getElementById('bann').style.display = "";
	document.getElementById('bann').src = "/colombia/img/home/banners/" + document.banner.banners.value;
	
	}
	
function cambiaImagencasos(){
	document.getElementById('bann').style.display = "";
	document.getElementById('bann').src = "/colombia/img/home/casos/" + document.banner.banners.value;
	
	}
	
function cambiaImagenrevista(){
	document.getElementById('bann').style.display = "";
	document.getElementById('bann').src = "/colombia/img/home/revista/" + document.banner.banners.value;
	
	}
	
function cambiaImagendistri(){
	document.getElementById('bann').style.display = "";
	document.getElementById('bann').src = "/colombia/img/home/distri/" + document.banner.banners.value;
	
	}
	
	
//Funcion para el apartado de distribuidores. Para cuando seleccionamos un estado, que nos aparezca el listado de distribuidores de ese estado.	
function cambiar(estado){
		//alert("/colombia/distribuidores/comprar.asp?menu=distri&id_estado=" + estado)
		
		location.href= "/colombia/distribuidores/comprar.asp?menu=distri&id_estado=" + estado;
	}
	
function abreDistri(){
	window.open('/colombia/distribuidores/comprar.asp','distribuidores','width=540, height=400, toolbars=no, resizable=no, directories=no, top=0, left= 0, scrollbars=yes');
	
	}
	
	
//Validador de campos de administrador y validador de fecha en el administrador

function getYear(d) { 
   return (d < 1000) ? d + 1900 : d;
   }
 
 function isDate (day, month, year) {
   // month argument must be in the range 1 - 12
   month = month - 1;  // javascript month range : 0- 11
   var tempDate = new Date(year,month,day);
   if ( (getYear(tempDate.getYear()) == year) &&
      (month == tempDate.getMonth()) &&
      (day == tempDate.getDate()) )
       return true;
   else
      return false
   }
 
 function fechak(fecha)
 {
 if (fecha!="")
 {
 var fecha2=fecha
 p=fecha2.split("/")
  if (isDate(p[0],p[1],p[2])==false)
  {
   alert("ERROR: por favor, introduzca una fecha correcta")
   
  }else{
	document.banner.submit();
}
}
}






function validarCampos(){
var campos = document.banner.elements.length - 1;
	var errores = 0;
	var error;
	for (i=0; i<=campos; i++){
		if (document.banner.elements(i).value == ""){
				errores = 1;
				
			}
		
		}
	if(errores == 1) {
		alert("Todos los campos son obligatorios.");
	
	
	}else{
		fechak(document.banner.fecha.value)
		
		}
	}






function estadoForm(estado,nombreFormulario){

	if(nombreFormulario == 'distri'){
		var longitud = document.distri.elements.length - 1;
	}
	if(nombreFormulario == 'contacto'){
		var longitud = document.contacto.elements.length;
	}
	if(nombreFormulario == 'revista'){
		var longitud = document.revista.elements.length;
	}
	for(i=1;i<=longitud;i++){
		campo = 'entrada' + i;
		//alert(campo);
		document.getElementById(eval('campo')).disabled = estado;
	}
}
function ocultaCapa(param){
	document.getElementById('capaerrores').style.display = 'none';	
}	

function posiciona(){
	var x_res = screen.width;
	var y_res = screen.height;
	var dividendo = 2;

	var posicionCapa = new Array;
	posicionCapa[0] = document.getElementById('capaerrores').style.top;
	posicionCapa[1] = document.getElementById('capaerrores').style.left;
	
	var x_final=((x_res) - posicionCapa[0])/dividendo;
	var y_final=((y_res) - posicionCapa[1])/dividendo;
	
	document.getElementById('capaerrores').top = x_final;
	document.getElementById('capaerrores').left = y_final;
}



function final(){
	document.getElementById('p1').innerHTML = 'El env&iacute;o del formulario se ha realizado correctamente. Gracias por su colaboraci&oacute;n';
	document.getElementById('p0').style.display = 'none';
	document.getElementById('capaerrores').style.display = "";
}
function validaFormrevista() {
	var campos = document.revista.elements.length - 1;
	var errores = 0;
	var error;

	for (i=0; i<=campos; i++){
		if (document.revista.elements(i).value == ""){
			errores = 1;
		}
	}	
	if(errores == 1) {
		posiciona();
		estadoForm(true,'revista');
		error = "Todos los campos son obligatorios."
		document.getElementById('p1').innerHTML = error;
 		document.getElementById('capaerrores').style.display = "";
 		
 		//location.href = "#";
	}
	else{	
		posiciona();
		estadoForm(true,'revista');
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.revista.email.value)){
			document.revista.submit();
		}
		else{
			estadoForm(true,'revista');
			error= "La dirección de EMAIL es incorrecta";
			document.getElementById('p1').innerHTML = error;
 			document.getElementById('capaerrores').style.display = "";
 		 	//location.href = "#";
	  	}
	}		
}


function validarEmaildistri() {
	estadoForm(true,'distri');
	var error = 0
	var errortelefono, errorfax, errorcp, errormail;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.distri.email.value)){
		document.getElementById('p4').style.display="none";
 	}
	else{
		error = 1;
		errormail= "La dirección de EMAIL es incorrecta";
		document.getElementById('p4').style.display="";
	}	
	if (isNaN(document.distri.telefono.value) == false){
		if (document.distri.telefono.value.length<9){
			error = 1;
			errortelefono = "El campo TELÉFONO es incorrecto"
			document.getElementById('p1').style.display="none";
		}
		else{
			document.getElementById('p1').style.display="none";
		}
	}
	else{
		error = 1;
		errortelefono = "El campo TELÉFONO es incorrecto"
		document.getElementById('p1').style.display="";
	}
	if(isNaN (document.distri.fax.value)== false){
		if (document.distri.fax.value.length<9){
			error = 1;
			errorfax = "El campo FAX es incorrecto"
			document.getElementById('p2').style.display="";
		}
		else{
			document.getElementById('p2').style.display="none";
		}
	}
	else{
		error = 1;
		errorfax = "El campo FAX es incorrecto"
	}
	if(isNaN (document.distri.cp.value)== false){
		if (document.distri.cp.value.length<5){
			error = 1;
			errorcp = "El campo CÓDIGO POSTAL es incorrecto"
			document.getElementById('p3').style.display="";
		}
		else{
			document.getElementById('p3').style.display="none";
		}
	}
	else{
		error = 1;
		errorcp = "El campo CÓDIGO POSTAL es incorrecto"
		document.getElementById('p3').style.display="";
	}
	 if (error == 1){
		 document.getElementById('p1').innerHTML = errortelefono;
		 document.getElementById('p2').innerHTML = errorfax;
		 document.getElementById('p3').innerHTML = errorcp;
		 document.getElementById('p4').innerHTML = errormail;
		 document.getElementById('capaerrores').style.display = "";
		 location.href = "#";
	 }
	 else{
	 	//alert("todoOK");
		document.distri.submit();
	 } 
	 
}
	
	

				
function validarFormcontacto() {
	var campos = document.contacto.elements.length;
	//alert(campos);
	var errores = 0;
	var error;
	for (i=1; i<=campos; i++){
		//alert(i);
		if (document.contacto.elements(i).value == ""){
			errores = 1;
		}
	}	
	if(errores == 1) {
		posiciona();
		estadoForm(true,'contacto');
		error = "Todos los campos son obligatorios."
		document.getElementById('p1').innerHTML = error;
 		document.getElementById('capaerrores').style.display = "";
	}
	else{
		posiciona();
		//alert('entra');
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.contacto.email.value)){
			estadoForm(true,'contacto');
			document.contacto.submit();
		}
		else{
			error= "La dirección de EMAIL es incorrecta";
			document.getElementById('p1').innerHTML = error;
 			document.getElementById('capaerrores').style.display = "";
 		 	//location.href = "#";
	  	}
	}		
}
function sacavalor(eloptionclikao){
	document.banner.nombre_municipio.value=document.banner.id_estado.options[eloptionclikao].text;	

}
function validarFormDistri(){
	if(document.banner.id_estado.selectedIndex == 0){
		alert("Por favor introduce el estado.");

	}
	else if (document.banner.nombre_distribuidor.value == "" || document.banner.nombre_distribuidor.value == null){
		alert("Por favor introduce el nombre del distribuidor.");

	}
	else{
		document.banner.submit();
	}
}

function validarPreciosUpgrade() {
	var p1;
	var p2;
	var i1;
	var i2;
	//Se hace un replace porque sólo entiende como separación decimal el punto.
	p1 = document.banner.precio1.value.replace(",",".");
	p2 = document.banner.precio2.value.replace(",",".");
	i1 = document.banner.iva1.value.replace(",",".");
	i2 = document.banner.iva2.value.replace(",",".");
	
	if(document.banner.precio1.value==""){
		alert("Debe indicar un precio 1.");
	}
	else if(isNaN(p1)){
		alert("El precio 1 es numérico.");
	}
	else if(document.banner.iva1.value==""){
		alert("Debe indicar un iva 1.");
	}
	else if(isNaN(i1)){
		alert("El iva 1 es numérico.");
	}
	else if(document.banner.precio2.value==""){
		alert("Debe indicar un precio 2.");
	}
	else if(isNaN(p2)){
		alert("El precio 2 es numérico.");
	}
	else if(document.banner.iva2.value==""){
		alert("Debe indicar un iva 2.");
	}
	else if(isNaN(i2)){
		alert("El iva 2 es numérico.");
	}
	else if(document.banner.area.value=="-"){
		alert("Debe indicar un área de producto.");
	}
	else if(document.banner.producto.value=="-"){
		alert("Debe indicar un producto.");
	}
	else{
		document.banner.submit();	
	}
}
function validarOfertaNaranja() {
	if(document.banner.oferta.value==""){
		alert("Debe indicar una oferta.");
	}
	/*else if(document.banner.resumen1.value==""){
		alert("Debe indicar un títular 1º.");
	}
	else if(document.banner.contenido1.value==""){
		alert("Debe indicar un contenido 1º.");
	}
	else if(document.banner.alt1.value==""){
		alert("Debe indicar un alt 1º.");
	}
	else if(document.banner.enlace1.value==""){
		alert("Debe indicar un texto para el enlace  1º.");
	}
	else if(document.banner.url1.value==""){
		alert("Debe indicar una url para el enlace  1º.");
	}
	else if(document.banner.resumen2.value==""){
		alert("Debe indicar un títular 2º.");
	}
	else if(document.banner.contenido2.value==""){
		alert("Debe indicar un contenido 2º.");
	}
	else if(document.banner.alt2.value==""){
		alert("Debe indicar un alt 2º.");
	}
	else if(document.banner.enlace2.value==""){
		alert("Debe indicar un texto para el enlace  2º.");
	}
	else if(document.banner.url2.value==""){
		alert("Debe indicar una url para el enlace  2º.");
	}*/
	else{
		document.banner.submit();	
	}
}
function recargaModuloInsertar(){
	document.banner.llenar_producto.value = "si";
	document.banner.action = "modulos.asp?menu=insertaprecio";
	document.banner.submit();	
}
function recargaModuloModificar(idPrecio){
	document.banner.action = "modulos.asp?menu=updateprecio&idprecio=" + idPrecio;
	document.banner.submit();	
}
function validaBanner(){
	if (document.banner.idImagen.value == ""){
		alert("No puede modificar el banner porque todavía no está activo.");
		return false;
	}else{
		if (document.banner.lado[0].checked == false && document.banner.lado[1].checked == false){
			alert("Debe indicar en qué lado quiere colocar el banner.");
			return false;
		}else{
			return true;
		}
	}
}
function aceptar(){
	var arrayBanners;
	if (document.banner.banners.value == "|||||"){
		alert("Debe seleccionar una imagen.");
	}else{
		arrayBanners = document.banner.banners.value.split("|");
		document.banner.idImagen.value = arrayBanners[0];
		document.banner.imagen.value = arrayBanners[1];
		document.banner.control.value = "ok";
		document.banner.action="/colombia/admin/modulos.asp?menu=banners&func=1";
		document.banner.submit();
	}		
}

function cambiaImagen(){
	
	var arrayBanners;
	var val_act;
	
	arrayBanners = document.banner.banners.value.split("|");
	
	document.getElementById('bann').style.display = "";
	document.getElementById('bann').src = "/colombia/img/home/banners/" + arrayBanners[1];
	document.banner.alt.value = arrayBanners[4];
	document.banner.url.value = arrayBanners[5];
	if (arrayBanners[2] == "1"){
		val_act = true;	
	}
	else if (arrayBanners[2] == "0"){
		val_act = false;
	}
	else{
		val_act = false;
	}
	document.banner.activo.checked = val_act;
	if (arrayBanners[3] == "d"){
		document.banner.lado[0].checked = true;
		document.banner.lado[1].checked = false;
	}
	else if (arrayBanners[3] == "i"){
		document.banner.lado[0].checked = false;
		document.banner.lado[1].checked = true;
	}
	else{
		document.banner.lado[0].checked = false;
		document.banner.lado[1].checked = false;
	}
	
}
function limpiarPantalla(){
	document.banner.alt.value = "";
	document.banner.url.value = "";	
	document.banner.activo.checked = false;
	document.banner.lado[0].checked = false;
	document.banner.lado[1].checked = false;
	document.banner.idImagen.value = "";
	document.banner.imagen.value = "";
}
function insertarPubBanner(){
	if (document.banner.lado[0].checked == false && document.banner.lado[1].checked == false){
		alert("Debe indicar en qué lado quiere colocar el banner.");
	}else{
		document.banner.action = "insertar.asp?menu=banner";
		document.banner.submit();
	}	
}
function modificarPubBanner(){
	if (validaBanner() == true){
		document.banner.action = "update.asp?op=banner&idbanner=" + document.banner.idImagen.value;
		document.banner.submit();
	}	
}
function borrarBanner(){
	var arrayBanners;
	var respuesta;
	if (document.banner.banners.value == "|||||"){
		alert("Debe seleccionar una imagen.");
	}else{
		arrayBanners = document.banner.banners.value.split("|");
		document.banner.idImagen.value = arrayBanners[0];
		document.banner.imagen.value = arrayBanners[1];
		
		respuesta = confirm("¿Está usted seguro de borrar la imagen junto con todos sus datos?");
		if (respuesta == true){
			document.banner.action = "delete.asp?menu=banner&idbanner=" + document.banner.idImagen.value;
			document.banner.submit();
		}
	}	
}

function validarCurso() {
	if(document.banner.curso.value==""){
			alert("Debe indicar un curso.");
	}
	else if(document.banner.fecha.value==""){
			alert("Debe indicar una fecha.");
	}
	else if(document.banner.ciudad.value==""){
			alert("Debe indicar una ciudad.");
	}
	else{
			document.banner.submit();	
	}
}

function validarNovedad() {
	if(document.banner.novedad.value==""){
			alert("Debe indicar una novedad.");
	}
	else{
			document.banner.submit();	
	}
}

function validarUVersion() {
	if(document.banner.titulo.value==""){
			alert("Debe indicar un título.");
	}
	else if(document.banner.descripcion.value==""){
			alert("Debe indicar una descripción.");
	}
	else{
			document.banner.submit();	
	}
}

function validarEvento() {
	if(document.banner.titulo.value==""){
			alert("Debe indicar un título.");
	}
	/*else if(document.banner.descripcion.value==""){
			alert("Debe indicar una descripción.");
	}*/
	else if(document.banner.autor.value==""){
			alert("Debe indicar un autor.");
	}
	else{
			document.banner.submit();	
	}
}