function CCustomSelect( strElementId, bFixWidth, bOptionOpenUp )
{
	this.m_strElementId = strElementId;
	this.m_bFixWidth = bFixWidth;
	this.m_bOptionOpenUp = bOptionOpenUp;
	this.m_strCsOption = "";
	this.m_arrCsBodyClick = Array();
	this.m_objCustomSelect = jQuery( "#" + this.m_strElementId );

	this.init = function( strObject )
	{
		strCssPrefix = "cs";
		if( this.m_bFixWidth == true )
		{
			strCssPrefix = "cs_fix";		
		}
		
		var strSel = "";
		var strTmp = '<table border="0" cellpadding="0" cellspacing="0" style="z-index: 999;"><tr><td><div class="cs_select" id="cs_' + this.m_strElementId + '">' + 
				     '<a id="curr_' + this.m_strElementId + '" class="' + strCssPrefix + '_current" onClick="' + strObject + '.customToggle(this.parentNode,\'' + strCssPrefix + '\',' + this.m_bOptionOpenUp + ');event.cancelBubble=true;">' + 
				     '<table cellpadding=2 cellspacing=0><tr><td></td><td></td></tr></table></a><div id="' + this.m_strElementId + '_drop_down" class="cs_hidden" style="margin-top: -1px; z-index: 999;">';
		
		var iIndex = 0;
		var strVal = "";
		var strSelVal = "";
		
		var iTemp = 0;
		var strElementId = this.m_strElementId;
		jQuery( "#" + this.m_strElementId + " div" ).each( function()
		{												 
			if( iIndex == 0 )
			{
				strVal = jQuery( this ).attr( "val" );
				iIndex++;
			}
		
			if( jQuery( this ).attr( "sel" ) == "true" )
			{
				strSel = jQuery( this ).html();													
				strSelVal = jQuery( this ).attr( "val" );
			}
		
			strValue = "";
			strValue = jQuery( this ).attr( "val" );
			
			if( jQuery( this ).attr( "sel" ) == "true" )
			{
				if( iTemp != 1 && iTemp != 0 )
				{
					strTmp += '<a href="javascript:;" val="' + strValue + '" class="choice_' + strElementId + ' cs_options_selected" style="color:#FFF;">' + jQuery( this ).html() + '</a>';
				} else {
					strTmp += '<a href="javascript:;" val="' + strValue + '" class="choice_' + strElementId + '">' + jQuery( this ).html() + '</a>';				
				}
			} else {
				strTmp += '<a href="javascript:;" val="' + strValue + '" class="choice_' + strElementId + '">' + jQuery( this ).html() + '</a>';				
			}
			
			iTemp++;
		});	
			
		strTmp += '</div><input type="hidden" value="' + strVal + '" name="' + this.m_strElementId + '" id="val_' + this.m_strElementId + '"></div></td>' + 
			      '<td height="100%"><table width="100%" height="100%" cellpadding="0" cellspacing="0">' +
		 	      '<tr><td class="cs_down"><img hspace="2" vspace="2" src="images/layout/select_arrow_black.png" onClick="' + strObject + '.customToggle(document.getElementById(\'cs_' + this.m_strElementId + '\'),\'' + strCssPrefix + '\',' + this.m_bOptionOpenUp + ');event.cancelBubble=true;" /></td></tr></table></td></tr></table>';
				  
		this.m_objCustomSelect.html( strTmp );
	
		if( strSel != "" )
		{
			jQuery( "#curr_" + this.m_strElementId ).html( strSel );
			jQuery( "#val_" + this.m_strElementId ).val( strSelVal );
		}
		
		this.selectIt( this.m_strElementId );
		this.clickBody( strObject, ".closeSelect" );
	}
	
	this.getPosition = function( strElementId )
	{
		var objElement = document.getElementById( strElementId );
		var strTagName = "";
		var iY = 0;
		var iX = 0;
		
		while( objElement != null )
		{
			iY += objElement.offsetTop;
			iX += objElement.offsetLeft;
			strTagName = objElement.tagName.toUpperCase();
		
			if( strTagName == "BODY" )
			{
				strTagName = 0;
			}
		
			if( typeof( objElement ) == "object" )
			{
				if( typeof( objElement.offsetParent ) == "object" )
				{
					objElement = objElement.offsetParent;
				}
			}
		}
			
		objPosition = new Object();
		objPosition.x = iX;
		objPosition.y = iY;
		
		return objPosition;
	}

	this.customToggle = function( objElement, strCssPrefix, bOptionOpenUp )
	{
		this.m_bOptionOpenUp = bOptionOpenUp;
		
		if( this.m_strCsOption != "" )
		{
			jQuery( "#" + this.m_strCsOption ).next().addClass( "cs_hidden" );
			this.m_strCsOption = "";
		}
		
		var strElementId = objElement.id;
		
		var objSelectDropDownDiv = jQuery( "#" + strElementId ).find( "div" );
		var strChoicesCss = objSelectDropDownDiv.attr( "class" );
		
		if( strChoicesCss == "cs_hidden" )
		{
			this.m_strCsOption = strElementId;
			this.closeSelect(); 
			
			if( this.m_bOptionOpenUp == true )
			{
				var objPosition = this.getPosition( strElementId );
				iNodeLen = document.getElementById( strElementId ).childNodes.length;
				for( iIndex = 0; iIndex < iNodeLen; iIndex++ )
				{
					objElement = document.getElementById( strElementId ).childNodes[iIndex];
					if( objElement != null )
					{
						if( objElement.className == "cs_hidden" )
						{
							objElement.className = strCssPrefix + '_options_above';
							objElement.style.top = ( ( objPosition.y - objSelectDropDownDiv.height() ) - 66 ) + "px";
						}
					}
				}
			} else {
				objSelectDropDownDiv.addClass( strCssPrefix + '_options_under');
			}
		} else {			
			// objSelectDropDownDiv.removeClass( strCssPrefix + '_options_above');
			objSelectDropDownDiv.removeClass( strCssPrefix + '_options_under');			
			
			iNodeLen = document.getElementById( strElementId ).childNodes.length;
			for( iIndex = 0; iIndex < iNodeLen; iIndex++ )
			{
				objElement = document.getElementById( strElementId ).childNodes[iIndex];
				if( objElement != null )
				{
					strClass = strCssPrefix + "_options_above";
					if( objElement.className == strClass )
					{
						objElement.className = "cs_hidden";
						objElement.style.top = "0px";
					}
				}
			}			

			this.m_strCsOption = "";
		}
	}

	this.selectIt = function( strElementId )
	{		
		jQuery( ".choice_" + strElementId ).click( function()
		{	
			jQuery( "#val_" + strElementId ).val( jQuery( this ).attr( "val" ) );
			jQuery( "#curr_" + strElementId ).html( jQuery( this ).html() );
			
			if( this != null )
			{				
				if( this.parentNode != null )
				{
					if( this.parentNode.parentNode != null )
					{
						strMainId = this.parentNode.parentNode.getAttribute('id');
						strMainId = strMainId.replace( /cs_/g, "" );
						if( strMainId != "" )
						{	
							objTmp = document.getElementById( strMainId );								
							if( objTmp != null )
							{
								objTmp.className = "cs_options_selected";
								
								objAttrTmp = objTmp.getAttribute( "onchange" );
								if( objAttrTmp != null )
								{
									if( objAttrTmp != "" )
									{
										eval( objAttrTmp );
									}
								}
							}
						}
					}
				}
			}
		} );
	}

	this.closeSelect = function()
	{	
		objCsPageBottom = document.getElementById("cs_page_bottom");
		if( objCsPageBottom != null )
		{
			iNodeLen = objCsPageBottom.childNodes.length;
			for( iIndex = 0; iIndex < iNodeLen; iIndex++ )
			{
				objElement = objCsPageBottom.childNodes[iIndex];
				if( objElement != null )
				{					
					if( objElement.className == "cs_options_above" )
					{
						objElement.className = "cs_hidden";
						objElement.style.top = "0px";
					}
				}
			}
		}
		
		jQuery('div').removeClass('cs_options_under');		
		jQuery('div').removeClass('cs_fix_options_under');
	}
	
	this.clickBody = function( strObjectName, strFunctionName )
	{
		eval( strObjectName + ".m_arrCsBodyClick[" + strObjectName + ".m_arrCsBodyClick.length] = " + strObjectName + strFunctionName + ";");
	}
}
