var basic_colour_class = "colour_cell passive"; 
var basic_size_class = "size_container passive"; 
var current_cell_colour = " passive"; 
var active_colour = " active"; 
var selected_cell_colour = " selected"; 
var selected_size = '0';
var selected_colour = '0';
var selected_colour_array = new Array();

var cell_activated = false;

var charts_active = true;

/**
* the function setup charts as active 
*/
function activate_charts()
{
	charts_active = true;
}

/**
* the function setup charts as disabled 
*/
function deactivate_charts()
{
	charts_active = false;
}

/**
* this function set the value for the element 
* @param identifier string the identifier of the object
* @param value string the value attribute of the element
*/
function set_value(identifier, value)
{
	$('#'+identifier).val(value); 
}



/**
* this function change the color of the border for selected area to active_colour 
* @param identifier string the identifier of the object
* @param main_class string the identifier of the current class of the element
*/
function switch_border(identifier, main_class)
{
	if (charts_active)
	{
		cell_activated = true;
		var ChangedElement = $('#'+identifier);

		current_cell_colour = ChangedElement.attr('class'); 

		ChangedElement.attr('class', main_class+active_colour); 	
	}
	else
	{
		//alert('sssvn');	
	}
}

/**
* this function revert the border color for selected area to previous  
* @param identifier string the identifier of the object
*/

function revert_border(identifier, main_class, e)
{
	if ( (charts_active) && (cell_activated) )
	{
		cell_activated = false;
		var ChangedElement = $('#'+identifier);
		ChangedElement.attr('class', current_cell_colour);	
	}
	else
	{
		//alert('revn');	
	}
}

/**
* this function revert the border color for selected area to previous  
* @param identifier string the identifier of the object
* @param item_value string new value for the input
* @param main class string the identifier of the current class of the element
*/
function set_item(identifier, item_value, main_class)
{
	//alert(identifier+' '+item_value+' '+main_class);
	var ChangedElement = $('#'+identifier);
	if (ChangedElement.length)
	{
		ChangedElement.val(item_value); 
	}
	
	if (identifier == 'Size') 
	{
		set_standard_border(identifier + '_' + selected_size, current_cell_colour); 
	}
	else if (identifier == 'Colour')
	{
		set_standard_border(identifier + '_' + selected_colour, current_cell_colour);
	}
	
	current_cell_colour = main_class+selected_cell_colour;
	if (identifier == 'Size')
	{
		selected_size = item_value; 
	}
	else if (identifier == 'Colour')
	{
		selected_colour = item_value;
	}
}

/**
* this function revert the border color for selected area to previous  
* @param identifier string the identifier of the object
* @param item_identifier string new identifier of the object
* @param item_value string new value for the input
* @param main class string the identifier of the current class of the element
*/
function set_colour_label_item(identifier, item_identifier, item_value,  main_class)
{
	if ( (charts_active) && (cell_activated) )
	{
		//alert(identifier+' '+item_value+' '+main_class);
		var ChangedElement = $('#'+identifier);
		if (ChangedElement.length)
		{
			ChangedElement.val(item_value); 
		}
		//alert(ChangedElement.value);
		
		set_standard_border(identifier + '_' + selected_colour_array[identifier], current_cell_colour);
		
		current_cell_colour = main_class+selected_cell_colour;
		selected_colour_array[identifier] = item_identifier;
		
		//alert(identifier+' '+'sc'+selected_colour_array[identifier]);
	}
	else
	{
		//alert('sdad');	
	}
}

/**
* this function set the default selected colour (it is called with onLoad event)  
* @param identifier string the identifier of the object
* @param item_identifier string new identifier of the object
* @param item_value string new value for the input
* @param main class string the identifier of the current class of the element
*/
function set_default_colour(identifier, item_identifier, item_value,  main_class)
{
	//alert(identifier+' '+item_value+' '+main_class);
	cell_activated = true;
	var ChangedElement = $('#' + identifier);
	if (ChangedElement.length)
	{
		ChangedElement.val(item_value); 
	}
	//alert(ChangedElement.value);
	
	current_cell_colour = main_class+selected_cell_colour;
	selected_colour_array[identifier] = item_identifier;
	
	if ($('#' + identifier + '_' + selected_colour_array[identifier]).length) 
	{
		revert_border(identifier + '_' + selected_colour_array[identifier]);
		//alert(identifier+' '+'sc'+selected_colour_array[identifier]);
	}
}

/**
* this function tries to revert the border color for prevously selected area back to standard  
* @param identifier string the identifier of the object
* @param class_set string the class to be set for the element
*/
function set_standard_border(identifier, class_set)
{
	var PrevSelectedElement = $('#' + identifier);
	//alert('ff'+identifier);
	if (PrevSelectedElement.length)
	{
		PrevSelectedElement.attr('class', class_set);
	}
	
}

function set_standard_border2(identifier, main_class, class_set)
{
	var PrevSelectedElement = $(el);
	//alert('ff'+identifier);
	if (PrevSelectedElement.length)
	{
		PrevSelectedElement.attr('class', class_set);
		PrevSelectedElement.before('<'+PrevSelectedElement[0].nodeName+' class="'+class_set+'" '
							 +'onmouseover="switch_border2(this, \''+identifier+'\', \''+main_class+'\');" '
							 +'onmouseout="revert_border2(this, \''+identifier+'\', \''+main_class+'\');" '							 
							 +'>'+PrevSelectedElement.html()+'</'+PrevSelectedElement[0].nodeName+'>');
		PrevSelectedElement.remove();
	}
	
}


/**
* this function set visibility class of the object with the certain identifier  
* @param identifier string the identifier of the object
*/

function toggle_pane(identifier)
{
	if ($('#PrintingSwitch').checked)
	{
		class_set = 'visible_pane';
	}
	else
	{
		class_set = 'hidden_pane';
	}
	
	
	var ChangedElement = $('#'+identifier).attr('class',class_set);
}
