/* requires 'usingIEStyles' as set by common/austlitStyle-ie.js */

/** really pretty dodgy hardcoding the stylesheet URLs here.
   would be better to give them names in their link references (in BasicUIExecutable)
   but then that'd require all link ones to have names, otherwise it'd cause other probs
   of inconsistency.
   ideally, you could give them all title attributes, but
   i once added in a title attribute on a non alt sylesheet and it stuffed things up.
   could check to see if ok, but too much effort right now */
var maintStyleSheetHref = '/common/austlit-maint.css';
var ieMaintStyleSheetHref = '/common/austlit-maint-ie.css';
var maintStyleSheetSet = false;


function setActiveStyleSheet(title)
{
	 var i, a, main;
	 for (i = 0; (a = document.getElementsByTagName("link")[i]); i++)
	 {
	   if ( a.getAttribute("rel").indexOf("style") != -1 &&
		a.getAttribute("title") )
	   {
	     a.disabled = true;
	     if (a.getAttribute("title") == title) a.disabled = false;
	   }
	 }
}


/* identType is the name of the attribute in the <link> tag referring to the
   stylesheet, whose value should equal 'ident'. you'd normally expect it to be
   either 'title' or 'href' */
function enableStyleSheet(identType, ident)
{
	 var i, a, main;
	 for (i = 0; (a = document.getElementsByTagName("link")[i]); i++)
	 {
	   if ( a.getAttribute("rel").indexOf("style") != -1 )
	   {
	      if ( a.getAttribute(identType) )
	      {
  	         if (a.getAttribute(identType) == ident) a.disabled = false;
	      }
	   }
	 }
}

function isStyleSheetActive( href )
{
	 var i, a, main;
	 for (i = 0; (a = document.getElementsByTagName("link")[i]); i++)
	 {
	   if ( a.getAttribute("rel").indexOf("style") != -1 &&
  			a.getAttribute("href") )
	   {
	     if (a.getAttribute("href") == href)
	     {
	        if (a.disabled == false)
	        {
	            return true;
	        }
	        else
	        {
	            return false;
	        }
	     }
	   }
	 }
}


function printPreview()
{
    if ( ( isStyleSheetActive(maintStyleSheetHref) ) ||
         ( isStyleSheetActive(ieMaintStyleSheetHref) ) )
    {
        maintStyleSheetSet = true;
    }

    if (usingIEStyles)
    {
		setActiveStyleSheet('iePrintPreview');
    }
    else
    {
		setActiveStyleSheet('printPreview');
	}
}


function returnFromPrintPreview()
{
	setActiveStyleSheet('display');
	if (usingIEStyles)
	{
    	enableStyleSheet('title', 'ieStyleSheet');
    }
    if (maintStyleSheetSet == true)
    {
       if (usingIEStyles)
       {
       		enableStyleSheet('href', ieMaintStyleSheetHref);
       }
       else
       {
       		enableStyleSheet('href', maintStyleSheetHref);
       }
    }
}


function printDoc()
{
	window.print();
}



