function setFieldFocus()
{
    try
    {
        var foundfield = false;
        
        for (f=0; f < document.forms.length; f++)
        {
            for(i=0; i < document.forms[f].length; i++)
            {
                if (document.forms[f][i].type != "hidden" && document.forms[f][i].disabled != true && document.forms[f][i].readOnly != true)
                {                    
                    if (document.forms[f][i].type == 'text' || document.forms[f][i].type == 'password')
                    {
                        document.forms[f][i].select();
                    }
                    
                    document.forms[f][i].focus();
                    
                    var foundfield = true;                  
                }
                
                if (foundfield == true)
                {
                    break;
                }
            }
                
            if (foundfield == true)
            {
                break;
            }
        }
    } catch(e)
    {
        // do nothing
    }
}

function resizeVideoPlayer(id,width,height)
{
	
	//alert("Resize: "+id+" - "+width+" - "+height);

	if (width > 960)
	{
		height = Math.round(height/width*960);
		width = 960;
	}
	
	$('#'+id).css({'width':width+'px','height':height+'px'});
	
	$('#'+id).fadeIn(250);
}

function CurrencyFormatted(amount)
{
    var i = parseFloat(amount);
    if(isNaN(i)) i = 0.00;
    var minus = '';
    if(i < 0) minus = '-';
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if(s.indexOf('.') < 0) { s += '.00'; }
    if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
    s = minus + s;

    var arr = s.split(".");
    s = arr.join(",");
    return s;
}

function isValidEmail(str) 
{
   return (str.indexOf(".") > 0) && (str.indexOf("@") > 0) && (str.indexOf(":") < 0);
}

function IsNumeric(sText)
{
    var ValidChars = "0123456789.";
    var IsNumber=true;
    var Char;

    for (i = 0; i < sText.length && IsNumber == true; i++)
    {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1)
        {
            IsNumber = false;
        }
    }
    
    return IsNumber;
}

function popup(url)
{
    var width = screen.height;
    var height = (screen.height)-200;
    newwindow = window.open(url,"register", "width=" + width + ",height=" + height + ",top=0, left=0, scrollbars=yes, resizable=yes");
    if (window.focus) {newwindow.focus()}
    return false;
}

function mouseover(id)
{
    $('#'+id).addClass('object-hover');
}

function mouseout(id)
{
    $('#'+id).removeClass('object-hover');    
}
            
/* --- Forum functions --- */
function sortTopic(id)
{
    var topic = $('#topic_' + id);
    var parent = topic.parent();
    var sort = parseInt($('#topic_' + id + '_sort').html());
    var nodes = parent.children('li');
    var insert;
    var foundMatch = false;
    nodes.each(function()
    {
        var id = $(this).attr('id');
        var nodeSort = parseInt($('#'+id+'_sort').html());
        insert = $(this);
        if(sort > nodeSort)
        {
            foundMatch = true;
            return false;
        }
    });
    if(((foundMatch) && (topic.next('li').attr('id') != insert.attr('id'))) || (!foundMatch))
    {
        topic.fadeOut("slow",function() 
        {
            if(foundMatch)
            {
                topic.insertBefore(insert);
            } else
            {
                topic.insertAfter(insert);
            }
            
            $('#topics li').removeClass('first');
            $('#topics li:first').addClass('first');
            topic.fadeIn("slow");
        });
    }    
}
