function initPopup()
{
  var popup2 = document.getElementById("popup2")
  var popup4 = document.getElementById("popup4")
	var popup3 = document.getElementById("popup3");

	var hold = document.getElementById("popup-hold");
	var nod = document.getElementById("with-popup");
	
	var test = document.getElementById("show_product");
	
	if(hold && nod && test)
	{
		hold.style.height = document.getElementById("main").offsetHeight + 200 + "px";
		text_b = nod.getElementsByTagName("div");
		for ( var i = 0; i < text_b.length; i++)
			{
				if( text_b[i].className.indexOf("popup-text") != -1){
//					if (text_b[i].getAttribute('productid'))
//						new Ajax.Updater('popup_content_ajax_'+text_b[i].getAttribute('productid'), '/product/show_ajax/'+text_b[i].getAttribute('productid'), {asynchronous:false, evalScripts:true});
					text = text_b[i].innerHTML;
				}
			}
		var button = document.getElementById("button");
		
			hold.innerHTML = text;
			
/** BY WEBPULSER **/
			text_tmp = hold.getElementsByTagName("img");
			for (var i = 0; i < text_tmp.length; i++)
			{
				if (text_tmp[i].getAttribute('rel') == "draggable_element"){
					text_tmp[i].setAttribute('id', "draggable_element_for_wishlist");
					a = new Draggable("draggable_element_for_wishlist", {revert:true});
				}
			}

			text_tmp = hold.getElementsByTagName("div");
			for (var i = 0; i < text_tmp.length; i++)
			{
				if (text_tmp[i].getAttribute('rel') == "drop_receiving_element_my_wishlist"){
					text_tmp[i].setAttribute('id', "drop_receiving_element_my_wishlist");
					Droppables.add("drop_receiving_element_my_wishlist", {hoverclass: 'selection-box-hover', onDrop:function(element){new Ajax.Request('/cart/add_product_ajax', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.getAttribute('product_id'))})}});
				}
			}
/** BY WEBPULSER **/

			document.body.className +=" display-popup";
		}

	if(hold && nod && !test)
	{
		hold.style.height = document.getElementById("main").offsetHeight + 108 + "px";
		text_b = nod.getElementsByTagName("div");
		for ( var i = 0; i < text_b.length; i++)
			{
				if( text_b[i].className.indexOf("popup-text") != -1){
//					if (text_b[i].getAttribute('productid'))
//						new Ajax.Updater('popup_content_ajax_'+text_b[i].getAttribute('productid'), '/product/show_ajax/'+text_b[i].getAttribute('productid'), {asynchronous:false, evalScripts:true});
					text = text_b[i].innerHTML;
				}
			}
		var button = document.getElementById("button");
		
		button.onclick = function ()
		{
			hold.innerHTML = text;
			
/** BY WEBPULSER **/
			text_tmp = hold.getElementsByTagName("img");
			for (var i = 0; i < text_tmp.length; i++)
			{
				if (text_tmp[i].getAttribute('rel') == "draggable_element"){
					text_tmp[i].setAttribute('id', "draggable_element_for_wishlist");
					a = new Draggable("draggable_element_for_wishlist", {revert:true});
				}
			}

			text_tmp = hold.getElementsByTagName("div");
			for (var i = 0; i < text_tmp.length; i++)
			{
				if (text_tmp[i].getAttribute('rel') == "drop_receiving_element_my_wishlist"){
					text_tmp[i].setAttribute('id', "drop_receiving_element_my_wishlist");
					Droppables.add("drop_receiving_element_my_wishlist", {hoverclass: 'selection-box-hover', onDrop:function(element){new Ajax.Request('/cart/add_product_ajax', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.getAttribute('product_id'))})}});
				}
			}
/** BY WEBPULSER **/

			document.body.className +=" display-popup";
			var close = hold.getElementsByTagName("a");
			for ( var j = 0; j < close.length; j++)
			{
				if( close[j].className.indexOf("close") != -1)
				{
					close[j].onclick = function ()
					{
						a.destroy();
						Droppables.remove("drop_receving_element_my_wishlist");
						text_tmp = hold.getElementsByTagName("img");
						for (var i = 0; i < text_tmp.length; i++)
						{
							if (text_tmp[i].getAttribute('id') == "draggable_element_for_wishlist"){
								text_tmp[i].setAttribute('id', "draggable_element");
							}
						}
						text_tmp = hold.getElementsByTagName("div");
						for (var i = 0; i < text_tmp.length; i++)
						{
							if (text_tmp[i].getAttribute('id') == "drop_receiving_element_my_wishlist"){
								text_tmp[i].setAttribute('id', "drop_receiving_element");
							}
						}
						document.body.className = document.body.className.replace("display-popup","");
					}
				}
			}
		}
	}

  if(popup2)
  {
    popup2.style.height = document.getElementById("main").offsetHeight + "px";
		var close = popup2.getElementsByTagName("a");
		for ( var j = 0; j < close.length; j++)
		{
			if( close[j].className.indexOf("close") != -1)
			{
				close[j].onclick = function ()
				{
					popup2.style.display ="none";
				}
			}
		}
  }
  if(popup4)
  {
    popup4.style.height = document.getElementById("main").offsetHeight + "px";
		var close = popup4.getElementsByTagName("a");
		for ( var j = 0; j < close.length; j++)
		{
			if( close[j].className.indexOf("close") != -1)
			{
				close[j].onclick = function ()
				{
					popup4.style.display ="none";
				}
			}
		}
  }
  if(popup3)
  {
    popup3.style.height = document.getElementById("main").offsetHeight + "px";
		var close = popup3.getElementsByTagName("a");
		for ( var j = 0; j < close.length; j++)
		{
			if( close[j].className.indexOf("close") != -1)
			{
			}
		}
  }

	var button_img = document.getElementById('button_img');
	
	if(button_img){
	
	button_img.onclick = function ()
	{
		hold.innerHTML = text;
		
/** BY WEBPULSER **/
		text_tmp = hold.getElementsByTagName("img");
		for (var i = 0; i < text_tmp.length; i++)
		{
			if (text_tmp[i].getAttribute('rel') == "draggable_element"){
				text_tmp[i].setAttribute('id', "draggable_element_for_wishlist");
        var target = text_tmp[i];  
				new Draggable("draggable_element_for_wishlist", {revert:true});
			}
		}

		text_tmp = hold.getElementsByTagName("div");
		for (var i = 0; i < text_tmp.length; i++)
		{
			if (text_tmp[i].getAttribute('rel') == "drop_receiving_element_my_wishlist"){
				text_tmp[i].setAttribute('id', "drop_receiving_element_my_wishlist");
				Droppables.add("drop_receiving_element_my_wishlist", {hoverclass: 'selection-box-hover', onDrop:function(element){new Ajax.Request('/cart/add_product_ajax', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.getAttribute('product_id'))})}});
			}
		}
/** BY WEBPULSER **/

		document.body.className +=" display-popup";
		var close = hold.getElementsByTagName("a");
		for ( var j = 0; j < close.length; j++)
		{
			if( close[j].className.indexOf("close") != -1)
			{
				close[j].onclick = function ()
				{
					document.body.className = document.body.className.replace("display-popup","");
				}
			}
		}
    new Insertion.Bottom(hold,'<iframe height="0px" width="0px" src="/home/iframe?xtpage='+encodeURIComponent(xtpage)+'&product_id='+ encodeURIComponent(target.getAttribute('product_id'))+'" style="display: none;"></iframe>');
	}
	}
}
if (window.addEventListener){
	window.addEventListener("load", initPopup, false);
}
else if (window.attachEvent && !window.opera){
	window.attachEvent("onload", initPopup);
}

function changeDivWithPopup(id)
{
	document.getElementById("with-popup-" + id).id = "with-popup";
	document.getElementById("button-" + id).id = "button";
	initPopup();
}

function changeDivWithPopupId(id)
{
	document.getElementById("with-popup").id = "with-popup-" + id;
	document.getElementById("button").id = "button-" + id;
	initPopup();
}

function changeDivWithPopupText(id)
{
	document.getElementById("with-popup-" + id).id = "with-popup";
	document.getElementById("button-text-" + id).id = "button";
	initPopup();
}

function changeDivWithPopupTextId(id)
{
	document.getElementById("with-popup").id = "with-popup-" + id;
	document.getElementById("button").id = "button-text-" + id;
	initPopup();
}

function close_mention_popup(card_product_id){
popup_mention = document.getElementById("popup3");

  if(popup_mention)
  {
		popup_mention.style.display ="none";
		popup_mention.id = "popup_mention" + card_product_id;

  }
}
function close_comment_popup(product_id){
popup_comment = document.getElementById("popup3");

  if(popup_comment)
  {
		popup_comment.style.display = "none";
		popup_comment.id = "popup_comment" + product_id;
  }
}
function close_comment_add_popup(){
popup_comment_add = document.getElementById("popup3");

  if(popup_comment_add)
  {
		popup_comment_add.style.display ="none";
		popup_comment_add.id = "popup_comment_add";
  }
}
function close_send_wishlist_popup(){
popup_comment_add = document.getElementById("popup3");

  if(popup_comment_add)
  {
		popup_comment_add.style.display ="none";
		popup_comment_add.id = "popup_send_wishlist";
  }
}
function close_record_wishlist_popup(){
	popup_record_wishlist = document.getElementById("popup3");

  if(popup_record_wishlist)
  {
		popup_record_wishlist.style.display ="none";
		popup_record_wishlist.id = "popup_record_wishlist";
  }
}
