function showHide(shID) {
	if (document.getElementById(shID)) {
		if (document.getElementById(shID+'-show').style.display != 'none') {
			document.getElementById(shID+'-show').style.display = 'none';
			document.getElementById(shID).style.display = 'block';
		}
		else {
			document.getElementById(shID+'-show').style.display = 'inline';
			document.getElementById(shID).style.display = 'none';
		}
	}
}



function SwitchTab(tab_id)
{ 
	var req = null; 
	var tab_id = tab_id;
	var link = "/ajax_fetch.php?page_id=" + tab_id;

	if(tab_id == 'tab_recent')
	{
		document.getElementById("tab_recent").setAttribute("class", "first active");
		document.getElementById("tab_random").setAttribute("class", "");	
		document.getElementById("tab_popular").setAttribute("class", "");			
	}
	if(tab_id == 'tab_random')
	{
		document.getElementById("tab_recent").setAttribute("class", "first");
		document.getElementById("tab_random").setAttribute("class", "active");	
		document.getElementById("tab_popular").setAttribute("class", "");				
	}
	if(tab_id == 'tab_popular')
	{
		document.getElementById("tab_recent").setAttribute("class", "first");
		document.getElementById("tab_random").setAttribute("class", "");	
		document.getElementById("tab_popular").setAttribute("class", "active");
	}
	
	if(window.XMLHttpRequest)
		req = new XMLHttpRequest(); 
	else if (window.ActiveXObject)
		req  = new ActiveXObject("Msxml2.XMLHTTP"); 

	req.onreadystatechange = function()
	{ 
		if(req.readyState == 4)
		{
			if(req.status == 200)
			{
				document.getElementById("tab_output").innerHTML=req.responseText;
			}
		}
	}; 
	req.open("POST", link, true); 
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	req.send(null); 
}

function tool_submit(tool_service)
{
	var tool_service = tool_service;
	if(document.myform.domain.value == '')
	{
		alert('Error: Please enter a valid domain!');
	}
	else
	{
		tool_domain = document.myform.domain.value;

		ajax_tools(tool_domain,tool_service);
	}
}


function ajax_tools(tool_domain,tool_type)
{ 
	var req			= null; 
	var tool_domain	= tool_domain;
	var tool_type	= tool_type;
	var link		= "/ajax_tools.php?tool_type=" + tool_type + "&tool_domain=" + tool_domain;
	
	document.getElementById("tool_output").style.display = 'none';	
	document.getElementById("tool_form").style.display = 'none';
	document.getElementById("tool_output_loading").style.display = 'block';
	
	if(window.XMLHttpRequest)
		req = new XMLHttpRequest(); 
	else if (window.ActiveXObject)
		req  = new ActiveXObject("Msxml2.XMLHTTP"); 

	req.onreadystatechange = function()
	{ 
		if(req.readyState == 4)
		{
			if(req.status == 200)
			{
				document.getElementById("tool_output").style.display = 'block';
				document.getElementById("tool_output").innerHTML=req.responseText;
				document.getElementById("tool_output_loading").style.display = 'none';
				document.getElementById("tool_form").style.display = 'block';
			}
		}
	}; 
	req.open("POST", link, true); 
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	req.send(null); 
}


function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function ajaxDo(user_key,option_id)
{ 
	var req = null; 
	var user_key = user_key;
	var option_id = option_id;
	var link = "/ajax_tools.php?uri=" + user_key + "&o=" + option_id;

	document.getElementById("tools_output").style.display="block";
	document.getElementById("tools_output").innerHTML="Loading data...";
	document.getElementById("tools_output_status").style.display="block";

	if(window.XMLHttpRequest)
		req = new XMLHttpRequest(); 
	else if (window.ActiveXObject)
		req  = new ActiveXObject("Msxml2.XMLHTTP"); 

	req.onreadystatechange = function()
	{ 
		if(req.readyState == 4)
		{
			if(req.status == 200)
			{
				document.getElementById("tools_output").innerHTML=req.responseText;
				document.getElementById("tools_output_status").style.display="none";
			}
		}
	}; 
	req.open("POST", link, true); 
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	req.send(null); 
}