// JavaScript Document

function emptyField(fld)
{
	fld.value = '';
}

function checkFilled(fld ,initval)
{
	if ( (fld.value == '') || (fld.value == initval) )
	{
		fld.value = initval;
	}
	else 
	{
	}
}


function CenterBox(box) {
    //[FK]
    var mybox = $j('#' + box);
    var h_box = $j(mybox).height();
    var h_doc = $j(document).height();
    var w_box = $j(mybox).width();

    var newtop = (h_doc / 2) - (h_box / 2);
    var newleft = 480 - (w_box / 2);

    if (newleft == 0)
        newleft = 210;

    $j(mybox.css('position', 'absolute'));
    $j(mybox.css('top', newtop + 'px'));
    $j(mybox.css('left', newleft + 'px'));
}

function urlencode(str) 
{
    str = escape(str);
    str = str.replace('+', '%2B');
    str = str.replace('%20', '+');
    str = str.replace('*', '%2A');
    str = str.replace('/', '%2F');
    str = str.replace('@', '%40');
    return str;
}

function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
}

// PhaseII functions [FK]

function finatGraph() {
    $j('.graph_bar').each(function () {
        var i_percent = $j(this).children().html();
        var i_length = $j(this).width();
        var i_barlen = Math.floor((i_length / 100) * i_percent);
        $j(this).children().css('width', i_barlen);
        $j(this).children().html('');
    });
}

function finatRating() {
    $j('.articleRating .stars').each(function () {
        var rating = parseInt($j(this).children().html());
        //alert(rating);
        $j(this).children().html('')
        for (var x = 1; x <= 5; x++) {
            if (x <= rating) { classname = 'rated'; } else { classname = 'unrated'; }
            $j(this).children().html($j(this).children().html() + '<a class="' + classname + '"></a>');
        }
    });
}


function finatMessaging() {
    $j('.messageList table tr:even td').css('background-color', '#F5F5F5');

    $j('.recipient .remove a').click(function () {
        alert("removing");
        return false;
    });
}

function toggleMessages() {
    alert("hi");
}

function finatUI() {
    $j('a.buttonWhite').each(function () {
        var str_class = $j(this).attr('class');
        var i_width = str_class.split(" ", 2);
        var str_style = $j(this).attr('style');
        var str_href = $j(this).attr('href');

        if (i_width == '') {
            i_width = '28';
        }

        var str_wb = '<div style="' + str_style + '" class="whiteButton wb' + i_width[1] + ' clearfix"><div class="left"></div><a class="mid" href="' + str_href + '">' + $j(this).html() + '</a><div class="right"></div></div>';
        $j(this).replaceWith(str_wb);
    });
}
