// JavaScript Document

var custom_select_boxes_all = Array();

function openCloseCustomSelectBox( csb_id )
{
	if ( document.getElementById( csb_id + "_list" ) )
	{
		var csb = document.getElementById( csb_id + "_list" );
		if ( csb.style.display == "block" )
		{
			csb.style.display = "none";
		}
		else
		{
			csb.style.display = "block";
		}
	}
	
}

function closeCustomSelectBox( csb_id )
{
	if ( document.getElementById( csb_id + "_list" ) )
	{
		document.getElementById( csb_id + "_list" ).style.display = "none";
	}
}

function openCustomSelectBox( csb_id )
{
	if ( document.getElementById( csb_id + "_list" ) )
	{
		if ( document.getElementById( csb_id + "_list" ).style.display != "block" )
			document.getElementById( csb_id + "_list" ).style.display = "block";
	}
}

function selectCustomSelectBoxItem( csb_item, csb_id )
{
	var label = document.getElementById( csb_id + "_label" );
	var input = document.getElementById( csb_id );
	var list = document.getElementById( csb_id + "_list" );
	var onchange = document.getElementById( csb_id + "_onchange" );
	//if ( input.value != "" )
	//{
		for( i = 0; i < list.childNodes.length; i ++ )
		{
			if ( list.childNodes[i].lang == input.value )
			{
				list.childNodes[i].className = "custom-select-red-list-item";
			}
		}
	//}
	input.value = csb_item.lang;
	label.innerHTML = csb_item.innerHTML;
	csb_item.className = "custom-select-red-list-item-selected";
	openCloseCustomSelectBox( csb_id )
		
	if ( onchange.value != "" )
	{
		eval( onchange.value );
	}
}

function hoverCustomSelectBoxItem( csb_item )
{
	if ( csb_item.className == "custom-select-red-list-item" )
	{
		csb_item.className = "custom-select-red-list-item-hover";
	}
	else if ( csb_item.className == "custom-select-red-list-item-hover" )
	{
		csb_item.className = "custom-select-red-list-item";
	}
}

document.onclick = closeCustomSelectBoxes;

function closeCustomSelectBoxes( e )
{
	
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	
	var list_id = "";
	if ( targ.className == "custom-select-red-label" || targ.className == "custom-select-red-button" )
	{
		var id = targ.id;
		id = id.replace( "_label", "" );
		id = id.replace( "_button", "" );
		//alert( id );
		list_id = id + '_list';
	}
	
	//if ( !( targ.className == "custom-select-red" || targ.className == "custom-select-red-label" || targ.className == "custom-select-red-button" ) )
	//{
		for( i = 0; i < custom_select_boxes_all.length; i ++ )
		{
			if ( custom_select_boxes_all[i] + "_list" != list_id && document.getElementById( custom_select_boxes_all[i] + "_list" ) && document.getElementById( custom_select_boxes_all[i] + "_list" ).style.display == "block" )
				document.getElementById( custom_select_boxes_all[i] + "_list" ).style.display = "none";
		}
	//}
}
