var BV=parseFloat(navigator.appVersion.indexOf("MSIE")>0?navigator.appVersion.split(";")[1].substr(6):navigator.appVersion);
var BN=navigator.appName;
var IsWin=(navigator.userAgent.indexOf('Win')!=-1);
var IsMac=(navigator.userAgent.indexOf('Mac')!=-1);
var OP=(navigator.userAgent.indexOf('Opera')!=-1&&BV>=4)?true:false;
var NS=(BN.indexOf('Netscape')!=-1&&(BV>=4&&BV<5)&&!OP)?true:false;
var SM=(BN.indexOf('Netscape')!=-1&&(BV>=5)||OP)?true:false;
var IE=(BN.indexOf('Explorer')!=-1&&(BV>=4)||SM)?true:false;


function MM_RestoreImage() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_LoadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_LoadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}


function MM_SwapImage() { //v3.0
  var i,j=0,x,a=MM_SwapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function SpawnWindow(sURL,sheight,swidth) {
	var sOptionStr;

	sOptionStr = "width="+ swidth + ",height="+ sheight +",toolbar=yes,status=yes,resizable=yes,scrollbars=yes";
	window.open(sURL,'NewWindow',sOptionStr);
}


// Check whether string s is empty.
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}


// Returns true if string s is empty or 
// whitespace characters only.
function isWhitespace (s)

{   

    var i;
    var whitespace = " \t\n\r";

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}



function setStylesheet(title) {
   var i, cacheobj;
   for(i=0; (cacheobj=document.getElementsByTagName("link")[i]); i++) 
   {
      if(cacheobj.getAttribute("rel").indexOf("style") != -1 && cacheobj.getAttribute("title")) {
         cacheobj.disabled = true;
         if(cacheobj.getAttribute("title") == title)
            cacheobj.disabled = false; //enable chosen style sheet
      }
   }
}

function chooseStyle(styletitle){
   if (document.getElementById){
      setStylesheet(styletitle);
      setCookie("mysheet", styletitle);
   }
}

function setCookie(name, value) { 
var exp = new Date();     //set new date object 
exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 30));     //set it 30 days ahead 
document.cookie = name + "=" + value + "; path=/" + ((exp == null) ? "" : "; exp=" + exp.toGMTString()); 
} 


function readCookie() {
    var dc = document.cookie; 
    var cname = "mysheet="; 
    var stylename;

    if (dc.length > 0) { 
      begin = dc.indexOf(cname); 
      if (begin != -1) { 
        begin += cname.length; 
        end = dc.indexOf("", begin);
        if (end == -1) end = dc.length;
	stylename = dc.substring(8)
	chooseStyle(stylename)
        } 
      } 
   
}

