Array.prototype.contains = function (elem) {
  var i;
  for (i = 0; i < this.length; i++) {
    if (this[i] == elem) {
      return true;
    }
  }

  return false;
};

merkzettel=function()
{

this.cookiename="dm_merkzettel";
this.cookieparms={ expires: 7, path: '/', domain: 'www.dasmoebel.at', secure: false };
this.read=function()
{  
   //console.log(jQuery.cookie(this.cookiename));
   return	jQuery.cookie(this.cookiename);
}
this.cookieval=this.read() || "";
this.cookie_array=this.cookieval!=""? this.cookieval.split(';'):new Array();

this.load=function()
{
 jQuery('#merk').load("/wp-content/plugins/miniMerk.php?cookiestring="+this.cookieval);
 
}
this.add = function(art)
{
 openbasket=false;
 //jQuery("#merk_anchor").stop().css("color", "#FFFF9C").animate({ color: "#009EE0"}, 1500);

 if (this.cookie_array.contains(art)) return;
 if (this.cookie_array.length==0) openbasket=true;
 this.cookie_array.push(art);
 
 this.cookieval=this.cookie_array.join(';');
 
 this.write();
 this.load();
 
 if (openbasket) this.open();
}

this.write = function()
{
 
 this.cookieparms={ expires: 7, path: '/', domain: 'www.dasmoebel.at', secure: false };
	jQuery.cookie(this.cookiename,this.cookie_array.join(';'),this.cookieparms);
	if (this.cookie_array.length==0) {jQuery.cookie(this.cookiename,null,this.cookieparms);tb_remove();};
}

this.purge = function(close)
{
 
	jQuery.cookie(this.cookiename,null,this.cookieparms);
	this.cookie_array=new Array();
	this.cookieval="";
	this.load();
	
	if (close==null) tb_remove();
	jQuery('#merksend').remove();
	return false;
}

this.open = function()
{
	tb_show('meine merkliste:','/merk.php?KeepThis=true&TB_iframe=true&width=820&height=450' , false);
        jQuery('#TB_iframeContent').after(' <div id=\"merkfooter\" ><br/><a class=\"merklink\" href=\"/bestellinfo\">bestellinfo</a>&nbsp;&nbsp;<a class=\"merklink\" href=\"/agbs\">AGBs</a>&nbsp;&nbsp;<a class=\"merklink\" href=\"/kontakt\">kontakt</a> <a id=\"merksend\"  href=\"#\">merkliste weiter >></a></div>');
        jQuery('#TB_ajaxWindowTitle').css({color:"#009ee0" , "font-size": "1.3em" }).append("<br/> <div id=\"merkheader\" style=\"color:black;font-size:12px\" >Wenn Sie diese Liste an uns schicken, bekommen Sie in den nächsten Tagen eine persönliche Antwort, da die Lieferkosten, die genaue Ausführung, Zahlungsbedingungen und eventuell andere Fragen noch zu klären sind.Solten Sie spezielle Fragen oder Wünsche haben, können Sie diese auch in das Textfeld eintragen.  </div> <a id=\"merkloesch\"  onclick=\"merk.purge();\"href=\"#\">merkliste l&ouml;schen</a>");
        jQuery('#TB_title').css({color:"#009ee0",height:"90px"});
	var mythis=this;
	
	jQuery('#merksend').unbind();
	jQuery('#merksend').html('merkliste weiter >>');
	jQuery('#merksend').click(function(){mythis.sendform();});
}
this.sendform = function()
{
	jQuery('#TB_iframeContent').attr('src','/merksend.php');
	var mythis=this;
	//console.log("se");
	jQuery('#merksend').unbind();
	jQuery('#merksend').html('<< zurück zur merkliste');
	jQuery('#merksend').click(function(){mythis.show()});
	//return false;
}
this.show = function()
{
	jQuery('#TB_iframeContent').attr('src','/merk.php');
	var mythis=this;
	//console.log("sh");
	jQuery('#merksend').unbind();
	jQuery('#merksend').html('merkliste weiter >>');
	jQuery('#merksend').click(function(){mythis.sendform();});
	//return false;
}
this.del = function(art)
{       //console.log(art);
	if (!this.cookie_array.contains(art)) return;
	for (key in this.cookie_array)
		if (art==this.cookie_array[key]) this.cookie_array.splice(key,1);
	this.write();
	this.cookieval=this.cookie_array.join(';');
	this.load();		
	
}












}
var merk = new merkzettel();
jQuery(document).ready(
function()
{

merk.load();
jQuery('#merk').click(function(){merk.open()});
});