/** Image declarations **/
var inputs;
var imgTrue = '../images/icons/checkbox_true.png';
var imgFalse = '../images/icons/checkbox_false.png';
var imgGreyed = '../images/icons/checkbox_greyed.png';

/** This function cares for setting the checkbox dependencies between categories and properties
@param className The className of the input fields to check for (propertySelection or categorySelection)
**/
function checkboxDependencies(className)
{
	var categorySelection=document.getElementsByClassName(className);
	
	//@TODO no complete reset but filtering. 
	
	//resetting the other checkboxes
	var properties='';
	var category='';

	if(className=='propertySelection')
	{
//		resetCheckBoxes('categorySelection');

		var categorySelection=document.getElementsByClassName('categorySelection');
		var propertySelection=document.getElementsByClassName('propertySelection');
		
		for(i=0;i<categorySelection.length;i++)
		{
			category=categorySelection[i];
			category.checked = true;

			for (p=0;p<propertySelection.length;p++)
			{
			   var property=propertySelection[p];
				if (property.checked)
				{
					iidx = category.alt.indexOf( ',' + property.value + ',' );
					if (iidx == -1)
						category.checked = false;
				}
			}	
		}
	}
	else
	{
		resetCheckBoxes('propertySelection');
/*
gl.log( 'init2' );

		var categorySelection=document.getElementsByClassName('categorySelection');
		var propertySelection=document.getElementsByClassName('propertySelection');

		//for every checkbox...
		for(i=0;i<categorySelection.length;i++)
		{
			category=categorySelection[i];
			
			if(category.checked==true)
			{	
				//the alt tag keeps the checkbox to activate 
				var properties=category.alt.split(",");
				
				for(n=0;n<properties.length;n++)
				{
					if(properties[n]!="" && properties[n]!="none")
					{ 
						$(properties[n]).checked=true;
			
					}	
				}	
			}	
		}
*/
	}

}

/** This function deactivates (unchecks) all checkboxes by a given className
@param className The class name identifies the checkboxes to uncheck
**/
function resetCheckBoxes(className)
{
	var propertySelection=document.getElementsByClassName(className);
	
	for(i=0;i<propertySelection.length;i++)
	{
		propertySelection[i].checked=false;
	}
}

/** For the Alternative Underlying Auswahl **/

/** Cares for displaying the products that match the criteria
@param checkBoxId Its used to identify the checkbox that got clicked. 
**/
function updateInPageMenu(checkBoxId)
{
	gl.log('updateInPageMenu(' + checkBoxId + ')','i');

	var criteria='';
	var rowCounter=0;
	
	try
	{	
		//hide all products by default
//		hideInPageMenu(false);
		
		var criterias=document.getElementsByClassName('criteria');
		var products=document.getElementsByClassName('products');

		//show the corresponding products...
		for(n=0;n<products.length;n++)
		{
			bHide = false;
			var parent=products[n].parentNode;

			for(m=0;m<criterias.length;m++)
			{					
				if(criterias[m].checked)
				{
					iidx = products[n].innerHTML.indexOf( ',' + criterias[m].id + ',' );
					gl.log( products.length + ' / ' + m + ' / ' + iidx );
					if (iidx == -1)
						bHide = true;
				}
			}
			if (bHide == true)
			{
//	   		gl.log( 'h' );					
				$(parent).addClassName('invisible');
			}
			else
			{
//	   		gl.log( 's' );					
				$(parent).removeClassName('invisible');
			}
			rowCounter++;
				
			//for switching the row color
			if((rowCounter%2)==0)
			{
				$(parent).removeClassName('bgTableRowEven1');
				$(parent).addClassName('bgTableRowOdd1');			
			}else
			{
				$(parent).removeClassName('bgTableRowOdd1');
				$(parent).addClassName('bgTableRowEven1');
			}
		}	
	}
	catch(err)
	{
		//display all products
		hideInPageMenu(false);	
	}
}

/** This function hides all products that keep the class name 'products' 
@param hide true when invis false when not
**/
function hideInPageMenu(hide)
{
	gl.log('=== hideInPageMenu(' + hide + ') ===','i');
	var products=document.getElementsByClassName('products');
	
	var rowCounter=0;
	
	for(n=0;n<products.length;n++)
	{
		var parent=products[n].parentNode;
		
		if(hide==true)
		{
			
			$(parent).addClassName('invisible');
		}
		else
		{
			$(parent).removeClassName('invisible');	
			rowCounter++;
			
			//for switching the row color
			if((rowCounter%2)==0)
			{
				
				$(parent).removeClassName('bgTableRowEven1');
				$(parent).addClassName('bgTableRowOdd1');			
			}
			else
			{
				
				$(parent).removeClassName('bgTableRowOdd1');
				$(parent).addClassName('bgTableRowEven1');
			}
		}		
		
	}
	gl.log('=== THE END hideInPageMenu(' + hide + ') ===','i');
}





