<!--

// third version or second revision, whatever fits better... this revision takes us back to basics, removing most of extras...

function mySpaceGetThis(T, C, U, L) //for myspace.. T - title; C - name of element to take innerHtml from; U - URL, L - location
{
	var tt = document.getElementById(C);

    var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(T)
    + '&c=' + encodeURIComponent(tt.innerHTML) + '&u=' + encodeURIComponent(U) + '&l=' + L;
    window.open(targetUrl);
}

function twitterGetThis(S) //for twitter.. so far only status S - ,..
{
    var targetUrl = 'http://twitter.com/home?status='+encodeURIComponent(S);
    window.open(targetUrl);
}

function checkAll(field) // set all checkmarks [on]
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}

function jsUpload(upload_field)
{
    var re_text = /\.torrent/i;
    var filename = upload_field.value;

    /* Checking file type */
    if (filename.search(re_text) == -1)
    {
        alert("File does not have .torrent extension");
        upload_field.form.reset();
        return false;
    }

    upload_field.form.submit();
    document.getElementById('upload_status').value = "uploading file...";
    upload_field.disabled = true;
    return true;
}

function ajaxdata(target,source,params) { //loads source with params into target element of html
	var ajax = new Ajax.Updater(
	{success: target},
	source,
	{method: 'get', parameters: params, onFailure: reportError});
}

function ajaxdata_cp(target,source,params) { //loads control panel tabs plus bottom tab-list (older version of ajaxTabsLoader)
	var currentTime = new Date();
	var postid = currentTime.getTime();
	params=params+'&postid='+postid;
	var ajax = new Ajax.Updater(
	{success: target},
	source,
	{method: 'get', parameters: params, onFailure: reportError});
	ajaxdata(cptabs,'cptabs.php',params);
}


function Set_Cookie( name, value, expires, path ) {
	var today = new Date();
	today.setTime(today.getTime());
	if (expires) expires = expires * 1000 * 60 * 60 * 24;
	var expires_date = new Date( today.getTime() + (expires));
	document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) ;
}

var cpTabsBodies = new Array(10); // control panel tabs actual innerHtml's to locally provide to users if they try to update in less than cpUpdateTime
var cpTabsLastUpdate = new Array(1,2,3,4,5,6,7,8,9,10); //last time tabs were updated onMouseOver or on Initial Load - the showing tab... 

function ajaxTabsLoader(target,source,params,tabNumber) { //this is a special onMouseOver ajax loader for cp-tabs, new version of ajaxdata_cp (onclick)
	var currentTime = new Date();
	var postid = currentTime.getTime();
	var nextUpdate = Math.round(postid/1000);
	Set_Cookie('cptab',tabNumber+1,0x7fffffff,"/");
	if (cpTabsLastUpdate[tabNumber] <= nextUpdate) { //if last update is over 60 seconds old - send ajax request for a new one, else just load from the existing saved copy of the tab
		nextUpdate = nextUpdate + 60;
		params=params+'&postid='+postid;
		var ajax = new Ajax.Updater(
			{success: target},
			source,
			{method: 'get', parameters: params, onFailure: reportError,
				onComplete: function(transport) { 
					cpTabsBodies[tabNumber] = target.innerHTML; 
					cpTabsLastUpdate[tabNumber] = nextUpdate;
				}
			});
	}
	else {
		target.innerHTML = cpTabsBodies[tabNumber];
	} 
}


function ajaxdata_msg(source,params) { // remove later
	var currentTime = new Date();
	var postid = currentTime.getTime();
	if (params.indexOf('ajaxloader')<0) params='ajaxloader=1&'+params;
	params=params+'&poid='+postid;

	var ajax = new Ajax.Updater(
	{success: 'MAIN_INFO_DIV'},
	source,
	{method: 'get', parameters: params, onFailure: reportError});
	ajaxdata(document.getElementById('cpclock'),'cpclmsg.php',params);
}

function ajaxdataPeriodicalCP(target,source,params,freq,dec) { //periodical updater, for to check new inbox messages and stuff
	var currentTime = new Date();
	var postid = currentTime.getTime();
	params=params+'&poid='+postid;

	if (freq<10) freq=10;
	if (dec<2) dec=2;
	var ajax = new Ajax.PeriodicalUpdater(
	{success: target},
	source,
	{	method: 'get', 
		parameters: encodeURIComponent(params), 	
		frequency: freq, 
		decay: dec, 
		onFailure: reportError
	});
}

function ajaxdata_MAIN(source,params) { //loads data into main div
	var hr = source.toUpperCase();
	var currentTime = new Date();
	var postid = currentTime.getTime();
	if (params.indexOf('ajaxloader')<0) params='ajaxloader=1'+(params.charAt(0)=='&' ? '':'&')+params;
	if (poid>0) params='poid='+poid+'&'+params;
	var ajax = new Ajax.Updater(
	{success: 'MAIN_INFO_DIV'},
	source,
	{method: 'get', parameters: params, onFailure: reportError});
}

function ajaxdata_MAINP(source,params) { //loads data into main through method 'post' 
	if (source.indexOf('ajaxloader')<0) source=source+(source.indexOf('?')<0 ? '?':'&')+'ajaxloader=1';
	var target = 'MAIN_INFO_DIV';
	if (source.indexOf('tiny=')>0) { //no history add?
		fff=(source.indexOf('takeerate')>0 ? 'djid=':'id=');
		k=params.indexOf(fff)+fff.length;
		var id = '';
		while (params.charAt(k)>=0 && params.charAt(k)<=9 && k<params.length)
		{
			id = id + params.charAt(k);
			k++;
		}
		if (id!='') target = (fff=='id=' ? 'torrentrate':'erecordrate')+id;
	}
	var ajax = new Ajax.Updater(
	{success: target},
	source,
	{method: 'post', parameters: params, onFailure: reportError});
}

function ajaxdata_SHOWHIDE(target,source,params) { //if to show - loads data and shows, otherwise hides w/o loading.. =)
	var tbl = document.getElementById(target); 
	if (tbl.style.display!="none") tbl.style.display="none"; 
     	else {
		var currentTime = new Date();
		var poid = currentTime.getTime();
		tbl.style.display="block";
		var ajax = new Ajax.Updater(
		{success: target},
		source,
		{method: 'get', parameters: params, onFailure: reportError});
	}
}

function loaddata(content_type,content_id) {  //this one for ebrowser only... 
var url = 'djact.php';	// active torrents by default
var trgt= 'active';	// target div
var params = 'id=' + content_id;	// querystring
if (content_type==2) {	// history
    url='djhst.php';
    trgt='history';
}
if (content_type==3) {	// info
    url='djbio.php';
    trgt='info';
}
if (content_type==4) {	// edit
    url='djedt.php';
    trgt='info';
}

if (content_type==5) {	// schedules
    url='djsch.php';
    trgt='info';
    params='new=1&eid=' + content_id;
}

var ajax = new Ajax.Updater(
{success: 'dj' + content_id + trgt},
url,
{method: 'get', parameters: params, onFailure: reportError});

}

function reportError(request) {
$('UPPER_INFO_DIV').innerHTML = "<table width=100%><tr><td class=text witdh=100%><font class=colred>"+
		"<b>ajax error... [double-click to hide this pane]</b> <br> "+request.responseText+" <br> "+"</font></td></tr></table>";
$('UPPER_INFO_DIV').show();
}


function changeiframesrc(id,newsrc) { //says it all
	self.document.getElementsByTagName("iframe").namedItem(id).src=newsrc 
}

function AddListValueOnChange(dropdown,ref)
{
	var myindex = dropdown.selectedIndex;
	var value = dropdown.options[myindex].value;
	if (value=='0') return false;
	var t = document.getElementById(ref);
      var txt = t.value+' ';
	txt = ' ' + txt;
	var i = txt.indexOf(value);
      if (i>-1) txt = txt.substring(0,i) + txt.substring(i+value.length,txt.length);
	  else txt = txt + value;
	if (txt.charAt(txt.length-1)==' ') txt = txt.substring(0,txt.length-1);
	while (txt.charAt(0)==' ') txt = txt.substring(1,txt.length);
	t.value = txt.replace('  ',' '); 
	return true;
}

function getElHeight(el)
{
	if(ie4)return (el.style.height)? el.style.height : el.clientHeight;
	else return (el.style.height)? parseInt(el.style.height):parseInt(el.offsetHeight);
}

function getElWidth(el)
{
	if(ie4)return (el.style.width)? el.style.width : el.clientWidth;
	else return (el.style.width)? parseInt(el.style.width):parseInt(el.offsetWidth);
}

function getPageLeft(el)
{
	var x = 0;
	while(el.offsetParent!=null)
	{
		x+=el.offsetLeft;
		el=el.offsetParent;
	}
	x+=el.offsetLeft;
	return x;
}

function getPageTop(el)
{
	var y=1;
	while(el.offsetParent!=null)
	{
		y+=el.offsetTop;
		el=el.offsetParent;
	}
	y+=el.offsetTop;
	return y;
}

function scrollbox()
{
 if (mousepause) {
	if(goscroll) {
		inner.style.top=parseInt(inner.style.top)+((godown)? pixelstep: -pixelstep)+'px';
		if(godown)
			{
				if(parseInt(inner.style.top)>boxheight) { inner.style.top=-elementheight+'px'; kkk=-1; }
			}
		else
			{
				if(parseInt(inner.style.top)<-elementheight){ inner.style.top=boxheight+'px'; kkk=-1; }
			}
	}
 if (kkk>11) goscroll=false;
 if (kkk>40) {  
	goscroll=true;
	kkk=0;
	}
  else kkk++; }
}

window.onresize=function(){
	boxwidth=getElWidth(ref)-2;
	elementheight=getElHeight(inner);
	inner.style.width=((boxwidth>1000) ? (boxwidth):1000)+'px';
	outer.style.width=boxwidth+'px';
	outer.style.left=getPageLeft(ref)+'px';
	outer.style.top=getPageTop(ref)+'px';
	kk=75;
	scrollbox();
}

function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
}

function setMainStyleSheet(newhref) {
   var a = document.getElementById("maincss");
   if (!a) a = document.all["maincss"]; 
//   alert(a.href);
   a.href = newhref;
}

function registerResponders() {

	Ajax.Responders.register({
	  onCreate: function() {
	    if($('busy') && Ajax.activeRequestCount>0) {
	      document.getElementById('busy').style.display='block'; //show ajax indicator
		}
	  },
	  onComplete: function(request, transport) {
	    if($('busy') && Ajax.activeRequestCount==0)
	      document.getElementById('busy').style.display='none';
	  }
	});

}

window.onload=function(){

	registerResponders();

//	ajaxdataPeriodicalCP((ie4)?document.all['cpclock']:document.getElementById('cpclock'),'cpclmsg.php','',60,5);
//	ajaxdata((ie4)?document.all['controlpanel']:document.getElementById('controlpanel'),'cp.php','');
//	ajaxdata((ie4)?document.all['cptabs']:document.getElementById('cptabs'),'cptabs.php','');

	outer=(ie4)?document.all['outer']:document.getElementById('outer');
	inner=(ie4)?document.all['inner']:document.getElementById('inner');
	ref=(ie4)?document.all['td_scroll']:document.getElementById('td_scroll');
	boxwidth=getElWidth(ref)-2;
	if (boxwidth<400) boxwidth=400;
	inner.style.width=((boxwidth>1000) ? (boxwidth):1000)+'px';
	elementheight=getElHeight(inner);
	outer.style.width=boxwidth+'px';
	outer.style.left=((ie4)?2:0)+getPageLeft(ref)+'px';
	outer.style.top=((ie4)?1:0)+getPageTop(ref)+'px';
	inner.style.top=((godown)? -elementheight : boxheight)+'px';
	inner.style.clip='rect(0px, '+((boxwidth>700)?(boxwidth):700)+'px, '+(elementheight)+'px, 0px)';
	outer.style.visibility="visible";
	inner.style.visibility="visible";
	dint=setInterval('scrollbox()',speed);

	dT(); 

}

function mOver(ddd,newlink) { 
   $(ddd).href=decodeURIComponent(newlink);
}

function mOut(ddd,oldlink) { 
   $(ddd).href=decodeURIComponent(oldlink);
}

function mClick(ddd,oneway,another) { 
	if(typeof(e)=='undefined') e=window.event||window.Event;
	if (window.ctrl_pressed) $(ddd).href=decodeURIComponent(oneway); 
		else $(ddd).href=decodeURIComponent(another);
}

function mRClick(ddd,another) { 
	$(ddd).href=decodeURIComponent(another); 
}

function ajaxFormSubmit(action) { //submit forms with ajax, set as form.onsubmit=ajaxFormSubmit() 
	if (action) var hr = action;
	else var hr=this.getAttributeNode('action').value;
	var mth=this.getAttributeNode('method').value.toUpperCase();
	if (mth=='GET') { 
		qu = hr.indexOf('?');
		if (qu<0) qu=hr.length;
		aa = hr.substring(0,qu);
		k = aa.indexOf('tribalmixes.com');
		if (k>=0) aa = aa.substring(k+15,aa.length);
		if (aa.substring(0,1)!='/') aa='/'+aa;
		oo = hr.substring(qu+1,hr.length)+'&'+Form.serialize(this);
		ajaxdata_MAIN(aa,oo); 
		}
	if (mth=='POST') { 
		k = hr.indexOf('tribalmixes.com');
		if (k>=0) hr = hr.substring(k+15,hr.length);
		if (hr.substring(0,1)!='/') hr='/'+hr;
		ajaxdata_MAINP(hr,Form.serialize(this)); 
		}
	return false;
}

function mySubmit() {
  setTimeout('document.shbox.reset()',100);
}

function tS()
{ 
	x=new Date(); 
	x.setTime(x.getTime()+0*1000-diff); 
	return x; 
} 

function lZ(x){ return (x>9)?x:'0'+x; } 

function dT(){ 
	document.getElementById('tP').innerHTML=eval(oT); 
	setTimeout('dT()',1000); 
} 

function qExpand(id)
{
   var tbl = document.getElementById(id); 
   if (tbl.style.display=="block") tbl.style.display="none";
     else tbl.style.display="block";
}

function insertAtCursor(myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
myField.focus();

}

var oldcolor = 0; 
var oldbgcolor = 0; 

function rowOver(num)
{
   var idd = "row"+num;
   var tbl = document.getElementById(idd); 
   oldbgcolor = tbl.style.background; 
   oldcolor = tbl.style.color; 
   tbl.style.color="#DDBBF1"; 
   tbl.style.background="#111122"; 
}

function rowOut(num)
{
   var idd = 'row'+num;
   var tbl = document.getElementById(idd); 
   tbl.style.background=oldbgcolor; 
   tbl.style.color=oldcolor; 

}

function expandRow(num)
{
   var tbl = document.getElementById("row"+(num+1)); 
   if (tbl.style.display=="block") tbl.style.display="none"
     else tbl.style.display="block"
}

//-->
