﻿//Valida fecha dd/MM/yyyy
function validaFecha( strValue ) {
  var objRegExp = /^\d{2}\/\d{2}\/\d{4}$/
  if(!objRegExp.test(strValue))
    return false;
  else {
    var arrayDate = strValue.split('/');
    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,'08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[0],10);
    if(arrayLookup[arrayDate[1]] != null) {
      if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
        return true;
    }
    var intMonth = parseInt(arrayDate[1],10);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2],10);
		if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
          return true;
       }
  }
  return false;
}
function colocarFondo(){
var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  var fondo = document.getElementById('miFondo');
  fondo.style.backgroundImage = "url('fondo.aspx?iW="+ myWidth +"&iH="+ myHeight +"')" 
}
function moverDerecha(){
	
	var capaPeliculas = document.getElementById('minis');
	var pixeles = capaPeliculas.style.left.replace('px', '');
	capaPeliculas.style.left = pixeles - 109;
	}
function moverIzquierda(){
	
	var capaPeliculas = document.getElementById('minis');
	var pixeles = capaPeliculas.style.left.replace('px', '');
	capaPeliculas.style.left = parseInt(pixeles) + 109;
	}
function seleccionarCine(){
	var comboCines = document.getElementById('Cines');
	if (comboCines.value != 0) {
	window.navigate('catalogo.aspx?idArea=30&idPadre=0&idNodo=10&idParrafo=' + comboCines.value);
	}
	}
function seleccionarPelicula(){
	var comboPeliculas = document.getElementById('comboPeliculas');
	if (comboPeliculas.value != 0) {
	window.navigate('peliculas.aspx?id=' + comboPeliculas.value);
	}
	}
function limpiarCuadroSuscripcion(){
	var cuadro = document.getElementById('direccionSuscripcion');
	
	if ((cuadro.value == 'introduce tu e-Mail y pulsa enter') || (cuadro.value == 'gracias por suscribirte a la cartelera!!'))
	{
		cuadro.value = '';
	}
	}
function llenarCuadroSuscripcion(){
	var cuadro = document.getElementById('direccionSuscripcion');
	
	if (cuadro.value == '')
	{
		cuadro.value = 'introduce tu e-Mail y pulsa enter';
	}
	}

function controlarTeclas(e)

{
    var KeyPress  
    if(e && e.which)    {
		e = e   
        KeyPress = e.which 
    } else {
        e = event
        KeyPress = e.keyCode
    }

    if(KeyPress == 13) {
		var cuadro = document.getElementById('direccionSuscripcion');
		if (mail(cuadro.value)){	
				document.frmSuscripcion.submit();
		} else {
			alert('La dirección de e-Mail introducida no es válida');
			return false;
			}
		return false     
    }
    else {
        return true
	}
}

function mail(texto){ 

    var mailres = true;             
    var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-"; 
     
    var arroba = texto.indexOf("@",0); 
    if ((texto.lastIndexOf("@")) != arroba) arroba = -1; 
     
    var punto = texto.lastIndexOf("."); 
                 
     for (var contador = 0 ; contador < texto.length ; contador++){ 
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){ 
            mailres = false; 
            break; 
     } 
    } 

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1)) 
     mailres = true; 
    else 
     mailres = false; 
                 
    return mailres; 
} 


