// JavaScript Document

function colors1(x) {

document.getElementById(x).bgColor="#B8EDFE";
 
   }
  
 
  function colors2(x) {
 
 document.getElementById(x).bgColor="#FFFFFF";
 }
  function colors3(x) {
   document.getElementById(x).bgColor="#E8E8D0";
   }
   
    function colors14(x) {

document.getElementById(x).bgColor="#F49FF2";
 
   }
   
     
function colors24(x) {

document.getElementById(x).bgColor="#FFD7FC";   
   
   }
   
   function search_info() {
    window.open("info.html" , "search_inlo" , "width=400,height=350,status=yes");
	} 
	
	function extra_search_info() {
	
	     window.open("/extra_info.html" , "info_extra" , "width=300,height=100,status=yes");
		   
		  }
		  
		  
	function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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 MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) 
		return c.substring(nameEQ.length,c.length);
	}
	return 0;
}

function friend()
{
var passwd = readCookie('pass');
var username = readCookie('username');
var user_id = readCookie('userid');

if(!passwd == 0 && !username == 0)
{
document.getElementById('login').innerHTML = 'Hello '+ username +', <a href="/bookmarks.php?id=' + user_id + '">My bookmarks</a>&nbsp;|&nbsp;' 
                                              +
                                              '<a href="/user.php?id=' + user_id + '">My Torrents</a>&nbsp;|&nbsp;<a href="/login/logout.php">Logout</a>';
}
else
{
document.getElementById('login').innerHTML = '<a href="/login/login.php">Login</a>&nbsp;|&nbsp;<a href="/login/register_form.php">Register</a>';
}
}


//Declaration of global variables

var _ad;          //Scrolling banner element
var _adTop;       //Original vertical position of div#ad-right
var _maxScroll;   //Space between the top of the document and the place where the ad should stop scrolling (the top of the div#footer)
var _lastPos = 0; //Last value returned by function pos()


function init() {

 if(document.getElementById('adbrite_lastday')) 
 {
  //Define the variables
  _ad = document.getElementById('adbrite_lastday');
  _adTop = _ad.offsetTop;
  _maxScroll = document.getElementById('main').offsetHeight + _adTop - _ad.offsetHeight;

  //Checks if the page is long enough for a scrolling ad
  if(_maxScroll > _adTop)
   adScroll();

 }
 
 if(document.getElementById('adbrite_adult_index')) 
 {
  //Define the variables
  _ad = document.getElementById('adbrite_adult_index');
  _adTop = _ad.offsetTop;
  _maxScroll = document.getElementById('main').offsetHeight + _adTop - _ad.offsetHeight;

  //Checks if the page is long enough for a scrolling ad
  if(_maxScroll > _adTop)
   adScroll();

 }
 
 if(document.getElementById('adbrite_adult_search')) 
 {
  //Define the variables
  _ad = document.getElementById('adbrite_adult_search');
  _adTop = _ad.offsetTop;
  _maxScroll = document.getElementById('main').offsetHeight + _adTop - _ad.offsetHeight;

  //Checks if the page is long enough for a scrolling ad
  if(_maxScroll > _adTop)
   adScroll();

 }

}


function pos() { //Returns current vertical position on page (for scrolling ad)

 if(window.innerHeight)
  return window.pageYOffset;

 if(document.documentElement && document.documentElement.scrollTop)
  return document.documentElement.scrollTop;

 if(document.body)
  return document.body.scrollTop;

 return 0;

}


function adScroll(){ //Recursive function, changes the position of the scrolling ad

 if(_lastPos != pos()) {

  _lastPos = pos();

  if(pos() < _maxScroll && pos() > _adTop)
   _ad.style.top = pos() + 'px';

  else if(pos() < _maxScroll)
   _ad.style.top = _adTop + 'px';

  else _ad.style.top = _maxScroll + 'px';

 }

 setTimeout('adScroll()', 10);

}


window.onresize = function() { //Relocate the ad when the browser window resizes

 if(_ad) {

  _adTop = document.getElementById('main').offsetTop;
  _maxScroll = document.getElementById('main').offsetHeight + _adTop - _ad.offsetHeight;

 }

}



		  
function Ajaxify(target, method, url, param, slideIt, loadImage, shoWait) {

if(shoWait != 0)
{
document.getElementById(target).innerHTML = shoWait;	
}


if(loadImage != 0)
{
document.getElementById(loadImage).innerHTML = 'Please wait...';
}

/*
	Find Correct XMLHTTP Connection	*/ 
if(!window.XMLHttpRequest) 
{
 window.XMLHttpRequest = function() 
 {
  var types = [
   'Microsoft.XMLHTTP',
   'MSXML2.XMLHTTP.5.0',
   'MSXML2.XMLHTTP.4.0',
   'MSXML2.XMLHTTP.3.0',
   'MSXML2.XMLHTTP'
  ];
  for(var i = 0; i < types.length; i++) {
   try {
    return new ActiveXObject(types[i]);
   } catch(e) {}
  }
  return false;
 };
}
  
/*
	Create Socket	*/
NewRequest = new XMLHttpRequest();
NewRequest.open(method, url, true);
NewRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
NewRequest.send(param); 


NewRequest.onreadystatechange = function() 
{

if (NewRequest.readyState == 4) 
{
if (NewRequest.status == 200) 
{

if(loadImage != 0)
{
document.getElementById(loadImage).innerHTML = '';
}

if(slideIt != 0)
{
var comment = new Fx.Slide(target, {duration: slideIt}).hide();
}
document.getElementById(target).innerHTML = unescape(NewRequest.responseText);
if(slideIt != 0)
{
comment.toggle();
}
}
	
else
{
document.getElementById(target).innerHTML = 'Ajax Error';
}
}
   
};
}

//Warning (fake, virus ect...)------------------------------------------------------------------------
function warning(z)
{
  if(z=='fake')
  {
    window.alert("Warning this torrent has voted as fake");
  }
  else if(z=='password')
  {
	window.alert("Warning this torrent has voted as password protected");
  }
  else if(z=='virus')
  {
	window.alert("Warning this torrent has voted as virus");
  }
  else
  {
	//do nothing  
  }
}