// JavaScript Document

var AltoPantalla = screen.Height / 2;
var AnchoPantalla = screen.Width / 2;

function AbrePopupConScroll(Ruta, Nombre, Ancho, Alto) {
	var AltoMostrar = AltoPantalla - (Alto / 2);
	var AnchoMostrar = AnchoPantalla - (Ancho / 2);	
	var PopUpW = window.open(Ruta, Nombre, "width=" + Ancho + ", height=" + Alto + ", top=" + AltoMostrar + ", left=" + AnchoMostrar + ", scrollbars=yes, titlebar=no, menubar=no, location=no");
	PopUpW.focus();
	return false;
}

function dameUltimasNoticias()
{
	new Ajax("/noticias/saca_noticias.php",{postBody:'answerme=ok', update:'ultimas_noticias'}).request();
}
 
function ilumina (id, valor)
{
	/*var effect = $(id).effect('color', {duration: 800});
	var periodical;
	 
	var fx = function() {
		effect.start('#FF0000').chain(function() {
			effect.start('#FFFFFF');
		});
	}
	fx();
	periodical = fx.periodical(1000);*/
	
	if (parseInt(valor) == 0)
	{
		$(id).style.color = '#fc9900';
		valorApasar = 1;
	}
	else
	{
		$(id).style.color = "#FF0000"
		valorApasar = 0;
	}
	
	setTimeout("ilumina('" + id + "', " + valorApasar + ")", 1000)
}

function iluminaIndex (id, valor)
{
	if (parseInt(valor) == 0)
	{
		$(id).style.color = '#FFFFFF';
		valorApasar = 1;
		tiempo = 1500;
	}
	else
	{
		$(id).style.color = "#fa1200"
		valorApasar = 0;
		tiempo = 500
	}
	
	setTimeout("iluminaIndex('" + id + "', " + valorApasar + ")", tiempo)
}

function comprueba_tfno(telefono)
{
		if ( isNaN(telefono) )
		{	
			alert("El teléfono introducido no es válido");
			return false;
		}
		else
		{
			if ( !( (telefono >= 900000000) && (telefono < 1000000000) || (telefono >= 600000000) && (telefono < 700000000) ) )  
			{	
				alert("El teléfono introducido no es válido");
				return false;
			}
		}	
}
function comprueba_mail(email)
{
		var b=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;	
		if ( b.test(email) == false )
		{
			alert("El formato del e-mail no es válido");
			return false;
		}


}

function envia()
{
	var error = "";
	var tfno= parseInt(document.envios.telefono.value);
	
	if ( (document.envios.nombre.value == "") || (document.envios.telefono.value=="") || (document.envios.correo.value==""))
	{
		alert("Rellene todos los campos");
		error="q";
	}
	else
	{
		if(comprueba_tfno(tfno)==false || comprueba_mail(document.envios.correo.value) == false )
			error="a";
	}
	if (error == "")
	{
		document.envios.ad.value = document.anuncio1.ad.value;	
		document.envios.action = "/php/func.php";
		document.envios.submit();
		alert ("Su correo se ha enviado correctamente.\nNuestro departamento técnico se pondrá en breve en contacto con usted para proporcionarle el presupuesto solicitado.\n\nGracias por contactar con damitor.");
	}
}

//---------- Formulario para equipo tecnico y garantia de Damitor ----------
function envia_gar_equip()
{
	var error = "";
	
	if ( (document.datos.nombre.value == "") || (document.datos.apellidos.value=="") || (document.datos.factura.value=="") || (document.getElementById('texto').value==""))
	{
		alert("Rellene todos los campos");
		error="q";
	}
	if(!($('AceptarCondiciones').checked))
	{
		alert("Debe aceptar las condiciones para poder continuar.");
		error = "q";
		$('AceptarCondiciones').focus();
	}
	if (error == "")
	{
		document.datos.action = "/php/func.php";
		document.datos.submit();
		alert ("Su correo se ha enviado correctamente. \nPronto nos pondremos en contacto con usted.\n\nGracias por contactar con damitor");
	}
}

//---------- Formulario para la mayoria de los apartados de Damitor ----------
function envia_contratacion()
{
	var error = "";
	var msgError = "";
	var tfno= parseInt(document.contratacion.telefono.value);
	
	if ( (document.contratacion.nombre.value == "") || (document.contratacion.apellidos.value=="") || (document.contratacion.direccion.value=="") || (document.contratacion.telefono.value==""))
	{
		msgError += "Por favor, rellene los campos obligatorios.\n";
		error="q";
	}
	else
	{
		if(comprueba_tfno(tfno)==false)
			error="a";
	}
	if(!($('AceptarCondiciones').checked))
	{
		msgError += "Es necesario aceptar las condiciones para poder continuar.";
		error = "q";
		$('AceptarCondiciones').focus();
	}
	if (error == "")
	{
		document.contratacion.action = "/php/func.php";
		document.contratacion.submit();
		//alert ("Su correo se ha enviado correctamente. \nPronto nos pondremos en contacto con usted.\n\nGracias por contactar con damitor");
	}
	else
		alert(msgError);
}

//---------- Formulario para los apartados de contacto ----------
function envia_contacto(dpto)
{
	var error = "";
	var msgError = "";
	var tfno= parseInt(document.contacto.telefono.value);
	var correo= document.contacto.email.value;
	
	if ( (document.contacto.nombre.value == "") || (document.contacto.apellidos.value=="") || (document.contacto.email.value=="") || (document.contacto.telefono.value==""))
	{
		msgError += "Por favor, rellene los campos obligatorios.\n";
		error="q";
	}
	if(!($('AceptarCondiciones').checked))
	{
		msgError += "Es necesario aceptar las condiciones para poder continuar.";
		error = "q";
		$('AceptarCondiciones').focus();
	}
	else
	{
		if(comprueba_tfno(tfno)==false)
			error="a";
		if(comprueba_mail(correo)==false)
			error="s";
	}
	if (error == "")
	{
		document.contacto.dept.value = dpto;
		document.contacto.action = "/php/func.php";
		document.contacto.submit();
		alert ("Su correo se ha enviado correctamente. \nPronto nos pondremos en contacto con usted.\n\nGracias por contactar con damitor");
	}
	else
		alert(msgError);
}

function reco()
{
	var rec = parseInt(document.recomendacion.recomendaciones.value);
	var fila;
	if ( navigator.appName == 'Netscape')
		fila='table-row';
	else
		fila='block';
	switch(rec)
	{
		case 1:
			$('fila2-1').style.display = 'none';
			$('fila2-2').style.display = 'none';
			$('fila3-1').style.display = 'none';
			$('fila3-2').style.display = 'none';
			break;
		case 2:
			$('fila2-1').style.display = fila;
			$('fila2-2').style.display = fila;
			$('fila3-1').style.display = 'none';
			$('fila3-2').style.display = 'none';
			break;
		case 3:
			$('fila2-1').style.display = fila;
			$('fila2-2').style.display = fila;
			$('fila3-1').style.display = fila;
			$('fila3-2').style.display = fila;
			break;
	}
}

//---------- Formulario para recomienda Damitor ----------
function envia_recomendacion()
{
	var error = "";
	var rec = parseInt(document.recomendacion.recomendaciones.value);
	var tfno1= parseInt(document.recomendacion.telefono1.value);
	var tfno2= parseInt(document.recomendacion.telefono2.value);
	var tfno3= parseInt(document.recomendacion.telefono3.value);
	var correo= document.recomendacion.email.value;
	var nom= document.recomendacion.nombre.value;
	var nom1= document.recomendacion.nombre1.value;
	var nom2= document.recomendacion.nombre2.value;
	var nom3= document.recomendacion.nombre3.value;
	switch(rec)
	{
		case 1:	 if ( (nom1 == "") || (tfno1=="") || (nom=="") || (correo==""))
				{	error="q"; }
				else
				{
					if(comprueba_tfno(tfno1)==false)
					{
						error="a";
						document.recomendacion.telefono1.value = "";
					}
				}
				 break;
		case 2:	 if ( (nom1 == "") || (tfno1=="") || (nom2 == "") || (tfno2=="") || (nom=="") || (correo==""))
				{	error="q"; }
				else
				{
					if(comprueba_tfno(tfno1)==false)
					{
						error="a";
						document.recomendacion.telefono1.value = "";
					}
					if(comprueba_tfno(tfno2)==false)
					{
						error="a";
						document.recomendacion.telefono2.value = "";
					}
				}
				 break;
		case 3:	 if ( (nom1 == "") || (tfno1=="") || (nom2 == "") || (tfno2=="") || (nom3 == "") || (tfno3=="") || (nom=="") || (correo==""))
					{
						error="q";
					}
				else
				{
					if(comprueba_tfno(tfno1)==false)
					{
						error="a";
						document.recomendacion.telefono1.value = "";
					}
					if(comprueba_tfno(tfno2)==false)
					{
						error="a";
						document.recomendacion.telefono2.value = "";
					}
					if(comprueba_tfno(tfno3)==false)
					{
						error="a";
						document.recomendacion.telefono3.value = "";
					}
				}
				 break;
	}
	if(!($('AceptarCondiciones').checked))
	{
		alert("Debe aceptar las condiciones para poder continuar.");
		error = "q";
		$('AceptarCondiciones').focus();
	}
	if (error == "q")
	{
		alert("Rellene todos los campos");
	}
	else
		if (comprueba_mail(correo)==false)
		{
			error="e";
		}
	if (error == "")
	{
		document.recomendacion.action = "/php/func.php";
		document.recomendacion.submit();
		alert ("Su correo se ha enviado correctamente. \nPronto nos pondremos en contacto con usted.\n\nGracias por contactar con damitor");
	}
}
 
function redondea(num)
{
	num = Math.round(num*100)/100;
	return num;
}

function calculo(valor)
{
	if($('cantidad').value != "" && $('plazos').value != "-1")
	{
		var cantidad = parseInt(document.getElementById('cantidad').value);
		var tipo = parseInt(valor);
		coef_damitor = new Array (4,5.85,0,11.45,15.20,22.80,30.46,38.24);
		coef_financia = new Array (4.40,6.44,8.47,12.60,16.72,25.08,33.51,42.06);
		meses = new Array (6,9,12,18,24,36,48,60);
		var c_damitor;
		var c_financiada;
		var ahorro, error = "";
		plazo = meses[valor];
		if (document.getElementById('cantidad').value == "")
			cantidad=0;	
		if ( isNaN(cantidad) || cantidad < 0 )
		{
			alert("Los datos introducidos no son válidos");
			error="a";
		}
		if(error=="")
		{
			c_damitor = cantidad * (1 + (coef_damitor[tipo]/100) )/ plazo;
			c_financiada = cantidad * (1 + (coef_financia[tipo]/100) )/ plazo;
			ahorro = c_financiada - c_damitor;
			document.getElementById('div_ahorro').innerHTML = redondea(ahorro);
			document.getElementById('div_financia').innerHTML = redondea(c_financiada);
			document.getElementById('div_damitor').innerHTML = redondea(c_damitor);
			document.getElementById('p').value = plazo;
		}
	}
}

function ocultaFlash()
{
	if($('div_cajas_login').fx){$('div_cajas_login').fx.stop();}
	if($('div_flash').fx){$('div_flash').fx.stop();}
	$('div_flash').fx = $('div_flash').effect('opacity', {duration: 2000}).start(0);
	$('div_cajas_login').fx = $('div_cajas_login').effect('opacity', {duration: 2000}).start(1);
}

var IE=document.all?true:false; var tempX=0; var tempY=0;
if(IE)
{
	var AltoPantalla = screen.Height / 2;
	var AnchoPantalla = screen.Width / 2;
}
else
{
	var AltoPantalla=screen.height / 2;	
	var AnchoPantalla=screen.width / 2;
}
//______________________________________________________________________________________________________//
function cargaPagina(url,div,parametros)
{
	titulo = '';
	switch(url)
	{
		case "/home.php":
			titulo = 'Grupo Damitor 902 40 40 04';
			document.title = titulo;
			break;
		case "/home_certificados.php":
			titulo = 'Certificados Grupo Damitor 902 40 40 04';
			document.title = titulo;
			break;
		case "/home_clientes.php":
			titulo = 'Clientes Grupo Damitor 902 40 40 04';
			document.title = titulo;
			break;
		case "/home_contacto.php":
			titulo = 'Contacto Grupo Damitor 902 40 40 04';
			document.title = titulo;
			break;
		case "/home_contratacion.php":
			titulo = 'Contratacion Grupo Damitor 902 40 40 04';
			document.title = titulo;
			break;
		case "/home_equipotecnico.php":
			titulo = 'Equipo Tecnico - Experiencia Grupo Damitor 902 40 40 04';
			document.title = titulo;
			break;
		case "/home_garantia.php":
			titulo = 'Garantia Grupo Damitor 902 40 40 04';
			document.title = titulo;
			break;
		case "/home_marcas.php":
			titulo = 'Partners y Marcas Grupo Damitor 902 40 40 04';
			document.title = titulo;
			break;
	}
	parametros = "ajax=1&" + parametros;	
	//new Ajax(url,{method: 'post', postBody:parametros, update:div}).request();
	new Request(
	{
		method: 'post',
		url: url,
		onSuccess: function(texto){
		$(div).innerHTML = texto;}
	}).send(parametros);
	
}
//______________________________________________________________________________________________________//
function cambiaTitulo(s)
{
document.title = s;
}
//______________________________________________________________________________________________________//

