
/**
 * One thing to remember on this:  
 *		Keep track of Wish List count in js.  When you try to go between php/js through ajax
 *		the count gets messed up.  
 */
function WishList()
{
	this.wl_dir = "http://activities.10best.com/WishList/";

	//this.modal = "";
	
	this.size = 0;
	
	
		
	this.init = function()
	{		
		/*this.modal = new DHTMLSuite.modalMessage();
		this.modal.setSize("auto", "auto");
		this.modal.setShadowDivVisible(true);	// Enable shadow for these boxes
		this.modal.setShadowOffset(3);*/
	}
	
	this.popupWrite = function(url)
	{
		callback = function()
		{
			if(xmlHttp.readyState == 4)
			{
				document.getElementById("WishList_Popup").innerHTML = xmlHttp.responseText;
				
				wish_list.popupDisplay(true);
			}
		}
	
		ajaxManager.ajaxGet(callback, url, "");
	}
	
	this.popupDisplay = function(display)
	{
		display = (display) ? "inline" : "none";
		
		document.getElementById("WishList_Popup").style.display = display;
	}
	
	this.addToCart = function(im_id, category_id)
	{	
		window.location = this.wl_dir + "add_to_cart.inc.php?im_id=" + im_id + "&cat=" + category_id;
	}
	
	this.emailPopup = function()
	{
		/*this.modal.setSource(this.wl_dir + "email_message.inc.php");
		this.modal.setIsModal(true);
		this.modal.display();*/
		
		this.popupWrite(this.wl_dir + "email_message.inc.php");
	}
	
	this.closePopup = function()
	{
		//this.modal.close();
		
		this.popupDisplay(false);	
	}
	
	this.email = function()
	{
		callback = function() 
		{
			if(xmlHttp.readyState == 4)
			{	document.getElementById("EmailWishList_status").innerHTML = xmlHttp.responseText;
			}	
		}
		
		to_address   = escape( document.getElementById("WishList_ToEmail").value );
		from_address = escape( document.getElementById("WishList_FromEmail").value );
		to_name      = escape( document.getElementById("WishList_ToName").value );
		from_name    = escape( document.getElementById("WishList_FromName").value );
		subject = escape( document.getElementById("WishList_SubjectEmail").value );
	
		ajaxManager.ajaxGet(callback, this.wl_dir + "email_wishlist.inc.php", "to_address=" + to_address + 
			"&from_address=" + from_address + "&to_name=" + to_name + "&from_name=" + from_name + 
			"&subject=" + subject);
	}
	
	this.updateSize = function()
	{						
		document.getElementById("wishListItemCount").innerHTML = this.size;
		
		if(document.getElementById("viewWishListCount"))
		{	document.getElementById("viewWishListCount").innerHTML = this.size;
		}
	}
	
	this.addNotify = function(status)
	{
		url = (status) ? 
			this.wl_dir + "add_notification.php" : this.wl_dir + "add_notification_failed.php";
	
		/*this.modal.setSource(url);
		this.modal.setIsModal(false);
		this.modal.display();*/
		
		this.popupWrite(url);
	}

	this.addProduct = function(im_id)
	{

		callback = function() 
		{
			if(xmlHttp.readyState == 4 && xmlHttp.responseText != "false")
			{	//wish_list.size++;
			 //wish_list.updateSize();
			  var element = document.getElementById("wishListContainer");
        //alert(xmlHttp.responseText);
  		  element.innerHTML = xmlHttp.responseText; 
  		  element.style.display='block';
        wish_list.addNotify(true);
      }	
			else if(xmlHttp.readyState == 4 && xmlHttp.responseText == "false")
			{	wish_list.addNotify(false);
			}	
		}	
		ajaxManager.ajaxGet(callback, this.wl_dir + "add_product.inc.php", "im_id=" + im_id + "&PHPSESSID"+ '');	
	  if(document.getElementById("explanation")!=null) document.getElementById("explanation").style.display='none';
    
  
  }
	
	this.removeProduct = function(im_id, index)
	{
	
		callback = function() 
		{	
			//if(xmlHttp.readyState == 4 && xmlHttp.responseText != "true")
			//{	//wish_list.size--;
				//wish_list.updateSize();
			//} 
		}	
			
		if(index!=-1)document.getElementById("WishList_Product_" + index).style.display = "none";
			
		ajaxManager.ajaxGet(callback, this.wl_dir + "remove_product.inc.php", "im_id=" + im_id + 
			"&index=" + index + "&PHPSESSID"+ '');
	}
	
	this.bookmark = function(title)
	{
		url = document.location;
	
		if (window.sidebar) 	// Mozilla Firefox Bookmark
		{ 	window.sidebar.addPanel(title, url,"");
		} 
		else if( window.external ) 		// IE Favorite
		{	window.external.AddFavorite( url, title); 
		}
		else if(window.opera && window.print) 	// Opera Hotlist
		{	alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
		}
	}
	
	this.removeAll = function()
	{
		list = new Array();
	
		i = 0;
			
		while(curr = document.getElementById("WishList_" + i))
		{
			if(curr.checked)
			{	this.removeProduct(curr.value, i);
			}
		
			i++;
		}
	}
	
	this.checkAll = function()
	{
		i = 0;
	
		while(curr = document.getElementById("WishList_" + i))
		{
			curr.checked = true;
		
			i++;
		}
	}
	
	this.uncheckAll = function()
	{
		i = 0;
	
		while(curr = document.getElementById("WishList_" + i))
		{
			curr.checked = false;
		
			i++;
		}
	}

}

window.DHTML_SUITE_THEME 		= "WishList";
window.DHTML_SUITE_THEME_FOLDER = "/js/DHTMLSuite/themes/";
window.DHTML_SUITE_JS_FOLDER    = "/js/DHTMLSuite/js/separateFiles/";

wish_list = new WishList();
