function mostrarSeleccion(opcionMenu) {
	// función llamada en el mouseover del mapa Menu para colocar la capa transparente sobre 
	//la pestaña del menú correspondiente
		cambiarCursorAMano;
		document.getElementById('capa-seleccion').style.visibility="visible"; 
		switch (opcionMenu)
		{
		case '1':
			document.getElementById('capa-seleccion').style.left="388";
			document.getElementById('capa-seleccion').style.width="83";
			break;
		case '2':
			document.getElementById('capa-seleccion').style.left="479";
			document.getElementById('capa-seleccion').style.width="100";
			break;
		case '3': //consumo energía
			document.getElementById('capa-seleccion').style.left="589";
			document.getElementById('capa-seleccion').style.width="83";
			break;
		case '4': //otros servicios
			document.getElementById('capa-seleccion').style.left="677";
			document.getElementById('capa-seleccion').style.width="73";
			break;
		case '5': //contacto
			document.getElementById('capa-seleccion').style.left="756";
			document.getElementById('capa-seleccion').style.width="73";
			break;
		}
	}

	function ocultarSeleccion () {
	// función llamada en el mouseout de la capa-seleccion para ocultar la capa transparente sobre 
	//la pestaña del menú correspondiente
		document.getElementById('capa-seleccion').style.visibility="hidden"; 
		document.body.style.cursor="default";
	}

function checkS(e){
// capture the mouse position
    var posx = 0;
    var posy = 0;
    if (!e) var e = window.event;
    if (e.pageX || e.pageY)
    {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY)
    {
        posx = e.clientX;
        posy = e.clientY;
    }

	/*document.getElementById('pos').innerHTML = 'Mouse position is: X='+posx+' Y='+posy;

	document.getElementById('pos').style.left = posx;
	document.getElementById('pos').style.top = posy;*/
	var estiloCursor = "";
	if (navigator.appName=='Microsoft Internet Explorer')	
		estiloCursor = "hand";
	else 
			if (navigator.appName=='Netscape') 
				estiloCursor = "pointer";				

	if (posx >= 397 && posx<= 480)
	{
		document.body.style.cursor=estiloCursor;
	}
	if (posx >= 489 && posx<= 588) 	{
		document.body.style.cursor=estiloCursor;
	}
	if (posx >= 597 && posx<= 678) 	{
		document.body.style.cursor=estiloCursor;
	}
	if (posx >= 688 && posx<= 759) 	{
		document.body.style.cursor=estiloCursor;
	}
	if (posx >= 768 && posx<= 837) 	{
		document.body.style.cursor=estiloCursor;
	}
}
function redireccionar (e) {
// capture the mouse position
    var posx = 0;
    var posy = 0;
    if (!e) var e = window.event;
	
		
    if (e.pageX || e.pageY)
    {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY)
    {
        posx = e.clientX;
        posy = e.clientY;
    }

	if (posx >= 397 && posx<= 480) 	{
		location.href = "default.html";
	}
	if (posx >= 489 && posx<= 588) 	{
		location.href = "generacionEnergia.html";
	}
	if (posx >= 597 && posx<= 678) 	{
		location.href = "consumoEnergia.html";
	}
	if (posx >= 688 && posx<= 759) 	{
		location.href = "otrosServicios.html";
	}
	if (posx >= 768 && posx<= 837) 	{
		location.href = "contacto.html";
	}
}

function cambiarCursor (){
	document.body.style.cursor="default";
}

function cambiarCursorAMano (){
	
	var estiloCursor = "";
	if (navigator.appName=='Microsoft Internet Explorer')	
		estiloCursor = "hand";
	else 
			if (navigator.appName=='Netscape') 
				estiloCursor = "pointer";				

	document.body.style.cursor=estiloCursor;
}

function cambiarIdioma(idioma,pagina) {

	if (idioma=='null') {
				location.href = 'default.html';
				return;
			}
				
	switch (pagina)
	{
		case 'default': 
			document.location.href = 'ga/default.html';
			break;
		case 'contacto': 
			document.location.href =  'ga/contacto.html';
			break;
		case 'generacionenergia': 
			document.location.href =  'ga/generacionEnergia.html';
			break;
		case 'consumoenergia': 
			document.location.href =  'ga/consumoEnergia.html';
			break;
		case 'otrosservicios': 
			document.location.href =  'ga/otrosServicios.html';
			break;
		case 'contacto': 
			document.location.href =  'ga/contacto.html';
			break;
	}
}

//Función que comprueba si a metido un número o un número con decimales
function checkDouble(field){
	if (field.value.match('^(\d)?(\d)*\,?\d*$'))
		return (true);
	else
		return (false);
}

//Funcion que comprueba si un CIF es valido o no.
function checkCIF(texto){
	var pares = 0;
	var impares = 0;
	var suma;
	var ultima;
	var unumero;
	var uletra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I");
	var xxx;
	
	texto = texto.toUpperCase();
	
	var regular =/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g;
	 if (!regular.exec(texto)) return false;
		 
	 ultima = texto.substr(8,1);

	 for (var cont = 1 ; cont < 7 ; cont ++){
		 xxx = (2 * parseInt(texto.substr(cont++,1))).toString() + "0";
		 impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
		 pares += parseInt(texto.substr(cont,1));
	 }
	 xxx = (2 * parseInt(texto.substr(cont,1))).toString() + "0";
	 impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
	 
	 suma = (pares + impares).toString();
	 unumero = parseInt(suma.substr(suma.length - 1, 1));
	 unumero = (10 - unumero).toString();
	 if(unumero == 10) unumero = 0;
	 
	 if ((ultima == unumero) || (ultima == uletra[unumero]))
		 return true;
	 else
		 return false;

} 

//Comprueba si el precio introducido es válido o no.
function checkPrice(field){
	//if (field.value.match('^(\d{1,18}\.?\d{0,2})$'))
	if(!isNaN(field.value))
		return (true);
	else
		return (false);
}

//Comprueba si el numero de teléfono introducido es válido o no.
function checkPhone(field){
	if(Len(field.value) != 9 || isNaN(field.value))
		return false;
	else
		return true;
}

//Comprueba si el código postal introducido es válido o no.
function checkCP(field){
	if(Len(field.value) != 5 || isNaN(field.value))
		return false;
	else
		return true;
}

//Comprueba si el email es correcto o no
function checkEmailAddress(field) {
	//if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(field))
	if (field.value.match('.*@.*\..*'))
		return (true);
	else
		return (false);
}
//Funcion que comprueba si un DNI es valido o no.
//letterDNI -> Indica si tiene que validar la letra del DNI, calcularla automáticamente u omitirla. Valores:
//	0-> Valida la letra del DNI
//	1-> No tiene en cuenta la letra
function checkDni(field, letterDNI){
	var Letra = 'TRWAGMYFPDXBNJZSQVHLCKET';
	if (field.value == '')
		return false;
	else if(letterDNI == 1)
		if (Len(field.value) != 9)
			return false;
		else if (isNaN(Left(field.value, Len(field.value)-1)))
			return false;
		else if (Right(field.value, 1) < 'A' || Right(field.value, 1) > 'Z')
			return false;
		else if (Mid(Letra, (Left(field.value, Len(field.value)-1) % 23), 1) != Right(field.value, 1) && letterDNI == 0)
			return false;
		else
			return true;
	else 
		if (Len(field.value) != 8)
			return false;
		else if (isNaN(field.value))
			return false;
		else
			return true;
}
//Comprueba que la fecha introducida sea correcta
function checkDate(field){
	//Formato dd/mm/yyyy valida si el año es bisiesto o no
	if (field.value.match('(((0[1-9]|[12][0-9]|3[01])([/])(0[13578]|10|12)([/])([1-2][0,9][0-9][0-9]))|(([0][1-9]|[12][0-9]|30)([/])(0[469]|11)([/])([1-2][0,9][0-9][0-9]))|((0[1-9]|1[0-9]|2[0-8])([/])(02)([/])([1-2][0,9][0-9][0-9]))|((29)(\.|-|\/)(02)([/])([02468][048]00))|((29)([/])(02)([/])([13579][26]00))|((29)([/])(02)([/])([0-9][0-9][0][48]))|((29)([/])(02)([/])([0-9][0-9][2468][048]))|((29)([/])(02)([/])([0-9][0-9][13579][26])))'))
		return (true);
	else
		return (false);
}
//Comprueba que la url introducida sea correcta
function checkURL(field){
	if(field.value.match('^(ht|f)tp(s?)\:\/\/[a-zA-Z0-9\-\._]+(\.[a-zA-Z0-9\-\._]+){2,}(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$'))
		return true;
	else
		return false;
}
//------------------------------ Funciones para trabajar con fechas --------------------------------
//Comprueba si es una fecha
function IsDate(Expression) {
  var test = new Date(Date.parse(Expression));
  return !(isNaN(test.getYear()));
}
//Devuelve el nombre de un mes
function MonthName(Month, Abbreviate) {
  var months = new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
  if (Month < 1 || Month > 13) {
	return "";
  }
  var retval = months[Month - 1];
  if (Abbreviate) retval = Left(retval, 3);
  return retval;
}
//Devuelve el día de la semana
function WeekdayName(Weekday, Abbreviate, FirstDayOfWeekValue) {
  var weekdays = new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
  if (Weekday < 1 || Weekday > 7) {
    return "";
  }
  if (FirstDayOfWeekValue < 0 || FirstDayOfWeekValue > 7) {
	return "";
  }
  var addval = (FirstDayOfWeekValue > 1) ? FirstDayOfWeekValue : 0;
  if (Weekday + addval > 7) addval -= 7;
  return weekdays[Weekday + addval - 1];
}
//------------------------------ Otras funciones --------------------------------
//Devuelve el resto de dividir a entre b
function Mod(a, b) {
    return a - Math.floor(a / b) * b;
}
//Comprueba si es nulo
function IsNull(Expression) {
  return (Expression == null);
}
//Comprueba si está vacío
function IsEmpty(Expression) {
  return (Expression.toString().length == 0);
}
//Comprueba si es un objeto
function IsObject(Expression) {
  return (typeof Expression == "object");
}
//Comprueba si es un array
function IsArray(VarName) {
  return (VarName.constructor.toString().indexOf("Array") == -1);
}
