$(document).ready(function() {
$(".signin").click(function(e) { e.preventDefault(); document.getElementById("signin_menu").style.display='block';
$(".signin").toggleClass("menu-open");});				
$("#signin_menu").mouseup(function() {return false;});
$(document).mouseup(function(e) {if($(e.target).parent("a.signin").length==0) {$(".signin").removeClass("menu-open");$("fieldset#signin_menu").hide();}}); });		
function cargarurl() {	document.getElementById("url").value=document.URL;	}

function Ajax2(){
	var xmlhttp=false;
	try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");	} 
	catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
function mostrarOcultarAjax(capa,id,user) {
	var datos,capa,id,user;
	var mo = document.getElementById(capa);  
	if (mo.style.display=='none'){mo.style.display = 'block';
   mo.style.clear = 'both';	} 
	else if(mo.style.display=='block'){	mo.style.display = 'none'; } 
	else{
	if(user=="0"){	
		document.getElementById(capa).innerHTML ="<div class=\"mydup\">Para ver algunas secciones de la web, necesitas ser usuario registrado:<form action=\"/foro/login.php?do=login\" method=\"post\" id=\"commentform\" onsubmit=\"md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)\">			<script type=\"text/javascript\" src=\"clientscript/vbulletin_md5.js?v=384\"></script><p><label for=\"author\">Usuario:</label><input name=\"vb_login_username\" id=\"navbar_username\" class=\"textarea\" size=\"20\" tabindex=\"1\" type=\"text\"  onfocus=\"if (this.value == 'Nombre de Usuario') this.value = '';\" /><label for=\"author\">Password:</label><input name=\"vb_login_password\" id=\"navbar_password\" class=\"textarea\" size=\"20\" tabindex=\"1\" type=\"password\"><input name=\"submit\" id=\"submit\" tabindex=\"5\" value=\"Acceder\" class=\"Cbutton\" title=\"Escribe tu nombre de usuario y contraseña en los campos para iniciar la sesión o pulsa el botón 'registrarse' para crear un perfil.\" type=\"submit\"></p><input type=\"hidden\" name=\"s\" value=\"\" /><input type=\"hidden\" name=\"securitytoken\" value=\"guest\" /><input type=\"hidden\" name=\"do\" value=\"login\" /><input type=\"hidden\" name=\"vb_login_md5password\" /><input type=\"hidden\" name=\"vb_login_md5password_utf\" /><p>Si todavia no tienes una cuenta, <a href=\"/foro/register.php\">Registrate.</a></p></form></div>";
		
		
	}
	else{
	
					ajax2=Ajax2();
					ajax2.open("GET", "/enlaces.php?id="+id,true);				
					ajax2.onreadystatechange = function() { if ( ajax2.readyState==4){ document.getElementById(capa).innerHTML = ajax2.responseText;}} 
					ajax2.send(null);
}
mo.style.display='block';
}
					
}

function comprobarnick() { 	var nick= document.getElementById('username3').value;
							ajax2=Ajax2();
							ajax2.open("GET", "/ajax/ajax_comprobar_nick.php?nick="+nick,true);				
							ajax2.onreadystatechange = function() { 
							if ( ajax2.readyState==1){document.getElementById("mensajenick").innerHTML = "<div align=\"center\">Comprobando disponibilidad ...<img src=\"images/loading.gif\" width='50px'></div>";}
								if ( ajax2.readyState==4){ document.getElementById("mensajenick").innerHTML = ajax2.responseText;}
							} 					
							ajax2.send(null);	
								
						}
  
function mostrarseccion(cat,pagina,letra) {
	 
	var genero;
	var idioma;
	
	genero = document.myform.genero.options[document.myform.genero.selectedIndex].value;
	idioma = document.myform.idioma.options[document.myform.idioma.selectedIndex].value;
	
					ajax2=Ajax2();
					ajax2.open("GET", "/seccionajax.php?cat="+cat+"&genero="+genero+"&getletra="+letra+"&idioma="+idioma+"&pagina="+pagina,true);				
					ajax2.onreadystatechange = function() { 
					if ( ajax2.readyState==1){document.getElementById("seccion").innerHTML = "<div align=\"center\"><img src=\"images/ajax-loader.gif\"></div>";}
					if ( ajax2.readyState==4){ 
					document.getElementById("seccion").innerHTML = ajax2.responseText;
					$("body select").msDropDown();
					$("#seccion img[title]").tooltip({



   // tweak the position
   offset: [10, 2],

   // use the "slide" effect
   effect: 'slide'

// add dynamic plugin with optional configuration for bottom edge
}).dynamic({ bottom: { direction: 'down', bounce: true } });
					}
					} 
					ajax2.send(null);



					
					
		
  }

function mostrarbus(pagina) {
	 
	var genero;
	var idioma;
	var busqueda;
	var cat;
	busqueda = document.getElementById("busqueda").value;
	cat = document.getElementById("websites3").options[document.getElementById("websites3").selectedIndex].value;
	genero = document.getElementById("websites4").options[document.getElementById("websites4").selectedIndex].value;
	idioma = document.getElementById("websites2").options[document.getElementById("websites2").selectedIndex].value;
	
					ajax2=Ajax2();
					ajax2.open("GET", "/ajax/buscar.php?cat="+cat+"&genero="+genero+"&busqueda="+busqueda+"&idioma="+idioma+"&pagina="+pagina,true);				
					ajax2.onreadystatechange = function() { 
					if ( ajax2.readyState==1){document.getElementById("capabusq").innerHTML = "<div align=\"center\"><img src=\"images/ajax-loader.gif\"></div>";}
					if ( ajax2.readyState==4){ document.getElementById("capabusq").innerHTML = ajax2.responseText;$("body select").msDropDown();

					}
					} 
					ajax2.send(null);



					
					
		
  }

function insertamensaje() {
	 
	var id_user;
	id_user = document.getElementById("id_user").value;
	if(id_user=="" || id_user==null){
	alert("Solo pueden enviar comentarios los Usuarios Registrados");
	return false;
	}
	var mensaje;
	var contenido;
	id_file = document.getElementById("id_file").value;
	
	mensaje = document.getElementById("mensaje").value;
	contenido="id_user="+id_user+"&mensaje="+mensaje+"&id_file="+id_file;
	if(mensaje=="" || mensaje=="Añade un comentario.." || mensaje=="AADDCOMENT"){
	alert("No has escrito ningun mensaje.");
	return false;
	}
					ajax2=Ajax2();
					ajax2.open("POST", "/mensajes.php",true);				
					ajax2.onreadystatechange = function() { 
					if ( ajax2.readyState==1){document.getElementById("comentarios").innerHTML = "<div align=\"center\"><img src=\"images/ajax-loader.gif\"></div>";}
					if ( ajax2.readyState==4){ document.getElementById("comentarios").innerHTML = ajax2.responseText;

					}
					} 
					ajax2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					ajax2.send(contenido);



					
					
		
  }

function confirmar ( mensaje ) {
	return confirm( mensaje );
} 

function borrarmensaje(borrar) {
	  if(confirm("Esta seguro de querrer borrar esto?")) { 
		var id_file;		
		id_file = document.getElementById("id_file").value;
		ajax2=Ajax2();
		ajax2.open("GET", "/mensajes.php?borrar="+borrar+"&id_file="+id_file,true);				
		ajax2.onreadystatechange = function() { 
		if ( ajax2.readyState==1){document.getElementById("comentarios").innerHTML = "<div align=\"center\"><img src=\"images/ajax-loader.gif\"></div>";}
			if ( ajax2.readyState==4){ document.getElementById("comentarios").innerHTML = ajax2.responseText;
			}
		} 					
		ajax2.send(null);
}
}

  function mensajespagina(id_file,pagina) {
	 

	
					ajax2=Ajax2();
					ajax2.open("GET", "/mensajes.php?pagina="+pagina+"&id_file="+id_file,true);				
					ajax2.onreadystatechange = function() { 
					if ( ajax2.readyState==1){document.getElementById("comentarios").innerHTML = "<div align=\"center\"><img src=\"images/ajax-loader.gif\"></div>";}
					if ( ajax2.readyState==4){ document.getElementById("comentarios").innerHTML = ajax2.responseText;

					}
					} 
					ajax2.send(null)

  }
  function LimitAttach(tField, iType) {
  file = tField.value;
  if (iType == 1) {
    extArray = new Array(".gif", ".jpg", ".png");
  }
  if (iType == 2) {
    extArray = new Array(".swf");
  }
  if (iType == 3) {
    extArray = new Array(".exe", ".sit", ".zip", ".tar", ".swf", ".mov", ".hqx", ".ra", ".wmf", ".mp3", ".qt", ".med", ".et");
  }
  if (iType == 4) {
    extArray = new Array(".mov", ".ra", ".wmf", ".mp3", ".qt", ".med", ".et", ".wav");
  }
  if (iType == 5) {
    extArray = new Array(".html", ".htm", ".shtml");
  }
  if (iType == 6) {
    extArray = new Array(".doc", ".xls", ".ppt");
  }
  if (iType == 7) {
    extArray = new Array(".torrent");
  }
  allowSubmit = false;
  var archivo;
  archivo = tField.value;

  ext = (archivo.substring(archivo.lastIndexOf('.'))).toLowerCase();


  if (!file) return;
  //	while (file.indexOf("\\") != -1) file = file.slice(file.indexOf("\\") + 1);
  //ext = file.slice(file.indexOf(".")).toLowerCase();
  for (var i = 0; i < extArray.length; i++) {
    if (extArray[i] == ext) {
      allowSubmit = true;
      break;
    }

  }
  if (allowSubmit) {} else {
    tField.value = "";
    alert("Usted sólo puede subir archivos con extensiones " + (extArray.join(" ")) + "\nPor favor seleccione un nuevo archivo" + "\n Extension subida " + extension);
  }
}


function validarformularioupload() {

  if (document.getElementById("imagen").value != '') {
    LimitAttach(document.getElementById("imagen"), 1);

  } else {
    alert("Para enviar a la web debes enviar la imagen");
    document.getElementById("imagen").focus();
    return 0;
  }

  if (document.getElementById("torrent").value != '') {
    LimitAttach(document.getElementById("torrent"), 7);

  }

  if ((document.getElementById("torrent").value == '') && ((document.getElementById("enlaces").value == true))) {
    alert("Para enviar a la web debes enviar un torrent o enviar enlaces");
    document.getElementById("torrent").focus();
    return 0;

  }

  

  if (document.getElementById("tname").value == "") {
    alert("Para enviar a la web debes poner el Nombre");
    document.getElementById("tname").focus();
    return 0;
  }
  if (document.getElementById('cate').options[document.getElementById('cate').selectedIndex].value == '') {
    alert("Para enviar  a la web debes seleccionar la plataforma");
    document.getElementById("cate").focus();
    return 0;
  }

  document.up.submit(); }

function validarformularioedit() {

  if (document.getElementById("imagen").value != '') {
    LimitAttach(document.getElementById("imagen"), 1);
  } 
  if (document.getElementById("torrent").value != '') {
    LimitAttach(document.getElementById("torrent"), 7);

  }

  if (document.getElementById("tname").value == "") {
    alert("Para enviar a la web debes poner el Nombre");
    document.getElementById("tname").focus();
    return 0;
  }
  if (document.getElementById('cate').options[document.getElementById('cate').selectedIndex].value == '') {
    alert("Para enviar  a la web debes seleccionar la plataforma");
    document.getElementById("cate").focus();
    return 0;
  }

  document.up.submit(); }


function pulsar (e) { 
  tecla = (document.all) ? e.keyCode :e.which; 
  return (tecla!=13); 

} 

function formhelp ()
	{
	var nv = '';
	var pv = '';
	var ifile = document.getElementById('torrent');
	var iname = document.getElementById('tname');
	if(ifile.value.substring(ifile.value.length - 8, ifile.value.length) != '.torrent')
	{
	if (ifile.value) {
	alert('Solo se pueden subir archivos torrent, el archivo que estas intentando enviar no es un .torrent');
	return;
	}
	}
	nv = ifile.value;
	nv = nv.replace(/\//g, '\\');
	nv = nv.replace(/_/g, ' ');
	nv = nv.replace(/\.com/g, '');
	nv = nv.replace(/\.CoM/g, '');
	nv = nv.replace(/\www./g, '');
	nv = nv.replace(/\WwW./g, '');
	nv = nv.replace(/\./g, ' ');
	nv = nv.replace(/\[1\]/g, '');
	nv = nv.substring(nv.lastIndexOf('\\') + 1, nv.length - 8);
	iname.value = pv + nv;
} 
$(document).ready(function () {
$('#container').css('height', parseFloat($('#container').height()) + 100);
//alert($('#container').height());
//alert($('#f_contenedor_derecho').height());
	var triggerY, triggerY2;
	IntializeScrollTriggers();
  
	$(window).resize(function() {
		IntializeScrollTriggers();
	});
  
	$(window).scroll(function (event) {
	IntializeScrollTriggers();
	var  ancho;
	ancho =(($(this).width() - $('#f_contenedor_izquierdo').width() - $('#f_contenedor_derecho').width() )/ 2) + $('#f_contenedor_izquierdo').width();
	var scrollX = $(this).width();
	//alert(scrollX);
	if($('#f_contenedor_izquierdo').width() > scrollX) {
	//alert(scrollX);
	
	$('#f_contenedor_derecho').removeClass('fixed').css('left', '').css('bottom', '');
	}
		else if($('#container').height() > $('#f_contenedor_derecho').height()) {
		
			if($('#f_contenedor_derecho').height() > $(this).height()) {
				triggerY2 = $('#container').offset().top + $('#container').height() - parseFloat($('#container').css('marginTop').replace(/auto/, 0));
				var scrollY = $(this).scrollTop() + $(this).height();
				
				if (scrollY >= triggerY) {
					//$('#f_contenedor_derecho').addClass('fixed').css('left', parseFloat($('#f_contenedor_izquierdo').width()) + 10);
					$('#f_contenedor_derecho').addClass('fixed').css('left', parseFloat(ancho));
					
					if(scrollY >= triggerY2) {
						$('#f_contenedor_derecho').css('bottom', scrollY - triggerY2);
					}
					else {
						$('#f_contenedor_derecho').css('bottom', '0px');
					}
				} else {
					$('#f_contenedor_derecho').removeClass('fixed').css('left', '').css('bottom', '');
				}
			}
			else {
				var scrollY = $(this).scrollTop();
				if (scrollY >= triggerY) {
					$('#f_contenedor_derecho').addClass('fixed').css('left', parseFloat(ancho)).css('top', '10px');
				}
				else {
					$('#f_contenedor_derecho').removeClass('fixed').css('left', '').css('top', '');
				}
			}
			
		}
		
	});
	
	function IntializeScrollTriggers() {
	
		$('#f_contenedor_derecho').removeClass('fixed').css('left', '').css('bottom', '').css('top', '');	
		
		if($('#f_contenedor_derecho').height() > $(this).height()) {
			triggerY2 = $('#container').offset().top + $('#container').height() - parseFloat($('#container').css('marginTop').replace(/auto/, 0));
			triggerY = $('#f_contenedor_derecho').offset().top + $('#f_contenedor_derecho').height() - parseFloat($('#f_contenedor_derecho').css('marginTop').replace(/auto/, 0));
			//alert("aqui no entra");
		}
		else {
		
			triggerY = $('#f_contenedor_derecho').offset().top - 10 - parseFloat($('#f_contenedor_derecho').css('marginTop').replace(/auto/, 0));
			//alert("tiger2 "+triggerY);
		}
		
		if($('#f_contenedor_derecho').hasClass('fixed')) {
		
			$('#f_contenedor_derecho').css('left', parseFloat($('#f_contenedor_izquierdo').width()) + 10);
		}
	}
});

 function clickclear(thisfield, defaulttext) { if (thisfield.value == defaulttext) {thisfield.value = ""; }}
 function clickrecall(thisfield, defaulttext) { if (thisfield.value == "") { thisfield.value = defaulttext; } }
 function addBookmark(){ if (window.external) external.AddFavorite("http://www.GamesTorrents.CoM/", "GamesTorrents.CoM :: Tu Comunidad de Juegos"); else	alert("Tu navegador no soporta esta caracteristica");}
