//function for changing stylesheets using document.getElementsByTagName( "link" )
function setLinkedStyleSheet( title )
{
	var linkNodes = document.getElementsByTagName("link");
	var currentTitle;
	for ( i = 0; i < linkNodes.length; i++ )
	{
		linkNode = linkNodes[i];
		relAttr = linkNode.getAttribute('rel');
		currentTitle = linkNode.getAttribute( "title" );

		//Stylesheets without a title attribute are left alone
		if (relAttr && (relAttr.indexOf( "style" ) != -1) && currentTitle)
		{
			//Disable each linked stylesheets
			linkNode.disabled = true;

			//Enable only the desired stylesheet
			if (currentTitle == title)
				linkNode.disabled = false;
        }
	}
}

//function for changing stylesheets using document.styleSheets
function setStyleSheet( theme )
{
	for (i = 0; i < document.styleSheets.length; i++)
	{
		if (document.styleSheets[i].title)
		{
			document.styleSheets[i].disabled = true;
			if (document.styleSheets[i].title == theme)
				document.styleSheets[i].disabled = false;
		}
	}
}


/*This function takes four parameters:
a - defines the action you want the function to perform.
o - the object in question.
c1 - the name of the first class
c2 - the name of the second class

Possible actions are:
swap - replaces class c1 with class c2 in object o.
add -  adds class c1 to the object o.
remove - removes class c1 from the object o.
check - test if class c1 is already applied to object o and returns true or false.*/
function jscss(a,o,c1,c2)
{
  switch (a){
    case 'swap':
      o.className=!jscss( 'check', o, c1 ) ? o.className.replace(c2,c1) : o.className.replace(c1,c2);
    break;
    case 'add':
      if(!jscss('check',o,c1)){o.className += o.className ? ' ' + c1 : c1;}
    break;
    case 'remove':
      var rep=o.className.match(' '+c1)?' '+c1:c1;
      o.className=o.className.replace(rep,'');
    break;
    case 'check':
      return new RegExp('\\b'+c1+'\\b').test(o.className)
    break;
  }
}

function getChildElementsByTagName(object,tagname)
{
    var children = object.childNodes;
    var elements = new Array();

    tagname = tagname.toLowerCase();   
    for (i = 0; i < children.length; i++)
    {
        if (children[i].tagName != null)
        {
            if (children[i].tagName.toLowerCase() == tagname)
                elements.push(children[i]);
        }
    }
    return elements;
}

function toggledisplay(_this)
{
    var content = getChildElementsByTagName(_this.parentNode.parentNode, "div")[1];
    var initialized = jscss('check',_this,"eyeclosed") || jscss('check',_this,"eyeopen");

    if (!initialized) jscss('add',_this,"eyeopen");
    
    if (jscss('check',_this,"eyeopen"))
    {
        jscss('swap',_this,"eyeopen","eyeclosed");
        jscss('add',content,"notdisplayed");
    }
    else
    {
        jscss('swap',_this,"eyeclosed","eyeopen");
        jscss('remove',content,"notdisplayed");
    }
}