function open_topic( type ){
	var opened_type = type + "_opened";
	var closed_type = type + "_closed";
	document.getElementById(opened_type).style.display = 'block';
	document.getElementById(closed_type).style.display = 'none';
}
function close_topic( type ){
	var opened_type = type + "_opened";
	var closed_type = type + "_closed";
	document.getElementById(opened_type).style.display = 'none';
	document.getElementById(closed_type).style.display = 'block';
}
function topic_view(type) {
  var cookie = readCookie(type);
  var title = cookie ? cookie : "block";
  if (cookie == "none") { close_topic(type); } else { open_topic(type);}
}


function review_list(file_name,file_title) {
  var host_url = "http://www.funnydays.info/files/";
  var default_data = "none:none:none:none:none:none:none";
  var list_num = 7;

  var cookie = readCookie("review_list");
  var url = cookie ? cookie.split(":") : default_data.split(":");
  var list_url = file_name;
  var cookie = readCookie("review_title");
  var title = cookie ? cookie.split(":") : default_data.split(":");
  var list_title = file_title;

  document.write("<DL>");
  for ( i = 0; i < list_num; i++ ) {
	var output_url = url[i] ? url[i] : "none";
	var output_title = title[i] ? unescape(title[i]) : "none";
	if ( output_url != "none" ) {
	  var output_html = "<DD>E<a href=\"" + host_url + output_url + ".html\" target=\"_self\">" + output_title + "</a></DD>";
	  document.write(output_html);
	}
	if ( output_url != file_name ) {
		list_url = list_url + ":" + url[i];
		list_title = list_title + ":" + title[i];
	}
  }
  document.write("</DL>");

  createCookie("review_list", list_url, 365);
  createCookie("review_title", list_title, 365);
}

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;
    }
  }
}

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")
       ) return a.getAttribute("title");
  }
  return null;
}





function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

