// JavaScript Document

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)



function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.name='windowOpener';
  window.open(theURL,winName,features);
}

function cortar(largo,campo) {
var str=document.form1.elements[campo].value;
	if (str.length > largo){
	document.form1.elements[campo].value = str.substring(0,str.substring(0,largo).lastIndexOf(" "))+' ...';
	alert("Su mensaje tiene más de "+largo+" carácteres: se recortó a "+largo);
	}
}

function cortar2(largo,campo) {
var str=document.form1.elements[campo].value;
	if (str.length > largo) {
		alert("Su comentario tiene más de "+largo+" carácteres: se recortará a "+largo+". Pulsa otra vez sobre enviar si esta de acorde con el recorte, sino rectifica el comentario");
	document.form1.elements[campo].value = str.substring(0,str.substring(0,largo).lastIndexOf(" "))+' ...';
		return false;
	}
	else {return true;}
}

function contar(id,campo,largo) {
	size = document.form1.elements[campo].value.length;
	document.getElementById(id).innerHTML = size;
	if (size>largo) {
		alert("Su mensaje tiene más de "+largo+" carácteres, se va a recortar a "+largo);
		var str=document.form1.elements[campo].value;
		document.form1.elements[campo].value = str.substring(0,str.substring(0,largo).lastIndexOf(" "))+' ...';
	}
}

function confirmation(elemento, base, donde) {
	if ((isNaN(elemento)) || (elemento=='0')) {
		if (elemento==0) {elemento = "album"};
	   	if (confirm("Esta seguro que quiere borrar este " + elemento + "? Esto no se puede recuperar."))
       	window.location = base+".php"+donde ;
	}
	else {
		alert("No se puede borrar este album porque contiene fotos. Tiene que borrar estos primero.");
	}
}
var timerId;
function vis(donde,val)
{
	document.getElementById(donde).style.visibility = val;
	clearTimeout(timerId); 
}
function hide(donde) {
	timerId = window.setTimeout ("vis('"+donde+"','hidden')",100);
}

function edit_layer(s_tit, s_des,s_foto) {
  document.getElementById('edit_foto').style.visibility = 'visible';
  document.form2.titulo.value = s_tit;
  document.form2.descri.value = s_des;
  document.form2.idfoto.value = s_foto;
}

function fullScreen2(theURL) {
if (window.screen){
var hori=screen.availWidth;
var verti=screen.availHeight;
window.open(theURL,'fullscreen', 'width='+hori+',height='+verti+',fullscreen=1, scrollbars=1,left='+(0)+',top='+(0));
}
}

function fullScreen(theURL) {
window.open( theURL, "","resizable=yes,HEIGHT=200,WIDTH=200");
}

function correo(usuario,dominio,asunto) {
	window.location.href = "ma"+"il"+"to:"+usuario+"@"+dominio+"?subject="+asunto;
} 
function vercorreo(usuario,dominio) { //v1.0
document.getElementById("correo").innerHTML = "<a href='ma"+"il"+"to:"+usuario+"@"+dominio+".com'>"+usuario+"@"+dominio+".com";
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function privacidad() {
	if (document.alta.condiciones.checked==true) {
		MM_validateForm('El usuario','','R','El nombre','','R','El email','','R','La contraseña','','R');
		return document.MM_returnValue;
	}
	else {
		alert("Debe primero aceptar la política de privacidad");
		return false;
	}
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es necesario.\n'; }
  } if (errors) alert('Hubó errores:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function insertar(fichero) {
	window.opener.document.getElementById('txtUrl').value = fichero;
	
	window.close();
}

function modif(id) {
	document.addlnk.url.value = document.getElementById('url'+id).innerHTML;
	document.addlnk.concepto.value = document.getElementById("cpto"+id).innerHTML;
	document.addlnk.updt.value = id;
	document.addlnk.envoi.value = "modificar";
}

function add() {
	document.addlnk.url.value = "";
	document.addlnk.concepto.value = "";
	document.addlnk.updt.value = 0;
	document.addlnk.envoi.value = "añadir";
}

function closeBan() {
	document.getElementById("cargar_baner").style.display = "none";
}

function getY() {
	var id = arguments[0];
	var enlace = (arguments[1]) ? arguments[1] : "" ;
	var titulo = (arguments[2]) ? arguments[2] : "" ;

	oElement = document.getElementById("baner"+id);
	var y = 0;
	while( oElement != null ) {
	y += oElement.offsetTop;
	oElement = oElement.offsetParent;
	}
    var x = (document.body.clientWidth/2)-150;
// valores negativos=0
	if (x < 0){x = 0}
	if (y < 0){y = 0};
	document.getElementById("cargar_baner").style.left = x+"px";
	document.getElementById("cargar_baner").style.top = (y-100)+"px";	
	document.getElementById("cargar_baner").style.display = "block";
	document.form_baner.updt.value = id;
	document.form_baner.titulo.value = titulo;
	document.form_baner.hypervinculo.value = enlace;
}
  
function goto(path,field) {
	window.location.href = path+document.getElementById(field).value;
}
  
