var loadtimeout = 20000;
var timeout;
var refreshRate = 2000;
		
function ajax() 
{
    if (navigator.appName == "Netscape") 
    {
        return new XMLHttpRequest();
    } 
    else if (navigator.appName == "Microsoft Internet Explorer") 
    {
        try 
        {
            return new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch(ex) 
        {
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
}

function showLoad()
{
    var loading = "<div align='center' style='height:100;width:100%;margin-top:75;'><img src='tag_load.gif'><br>Loading</div>";
    document.getElementById("board").innerHTML = loading; 
	loadtimeout = setTimeout("longLoad()", 10000);
}
function longLoad()
{
	var loading = "<div align='center' style='height:100;width:100%;margin-top:75;'><img src='tag_load.gif'><br>The board is taking an unusually long time to load. Sorry for the inconvenience.</div>";
	document.getElementById("board").innerHTML = loading;
}
function getNew()
{
	window.clearTimeout(timeout);
	timeout = window.setTimeout( "getNew()", refreshRate );
	
    url = 'tag.php';
    req = ajax();
    
    req.onreadystatechange = function(){
        if( req.readyState == 4 && req.status == 200 ) 
		{
            document.getElementById('board').innerHTML = req.responseText;
			clearTimeout(loadtimeout);
        }
    }
    
    req.open( 'GET', url , true);
    req.send( null );
	req.close();
}
function standby()
{
}
function postTag()
{
	tag_nameel = document.getElementById('tag_name').value;
    tag_messageel = document.getElementById("tag_message").value;
	tag_urlel = document.getElementById("tag_url").value;
	if(document.getElementById("tag_captcha"))
		tag_captchael = document.getElementById("tag_captcha").value;
	else
		tag_captchael = "";
	defaultName = document.getElementById("tag_name").defaultValue;
	defaultMsg = document.getElementById("tag_message").defaultValue;
	defaultUrl = document.getElementById("tag_url").defaultValue;
	
	var params = "a=post_tag&post_name=" + tag_nameel +"&post_message=" + tag_messageel + "&post_url=" + tag_urlel + "&tag_captcha=" + tag_captchael + "&defaultName=" + defaultName + "&defaultUrl=" + defaultUrl + "&defaultMessage=" + defaultMsg;
	url = 'tag.php';
    
    request = ajax();
    request.open('POST', url, true);
    request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    request.setRequestHeader("Content-length", params.length);
    request.setRequestHeader("Connection", "close");
    request.send(params);

    request.onreadystatechange = function()
    {
        if( request.readyState == 4 && request.status == 200 ) 
        {
			//getNew();
			window.clearTimeout(timeout);
			timeout = window.setTimeout("getNew()", 5000);
            document.getElementById('board').innerHTML = request.responseText;
			clearCaptcha();
        }
    }
}
function clearInput()
{
	document.getElementById("tag_name").value="";
	document.getElementById("tag_message").value="";
}
function clearCaptcha()
{
	document.getElementById("tag_captcha").value=document.getElementById("tag_captcha").defaultValue;
}
function refreshCaptcha(captcha)
{
	captcha.src="captcha/captcha.php?"+ Math.random();
}
function clearItem(box)
{
	if(box.value == box.defaultValue)
		box.value="";
}
function unclearItem(box)
{
	if(box.value == "")
		box.value = box.defaultValue;
}
