function number_format(number, decimals, dec_point, thousands_sep) {
    // Formats a number with grouped thousands  
    // 
    // version: 1009.2513
    // discuss at: http://phpjs.org/functions/number_format
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival
    // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +   improved by: davook
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Jay Klehr
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Theriault
    // +      input by: Amirouche
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *    example 10: number_format('1.20', 2);
    // *    returns 10: '1.20'
    // *    example 11: number_format('1.20', 4);
    // *    returns 11: '1.2000'
    // *    example 12: number_format('1.2000', 3);
    // *    returns 12: '1.200'
    // *    example 13: number_format('1 000,50', 2, '.', ' ');
    // *    returns 13: '100 050.00'
    number = (number+'').replace(',', '').replace(' ', '');
    var n = !isFinite(+number) ? 0 : +number, 
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}

function ToggleForm(DvName, Which)
{
    if(Which)
    {
        document.getElementById(DvName + '1').style.display = "none";
        document.getElementById(DvName + '2').style.display = "";
    }
    else
    {
        document.getElementById(DvName + '1').style.display = "";
        document.getElementById(DvName + '2').style.display = "none";
    }

    return false;
}

function TopSearchKeypress(Val)
{
    if(Val != 13)
        return true;
    else
        return DoTopSearch();
}

function FixHeight()
{
    var Lt, Main, Rt;
    var Max = 0;
    Lt = Main = Rt = 0;

    if(document.getElementById("main_leftside")) Lt = document.getElementById("main_leftside").offsetHeight;
    if(document.getElementById("main_content")) Main = document.getElementById("main_content").offsetHeight;
    if(document.getElementById("main_largecontent")) Main = document.getElementById("main_largecontent").offsetHeight;
    if(document.getElementById("main_rightside")) Rt = document.getElementById("main_rightside").offsetHeight;

    Max = Lt;
    if(Main > Max) Max = Main;
    if(Rt > Max) Max = Rt;

    document.getElementById('main_wrapper').style.height = Max + "px";
    return true;
}
function hi() {
alert('hi');
}

function RefreshDiv(divID, data)
{
//	alert('hi');
	/*alert(DvName);*/
	if (data == "clear")
	{
		$("#" + divID).html('');
		$("#" + divID).hide();
	}
	else
	{
		$("#" + divID).show();
		$("#" + divID).html(data);
	}

/*	if(data == "clear")
    {
        document.getElementById(DvName).innerHTML = "";
        document.getElementById(DvName).style.display = "none";
    }
    else
    {
        document.getElementById(DvName).style.display = "";
        document.getElementById(DvName).innerHTML = data;
    }
	*/
    //return false;
}

function ShowNyro(data)
{
    // If forcing redirect, do that now
    var RedirSplit = data.split("|");

    if(RedirSplit[0].toLowerCase() == "redirect")
        window.location.href = RedirSplit[1];
    else
        $.nyroModalManual({minWidth: '350', minHeight: '250',  content: data});

    return true;
}

function Hvr(Itm, Clss, Sfx)
{
    document.getElementById(Itm).className = Clss + Sfx;

    return false;
}

function ShowRealPlaya(PlayaNum, MP3File, Width)
{
    FrmHTML = "";

    FrmHTML += "<object height=\"20\" width=\"" + Width + "\">";
    FrmHTML += "<embed src=\"" + document.getElementById('base_url').value + "images/mp3player.swf?&amp;file=" + document.getElementById('base_url').value + MP3File + "&amp;autostart=t&amp;song_title=Audio\" height=\"20\" width=\"" + Width + "\"></embed>";
//    FrmHTML += "<embed src=\"http://www.fantourage.com/images/mp3player.swf?&amp;file=http://www.fantourage.com/" + MP3File + "&amp;autostart=t&amp;song_title=Audio\" height=\"20\" width=\"" + Width + "\"></embed>";
//    FrmHTML += "<embed src=\"" + document.getElementById('base_url').value + "images/mp3player.swf?&amp;file=" + document.getElementById('base_url').value + MP3File + "&amp;autostart=t&amp;song_title=Audio\" height=\"20\" width=\"" + Width + "\"></embed>";
//FrmHTML += "<embed src=\"" + $('#the_base_url').val() + "images/mp3player.swf?&amp;file=" + $('#the_base_url').val() + MP3File + "&amp;autostart=t&amp;song_title=Audio\" height=\"20\" width=\"" + Width + "\"></embed>";
//the_base_url
    FrmHTML += "</object>";

    document.getElementById('PlayaNum_' + PlayaNum).innerHTML = FrmHTML;

}

function PlaySound(file)
{
    var embed = document.createElement("embed");

    embed.setAttribute('src', file);
    embed.setAttribute('hidden', true);
    embed.setAttribute('autostart', true);

    document.body.appendChild(embed);
}

function ResizeTA(TA, Extra)
{
    var NewRows =  parseInt( (TA.value.length) / (TA.cols - 2)) + Extra + 1;

    if(NewRows > TA.rows) TA.rows = NewRows;

    return true;
}

function ValidateVideo()
{
    var VideoTitle = document.getElementById('VideoTitle').value;
    var VideoURL = document.getElementById('VideoURL').value;

    if(VideoTitle == "" || VideoURL == "")
    {
        alert("Please enter Video Title and paste in link to video.");
        return false;
    }

    // Only accept YouTube videos for now
    if(VideoURL.indexOf("youtube.com") == -1)
    {
        alert("Please choose a supported video type: YouTube");
        return false;
    }

    // Only accept link
    if(VideoURL.indexOf("/embed") != -1)
    {
        alert("Please paste the link (not the embed code)");
        return false;
    }

    return true;
}

function nyroMessageShow(message)
{
	if (message == null || message == "")
		message = "#nyroMessage";
		
		
	if (jQuery(message + " .nyro_content").text() != '')
	{

		// make sure we can to the modal box!
		if (jQuery.browser.msie && (jQuery.browser.version == "6.0" || jQuery.browser.version == "7.0")) { 
		
		   var zIndexNum = 20000; // fix for IE7 (6?) Z-index bug. we set the zindex for all li and divs 
			jQuery('li').each(function(){
				jQuery(this).css('zIndex',zIndexNum);
				zIndexNum -= 5;
			});
		
			var zIndexNum = 10000;
			jQuery('div').each(function(){
				jQuery(this).css('zIndex',zIndexNum);
				zIndexNum -= 5;
			});
		}
		
		jQuery("body")
			.append('<div class="dark_overlay"></div><div class="dark_container"></div>');
		jQuery(".dark_overlay").animate({
			"opacity":"0.75",
			"height": jQuery("body").height(),
			"width": jQuery("body").width()
		}, 400, "linear", function()
		{
			//$("#CelebPointsBubble").css({"z-index": "51", "width": $("#CelebPointsBubble").width(), "position": "absolute"});
			if (jQuery(message))
			{
				jQuery(message).fadeIn(1000, function()
				{
					if(jQuery.browser.msie)
						jQuery(this).get(0).style.removeAttribute('filter');
				});
			}
		});
	}
}




function showLoadingContentA(parentDiv, loadingDiv, fadeOut)
{
		if (fadeOut)
		{
			$(loadingDiv + '_content_fade').fadeOut('slow');
			$(loadingDiv + '_content_loading').fadeOut('slow');

		}
		else
		{
			var halfWay = $(parentDiv).position().left + $(parentDiv).width()/2;
			$(loadingDiv + '_content_fade').css({'left':$(parentDiv).position().left, 'top':$(parentDiv).position().top, 'z-index':500, 'width':$(parentDiv).outerWidth(), 'height': $(parentDiv).outerHeight()});
			$(loadingDiv + '_content_loading').css({'left': halfWay, 'top': $(parentDiv).position().top + 20, 'z-index': 500});
	
	//		$(".celeb_post_content_fade").width($('.post_content_text_box_container').outerWidth());
	//		$(".celeb_post_content_fade").height($('.post_content_text_box_container').outerHeight());
	
	
	/*		$(".celeb_post_content_fade").css({'left': $('.post_content_text_box_container').offset().left, 'top': $('.post_content_text_box_container').offset().top, 'z-index': 500});
			
			var halfWay = $('.post_content_text_box').offset().left + $('.post_content_text_box_container').width()/2;
			$(".celeb_post_content_loading").css({'left': halfWay, 'top': $('.post_content_text_box_container').offset().top + 20, 'z-index': 500});*/
			
			
			$(loadingDiv + '_content_fade').fadeIn('slow');
			$(loadingDiv + '_content_loading').fadeIn('slow');
		}
}
// easily update selective text within html/xml through json - requires JQuery, there're standard fields it'll look for of course
/*
function updateText(jsonArray)
{
	$.each(jsonArray, function()
	{
		// text to update?
		if (this.text)
		{
			// id first? then check class
			if (this.id)
			{
				if ($("#" + this.id))
					$("#" + this.id).html(this.text);
			}
			
			// class?
			if (this.class)
			{
				if ($("." + this.class))
					$("." + this.class).html(this.text);
			}
		}
	});
							   
}
alert('hi');*/
function rgb2hex(rgb) {
 rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
 return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}




function AjxDivTransition(fadDiv, loadingDiv, targetDiv, fadeOut, outerDimensions)
{
	if (fadeOut)
	{
		jQuery(loadingDiv).fadeOut('slow');	
		jQuery(fadDiv).fadeOut('slow');	
	}
	else
	{
		if (outerDimensions)
		{
			jQuery(fadDiv).width(jQuery(targetDiv).outerWidth());
			jQuery(fadDiv).height(jQuery(targetDiv).outerWidth());
		}
		else
		{
			jQuery(fadDiv).width(jQuery(targetDiv).width());
			jQuery(fadDiv).height(jQuery(targetDiv).height());
		}

		jQuery(fadDiv).css({'left': 0, 'top': 0});
		
		jQuery(loadingDiv).css({'left': '50%', 'top': '20px', 'z-index': '300'});
		
		//$(".fan_videos_fade").position($(divhtml).position());
		jQuery(fadDiv).fadeIn('slow');
		jQuery(loadingDiv).fadeIn('slow');
	}
}

