/*==========================================================================*\
|| ######################################################################## ||
|| # ILance Marketplace Software
|| # -------------------------------------------------------------------- # ||
|| # Copyright ©2000–2007 ILance Inc. All Rights Reserved.	          # ||
|| # This file may not be redistributed in whole or significant part. 	  # ||
|| # ----------------- ILANCE IS NOT FREE SOFTWARE ---------------------- # ||
|| # http://www.ilance.com | http://www.ilance.com/eula	| info@ilance.com # ||
|| # -------------------------------------------------------------------- # ||
|| ######################################################################## ||
\*==========================================================================*/
function iL_Inline(varname, auctiontype, formobjid, submitname, ilancecookie)
{
	this.varname = varname;
	if (auctiontype.toLowerCase() == 'service')
	{
		this.auctiontype = 'service';	
	}
	else if (auctiontype.toLowerCase() == 'product')
	{
		this.auctiontype = 'product';
	}
	else if (auctiontype.toLowerCase() == 'provider')
	{
		this.auctiontype = 'provider';
	}
	this.formobj = fetch_object(formobjid);
	this.submitname = submitname;
	if (typeof ilancecookie != 'undefined')
	{
		this.ilancecookie = ilancecookie;
	}
	else
	{
		this.ilancecookie = 'ilance_inline';
	}
	if (this.auctiontype == 'service')
	{
		this.list = 'service_';
	}
	else if (this.auctiontype == 'product')
	{
		this.list = 'product_';
	}
	else if (this.auctiontype == 'provider')
	{
		this.list = 'provider_';
	}
	this.cookie_ids = null;
	this.cookie_array = new Array();
	this.init = function(elements)
	{
		for (i = 0; i < elements.length; i++)
		{
			if (this.is_in_list(elements[i]))
			{
				elements[i].inlineID = this.varname;
				elements[i].onclick = inline_checkbox_onclick;
			}
		}
		this.cookie_array = new Array();
		if (this.fetch_ids())
		{
			for (i in this.cookie_ids)
			{
				if (this.cookie_ids[i] != '')
				{
					if (checkbox = fetch_object(this.list + this.cookie_ids[i]))
					{
						checkbox.checked = true;
					}
					this.cookie_array[this.cookie_array.length] = this.cookie_ids[i];
				}
			}
		}
		this.set_output_counters();
	}
	this.fetch_ids = function()
	{
		this.cookie_ids = obtainv3cookie(this.ilancecookie + this.auctiontype);
		if (this.cookie_ids != null && this.cookie_ids != '')
		{
			this.cookie_ids = this.cookie_ids.split('-');
			if (this.cookie_ids.length > 0)
			{
				return true;
			}
		}
		return false;
	}
	this.toggle = function(checkbox)
	{
		this.save(checkbox.id.substr(8), checkbox.checked);
	}
	this.save = function(checkboxid, checked)
	{
		this.cookie_array = new Array();
		if (this.fetch_ids())
		{
			for (i in this.cookie_ids)
			{
				if (this.cookie_ids[i] != checkboxid && this.cookie_ids[i] != '')
				{
					this.cookie_array[this.cookie_array.length] = this.cookie_ids[i];
				}
			}
		}
		if (checked)
		{
			this.cookie_array[this.cookie_array.length] = checkboxid;
		}
		this.set_output_counters();
		this.set_cookie();
		return true;
	}

	/**
	* Saves the inline cookie
	*/
	this.set_cookie = function()
	{
		expires = new Date();
		expires.setTime(expires.getTime() + 3600000);
		updatev3cookie(this.ilancecookie + this.auctiontype, this.cookie_array.join('-'), expires);
	}

	this.is_in_list = function(obj)
	{
		return (obj.type == 'checkbox' && obj.id.indexOf(this.list) == 0 && (obj.disabled == false || obj.disabled == 'undefined'));
	}

	/**
	* Sets the value of the inline go button and the menu feedback
	*/
	this.set_output_counters = function()
	{
		if (obj = fetch_object('inlinebutton'))
		{
			obj.value = this.submitname + " (" + this.cookie_array.length + ")";
		}
	}
	this.init(this.formobj.elements);
}

/**
* Function to handle checkboxes being clicked
*
* @param	event	Event object
*/
function inline_checkbox_onclick(e)
{
	var inlineObj = eval(this.inlineID);
	inlineObj.toggle(this);
};

/*======================================================================*\
|| ####################################################################
|| # CVS: $RCSfile: inline.js,v $ - $Revision: 1.00 $
|| ####################################################################
\*======================================================================*/
