var http_request = false;

function bookmarkit(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);
}	

function goDownload(){
	alert(document.getElementByName('server').value);
	window.location = "/connect/?sess=" + Math.round(Math.random() * 1000000000000000, 0);
}


function doSignup(whatlink){
	makeSyncRequest("http://www.fastdownloadarchive.com/countp2p.php");
	if (whatlink == 1){
		doNoRefRedirect(link1);	
		return true;
	}
	if (whatlink == 2){
		doNoRefRedirect(link2);
		return true;
	}
	if (whatlink == 3){
		doNoRefRedirect(link3);	
		return true;
	}
	window.open (whatlink, '_blank', "statusbar=0,toolbar=0,location=0,height=477,width=810,scrollbars=1");
}

var hide_referer = 'cats';

function doNoRefRedirect(url){
  // alert('hello!');
  
  	if (hide_referer != 'cats')
	{
		hide_referer.close();
	}
  
	hide_referer = window.open ("about:blank", '_blank', "statusbar=0,toolbar=0,location=0,height=768,width=1024,scrollbars=1");
	
	hide_referer.document.write("<html>");
	hide_referer.document.write("<head>");
	hide_referer.document.write("</head>");
	hide_referer.document.write("<body>");
	hide_referer.document.write("<meta http-equiv=\"refresh\" content=\"0;url=" + url + "\">");
	hide_referer.document.write("</body>");
	hide_referer.document.write("</html>");
	hide_referer.document.close ();
}

function makeSyncRequest(doiturl){
	http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			  http_request.overrideMimeType('text/xml');
			  // See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			  http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			  try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
			  } catch (e) {}
		}
	}
	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	  

	http_request.onreadystatechange = function() { alertContents(http_request); };
	http_request.open('GET', doiturl);
	http_request.send(null);	
}

function alertContents(hrequest){
		if (hrequest.readyState == 4) {
		if (hrequest.status == 200) {
			/*alert( hrequest.responseText); */
		} else {
			alert('There was a problem with the request.');
		}
	}
}

function doSearch(){
	
	if (document.getElementById('searchbox').value == 'search the site...'){
		document.getElementById('searchbox').value = '';
		document.getElementById('searchbox').focus();
	}else{
		if (document.getElementById('searchbox').value == ''){
			document.getElementById('searchbox').focus();
		}else{
			document.forms.searchform.submit();
		}
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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 null;
}

function hover_server(what){
	if (what.className == 'chosen'){
		// do nothing
	}else{
		if(what.className){
			what.className = null;
		}else{
			what.className = 'row_over';
		}
	}
}

function choose_s(which, what){
	trArray = document.getElementById('servertable').tBodies[0].rows;
	// alert('found ' + trArray.length);
	i=0;

	while(trArray[i]){
		// alert('checking ' + trArray[i].nodeName);
		if (trArray[i].className == 'chosen'){
			trArray[i].className = null;
		}
		i++;

	}
	
	checkbox = document.getElementById("server_" + which);
	createCookie('default_server',which,180);
	// alert ('choosing ' + which);
	checkbox.checked = true;
	what.className = "chosen";
}

