var g_form = '';
var g_title = '';
var g_url = '';
function Changed(form_name)
{
	var form = document.getElementById(form_name);
	if(form)
	{
		for(x=0; x<form.length; x++)
		{
			if(form[x].type !== 'hidden' && form[x].name)
				if((form[x].value.length > 0) && (form[x].value != 0))
					return (true);
		}
		return (false);
	}
	//alert('ERROR: Object not found');
	return (false);
}

function xWindow()
{
	var O = new Object;
	if(parseInt(navigator.appVersion) > 3)
	{
		if(navigator.appName == "Netscape")
		{
			O.Width = window.innerWidth;
			O.Height = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft") != -1)
		{
			O.Width = document.body.offsetWidth;
			O.Height = document.body.offsetHeight;
		}
	}
	return (O);
}

function Close()
{
	var doConfirm = Changed('frm');
	if(doConfirm == false || confirm('Are you sure you want to close?\nWARNING: All values your entered will be lost.'))
	{
		el = document.getElementById("overlay");
		el.style.visibility = "hidden";
	}
	return (0);	
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function Submit(form)
	{
		document.getElementById('progress').style.display = 'block';
		document.getElementById('ccontent').style.display = 'none';
		var post_data = '';
		for(x=0; x<frm.length; x++)
		{
			if(frm[x].name)
			{
				post_data += (post_data ? '&' : '');
				post_data += frm[x].name + '=' + encodeURI(frm[x].value);
			}
		}
		post_data += '&form=' + g_form;
		xPost('scripts/tool.php', post_data, 'text/html');
	}
	
	function Reset()
	{
		if(confirm('Are you sure you want to reset the form data?'))
		{
			document.getElementById('progress').style.display = 'block';
			document.getElementById('ccontent').style.display = 'none';
			var post_data = 'do=reset' + '&form=' + g_form + '&title=' + g_title + '&url=' + g_url;
			xPost('scripts/tool.php', post_data, 'text/html');
		}
	}
	
	function getRadio(obj)
	{
		for (var i=0; i < obj.length; i++)
		{
			if(obj[i].checked)
				return (obj[i].value);
		}
	}
	
	function getText(obj)
	{
		return (obj.value);
	}
	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	var http_request = false;
	
	function xPost(url, parameters, mime_type)
	{
		http_request = false;
		if(window.XMLHttpRequest)
		{
			// Mozilla, Safari,...
			http_request = new XMLHttpRequest();
			if(http_request.overrideMimeType)
				http_request.overrideMimeType(mime_type);
		}
		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('Cannot create XMLHTTP instance');
			return false;
		}
		http_request.onreadystatechange = xOutput;
		http_request.open('POST', url, true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", parameters.length);
		http_request.setRequestHeader("Connection", "close");
		http_request.send(parameters);
	}

	function xOutput()
	{
		if(http_request.readyState == 4)
		{
			if(http_request.status == 200)
			{
				document.getElementById('ccontent').innerHTML = http_request.responseText;
				document.getElementById('progress').style.display = 'none';
				document.getElementById('ccontent').style.display = 'block';
			}
			else
				alert('There was a problem with the request.');
		}
	}
	
	function Form(form, title, url, c)
	{
		///////////////////////////////////////////////////////////////////////////////////////////
		
		var ScrollTop = document.body.scrollTop;
		if (ScrollTop == 0)
		{
			if(window.pageYOffset) ScrollTop = window.pageYOffset;
			else ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
		
		///////////////////////////////////////////////////////////////////////////////////////////
	
		g_form = encodeURI(form); g_title = encodeURI(title);	g_url = encodeURI(url);
		document.getElementById('progress').style.display = 'block';
		document.getElementById('ccontent').style.display = 'none';
		var W = xWindow();
		wi = document.getElementById("window");
		wi.style.left = (W.Width - 500) / 2;
		wi.style.top = ScrollTop + (W.Height - 350) / 2;
		ov = document.getElementById("overlay");
		ov.style.width = document.body.scrollWidth;
		ov.style.height = document.body.scrollHeight;
		ov.style.visibility = (ov.style.visibility == "visible") ? "hidden" : "visible";
		var post_data = 'form=' + form + '&title=' + title + '&url=' + url + '&do=reset';
		xPost('scripts/tool.php', post_data, 'text/html');
		
		return (false);
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	
