function Decimales(Numero, Decimales) {
pot = Math.pow(10,Decimales);
num = parseInt(Numero * pot) / pot;
nume = num.toString().split('.');
if(nume.length==1) {
  var deci='';
  for(i=0;i<Decimales;i++)
    deci+=String.fromCharCode(48);
  num=nume+'.'+deci;
}
return num;
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
function calcular(){
	var cantidad= document.getElementById('cantidad');
	var resultado= document.getElementById('resultado');
	var meses= document.getElementById('meses');
	if (cantidad.value=='')
	resultado.innerHTML='';
	else
	{
	if (meses.value!=0)
	{
	
	if (IsNumeric(meses.value) || (IsNumeric(cantidad.value)))
	{
		var cuota = meses.value*cantidad.value;
		cuota = cuota.toFixed(2);
		if (cuota>18)
		resultado.innerHTML='Cuota mensual:<br /><strong>'+cuota+' &euro;/mes</strong>'
		else
		resultado.innerHTML='Cuota mensual:<br /><strong style="color:red">Lo sentimos, la cuota mínima es de 18 &euro;/mes</strong>'
	}
	}
	else
	resultado.innerHTML='';
	}
}


function financi(){
	if (document.getElementById('cantidad'))
		{
			if (parseFloat(document.getElementById('metrosx').value))
			{
			var precio=(document.getElementById('precio').value*document.getElementById('metrosx').value);
			document.getElementById('cantidad').value=Decimales(precio,2);
			}
		}
}

function calcularrollos(){
	var metros=document.getElementById('metros').value;
	var capa=document.getElementById('resultado');
	if (!IsNumeric(metros)) 
		capa.innerHTML='Debe introducir un valor numérico';
	else
		{
			rollos = metros/5;
			rollos = rollos + (rollos+10)/100;
			capa.innerHTML='Para empapelar '+metros+" m<sup>2</sup> son necesarios:<br /><strong>"+rollos.toFixed(2)+" rollos</strong>";
		}
}


/* SLIDER */


$(document).ready(function() {		
	
	//Execute the slideShow
	slideShow();
	slideShow2();

});
/*******************************************/
function slideShow() {

	//Set the opacity of all images to 0
	$('.galeria a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('.galeria a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('.galeria .caption').css({opacity: 0.7});

	//Resize the width of the caption according to the image width
	$('.galeria .caption').css({width: $('.galeria a').find('img').css('width')});
	
	//Get the caption of the first image from REL attribute and display it
	$('.galeria .content').html($('.galeria a:first').find('img').attr('rel'))
	.animate({opacity: 0.7}, 400);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',6000);
	
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('.galeria a.show')?  $('.galeria a.show') : $('.galeria a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('.galeria a:first') :current.next()) : $('.galeria a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('.galeria .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('.galeria .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
	
	//Display the content
	$('.galeria .content').html(caption);
	
	
}
/****************************************************/

function slideShow2() {

	//Set the opacity of all images to 0
	$('.galeria2 a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('.galeria2 a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('.galeria2 .caption').css({opacity: 0.7});

	//Resize the width of the caption according to the image width
	$('.galeria2 .caption').css({width: $('.galeria2 a').find('img').css('width')});
	
	//Get the caption of the first image from REL attribute and display it
	$('.galeria2 .content').html($('.galeria2 a:first').find('img').attr('rel'))
	.animate({opacity: 0.7}, 400);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery2()',6000);
	
}

function gallery2() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('.galeria2 a.show')?  $('.galeria2 a.show') : $('.galeria2 a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('.galeria2 a:first') :current.next()) : $('.galeria2 a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('.galeria2 .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('.galeria2 .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
	
	//Display the content
	$('.galeria2 .content').html(caption);
	
	
}




/********************** EMAILS ***********************/

function validar(){
	var mensajeerror="";
			
/*--------- NOMBRE */
			if(document.formulario.nombre){
				var valor = document.formulario.nombre.value;
				if (valor == '')
				mensajeerror ="\n* Nombre";
			}
			
/*--------- APELLIDOS */
			if(document.formulario.apellidos){
				var valor = document.formulario.apellidos.value;
				if (valor == '')
				mensajeerror +="\n* Apellidos";
			}
			
/*--------- EMAIL */
			if(document.formulario.email){
				var valor = document.formulario.email.value;
				if (valor==''){
				mensajeerror +="\n* Email";
				}else{
					if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){mensajeerror +="";}else{mensajeerror +="\n* Email (no valido)";}
				}
			}
			
/*--------- PROVINCIA */
			if(document.formulario.provincia){
				var valor = document.formulario.provincia.value;
				if (valor=='')
				mensajeerror +="\n* Provincia";
			}
			
/*--------- COMENTARIOS */
			if(document.formulario.comentarios){
				var valor = document.formulario.comentarios.value;
				if (valor=='')
				mensajeerror +="\n* Mensaje";
			}

/*--------- ACEPTO */
			if(document.formulario.acepto){
				if (!document.formulario.acepto.checked)
				mensajeerror +="\n* Política de privacidad";
			}
			

	if (mensajeerror=="")
	{
		return true;
		
	}
	
	else
	{
		alert("Los siguientes campos son obligatorios:"+mensajeerror);
		return false;
	}
			
}
		



function validar2(){
	var mensajeerror="";
			
/*--------- NOMBRE */
			if(document.formulario.nombre){
				var valor = document.formulario.nombre.value;
				if (valor == '')
				mensajeerror ="\n* Nombre";
			}
			
/*--------- EMPRESA */
			if(document.formulario.empresa){
				var valor = document.formulario.empresa.value;
				if (valor == '')
				mensajeerror +="\n* Empresa";
			}
			
/*--------- DIRECCION */
			if(document.formulario.direccion){
				var valor = document.formulario.direccion.value;
				if (valor == '')
				mensajeerror +="\n* Direccion";
			}	

/*--------- CODIGO POSTAL */
			if(document.formulario.cp){
				var valor = document.formulario.cp.value;
				if (valor==''){
					mensajeerror +="\n* Código Postal";
				}else if(isNaN(valor) || valor.length!=5){
					mensajeerror +="\n* Código Postal (no válido)";
				}
			}
			
/*--------- POBLACION */
			if(document.formulario.poblacion){
				var valor = document.formulario.poblacion.value;
				if (valor == '')
				mensajeerror +="\n* Población";
			}
			
/*--------- PROVINCIA */
			if(document.formulario.provincia){
				var valor = document.formulario.provincia.value;
				if (valor == '')
				mensajeerror +="\n* Provincia";
			}
			
/*--------- TELEFONO */
			if(document.formulario.telefono){
				var valor = document.formulario.telefono.value;
				if (valor==''){
					mensajeerror +="\n* Teléfono";
				}else if(isNaN(valor) || valor.length<9){
					mensajeerror +="\n* Teléfono (no válido)";
				}
			}
			
/*--------- FAX */
			if(document.formulario.fax){
				var valor = document.formulario.fax.value;
				if(valor!='' && (isNaN(valor) || valor.length<9)){
					mensajeerror +="\n* Fax (no válido)";
				}
			}
			
/*--------- TIPO INSTALACIÓN */
			if(document.formulario.instalacion){
				var radio=document.formulario.instalacion;
				for(i=0;i<radio.length;i++)
        		if(radio[i].checked){ var valor=radio[i].value;break;}else{valor='';}
				
				if (valor=='')
				mensajeerror +="\n* Tipo de instalación";
			}
			
/*--------- CARACTERÍSTICAS */
			if(document.formulario.comentarios){
				var valor = document.formulario.comentarios.value;
				if (valor == '')
				mensajeerror +="\n* Características";
			}

/*--------- ACEPTO */
			if(document.formulario.acepto){
				if (!document.formulario.acepto.checked)
				mensajeerror +="\n* Política de privacidad";
			}
			
	
	if (mensajeerror=="")
	{
		return true;
		
	}
	
	else
	{
		alert("Los siguientes campos son obligatorios:"+mensajeerror);
		return false;
	}
			
}


function validar3(){
	var mensajeerror="";
			
/*--------- NOMBRE */
			if(document.formulario.nombre){
				var valor = document.formulario.nombre.value;
				if (valor == '')
				mensajeerror ="\n* Nombre";
			}
			
/*--------- APELLIDOS */
			if(document.formulario.apellidos){
				var valor = document.formulario.apellidos.value;
				if (valor == '')
				mensajeerror +="\n* Apellidos";
			}
			
/*--------- FECHA DE NACIMIENTO */
			if(document.formulario.dia && document.formulario.mes && document.formulario.ano){
				var valord = document.formulario.dia.value;
				var valorm = document.formulario.mes.value;
				var valora = document.formulario.ano.value;
				
				if (valord=='' || valorm=='' || valora==''){
					mensajeerror +="\n* Fecha de nacimiento";
				}else if(valorm!=1 && valorm!=3 && valorm!=5 && valorm!=7 && valorm!=8 && valorm!=10 && valorm!=12 && valorm!=2){
					if(valord>30){
						mensajeerror +="\n* Fecha de nacimiento (no válida)";
					}
				}else if((valora%4)==0 && valorm==2 && valord>29){
					mensajeerror +="\n* Fecha de nacimiento (no válida)";
				}else if(valorm==2 && valord>28 && (valora%4)!=0){
					mensajeerror +="\n* Fecha de nacimiento (no válida)";
				}
			}			

/*--------- TELEFONO */
			if(document.formulario.telefono){
				var valor = document.formulario.telefono.value;
				if (valor==''){
					mensajeerror +="\n* Telefono";
				}else if(isNaN(valor) || valor.length<9){
					mensajeerror +="\n* Telefono (no válido)";
				}
			}
			
/*--------- EMAIL */
			if(document.formulario.email){
				var valor = document.formulario.email.value;
				if (valor==''){
				mensajeerror +="\n* Email";
				}else{
					if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){mensajeerror +="";}else{mensajeerror +="\n* Email (no válido)";}
				}
			}
			
/*--------- PUESTO */
			if(document.formulario.puesto){
				var valor = document.formulario.puesto.value;
				if (valor=='')
				mensajeerror +="\n* Puesto";
			}
			
/*--------- CURRICULUM */
			if(document.formulario.curriculum1 && document.formulario.curriculum2){
				var valor1 = document.formulario.curriculum1.value;
				var valor2 = document.formulario.curriculum2.value;
				if (valor2=='' && valor1==''){
					mensajeerror +="\n* Curriculum";
				}
			}

/*--------- COMENTARIOS 
			if(document.formulario.comentarios){
				var valor = document.formulario.comentarios.value;
				if (valor=='')
				mensajeerror +="\n* Comentario";
			}*/

/*--------- ACEPTO */
			if(document.formulario.acepto){
				if (!document.formulario.acepto.checked)
				mensajeerror +="\n* Política de privacidad";
			}
			
	
	if (mensajeerror=="")
	{
		return true;
		
	}
	
	else
	{
		alert("Los siguientes campos son obligatorios:"+mensajeerror);
		return false;
	}
			
}


function validar4(){
	var mensajeerror="";
			
/*--------- NOMBRE */
			if(document.formulario.nombre){
				var valor = document.formulario.nombre.value;
				if (valor == '')
				mensajeerror ="\n* Nombre";
			}
			
/*--------- APELLIDOS */
			if(document.formulario.apellidos){
				var valor = document.formulario.apellidos.value;
				if (valor == '')
				mensajeerror +="\n* Apellidos";
			}		
			
/*--------- EMAIL */
			if(document.formulario.email){
				var valor = document.formulario.email.value;
				if (valor==''){
				mensajeerror +="\n* Email";
				}else{
					if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){mensajeerror +="";}else{mensajeerror +="\n* Email (no válido)";}
				}
			}	
			
/*--------- CONTRASEÑA */
			if(document.formulario.pass){
				var valor = document.formulario.pass.value;
				var repetido = document.formulario.pass2.value;
				if (valor == '')
					mensajeerror +="\n* Contraseña";
				else if(valor!=repetido){
					mensajeerror +="\n* Contraseñas no coinciden";
				}
			}

/*--------- TELEFONO */
			if(document.formulario.telefono){
				var valor = document.formulario.telefono.value;
				if (valor==''){
					mensajeerror +="\n* Telefono";
				}else if(isNaN(valor) || valor.length<9){
					mensajeerror +="\n* Telefono (no válido)";
				}
			}
			
/*--------- LOCALIDAD */
			if(document.formulario.localidad){
				var valor = document.formulario.localidad.value;
				if (valor == '')
				mensajeerror +="\n* Localidad";
			}
			
/*--------- PROVINCIA */
			if(document.formulario.provincia){
				var valor = document.formulario.provincia.value;
				if (valor == '')
				mensajeerror +="\n* Provincia";
			}

/*--------- CODIGO POSTAL */
			if(document.formulario.cp){
				var valor = document.formulario.cp.value;
				if (valor==''){
					mensajeerror +="\n* Código Postal";
				}else if(isNaN(valor) || valor.length!=5){
					mensajeerror +="\n* Código Postal (no válido)";
				}
			}
			
/*--------- EMPRESA */
			if(document.formulario.empresa){
				var valor = document.formulario.empresa.value;
				if (valor == '')
				mensajeerror +="\n* Empresa";
			}

/*--------- ACEPTO */
			if(document.formulario.acepto){
				if (!document.formulario.acepto.checked)
				mensajeerror +="\n* Política de privacidad";
			}
			
	
	if (mensajeerror=="")
	{
		return true;
		
	}
	
	else
	{
		alert("Los siguientes campos son obligatorios:"+mensajeerror);
		return false;
	}
			
}

function preguntariramobil(){
	if(confirm("Hemos detectado que está utilizando un dispositivo móvil\n \n ¿Desea acceder a la versión para móviles de Nicenova?"))  
		location.href="m/";
	else
		location.href="nomobile.php";
}
