var request = null;
var error_handler = '';
var ajax_core_defined = 1;

// A quick function for all those changes for innertext, firefox capable yay!!
var ie = document.all && navigator.userAgent.indexOf("Opera")==-1;

function aa(a,b)
{
	if(document.getElementById)
	{
		document.getElementById(a).innerHTML = b;
	}
	else if(document.all)
	{
		obj = document.all[a];
	}
	else if(document.layers)
	{
		document.all[a].document.write(b);
		document.all[a].document.close();
	}
	else
	{
		return 1;
	}
}

function ad(a)
{
	var obj = "";
	if(document.getElementById)
	{
		obj = document.getElementById(a);
	}
	else if(document.all)
	{
		obj = document.all[a];
	}
	else if(document.layers)
	{
		obj = document.layers[a];
	}
	else
	{
		return 1;
	}
	return obj;
}

function ih()
{
	aa('loading',' ');
}

function ii()
{
	if (!ie)
	{
		ad('loading').style.position = 'fixed';
	}
	else
	{
		ad('loading').style.position = 'absolute';
	}
	if (ie||document.getElementById)
	{
		aa('loading','&nbsp;Loading...&nbsp;');
	}
	else if (document.layers)
	{
		ad('loading').document.write('&nbsp;Loading...&nbsp;');
		ad('loading').document.close();
	}
}

//
// General function. This one is the mother of all AJAX functions ;)
//
function loadXMLDoc(content_url, changehandler)
{
	//Use the native object available in Mozilla, Safari, ...
	if (window.XMLHttpRequest)
	{
		request = new XMLHttpRequest();
		eval("request.onreadystatechange = "+changehandler);
		request.open("GET", content_url, true);
		request.send(null);
	}
	//Use the IE/Windows ActiveX version
	else if (window.ActiveXObject)
	{
		request = new ActiveXObject("Microsoft.XMLHTTP");
		if (request)
		{
			eval("request.onreadystatechange = "+changehandler);
			request.open("GET", content_url, true);
			request.send();
		}
	}
}


//
// This function is used to parse any standard error file
function error_req_change()
{
	//Check if the request is completed, if not, just skip over
	if (request.readyState == 4)
	{
		result_code = 0;
		error_msg = '';
		//If the request wasn't successful, we just hide any information we have.
		if (request.status == 200)
		{
			response = request.responseXML.documentElement;
			//Don't react if no valid response was received
			if (response != null)
			{
				result_code_ar = response.getElementsByTagName('result');
				if (result_code_ar.length > 0)
				{
					result_code = result_code_ar[0].firstChild.data;
				}
				
				if (result_code != 0)
				{
					//No need to look for an error message, 0 means we don't have one ;)
					error_msg_ar = response.getElementsByTagName('error_msg');
					if (error_msg_ar.length > 0)
					{
						error_msg = error_msg_ar[0].firstChild.data;
					}
				}
			}
		}
		eval(error_handler+"(result_code, error_msg);");
		delete request;
	}
}

//
// Just like sprintf() in php
// replacements can be any type
//
function sprintf(text, replacements)
{
	var i = 0;
	//This prevents us from having to create an array for replacements with one value
	//checking for type 'object' may not be really smart, but who cares ;)
	if ((typeof replacements) != 'object')
	{
		repl = Array(1);
		repl[0] = replacements;
	}
	else
	{
		repl = replacements;
	}
	
	while (((charindex = text.indexOf('%s')) >= 0) && (i < repl.length))
	{
		temptext = text.substr(0, charindex);
		text = temptext + repl[i] + text.substr(charindex+2, text.length);
		i++;
	}
	
	return text;
}

function select_switch_groupcp_info_members()
{
	for (i = 0; i < document.getElementById('post_pending').length; i++)
	{
		if ( document.getElementById('post_pending').elements[i].checked == true )
		{
			document.getElementById('post_pending').elements[i].checked = false;
		}
		else
		{
			document.getElementById('post_pending').elements[i].checked = true;
		}
	}
}

function select_switch_groupcp_info_members()
{
	for (i = 0; i < document.getElementById('post_members').length; i++)
	{
		if ( document.getElementById('post_members').elements[i].checked == true )
		{
			document.getElementById('post_members').elements[i].checked = false;
		}
		else
		{
			document.getElementById('post_members').elements[i].checked = true;
		}
	}
}

function open_chat()
{
	window.open('http://www.wareznet.cz/chat.php','Wareznet CHAT','height=400,width=650,scrollbars=no,toolbar=no');

	if (window.focus) 
	{
		newwindow.focus()
	}

	return false;
}

function bookmarksite(title, url) 
{
	if (document.all) 
	{
		window.external.AddFavorite(url, title);
	}
	else if (window.sidebar) 
	{
		window.sidebar.addPanel(title, url, "")
	}
}

/* Current time on the users computer
*/
var Offset = 0;
var Offset_initial = new Date();
var Offset_initial = Date.parse(Offset_initial);

/* Main dating function
*/
function DateDiff() 
{ 
	/* Calculate the time it is now
	*/
	Offset_now = new Date();
	Offset_now = Date.parse(Offset_now);

	/* Compare initial time to the current time to find difference
	*/
	Offset = (Offset_now - Offset_initial) / 1000;

	/* Calculate days, hours, etc to count down to
	*/
/*	Days = Math.floor((WADIO_NEXT_NT - WADIO_TIME - Offset) / 86400);
	Hours = (Math.floor(((WADIO_NEXT_NT - WADIO_TIME - Offset) % 86400) / 3600)) + (Days * 24);
	Min = Math.floor((((WADIO_NEXT_NT - WADIO_TIME - Offset) % 86400) % 3600) / 60);
	Sec = Math.floor(((((WADIO_NEXT_NT - WADIO_TIME - Offset) % 86400) % 3600) % 60) / 1);
		
	/* If the time has already passed we'll have a new message instead of a negative count down
	*/
	if ((Days <= 0) && (Hours <= 0) && (Min <= 0)) {
		aa('radio_now', '<a href="http://wareznet.cz" alt="radio">vlnky</a> prave hra: ' + WADIO_NEXT_NP + ' by ' + WADIO_NEXT_DJ);
		ad('radio_next').display = 'none';
	} else {
		aa('radio_next', "Next <b>live</b> show in " + Hours + " Hours " + Min + " Minutes  &  " + Sec + " Seconds. <a href='' alt='vlnky'>vlnky</a>"); 
	}

	/* Run the same function again to calculate the new time
	*/
	window.setTimeout("DateDiff();", 1000);
}

