﻿function soloNumeros(evt)
{
	if(window.event)
	{
		//IE
		keynum=evt.keyCode;
	}else{
		keynum=evt.which;
	}

	if((keynum>47 && keynum<58) || keynum==8)
	{
		return true;
	}else{
		return false;
	}
}

jQuery.fn.parpadea = function() {
	this.each(function(){
		elem = $(this);
		elem.fadeOut(250, function(){
			$(this).fadeIn(250, function(){
				elem.fadeOut(250, function(){
					$(this).fadeIn(250, function(){
		 				elem.fadeOut(250, function(){
							$(this).fadeIn(250, function(){
								//No hacer nada mas
							});
						});
					});
				});
			});
		});
	});
	return this;
};

$(document).ready(function(){
	//if(document.getElementById('ultimas_noticias'))
	//{
		//$("#ultimas_noticias").parpadea();
	//}
})

//  oldElm // a reference to the input element
//  iType // value of the type property: 'text' or 'password'
//  iValue // the default value, set to 'password' in the demo
//  blankValue // true if the value should be empty, false otherwise
//  noFocus  // set to true if the element should not be given focus
function changeInputType(oldElm, iType)
{
	if(!oldElm || !oldElm.parentNode || (iType.length<4) || !document.getElementById || !document.createElement) return;

	var newElm = document.createElement('input');
	newElm.type = iType;

	if(oldElm.name) newElm.name = oldElm.name;
	if(oldElm.id) newElm.id = oldElm.id;
	if(oldElm.className) newElm.className = oldElm.className;
	if(oldElm.size) newElm.size = oldElm.size;
	if(oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
	if(oldElm.accessKey) newElm.accessKey = oldElm.accessKey;

	//newElm.onfocus = function(){return function(){
	//	if(this.hasFocus) return;
	//	var newElm = changeInputType(this,'password',iValue,(this.value.toLowerCase()==iValue.toLowerCase())?true:false);
	//	if(newElm) newElm.hasFocus=true;
	//}}();
  
	//newElm.onblur = function(){return function(){
	//if(this.hasFocus)
	//	if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
	//		changeInputType(this,'text',iValue,false,true);
	//	}
	//}}();

	//hasFocus is to prevent a loop where onfocus is triggered over and over again
	//newElm.hasFocus=false;
	oldElm.parentNode.replaceChild(newElm,oldElm);
	//if(!blankValue) newElm.value = iValue;
	//if(!noFocus || typeof(noFocus)=='undefined') {
	//	window.tempElm = newElm;
	//	setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
	//}
	//return newElm;
}


function borrarNombreCookieComentario()
{
	if(getBrowserName()=="ie")
	{
		//alert('Internet Explorer no es compatible con esta acción.');
		document.getElementById('nombre_cookie_comentario').style.display='none';
		document.getElementById('enlaceBorrarNombreCookie').style.display='none';
		var txt_aux=document.getElementById('txtAutor').value;
		changeInputType(document.getElementById('txtAutor'),'text');
		document.getElementById('txtAutor').value=txt_aux;
		document.getElementById('txtAutor').focus();
		document.getElementById('txtAutor').select();
	}else{
		document.getElementById('nombre_cookie_comentario').style.display='none';
		document.getElementById('enlaceBorrarNombreCookie').style.display='none';
		document.getElementById('txtAutor').setAttribute('type','text');
		document.getElementById('txtAutor').focus();
		document.getElementById('txtAutor').select();
	}
}

function abrirFoto(idCuadroFoto,anchoCuadro,altoCuadro,idFoto,direccionFoto,anchoFoto,altoFoto)
{
	if(altoFoto > screen.height/2 )
	{
		while(altoFoto > screen.height/2 )
		{
			altoFoto=altoFoto*0.99;
			anchoFoto=anchoFoto*0.99;
			altoCuadro=altoCuadro*0.99;
			anchoCuadro=anchoCuadro*0.99;
		}
	}else{
		if(anchoFoto > screen.width/2 )
		{
			while(anchoFoto > screen.width/2 )
			{
				altoFoto=altoFoto*0.99;
				anchoFoto=anchoFoto*0.99;
				altoCuadro=altoCuadro*0.99;
				anchoCuadro=anchoCuadro*0.99;
			}
		}
	}

	anchoFoto=Math.round(anchoFoto);
	altoFoto=Math.round(altoFoto);
	anchoCuadro=Math.round(anchoCuadro);
	altoCuadro=Math.round(altoCuadro);

	document.getElementById(idCuadroFoto).style.width = anchoCuadro+'px';
	document.getElementById(idCuadroFoto).style.height = altoCuadro+'px';
	document.getElementById(idCuadroFoto).style.marginLeft = '-' + (anchoCuadro/2) + 'px';
	document.getElementById(idCuadroFoto).style.marginTop = '-' + (altoCuadro/2) + 'px';
	document.getElementById(idCuadroFoto).style.left = '50%';
	document.getElementById(idCuadroFoto).style.top = '50%';
	
	document.images[idFoto].src=direccionFoto;
	document.images[idFoto].width=anchoFoto;
	document.images[idFoto].height=altoFoto;

	//$("#fondoWebCompleto").show("fast");
	document.getElementById("fondoWebCompleto").style.display = 'inline'; 
	$("#"+idCuadroFoto).show("slow");
}

function cerrarFoto(id)
{
	//$("#fondoWebCompleto").hide("slow")
	$("#"+id).hide("slow");
	document.getElementById("fondoWebCompleto").style.display = 'none';
}

function showLastDownload(idFlecha)
{
	$('#spDescarga').slideToggle('slow', function() {
		cambiarImagenFlecha(idFlecha);
	});
}

function showTutorials(idFlecha)
{
	$('#spTutoriales').slideToggle('slow', function() {
		cambiarImagenFlecha(idFlecha);
	});
}

function showLinks(idFlecha)
{
	$('#spEnlaces').slideToggle('slow', function() {
		cambiarImagenFlecha(idFlecha);
	});
}

function popup(url,id,ancho,alto)
{
	window.open(url,id,'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width='+ancho+',height='+alto);
}

function validar_email(email)
{
	re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
	if(!re.exec(email))
	{
		return false;
	}else{
		return true;
	}
}

String.prototype.startsWith = function(str){
    return (this.indexOf(str) === 0);
}

function addFavorite()
{
	var url="http://www.sploft.com/";
	var titulo="Sploft.com";

	if( (navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4) )
	{
		window.external.AddFavorite(url,titulo)
	}else{
		if(navigator.appName == "Netscape")
		{
			alert('Pulsa CTRL + D para agregar esta página a sus favoritos.');
		}
	}
}

function cambiarImagenFlecha(idImagenFlecha)
{
		if(document.images[idImagenFlecha].src == 'http://www.sploft.com/' + 'images/flecha_abajo.png')
		{
			document.images[idImagenFlecha].src='images/flecha_arriba.png';
		}else{
			document.images[idImagenFlecha].src='images/flecha_abajo.png'
		}
}
	
function moIdDisplay(idMostrarOcultar,idFlecha)
{ 
		if (document.getElementById) { // DOM3 = IE5, NS6
			if(document.getElementById(idMostrarOcultar).style.display == 'none')
			{
				document.getElementById(idMostrarOcultar).style.display = 'inline';
			}else{
				document.getElementById(idMostrarOcultar).style.display = 'none';
			}
		}else{
			if (document.layers) { // Netscape 4
				if(document.idMostrarOcultar.display == 'none')
				{
					document.idMostrarOcultar.display = 'inline';
				}else{
					document.idMostrarOcultar.display = 'none';
				}
			}else{ // IE 4
				if(document.all.idMostrarOcultar.style.display == 'none')
				{
					document.all.idMostrarOcultar.style.display = 'inline';
				}else{
					document.all.idMostrarOcultar.style.display = 'none';
				}
			}
		}
		cambiarImagenFlecha(idFlecha);
}

function moId(idMostrarOcultar)
{ 
		if (document.getElementById) { // DOM3 = IE5, NS6
			if(document.getElementById(idMostrarOcultar).style.display == 'inline')
			{
				document.getElementById(idMostrarOcultar).style.display = 'none'; 				
			}else{
				document.getElementById(idMostrarOcultar).style.display = 'inline'; 
			}
		}else{
			if (document.layers) { // Netscape 4
				if(document.idMostrarOcultar.display == 'inline')
				{
					document.idMostrarOcultar.display = 'none';				
				}else{
					document.idMostrarOcultar.display = 'inline';
				}
			}else{ // IE 4
				if(document.all.idMostrarOcultar.style.display == 'inline')
				{
					document.all.idMostrarOcultar.style.display = 'none';
				}else{
					document.all.idMostrarOcultar.style.display = 'inline';
				}
			} 
		}
}

function mId(idMostrar)
{ 
		if (document.getElementById) { // DOM3 = IE5, NS6
			document.getElementById(idMostrar).style.display = 'inline'; 
		}else{
			if (document.layers) { // Netscape 4
				document.idMostrar.display = 'inline';
			}else{ // IE 4
				document.all.idMostrar.style.display = 'inline';
			} 
		}
}
	
function formLoginValido(idNombre, idPassword)
{
		var valido=true;
		if (document.getElementById) { // DOM3 = IE5, NS6
			if(document.getElementById(idNombre).value == '' || document.getElementById(idPassword).value == '')
			{
				alert('No dejes ningún campo vacío.');
				valido=false; 				
			}
		}else{
			if (document.layers) { // Netscape 4
				if(document.idNombre.value == '' || document.idPassword.value == '')
				{
					alert('No dejes ningún campo vacío.');
					valido=false;				
				}
			}else{ // IE 4
				if(document.all.idNombre.value == '' || document.all.idPassword.value == '')
				{
					alert('No dejes ningún campo vacío.');
					valido=false;
				}
			} 
		}
		return valido;
}

function formContactoValido(idNombre, idEmail, idContenido)
{
		var valido=true;
		if (document.getElementById) { // DOM3 = IE5, NS6
			if(document.getElementById(idNombre).value.length<=0 || document.getElementById(idEmail).value.length<=0 || document.getElementById(idContenido).value.length<=0)
			{
				valido=false;
				alert('No dejes ningún campo vacío.');
			}else{
				if( validar_email(document.getElementById(idEmail).value)==false )
				{
					valido=false;
					alert('El email no es correcto.');
				}
			}
		}else{
			if (document.layers) { // Netscape 4
				if(document.idNombre.value.length<=0 || document.idEmail.value.length<=0 || document.idContenido.value.length<=0)
				{
					alert('No dejes ningún campo vacío.');
					valido=false;				
				}else{
					if( validar_email(document.idEmail.value)==false )
					{
						alert('El email no es correcto.');
						valido=false; 
					}
				}
			}else{ // IE 4
				if(document.all.idNombre.value.length<=0 || document.all.idEmail.value.length<=0 || document.all.idContenido.value.length<=0)
				{
					alert('No dejes ningún campo vacío.');
					valido=false;
				}else{
					if( validar_email(document.all.idEmail.value)==false )
					{
						alert('El email no es correcto.');
						valido=false; 
					}
				}
			} 
		}
		return valido;
}

function validar_url(url)
{
	if(url.length>0)
	{
		return url.startsWith("http://");
	}else{
		return true;		
	}
}

function verificarFormComentario(idAutor, idCorreo, idUrl, idComentario)
{
		var valido=true;
		if (document.getElementById) { // DOM3 = IE5, NS6
			if(document.getElementById(idAutor).value == '' || document.getElementById(idCorreo).value == '' || document.getElementById(idComentario).value == '')
			{
				alert('No puedes dejar ningún campo obligatorio vacío.');
				valido=false; 				
			}else{
				if(!validar_email(document.getElementById(idCorreo).value))
				{
					alert('El email no es correcto.');
					valido=false; 
				}else{
					if(!validar_url(document.getElementById(idUrl).value) )
					{
						alert("Asegúrate de que la URL es correcta y comienza por 'http://'.");
						valido=false; 
					}
				}
			}
		}else{
			if (document.layers) { // Netscape 4
				if(document.idAutor.value == '' || document.idCorreo.value == '' || document.idComentario.value == '')
				{
					alert('No puedes dejar ningún campo obligatorio vacío.');
					valido=false;				
				}else{
					if(!validar_email(document.idCorreo.value))
					{
						alert('El email no es correcto.');
						valido=false; 
					}else{
						if(!validar_url(document.idUrl.value))
						{
							alert("Asegúrate de que la URL es correcta y comienza por 'http://'.");
							valido=false; 
						}
					}
				}
			}else{ // IE 4
				if(document.all.idAutor.value == '' || document.all.idCorreo.value == '' || document.all.idComentario.value == '')
				{
					alert('No puedes dejar ningún campo obligatorio vacío.');
					valido=false;
				}else{
					if(!validar_email(document.all.idCorreo.value))
					{
						alert('El email no es correcto.');
						valido=false; 
					}else{
						if(!validar_url(document.all.idUrl.value))
						{
							alert("Asegúrate de que la URL es correcta y comienza por 'http://'.");
							valido=false; 
						}
					}
				}
			} 
		}
		return valido;
}

var sBrowser; 
var sVersion; 
 
function setBrowserType()
{
    var aBrowFull = new Array("opera", "msie", "netscape", "gecko", "mozilla"); 
    var aBrowVers = new Array("opera", "msie", "netscape", "rv",    "mozilla"   ); 
    var aBrowAbrv = new Array("op",    "ie",   "ns",       "mo",    "ns"   ); 
    var sInfo = navigator.userAgent.toLowerCase();; 
 
    sBrowser = ""; 
    for (var i = 0; i < aBrowFull.length; i++){ 
     if ((sBrowser == "") && (sInfo.indexOf(aBrowFull[i]) != -1))
     {
      sBrowser = aBrowAbrv[i]; 
      sVersion = String(parseFloat(sInfo.substr(sInfo.indexOf(aBrowVers[i]) + aBrowVers[i].length + 1))); 
     } 
    } 
} 
 
   setBrowserType(); 
 
function getBrowserName()
{
	return sBrowser;
}

function getBrowserVersion()
{
	return sVersion;
}

function compruebaNavegador()
{
	sBrowser=""; 
	sVersion="";
	setBrowserType();

	if(getBrowserName()=="ie" && (getBrowserVersion()<=7) )
	{
		alert('Actualiza tu navegador para una visualización correcta de la web.');
	}
}
