function $$(id)
{
	return document.getElementById(id);
}



/*--------------------------------------------------------------------------*/
/*  Cookie Functions */
/*--------------------------------------------------------------------------*/
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function SimpleSetCookie(key, value)
{
	var expdate = new Date ();
	FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
	expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000));
		SetCookie(key, value, expdate);		
	return true;
}
function SimpleGetCookie(key)
{
	return GetCookie(key);
}







function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("stylesheet") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

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;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       && a.getAttribute("title").indexOf("1") !=3 -1
       ) return a.getAttribute("title");
  }
  return null;
}


window.onload = function() {
var cookie = SimpleGetCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title)
	setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  SimpleSetCookie("style", title);
}







function PopupWindow(url,width,height,resize,params, name)
{	
	if (name == null) name = "EditWin";
	
	screenx = screen.availWidth;
	screeny = screen.availHeight;
	x = null;
	y = null;
	if (width != null)
	{
	    if (width < 1) width = screenx * width;
	    x = (screenx / 2) - (width / 2);
	}
	if (height != null)
	{
	    if (height < 1) height = screeny * height;
	    y = (screeny / 2) - (height / 2);
	}
	
	if (width != null) width = ",width=" + Math.round(width);
	if (height != null) height = ",height=" + Math.round(height);
	if (resize == null) resize = "yes";
	
	if (x != null) x = ",screenX=" +  Math.round(x) + ",Left=" + Math.round(x);
	if (y != null) y = ",screenY=" + Math.round(y) + ",Top=" + Math.round(y);

//Set parameters
    lparams = new Object();
	if (params != null)
	{
    	aparams = params.split(";");
	    for (i = 0; i < aparams.length; i++)
    	{
	        sparams = aparams[i].split("=");
	        lparams[sparams[0]] = sparams[1];
    	}
    }
    
    //alert("scrollbars=yes,dependant=yes" + width + height + x + y + ",centerscreen=yes,resizable=" + resize);

//Create window
	editWin = window.open(url,name,"scrollbars=yes,dependant=yes" + width + height + x + y + ",centerscreen=yes,resizable=" + resize);
	if (!editWin)
	{
	    alert("Your browser has blocked a popup. Please configure your browser to allow popups on this Website.");
	    return;
	} else {
	    //editWin.focus();
	}
	
	try {
	    editWin.params = lparams	
	} catch (e) {}
}














 function CreateBookmarkLink() {

 title = document.title; 
  // Blogger - Replace with <$BlogItemTitle$> 
  // MovableType - Replace with <$MTEntryTitle$>

 url = document.location.href + "";
  // Blogger - Replace with <$BlogItemPermalinkURL$> 
  // MovableType - Replace with <$MTEntryPermalink$>
  // WordPress - <?php bloginfo('url'); ?>

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }










