/* browser CSS switcher script - (c)2007 Nuvola Ltd */

function choosestyle()
/*	call this function from body onload 
	requires stylesheets to be set with titles css_ie, css_firefox and css_safari (css_safari MUST be first as safari has a bug...)
	note this will not switch the stylesheet if it's not one of these browsers, or one of these stylesheets is missing*/
{
	var a = navigator.userAgent;
	var ok;
	
	if(a.indexOf('MSIE') > -1)		//Internet Explorer
	{
		ok = setActiveStyleSheet('css_ie');
		//ok = setActiveStyleSheet('css_default');
	}
	if(a.indexOf('Firefox') > -1)		//Firefox
	{
		ok = setActiveStyleSheet('css_firefox');
	}
	if(a.indexOf('Safari') > -1)		//Safari
	{
		ok = setActiveStyleSheet('css_safari');
	}
	else								//this stylesheet must be there
	{
		ok = setActiveStyleSheet('css_default');
	}	
	
	if(!ok) setActiveStyleSheet('css_default');
	
}
	
	
function setActiveStyleSheet(title) 
{
	var i, a, found = false;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) 		//loop through link tags
	{
    	if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") == title) 	//if this is the specified stylesheet, activate it
    	{
	    	a.disabled = false;
	    	found = true;
	    }
    }
    if(found)		//if we found the specified stylesheet, loop through again to deactivate the rest
    {
    	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) 
		{
	    	if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") != title) 
	    	{
	    		a.disabled = true;
	    	}
		    
	    }
	}
	return found;
}

function getActiveStyleSheet() {
 var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
 }
  return null;
}
