//lo primero de todo
window.onload = function alcargar(){titulo();miraResolucion();showtime(); }
window.onresize = function cambiaTamano(){miraResolucion()}

// maximiza
function maximizar(){
window.moveTo(0,0);
window.resizeTo(screen.width,screen.height);
}
// desactivar boton derecho 

var mensaje = "[Copyright - LA CASITA DE LOS BOMBONES]";
function derecho(e)
{
   if (navigator.appName == 'Netscape' && e.which == 3)
      alert(mensaje);
   else if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2)
      alert(mensaje);
}
document.onmousedown = derecho;

// Pone el titulo en la ventana dependiendo del titulo de la pagina

function titulo(){
	var cual = document.getElementsByTagName('div');
	for (var i=0; i<cual.length; i++) {
	    if (cual[i].className=='titulo') {
	        document.title = "...: La casita de los bombones - "+cual[i].innerText+" :...";
	    }
	}
}


function mititulo(){
	var titulo;
    var cual = document.getElementsByTagName('div');
	for (var i=0; i<cual.length; i++) {
	    if (cual[i].className=='titulo') {
	        titulo = cual[i].innerText;
	    }
	}
	return titulo;
}

// Cambia el aspecto del contenido dependiendo del tama�o de la ventana del navegador							

function miraResolucion(){
    var ancho = document.documentElement.clientWidth;
    var alto = document.documentElement.clientHeight;
    var cual = document.getElementsByTagName('div');
    var logo = document.getElementsByTagName('img');
    var quelogo;
 
    if (ancho<970&&alto<548) {
    	for (var i=0; i<cual.length; i++) {
	        if (cual[i].id=='contenedor' ||cual[i].id=='contenedor_800x600'||cual[i].id=='contenedor_AltoMayor600'||cual[i].id=='contenedor_AnchoMayor800') {
                cual[i].id='contenedor_800x600';
            }
        }
      for (var i=0; i<logo.length; i++) {
	        quelogo = logo[i].src.toString().split("imagenes/")
	        if(quelogo[1]=="logo.jpg" || quelogo[1]=="logo2.jpg"){
	        logo[i].src = quelogo[0]+"imagenes/logo2.jpg";
	        }
        }
			document.getElementById('menu').style.width = '896px';
			document.getElementById('menu_absolute').style.width = '890px';
			document.getElementById('ruta').style.width = '896px';
    }
    else if (ancho<970&&alto>548) {
    	for (var i=0; i<cual.length; i++) {
	        if (cual[i].id=='contenedor' ||cual[i].id=='contenedor_800x600'||cual[i].id=='contenedor_AltoMayor600'||cual[i].id=='contenedor_AnchoMayor800') {
                cual[i].id='contenedor_AltoMayor600';
            }
        }
        for (var i=0; i<logo.length; i++) {
	        quelogo = logo[i].src.toString().split("imagenes/")
	        if(quelogo[1]=="logo.jpg" || quelogo[1]=="logo2.jpg"){
	        logo[i].src = quelogo[0]+"imagenes/logo2.jpg";
	        }
        }
			document.getElementById('menu').style.width = '896px';
			document.getElementById('menu_absolute').style.width = '890px';
			document.getElementById('ruta').style.width = '896px';
    }
    else if (ancho>970&&alto<548) {
        for (var i=0; i<cual.length; i++) {
	        if (cual[i].id=='contenedor' ||cual[i].id=='contenedor_800x600'||cual[i].id=='contenedor_AltoMayor600'||cual[i].id=='contenedor_AnchoMayor800') {
                cual[i].id='contenedor_AnchoMayor800';
            }
        }
        for (var i=0; i<logo.length; i++) {
	        quelogo = logo[i].src.toString().split("imagenes/")
	        if(quelogo[1]=="logo.jpg" || quelogo[1]=="logo2.jpg"){
	        logo[i].src = quelogo[0]+"imagenes/logo.jpg";
	        }
        }
		document.getElementById('menu').style.width = '791px';
			document.getElementById('menu_absolute').style.width = '782px';
			document.getElementById('ruta').style.width = '791px';

    }
    else if (ancho>970&&alto>548) {
      for (var i=0; i<cual.length; i++) {
	        if (cual[i].id=='contenedor' ||cual[i].id=='contenedor_800x600'||cual[i].id=='contenedor_AltoMayor600'||cual[i].id=='contenedor_AnchoMayor800') {
                cual[i].id = 'contenedor';
            }
      }
      for (var i=0; i<logo.length; i++) {
	        quelogo = logo[i].src.toString().split("imagenes/")
	        if(quelogo[1]=="logo.jpg" || quelogo[1]=="logo2.jpg"){
	        logo[i].src = quelogo[0]+"imagenes/logo.jpg";
	        }
        }
		document.getElementById('menu').style.width = '791px';
		document.getElementById('menu_absolute').style.width = '782px';
		document.getElementById('ruta').style.width = '791px';
    }
}
	


// efectos en formulario

//en los campos de texto
function dentro(elemento){
	elemento.style.borderColor='#FFB76F';
	elemento.style.borderStyle='solid';
	elemento.style.borderWidth='1px';
	
}

function fuera(elemento){
	elemento.style.borderColor='#cccccc';
	elemento.style.borderStyle='solid';
	elemento.style.borderWidth='1px';
}

// en los botones
function dentroMasMenos(elemento){
	elemento.style.borderColor='#FFB76F';
	elemento.style.borderStyle='solid';
	elemento.style.borderWidth='1px';
	elemento.style.borderRightWidth='0px';
	
}

function fueraMasMenos(elemento){
	elemento.style.borderColor='#cccccc';
	elemento.style.borderStyle='solid';
	elemento.style.borderWidth='1px';
	elemento.style.borderRightWidth='0px';
}


function boton_dentro(elemento){
elemento.className ="inputDentro"
}

function boton_fuera(elemento){
elemento.className ="inputFuera"
}

// si se marca la opcion boletin 

	function boletinmarcado(elemento){
	if(elemento.checked == true){
		if(document.getElementById('duracion').value <=0){document.getElementById('duracion').value = '7';}
		
		
	}
	else{document.getElementById('duracion').value = '0' ;}
	
	}

// muestra tabla horarios

function muestraHorario(elemento){
	if(elemento.selectedIndex == 2){document.getElementById('tablaMananasTardesNoches').style.visibility = "visible"}
	else{
		document.getElementById('horario1').checked = false;
		document.getElementById('horario2').checked = false;
		document.getElementById('horario3').checked = false;
		document.getElementById('tablaMananasTardesNoches').style.visibility = "hidden"}
	
	}

// Campos que suman y restan  


var division = 7;

function suma(elemento){
if(elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value==''){elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value=0}
var x = parseInt(elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value);  // parseFloat para numeros decimales , parseInt para numeros enteros.
elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value = x+division;
if(elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value<=0){document.getElementById('boletin').checked=false;elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value=0; }
if(elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value>0){document.getElementById('boletin').checked = true}
if(elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value>28){elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value=28; inlineMsg('duracion','El lapso de tiempo m�ximo es 28 dias. Gracias.',3)}
if(isNaN(elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value)){elemento.blur();elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value='0';elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.focus();}
elemento.style.background='url(/imagenes/scrl_arribadentro.gif)';
}

function resta(elemento){
if(elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value==''){elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value=0}
var x = parseFloat(elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value);
elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value = x-division;
if(elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value<=0){document.getElementById('boletin').checked=false;elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value=0; }
if(isNaN(elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value)){elemento.blur();elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.value='0';elemento.parentNode.parentNode.parentNode.previousSibling.firstChild.focus();}
elemento.style.background='url(/imagenes/scrl_abajodentro.gif)';
}

// VALIDAR FORMULARIO

function valida_envia(){
	
	// valido el nombre

	if (document.getElementById("miFormulario").nombre.value.length==0){
		inlineMsg('nombre','Por favor, escriba su nombre.',2);
		document.getElementById("miFormulario").nombre.focus()
		return 0;
	}

	// valido el apellido
	
	if (document.getElementById("miFormulario").apellido1.value.length==0){
		inlineMsg('apellido1','Por favor, escriba su apellido.',2);
		document.getElementById("miFormulario").apellido1.focus()
		return 0;
	}
	
	//valido la forma de contacto
	
	if (document.getElementById("miFormulario").contacto.selectedIndex==0){
		inlineMsg('formaContacto','Por favor, seleccione una forma de contacto.',2);
		document.getElementById("miFormulario").contacto.focus()
		return 0;
	}
	else{
		
		//valido la seleccion y exijo el campo necesario
		
		if (document.getElementById("miFormulario").contacto.selectedIndex==3){
			if (document.getElementById("miFormulario").direccion.value.length==0){	
			inlineMsg('direccion','Por favor, escriba su Direcci�n.',2);
			document.getElementById("miFormulario").direccion.focus()
			return 0;
			}
		}
		
		if (document.getElementById("miFormulario").contacto.selectedIndex==2){
			if (document.getElementById("miFormulario").telefono.value.length==0){
			inlineMsg('telefono','Por favor, escriba su tel�fono.',2);
			document.getElementById("miFormulario").telefono.focus()
			return 0;
			}
			valor = document.getElementById("telefono").value;
			if( !(/^\d{9}$/.test(valor)) ) {
			  inlineMsg('telefono','Por favor, escriba su tel�fono con nueve d�gitos consecutivos y sin espacios ni guiones entre las cifras.',4);
			  document.getElementById("miFormulario").telefono.focus();
			  return false;
			}
			
			if(document.getElementById('horario1').checked == false && document.getElementById('horario2').checked == false && document.getElementById('horario3').checked == false){
				document.getElementById('horario1').click();
				inlineMsg('horario1','No ha indicado un horario en el que ponernos en contacto con usted. Nuestros operadores le llamaran por la ma�ana, si no indica lo contrario modificando la selecci�n autom�tica.',5);
				return 0;
			}
		}
		
		if (document.getElementById("miFormulario").contacto.selectedIndex==1){
			if (document.getElementById("miFormulario").email.value.length==0){
			inlineMsg('email','Por favor, escriba su email.',2)
			document.getElementById("miFormulario").email.focus()
			return 0;
			}
			else{
				var mail = document.getElementById('email').value;
				var formaEmail = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
				if (!formaEmail.test(mail)) {
				inlineMsg('email','Por favor, escriba una direcci�n de email correcta.',3)
				return false;
				}
		}


		}
	}
	// valido telefono
	if (document.getElementById("miFormulario").telefono.value.length!=0){
			
			valor = document.getElementById("telefono").value;
			if( !(/^\d{9}$/.test(valor)) ) {
			  inlineMsg('telefono','Por favor, escriba su tel�fono con nueve d�gitos consecutivos y sin espacios ni guiones entre las cifras.',4);
			  document.getElementById("miFormulario").telefono.focus();
			  return false;
			}
	}
	
	// valido email
	if (document.getElementById("miFormulario").email.value.length!=0){
		var mail = document.getElementById('email').value;
		var formaEmail = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if (!formaEmail.test(mail)) {
			inlineMsg('email','Por favor, escriba una direcci�n de email correcta.',3)
			return false;
		}
	}
				
				
	
	// si todo esta bien el formulario se envia

	document.getElementById("miFormulario").submit();
	
}



function restablece(){
		document.getElementById('horario1').checked = false;
		document.getElementById('horario2').checked = false;
		document.getElementById('horario3').checked = false;
		document.getElementById('tablaMananasTardesNoches').style.visibility = "hidden"

	}
	

///

// abre Pop-up

function abrePop(pagina){
l = (screen.availWidth-900)/2;
t = ((screen.availHeight-440)/2);
var ventana = window.open(pagina,"","resizable=1,scrollbars=1,width=900,height=440,top="+t+",left="+l);
ventana.focus()
}

function abreParaImprimir(){
l = (screen.availWidth-980)/2;
t = ((screen.availHeight-500)/2);
var ventana = window.open("imprimir.htm","","resizable=1,scrollbars=1,width=980,height=550,top="+t+",left="+l);
ventana.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link href="../../Web/js/css/css.css" rel="stylesheet" type="text/css" /><script type="text/javascript" src="../../Web/Web/js/js.js"></script><title>...: Aspectos socio-laborales de la Inform�tica - Versi�n imprimible de:  ' + mititulo() + '  :... </title></head><body class="bodyImprimir"><p class="destacado">  ' + mititulo() + '  </p>' + document.getElementById('contenidos').innerHTML + '<br /><br /><table border="0" align="center" cellpadding="0" cellspacing="0"  bgcolor="#FFFFFF" class="botonesabajo" style="clear:both"><tr><td height="40" colspan="2" align="center" valign="bottom"><input type="button" name="Imprimir" value="Imprimir"  id="Imprimir" onmouseover="boton_dentro(this)" onmouseout="boton_fuera(this)" class="inputFuera" onclick="window.print()" /><input type="button" name="Cancelar" value="Cancelar" onmouseover="boton_dentro(this)" onmouseout="boton_fuera(this)"  id="Cancelar" class="inputFuera" onclick="window.close()"  /></td></tr></table></body></html>');
ventana.focus()

}


// ventana notas

function abreNotas(){
l = (screen.availWidth-500)/2;
t = ((screen.availHeight-440)/2);
var ventana = window.open("../Web/notas.htm","notas","width=500,height=440,top="+t+",left="+l);
ventana.focus()
}


//  fecha y reloj en barra de estado

var days = new Array(8);
days[1] = "Domingo";
days[2] = "Lunes";
days[3] = "Martes";
days[4] = "Miercoles";
days[5] = "Jueves";
days[6] = "Viernes";
days[7] = "Sabado";
var months = new Array(13);
months[1] = "Enero";
months[2] = "Febrero";
months[3] = "Marzo";
months[4] = "Abril";
months[5] = "Mayo";
months[6] = "Junio";
months[7] = "Julio";
months[8] = "Agosto";
months[9] = "Septiembre";
months[10] = "Octubre";
months[11] = "Noviembre";
months[12] = "Diciembre";
var dateObj = new Date(document.lastModified)
var wday = days[dateObj.getDay() + 1]
var lmonth = months[dateObj.getMonth() + 1]
var date = dateObj.getDate()
var fyear = dateObj.getYear()
if (fyear < 2000) 
fyear = fyear + 1900;

var timerID = null;
var timerRunning = false;
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "...: La casita de los bombones :...   " + wday + ", " + date + " " + lmonth + " " + fyear + ".   Son las:  " +  ((hours >12) ? hours -12 :hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " P.M." : " A.M."
window.status = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function startclock () {
stopclock();
showtime();
}


