/**
	* Function to get an element by it's ID parameter in both IE and Mozilla 
	* based browsers.
	* @param mixed id The ID of the element to get
	*/
function getElement(id)
{
  if(document.all)
  {
    return document.all[id];
  }
  else if(document.getElementById)
  {
    return document.getElementById(id);
  }
  else
  {
    for(iLayer = 1; iLayer < document.layers.length; iLayer++)
    {
      if(document.layers[iLayer].id == id)
      {
        return document.layers[iLayer];
      }
    }
  }
  return null;
}

/**
	* Set an input value
	* @param mixed id The ID of the input
	* @param mixed value The value to set
	*/
function setValue(id, value)
{
	var obj = getElement(id);
	obj.value = value;
}

/**
	* Submits a form with the specified ID and action
	* @param mixed form_id The ID of the form
	* @param mixed form_action The action to assign the form
	*/
function submitForm(form_id, form_action)
{
	var form = getElement(form_id);
	try
	{
		if(form_action != "")
		{
			form.elements.action.value = form_action;
		}
		form.submit();
	}
	catch(error)
	{
		alert("There was an error.\n\nThe likely cause is that you are using Internet Explorer which generally doesn't follow the rules.\n\nYou should really be using Firefox.\n\nTo get Firefox please goto http://www.getfirefox.com.\n\nThe error generated was: "+error.description);
	}
}

/**
	* Set the focus onto the element with the specified ID
	* @param mixed id The ID of the element
	*/
function setFocus(id)
{
	var obj = getElement(id);
	try
	{
		obj.focus();
	}
	catch(e)
	{
		// For IE which seems to have trouble with getElement() used in conjunction with focus()
		try
		{
			document.getElementById(id).focus();
		}
		catch(e)
		{
			alert('We were unable to set focus on the comment form. Please scroll up to view the form and add your comment.');
		}
	}
}

/**
	* Hide or show a block level element
	* @param mixed id The ID of the element
	*/
function toggleVisible(id)
{
	var obj = getElement(id);
	if(obj.style.display == "block")
	{
		obj.style.display = "none";
	}
	else if(obj.style.display == "none")
	{
		obj.style.display = "block";
	}
	else
	{
		obj.style.display = "block";
	}
}

function confirmDelete()
{
	return answer = confirm("Are you sure you wish to delete this item?");
}

/**
	* Refresh the image script for the verification image
	*/
function generateNewCode(src)
{
	var obj = getElement('verification');
	obj.src = src+"?cb="+(Math.floor(Math.random()*500000)+100000);
}

/**
	* Goto the specified URL
	*/
function gotoUrl(url)
{
	document.location.href=url;
}

function clearUsername()
{
	var obj = getElement('username');
	if(obj.value == "Username")
	{
		obj.value = "";
	}
}

function clearPassword()
{
	var obj = getElement('password');
	if(obj.value == "Password")
	{
		obj.value = "";
	}
	obj.type = "password"
}

function clearIndexUsername()
{
	var obj = getElement('index_username');
	if(obj.value == "Username")
	{
		obj.value = "";
	}
}

function clearIndexPassword()
{
	var obj = getElement('index_password');
	if(obj.value == "Password")
	{
		obj.value = "";
	}
	obj.type = "password"
}

function checkEnter(event)
{
	return(event.keyCode == 13);
}

function hideCloud()
{
	getElement("keyword_cloud").className = "cloud_small";
	getElement("cloud_tip").className = "cloud_tip";
}

function showCloud()
{
	getElement("keyword_cloud").className = "cloud_large";
	getElement("cloud_tip").className = "do_not_display";
}