// Copiat de
// http://edochan.com/programming/layout.htm
var selectedCSS;

writeSheet();



function logcss(mycss) {
   // var today = new Date()
   // var expires = new Date()
   // expires.setTime(today.getTime() + 1000*60*60*24*7)
   setCookie("EdsCSSPicker", mycss, null, '/')  
   if ( document.cookie.length > 0)
      { history.go(0) }
   else 
      { sorryNoCookies(); }
      
}

function logcss_Tamany(mycss) {
   // var today = new Date()
   // var expires = new Date()
   // expires.setTime(today.getTime() + 1000*60*60*24*7)
   setCookie("EdsCSSPicker_Tamany", mycss, null, '/')  
   if ( document.cookie.length > 0)
      { history.go(0) }
   else 
      { sorryNoCookies(); }
      
}

function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


function getCookie(Name) 
{   
	var search = Name + "="   
	if (document.cookie.length > 0) { // if there are any cookies      
	offset = document.cookie.indexOf(search)       
	if (offset != -1) { // if cookie exists          
		offset += search.length          
		// set index of beginning of value         
		end = document.cookie.indexOf(";", offset)          
		// set index of end of cookie value         
		if (end == -1)             
			end = document.cookie.length         
		return unescape(document.cookie.substring(offset, end))
		}
	}
}

function sorryNoCookies()
{
//document.writeln("This doesn\'t work unless you let me use cookies, you dangerous subversive, you.");
}


function testForCookies() {
//Try to read a cookie - if there aren't any, try setting one then try reading that.

   if (document.cookie.length > 0) { 
      return true; 
   } else {
      setCookie ("testCookie", "testingForCookies");
         if (document.cookie.length > 0) { 
         return true; 
         } else {
         return false;
      }
   }
}



function writeSheet() {
//Reads the CSS from the cookie if there is one and writes it into the head of the page.

  var cookiecss;

  //Netscape makes a mess of my normal default CSS, so I'll give Netscape users a different one that works OK.
  if (browserIsCrap()) {
     var defaultcss='http://www.w3.org/StyleSheets/Core/Modernist';
     /* defaultcss='/css/estils_gris.css';*/
     defaultcss='/css/estils_claro.css';
     //var defaultcss_Tamany='/css/estils_10.css';
     
  } else {
     var defaultcss='http://www.w3.org/StyleSheets/Core/Modernist';
     /* defaultcss='/css/estils_gris.css';*/
     defaultcss='/css/estils_claro.css';
     //var defaultcss_Tamany='/css/estils_12.css';
   }



  cookiecss = getCookie("EdsCSSPicker");
  if ( cookiecss != "NOSHEET" ){
	  if ( cookiecss != null ) {
	     selectedCSS = cookiecss;	     
       	  } else {
	     selectedCSS = defaultcss;
	  }
  }

  /* sobre el tamaņo ya no se hace nada
  cookiecss_Tamany = getCookie("EdsCSSPicker_Tamany");
  if ( cookiecss_Tamany != "NOSHEET" ){
	  if ( cookiecss_Tamany != null ) {
	     selectedCSS_Tamany = cookiecss_Tamany;	     
       	  } else {
	     selectedCSS_Tamany = defaultcss_Tamany;
	  }
  }*/

document.write("<LINK REL=STYLESHEET HREF=\"" + selectedCSS + "\" TYPE=\"text/css\">");
//document.write("<LINK REL=STYLESHEET HREF=\"" + selectedCSS_Tamany + "\" TYPE=\"text/css\">");
   
}


function isNav() {
//Some very simple browser detection...

   var browser = navigator.appName;
   var ver = navigator.appVersion;
   return ((browser == "Netscape") && (ver < 6));

}


function browserIsCrap() {

   var browser = navigator.appName;

   if ((browser == "Netscape") && (navigator.appVersion.substring(0,1) < "5")) {
      //alert(navigator.appVersion);

      return true;
   } else {
      return false;
   }
}


//Just to say this file has finished loading OK. I don't want to call subroutines in it unless it has...
var cssScriptLoadedOK = true;

