/**
 * @author cwolff
 */
function sortAlphaNumeric(a,b)
{
	var a = a[fdTableSort.pos];
    var b = b[fdTableSort.pos];

	if(isNaN(a)){a = 999;}
	if(isNaN(b)){b = 999;}
	a = parseInt(a);
	b = parseInt(b);

	if(a == b){return 0;}
	if(a < b){return -1;}
	return 1;
}

var UI = {
	ALERT : {
		BasicPopup : function(id,title,width,height)
		{
			$("#" + id).dialog({
				bgiframe: true,
				title : title,
				height:height,
				width:width
			});
			
			$("#" + id).dialog('open');
		},
		
		SetErrorPopup : function(id,modaltype)
		{		
			$("#" + id).dialog({
				bgiframe: true,
				modal: modaltype,
				close: function(event, ui) 
				{
					$('#message_holder_left').html($("#error_holder_hidden").html());
					$('#message_holder_left').show();
				}
			});
			
			$("#" + id).dialog('open');
			
		},
		
		SetConfirmationWarning : function(id,btn_message,form,height,width)
		{
			
			$("#" + id).dialog({
				bgiframe: true,
				modal: true,
				height:height,
				width:width,
				buttons : {'Continue' : function()
									{											
										$(this).dialog('close');
										$(form).submit();
									},
							Cancel	: function()
									{	
										$(this).dialog('close');
										
									}
						}
			});	
			
			$("#" + id).dialog('open');
		},
		
		SetFormPopup : function(id,callback)
		{
			$("#" + id).dialog({
				bgiframe: true,
				modal: true,
				buttons : {
					'Ok' : function(){
						callback();
						$(this).dialog('close');
					},
					'Cancel' : function(){
						$(this).dialog('close');
					}
				}
			});
			
			$("#" + id).dialog('open');
		}
	},
	
	TABLE : {
		Restripe : function(tbody,even,odd)
		{
			var counter = 0;
			$(tbody).find('tr').each(function()
			{
				if ($(this).is(':hidden') == false) {
					$(this).removeClass(even);
					$(this).removeClass(odd);
					
					if ((counter % 2) == 0) {
						$(this).addClass(even);
					}
					else {
						$(this).addClass(odd);
					}
					
					counter++;
				}
			});
		}
	},
	
	TRIGGERS : {
		RADIO : 
		{
			Select : function(trigger_id,radio_input_id)
			{				
				$('#' + trigger_id).focus(function()
				{
					$('#' + radio_input_id).attr('checked','checked');
				});
			},
			
			HideField : function(radio_id,field_id)
			{				
				if($('#' + radio_id).is(':checked'))
				{
					$('#' + field_id).hide();
				}
				else
				{
					$('#' + field_id).show();
				}
				
				$('#' + radio_id).click(function()
				{
					$('#' + field_id).hide();
				});
			},
			
			ShowField : function(radio_id,field_id)
			{				
				if($('#' + radio_id).is(':checked'))
				{
					$('#' + field_id).show();
				}
				else
				{
					$('#' + field_id).hide();
				}
				
				$('#' + radio_id).click(function()
				{
					$('#' + field_id).show();
				});
			}
		},
		
		CHECKBOX : 
		{
			HideField : function(checkbox_id,field_id)
			{
				if($('#' + checkbox_id).is(':checked'))
				{
					$('#' + field_id).hide();
				}
				else
				{
					$('#' + field_id).show();
				}
				
				$('#' + checkbox_id).click(function()
				{
					$('#' + field_id).toggle();
				});
			},
			
			ShowField : function(checkbox_id,field_id)
			{
				if($('#' + checkbox_id).is(':checked'))
				{
					$('#' + field_id).show();
				}
				else
				{
					$('#' + field_id).hide();
				}
				
				$('#' + checkbox_id).click(function()
				{
					$('#' + field_id).toggle();
				});
			}
		},
		
		TEXTBOX :
		{
			Select : function(trigger_id)
			{
				$('#' + trigger_id).focus(function()
				{
					$(this).select();
				});
			}
		},
		
		SELECTBOX :
		{
			Hide : function(trigger_id,hideall)
			{
				$('#' + trigger_id).change(function()
				{
					var showid = $(this).attr('value');
					$(hideall).hide();
					$(showid).show();		
				});
			}
		},
		
		ELEMENT :
		{
			FieldToggle : function(element_id, field_id,start)
			{
				if(start == 'hide')
				{
					$('#' + field_id).hide();
				}
				else
				{
					$('#' + field_id).show();
				}
				
				$('#' + element_id).click(function()
				{
					if($('#' + field_id).is(':hidden'))
					{
						$('#' + field_id).show();
					}
					else
					{
						$('#' + field_id).hide();
					}
					
					return false;
				});
			}
		}
	},
	
	AjaxBlockElementById : function(id,message)
	{
		$('#' + id).block({
			message : message + '<br />' + $('#ajax-loader').html(),
			css: {width:'140px',height:'40px'}
		});
	},
	
	AjaxUnBlockElementById : function(id)
	{
		$('#' + id).unblock();
	},
	
	AjaxLoad : function()
	{
		$('#game_content').block({
			message : 'Loading Content<br />' + $('#ajax-loader').html(),
			css: {width:'140px',height:'40px'}
		});
	},
	
	AjaxDone : function()
	{
		$('#game_content').unblock();
	}
}
