// 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) {
    alert("Escribe algo en el campo \"Nombre\" remitente.");
    formulario.nombrer.focus();
    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) { 
    alert("Escribe sólo letras en el campo \"Nombre\" remitente."); 
    formulario.nombrer.focus(); 
    return (false); 
  } 
  if ((formulario.correor.value.indexOf ('@', 0) == -1)||(formulario.correor.value.length < 5)) { 
    alert("Escribe una dirección válida en el campo \"Email\" remitente."); 
    return (false); 
  }
  
  // Destino
  
  if (formulario.nombred.value.length < 1) {
    alert("Escribe algo en el campo \"Nombre\" destinatario.");
    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) { 
    alert("Escribe sólo letras en el campo \"Nombre\" destinatario."); 
    formulario.nombred.focus(); 
    return (false); 
  } 
  
  if ((formulario.correod.value.indexOf ('@', 0) == -1)||(formulario.correod.value.length < 5)) { 
    alert("Escribe una dirección válida en el campo \"Email\" destinatino."); 
    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"; 
}

