/*****************************************************************\
|*  In the name of Allah, The Most Gracious, The Most Merciful   *|
|*****************************************************************|
|*          ####  #     ####  ####  ####  ####  ####             *|
|*          #  #  #     #     #  #  #  #  #  #  #                *|
|*          ####  #     ###   ####  ####  #  #  ####             *|
|*          #  #  #     #     #     #     #  #     #             *|
|*    www.  #  #  ####  ####  #     #     ####  ####  .net       *|
|*****************************************************************|
|*  aleppos version 1.0.0
|*****************************************************************|
|* Copyright ©2005–2006 Aleppos Network Ltd. All Rights Reserved *|
|*This file may not be redistributed in whole or significant part*|
|* http://www.aleppos.net           ALEPPOS IS NOT FREE SOFTWARE *|
\*****************************************************************/

/**
* Array to store initialized AL_AJAX_Style objects
*
* @var	array
*/
var AL_Style = new Array()
var AL_Style = {
	'style_prefix'  : 'style_'
};

// #############################################################################
// AL_AJAX_style
// #############################################################################

function AL_AJAX_Style_Init()
{
	var images = fetch_tags(document, 'img');
	for (var i = 0; i < images.length; i++)
	{
		if (images[i].id && images[i].id.substr(0, AL_Style['style_prefix'].length) == AL_Style['style_prefix'])
		{
			images[i].style.cursor = pointer_cursor;
			images[i].onclick = AL_AJAX_Style.prototype.style_click;
		}
	}
};

function AL_AJAX_Style()
{
	// AJAX handler
	this.xml_sender = null;

	// Styleid
	this.stylid = '';

	// Closure
	var me = this;

	/**
	* OnReadyStateChange callback. Uses a closure to keep state.
	* Remember to use me instead of this inside this function!
	*/
	this.handle_ajax_response = function()
	{
		if (me.xml_sender.handler.readyState == 4 && me.xml_sender.handler.status == 200)
		{
			if (me.xml_sender.handler.responseXML)
			{
				var csssrc = me.xml_sender.fetch_data(fetch_tags(me.xml_sender.handler.responseXML, 'csssrc')[0]);
				if (csssrc)
				{
					fetch_object('vbulletin_css').href = csssrc;
				}
			}

			if (is_ie)
			{
				me.xml_sender.handler.abort();
			}
		}
	}
};

/**
* Submits the form via Ajax
*/
AL_AJAX_Style.prototype.fetch_style = function()
{
	this.xml_sender = new vB_AJAX_Handler(true);
	this.xml_sender.onreadystatechange(this.handle_ajax_response);
	this.xml_sender.send(BBURL + '/al_ajax.php?do=style&styleid=' + this.styleid, 'do=style&styleid=' + this.styleid);
};

/**
* Handles the form 'submit' action
*/
AL_AJAX_Style.prototype.style_click = function(e)
{
    var styleid = this.id.substr(AL_Style['style_prefix'].length);
	if (AJAX_Compatible)
	{
		var AJAX_style = new AL_AJAX_Style();
		AJAX_style.styleid = styleid;
		AJAX_style.fetch_style();
	}
	else
	{
		window.location = 'index.php?' + SESSIONURL + 'do=styleid=' + styleid;
	}

	return false;
};

/*****************************************************************\
|*  CVS: $RCSfile: aleppos_ajax_style.js,v $ - $Revision: 1.0 $
\*****************************************************************/
