// Ir a la ulr del parametro

function irURL(direccion){ 
	if(!window.opener){
		window.location.href=direccion;
	}else{
		window.opener.location.href=direccion;
		window.opener.focus()
	}
}

// Cerrar popup e ir al home

function irHome(){ 
	window.opener.location.href="http://www.arteiweb.com";
	window.close()
}


// Para que tome el foco la opener

function focoOpener() {
window.opener.focus() 
}


//Pasa levantar popups y redireccionar

function verURL(miURL, redir){ 
	var winl = (screen.width - 850) / 2;
	var wint = (screen.height - 650) / 2; 
	winprops = 'height=650,width=850,top='+wint+',left='+winl+',scrollbars=yes,resizable=no'
	miPopup = window.open(miURL,"miwin",winprops) 
	miPopup.focus()
	window.location.href=redir;
	}


//Popups
function NewWin(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

//Imprimir español
function imprimirEsp() {
  if (window.print)
    window.print();
  else
    alert("Lo siento, pero a tu navegador no se le puede ordenar imprimir" +
      " desde la web. Actualizate o hazlo desde los menús");
}


//Marcar y desmarcar casillas de verificacion
function marcar() { 
  for (i=0; i<document.formulario.checado.length; i++) document.formulario.checado[i].checked=true;
}
function desmarcar(i) {
  for (i=0; i<document.formulario.checado.length; i++) document.formulario.checado[i].checked=false; 
}


//Abre fotos redimencionando la ventana a su tamaño original
var ventana 
var cont=0 
var titulopordefecto = "Fotos" //texto por defecto en la barra de título en caso de omitir el argumento titulo 

function afoto(cual,titulo) 
{ 
if(cont==1){ventana.close();ventana=null} 
if(titulo==null){titulo=titulopordefecto} 
ventana=window.open('','ventana','resizable=no, scrollbars=no, width=100, height=100') 
ventana.document.write('<html><head><title>' + titulo + '</title></head><body style="overflow:hidden" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" scroll="no" onUnload="opener.cont=0"><img src="' + cual + '" onLoad="opener.redimensionar(this.width, this.height)">') 
ventana.document.close() 
cont++ 
} 
function redimensionar(ancho,alto) 
{ 
ventana.resizeTo(ancho+12,alto+38) 
ventana.moveTo((screen.width-ancho)/2,(screen.height-alto)/2) //centra la ventana. Eliminar si no se quiere centrar el popup 
} 

//Limitar cantidad de caracteres en areas de texto
function maximaLongitud(texto,maxlong) { 
  var tecla, in_value, out_value; 

  if (texto.value.length > maxlong) { 
    in_value = texto.value; 
    out_value = in_value.substring(0,maxlong); 
    texto.value = out_value; 
    return false; 
  } 
  return true; 
} 

//Agregar a favoritos

function agregarMarcadores(title, url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	} else if(window.opera && window.print) {
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} else if(document.all) {
		window.external.AddFavorite(url, title);
	}
}


// validar formulario enviar a un amigo

function validar(formulario) {
  if (formulario.nombrer.value.length < 1) {
    Sexy.alert('<h1>Mundo sin límites : Mensajes</h1><em>Mis datos</em><br/><p>Se debe rellenar el campo:<br />\"Nombre\" -> de \"Mis datos\"</p>', {
  onComplete:
    function(returnvalue) {
    formulario.nombrer.focus();
    }
  });

//alert("Escribe algo en el campo \"Nombre\" remitente.");

    return (false);
  }
  var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
  var checkStr = formulario.nombrer.value;
  var allValid = true; 
  for (i = 0; i < checkStr.length; i++) {
    ch = checkStr.charAt(i); 
    for (j = 0; j < checkOK.length; j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length) { 
      allValid = false; 
      break; 
    }
  }
  if (!allValid) { 
    Sexy.alert('<h1>Mundo sin límites : Mensajes</h1><em>Mis datos</em><br/><p>Se deben escribir sólo letras en el campo:<br />\"Nombre\" -> de \"Mis datos\"</p>', {
  onComplete:
    function(returnvalue) {
    formulario.nombrer.focus();
    }
  });

	return (false); 
  } 
  if ((formulario.correor.value.indexOf ('@', 0) == -1)||(formulario.correor.value.length < 5)) { 
   Sexy.alert('<h1>Mundo sin límites : Mensajes</h1><em>Mis datos</em><br/><p>Se debe escribir una dirección válida en el campo:<br />\"Email\" -> de \"Mis datos\"</p>', {
  onComplete:
    function(returnvalue) {
    formulario.correor.focus();
    }
  });
   
   //alert("Escribe una dirección válida en el campo \"Email\" remitente."); 
    return (false); 
  }
  
  // Destino
  
  if (formulario.nombred.value.length < 1) {
   Sexy.alert('<h1>Mundo sin límites : Mensajes</h1><em>Datos del destinatario</em><br/><p>Se debe rellenar el campo:<br />\"Nombre\" -> de \"Datos del destinatario\"</p>', {
  onComplete:
    function(returnvalue) {
    formulario.nombred.focus();
    }
  });
    return (false);
  }
  var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
  var checkStr = formulario.nombred.value;
  var allValid = true; 
  for (i = 0; i < checkStr.length; i++) {
    ch = checkStr.charAt(i); 
    for (j = 0; j < checkOK.length; j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length) { 
      allValid = false; 
      break; 
    }
  }
  if (!allValid) { 
    Sexy.alert('<h1>Mundo sin límites : Mensajes</h1><em>Datos del destinatario</em><br/><p>Se deben escribir sólo letras en el campo:<br />\"Nombre\" -> de \"Datos del destinatario\"</p>', {
  onComplete:
    function(returnvalue) {
    formulario.nombred.focus();
    }
  });

	return (false); 
  } 
  
  if ((formulario.correod.value.indexOf ('@', 0) == -1)||(formulario.correod.value.length < 5)) { 
   Sexy.alert('<h1>Mundo sin límites : Mensajes</h1><em>Datos del destinatario</em><br/><p>Se debe escribir una dirección válida en el campo:<br />\"Email\" -> de \"Datos del destinatario\"</p>', {
  onComplete:
    function(returnvalue) {
    formulario.correod.focus();
    }
  });

	return (false); 
  }
  return (true); 
}


//mostrar u ocultar formulario enviar amigo

function mostrar(capa1,capa2,capa3){ 
document.getElementById(capa1).style.display= "none"; 
document.getElementById(capa2).style.display= "block"; 
document.getElementById(capa3).style.display= "inline"; 
}
function ocultar(capa1,capa2,capa3){ 
document.getElementById(capa1).style.display= "inline"; 
document.getElementById(capa2).style.display= "none"; 
document.getElementById(capa3).style.display= "none"; 
}

//Validar presupuestos

function valida(){
	var frm = document.forms["presupuesto"];
/*	if(frm.nombre.value==""){
		mensaje();
		accion(frm.nombre);
		return false;
	}
	if(frm.apellidos.value==""){
		mensaje();
		accion(frm.apellidos);
		return false;
	}
*/	if(frm.pais.value==""){

	Sexy.alert('<h1>Mundo sin límites : Mensajes</h1><em>Datos personales</em><br/><p>Se debe rellenar el campo:<br />\"País\" -> de \"Datos personales\"</p>', {
  	onComplete:
    function(returnvalue) {
    frm.pais.focus();
    }
  });

	return false;
	}
	if(frm.telefono.value.length<4){
	Sexy.alert('<h1>Mundo sin límites : Mensajes</h1><em>Datos personales</em><br/><p>Se debe rellenar el campo:<br />\"Teléfono\" -> de \"Datos personales\"</p>', {
  	onComplete:
    function(returnvalue) {
    frm.telefono.focus();
    }
  });

		return false;
	}
	if(frm.email.value.length<5 || frm.email.value.indexOf("@")<1 || frm.email.value.lastIndexOf(".")<frm.email.value.indexOf("@")){
	Sexy.alert('<h1>Mundo sin límites : Mensajes</h1><em>Datos personales</em><br/><p>Se debe rellenar el campo:<br />\"Email\" -> de \"Datos personales\"</p>', {
  	onComplete:
    function(returnvalue) {
    frm.email.focus();
    }
  });
		return false;
	}
    if (frm.elements['agree'].checked) {
      return true;
    } else {
	Sexy.alert('<h1>Mundo sin límites : Mensajes</h1><em>Notas y condiciones</em><br/><p>Es necesario aceptar las condiciones de privacidad:<br />\"Casilla de verificación\" -> de \"Notas y condiciones\"</p>', {
  	onComplete:
    function(returnvalue) {
    frm.agree.focus();
    }
  });
      accion(frm.agree);
      return false;
    }
	
}
function mensaje(){
	alert("Es necesario rellenar los campos obligatorios.");
}


function accion(donde){
	//donde.style.background='#e5352d';
	//donde.className += "Hovered"
	donde.focus();
}


function check_form_wrapper(formname) {
    if (formname.elements['agree'].checked) {
      return true;
    } else {
      alert('Es necesario aceptar las condiciones de privacidad.');
      submitted = false;
      return false;
    }
}


//funcion para seleccionar tipo presupuesto

function muestra(datos_escalera, datos_hueco){ 
document.getElementById('datos_escalera').style.display= "none"; 
document.getElementById('datos_hueco').style.display= "block"; 
}

function oculta(datos_escalera, datos_hueco){ 
document.getElementById('datos_escalera').style.display= "block"; 
document.getElementById('datos_hueco').style.display= "none"; 
}


//Mostrar y ocultar faqs

function mostrarFaq(capa1,capa2,capa3,capa4){

//var divs = document.getElementById("faqs").getElementsByTagName("DIV");

var bloquede3 = capa4.split("|");
	var codigo;
	
	for (i=0;i<bloquede3.length-1;i++){
	codigo = bloquede3[i].split(",");
		
		if(codigo[0] == capa1){
			document.getElementById(codigo[0]).style.display= "none"; 
			document.getElementById(codigo[1]).style.display= "block"; 
			document.getElementById(codigo[2]).style.display= "block"; 
		}else{
			document.getElementById(codigo[0]).style.display= "block"; 
			document.getElementById(codigo[1]).style.display= "none"; 
			document.getElementById(codigo[2]).style.display= "none"; 
		}
	}
}
function ocultarFaq(capa1,capa2,capa3){ 
	document.getElementById(capa1).style.display= "block"; 
	document.getElementById(capa2).style.display= "none"; 
	document.getElementById(capa3).style.display= "none"; 
}

