﻿function ACCSetting(strInputID, strImageUrl, strAlternateImageUrl, role, manager)
{
	this.strInputID = strInputID;
	this.strImageUrl = strImageUrl;
	this.strAlternateImageUrl = strAlternateImageUrl;
	this.strRole = role;
	this.manager = manager;
	
	this.input = null;
	this.label = null;
	this.img = null;

	var me = this;

	this.ExtendClickEvent = function(ev)
	{6
		AddEvent(me.input, "click", ev);
	}

	this.SetImage = function()
	{
		if(me.img != null)
		{
			if(me.input.checked)
				me.img.src = strImageUrl;
			else
				me.img.src = strAlternateImageUrl;
		}
	}
	
	this.SetLabelClass = function()
	{
		if(me.input.checked)
		{
			AddCssClass(me.label, "checked");
		}
		else
		{
			RemoveCssClass(me.label, "checked");
		}
	}

	this.OnClick = function()
	{
		me.SetImage();
		me.SetLabelClass();
		if(me.input.type == "radio")
		{
			for(var i=0; i<g_AllACCRadioSettings.length; i++)
			{
				g_AllACCRadioSettings[i].SetImage();
				g_AllACCRadioSettings[i].SetLabelClass();
			}
		}
	}
	
	this.OnClickImage = function()
	{
		if(document.all && navigator.appVersion.indexOf("MSIE")>-1 && navigator.appVersion.indexOf("Windows")>-1)
		{
			me.input.click();
		}
		me.OnClick();
	}
	
	this.SetChecked = function(check)
	{
		me.input.checked = check;
		me.OnClick();
	}
	
	this.GetChecked = function()
	{
		return me.input.checked;
	}

	this.GetMainInput = function()
	{
		return me.input;
	}

	this.Init = function()
	{
		me.input = GetBlock(me.strInputID);
		//me.input.parentNode.parentNode.className = "ACCSetting_container";
		AddEvent(me.input, "click", me.OnClick);
		me.label = me.input.nextSibling;
		if(me.label.nodeName.toLowerCase() != "label")
			me.label = null;
		
		me.img = me.label.lastChild;
		if(me.img.nodeName.toLowerCase() != "img")
			me.img = null;
		if(me.img)
		{
			AddEvent(me.img, "click", me.OnClickImage);
			me.SetImage();
		}
		me.SetLabelClass();
		if(me.input.type == "radio")
			g_AllACCRadioSettings[g_AllACCRadioSettings.length] = me;
			
		if (me.manager != "undefined" && me.manager != null)
		{
			if (me.manager.strManagerType == "AdvancedPropManager")
				me.manager.AddSelectorSetting(me);
			else if (me.manager.strManagerType == "DetailedCheckPropManager")
				me.manager.AddCheckSetting(me);
			else if (me.manager.strManagerType == "DetailedRadioPropManager")
				me.manager.AddRadioSetting(me);
		}
	}
	me.Init();
}

var g_AllACCRadioSettings = [];
