var cookiename = "2goclosed";
var today = new Date();
var cookie_expire_date = new Date(today.getTime() + (8 * 7 * 86400000));


function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}


function sh(dId){
	var imgId = "img"+dId;
	
	if(	document.getElementById(dId).className == "b_ch" ){
		document.getElementById(dId).className = "b_c";
		document.getElementById(imgId).src="imgs/m.gif";

		var add = Get_Cookie(cookiename);
		var cookiestring = add.replace("|"+dId, "");
		Set_Cookie(cookiename, cookiestring, cookie_expire_date, "/", "", "");
	}
	else{
		document.getElementById(dId).className = "b_ch";
		document.getElementById(imgId).src="imgs/p.gif";
		
		var add = Get_Cookie(cookiename);
		if(add != null){
			var cookiestring = add.replace("|"+dId, "");
			var cookiestring = cookiestring+"|"+dId;
		}
		else{
			var cookiestring = "|"+dId;
		}
		Set_Cookie(cookiename, cookiestring, cookie_expire_date, "/", "", "");
	}
}

function closeOnload(){
	var ids = Get_Cookie(cookiename);
	if(ids != null){
		var ids_array = ids.split("|");
		for(i = 1; i < ids_array.length; i++){
			var imgId = "img"+ids_array[i];
			if(document.getElementById(ids_array[i]) != undefined){
				document.getElementById(ids_array[i]).className = "b_ch";
				document.getElementById(imgId).src="imgs/p.gif";
			}
		}
	}
}

function delc(){
	var today = new Date();
	var cookie_expire_date = new Date(today.getTime() + (8 * 7 * 86400000));
	Set_Cookie("closed", "", cookie_expire_date, "/", "", "");
}

function zoek(){
	
	var st = document.getElementById('st').value;
	var gog = document.getElementById('zmg');
	var got = document.getElementById('zmo');
	var ebay = document.getElementById('ebay');	
	var wiki = document.getElementById('wiki');	
	
	if(gog.checked){ 
		window.open("http://www.google.nl/search?hl=nl&q="+st+"&btnG=Google+zoeken&meta=");
	}
	if(got.checked){
		document.location.href="zoeken.php?q="+st;	
	}
	if(ebay.checked){
		window.open("http://clk.tradedoubler.com/click?p=1696&amp;a=1184979&amp;g=0&amp;URL=http://search.ebay.nl/"+st+"");
	}
	if(wiki.checked){
		window.open("http://nl.wikipedia.org/wiki/"+st+"");
	}
}

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);
