var schowek_dodaj = 'Dodaj do schowka';
var schowek_usun = 'Usuń ze schowka';

function Dodaj(value) {
  if(document.all && document.all('schowek')) {
    document.all('schowek').innerHTML = '<a href="javascript:DeleteCookie(\'schowek\',\''+value+'\');Usun(\''+value+'\');" class="detale">'+schowek_usun+'</a>';
  } else {
    if (document.getElementById && document.getElementById('schowek')) {
      document.getElementById('schowek').innerHTML = '<a href="javascript:DeleteCookie(\'schowek\',\''+value+'\');Usun(\''+value+'\');" class="detale">'+schowek_usun+'</a>';
    }
  }
}

function Usun(value) {
  if(document.all && document.all('schowek')) {
    document.all('schowek').innerHTML = '<a href="javascript:SetCookie(\'schowek\',\''+value+'\');Dodaj(\''+value+'\');" class="detale">'+schowek_dodaj+'</a>';
  } else {
    if (document.getElementById && document.getElementById('schowek')) {
      document.getElementById('schowek').innerHTML = '<a href="javascript:SetCookie(\'schowek\',\''+value+'\');Dodaj(\''+value+'\');" class="detale">'+schowek_dodaj+'</a>';
    }
  }
}

function GetCookie(name)
  {
  var search = name + "=";
  if (document.cookie.length > 0)
    {
    offset = document.cookie.indexOf(search);
    if (offset != -1)
      {
      offset += search.length;
      end = document.cookie.indexOf(";", offset)
      if (end == -1) end = document.cookie.length
        return unescape(document.cookie.substring(offset, end))
      }
    }

}

function SetCookie (name, value) {  
  if (GetCookie(name)) {
    var stare = GetCookie(name) + ",";
  } else {
    var stare = '';
  }  
    if (stare.indexOf(value)==-1) {
      var argv = SetCookie.arguments;  
      var argc = SetCookie.arguments.length;  
      var expires = (argc > 2) ? argv[2] : null;  
      var path = (argc > 3) ? argv[3] : null;  
      var domain = (argc > 4) ? argv[4] : null;  
      var secure = (argc > 5) ? argv[5] : false;  
      document.cookie = name + "=" + stare + escape (value) + 
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
        ((path == null) ? "" : ("; path=" + path)) +  
        ((domain == null) ? "" : ("; domain=" + domain)) +    
        ((secure == true) ? "; secure" : "");
      }
    CheckCookie(value);
}


function DeleteCookie(name, value) {
  if (GetCookie(name)) {
    var stare = GetCookie(name);
    var pos = stare.indexOf(value);
    if (pos!=-1) {
      var nowe = stare.replace(value, '');
      nowe = nowe.replace(',,', ',');
      if (nowe.indexOf(',')==0) nowe = nowe.substr(1,nowe.length-1);
      document.cookie = name + "=" + nowe;
    }
  } 

  CheckCookie(value);
}

function DeleteCookieSchowek(name, value) {
  if (GetCookie(name)) {
    var stare = GetCookie(name);
    var pos = stare.indexOf(value);
    if (pos!=-1) {
      var nowe = stare.replace(value, '');
      nowe = nowe.replace(',,', ',');
      if (nowe.indexOf(',')==0) nowe = nowe.substr(1,nowe.length-1);
      document.cookie = name + "=" + nowe;
    }
  }
}

function DeleteAll(name, path, domain) {
    if (GetCookie(name)) {
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
         ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT" 
   }
   showOferFromClipboard('/?d=schowek');
}


function IsCookie (name, value) {
  if (GetCookie(name)) {
    var stare = GetCookie(name);
    if (stare.indexOf(value)!=-1) {
      return true;
    }  
  }
  return false;
}

function CheckCookie(value) {
  if ( IsCookie('schowek', value) ){
	Dodaj(value); 
  }else{
	Usun(value);
  }
  
   if(IsCookie('schowek', '')) {
  	if(document.getElementById('idzschowek')) {
  		document.getElementById('idzschowek').style.fontWeight = 'bold';
	}
  } else {
  	if(document.getElementById('idzschowek')) {
  		document.getElementById('idzschowek').style.fontWeight = 'normal';
	}
  }
}

function showOferFromClipboard(src) {
  document.location = src;
}
