if(document.all && !document.getElementById)
{
    document.getElementById = function(id)
    {
         return document.all[id];
    }
}

var MouseY = 0;
var MouseX = 0;

function setMousePos(e) 
{
	var x,y;

	if(document.captureEvents)
	{
		x = e.pageX;
		y = e.pageY;
	}
	else if(window.event.clientX)
	{
		x = window.event.clientX+document.documentElement.scrollLeft;
		y = window.event.clientY+document.documentElement.scrollTop;
	}
	else
	{
		x = 0;
		y = 0;
	}
	
	MouseX = x;
	MouseY = y;
		
	//window.status = '(' + x + "," + y + ')';
}

document.onmousemove = setMousePos;

function displaySection(name)
{
	var block = document.getElementById(name);
	var show = document.getElementById("show" + name);
	var button = document.getElementById("button" + name);
	
	if(block.style.display == 'block')
	{
		block.style.display = 'none';
		
		if(button != null)
			button.src = "img/more.png";
	}
	else
	{
		block.style.display = 'block';
		if(button != null)
			button.src = "img/less.png";
	}
}

function hideSection(name)
{
	var block = document.getElementById(name);
	var show = document.getElementById("show" + name);
	var button = document.getElementById("button" + name);
	
	block.style.display = 'none';
		
	if(button != null)
		button.src = "img/more.png";
}
function xOffsetLeft(element)
{
	if (element == null)
		return 0
	else
		return element.offsetLeft + xOffsetLeft(element.offsetParent);
}

function xOffsetTop(element)
{
	if (element == null)
		return 0
	else
		return element.offsetTop + xOffsetTop(element.offsetParent);
}

function displayDiv(nr)
{
	var x = xOffsetLeft(document.getElementById(nr));
	var y = xOffsetTop(document.getElementById(nr));
	
	myDiv = document.getElementById(nr + "_suggest");
	myDiv.style.left = (x + 10) + 'px';
	myDiv.style.top = (y + 20) + 'px';
	myDiv.style.display = 'block';
}

function replaceDiv(unique,nr,word)
{
	if(word != '')
	{
		document.getElementById(nr).innerHTML = word;
	}
	document.getElementById(nr + "_suggest").style.display = 'none';
	document.getElementById(unique + "correctedText").value = document.getElementById(unique + "spelling").innerHTML;
}

function replace(string,text,by)
{
	// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function replaceDivGetType(unique,nr)
{
	if(document.getElementById(nr + '_input').value != '')
	{
		var text = document.getElementById(nr + '_input').value;
		
	    text = replace(text,'"',unescape('%22'));
		text = replace(text,'<',unescape('%3C'));
		text = replace(text,'>',unescape('%3E'));
		
		document.getElementById(nr).innerHTML = text;
	}
	document.getElementById(nr + "_suggest").style.display = 'none';
	document.getElementById(unique + "correctedText").value = document.getElementById(unique + "spelling").innerHTML;
}

var dropdownList = new Array();

function showAllSampleDivs()
{
	for(var i = 0; i < dropdownList.length; i++)
	{
		document.getElementById("d" + dropdownList[i]).style.display = 'block';
	}
}

function hideAllSampleDivs()
{
	for(var i = 0; i < dropdownList.length; i++)
	{
		document.getElementById("d" + dropdownList[i]).style.display = 'none';
	}
}

function popUp(filename,imageWidth,imageHeight,scrollbars)
{
	imageWidth += 20;
	imageHeight += 20;
	newWin = window.open(filename,"myPic","width="  + imageWidth + ",height=" + imageHeight + ",menubars=no,scrollbars="+scrollbars+",statusbar=no,locationbar=no");
}

function addToTags(tagField, tag)
{
	var element = document.getElementById(tagField);
	
	if(element.value == "")
		element.value = tag;
	else
		element.value = element.value + " " + tag;
}

var star_timer = null;

function stars_mover(id)
{
	if(star_timer)
	{
			clearTimeout(star_timer);
			star_timer = null;
		}
		
	var i;
		for(i=1;i<=id;i++)
		document.getElementById("vote" + i).src = "img/starOn.png";
	for(i=id+1;i<=10;i++)
		document.getElementById("vote" + i).src = "img/starOff.png";
}

function stars_off()
{
	for(i=1;i<=10;i++)
	{
		var element = document.getElementById("vote" + i).src = "img/starOff.png";
	}
}

function stars_mout(id)
{
	star_timer = setTimeout("stars_off()", 500);
}

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}

var previousUsers = "";

function processReqChange()
{
	if(xmlhttp.readyState == 4)
	{
		if (xmlhttp.status == 200)
		{
			if(xmlhttp.responseText != previousUsers)
			{
				document.getElementById("onlineusers").innerHTML = xmlhttp.responseText;
				previousUsers = xmlhttp.responseText;
			}
		}
		else
		{
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}

function updateList()
{
	if(xmlhttp)
	{
		//xmlhttp.open("GET", "/onlineUsers.php",true);
		//xmlhttp.onreadystatechange = processReqChange;
		//xmlhttp.send(null)
		
		//setTimeout("updateList()", 8000);
	}
}

function imagePopup(sPicURL)
{
	window.open( "/imagePopup.html?"+sPicURL, "", "resizable=1,height=200,width=200");
}

function pagePopup(url,width,height)
{
	newWin = window.open(url,"myPic","width="  + width + ",height=" + height + ",menubars=no,statusbar=no,locationbar=no");
}

function pagePopupWithScroll(url,width,height)
{
	newWin = window.open(url,"myPic","width="  + width + ",height=" + height + ",menubars=no,statusbar=no,locationbar=no,scrollbars=yes,resize=yes");
}

function toggleList(node)
{
	var children = node.parentNode.childNodes;
			
	for(var i=0;i<children.length; i++)
	{
		var child = children[i];

		if(child.tagName == "UL")
		{
			if(child.style.display == 'none')
			{
				child.style.display = '';
				node.innerHTML = '<img src="/img/less.png" border="0" width="10" height="10">';
			}
			else
			{
				child.style.display = 'none';
				node.innerHTML = '<img src="/img/more.png" border="0" width="10" height="10">';
			}	
		}
	}
}
