function LoadAjaxPage(url, id)
{
	var url=url;

	jQuery('#'+id).html("<div class='indicator'>&nbsp;</div>");
	jQuery.get(url,function(data){
		jQuery('#'+id).html(data);
	});
}

/************ POPUP FUNCTIONS *******************/
function showGeneralPopup(url)
{
	$('body').append($('<div></div>').attr({ 'id' : 'popupContainer' }));
	$("body").append($('<div></div>').attr({ 'id' : 'lightBoxContener' }));

	$('#lightBoxContener').addClass('lightBoxCont');
	$("#popupContainer").click(function(){
		hidePopup();
	});

	$("#popupContainer").show();
	$("#lightBoxContener").show();

	jQuery('#lightBoxContener').html("<div class='indicator'>&nbsp;</div>");

	LoadAjaxPage(url, 'lightBoxContener');
}

function hidePopup()
{
	$("#lightBoxContener").fadeOut('slow',function(){
		$(this).remove();
		$('#popupContainer').fadeOut('slow',function(){
			$(this).remove();
		});
	});
}
/**************************************************/



/**************** AUTOCOMPELE SEARCH FUNCTIONS   *******************/
function formatResult(row) {
	return row[0].replace(/(<.+?>)/gi, '');
}
function strrpos( haystack, needle, offset){
	var i = (haystack+'').lastIndexOf( needle, offset ); // returns -1
	return i >= 0 ? i : false;
}

function hightlightSearch(value,search)
{

	match_pos = strrpos(value,search);
	match = value.substr(match_pos, search.length);

	new_match = match;
	new_match = "<b>"+match+"</b>";

	res =  str_replace(match,new_match,value);

	return res;
}


function formatItem(row,position,length) {
	search_text = jQuery('#search_company_symbol').val();
	match_pos = strrpos(row[0],search_text);
	match = row[0].substr(match_pos,search_text.length);

	new_match = match;
	res = row[0].replace(match,new_match);
	return res;
}

function str_replace(search, replace, subject) {
	var f = search, r = replace, s = subject;
	var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;

	while (j = 0, i--) {
		if (s[i]) {
			while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
		}
	};

	return sa ? s : s[0];
}
/******************************************************/

/***************  Cookie Manipulation  ******************/
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
	var cookie_string = name + "=" + escape ( value );

	if ( exp_y )
	{
		var expires = new Date ( exp_y, exp_m, exp_d );
		cookie_string += "; expires=" + expires.toGMTString();
	}

	if ( path )
	cookie_string += "; path=" + escape ( path );

	if ( domain )
	cookie_string += "; domain=" + escape ( domain );

	if ( secure )
	cookie_string += "; secure";

	document.cookie = cookie_string;
}

function delete_cookie( name, path, domain )
{
	document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

/**************************************************/



function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}

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 += '.'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function change_tab(id,swp){
	$('#'+swp).removeClass('selected');
	$('#'+id).addClass('selected');
	
}
//***************************   Clock  ****************************************//
var sep=":";
function updateClock ( ){
	sep = sep==":"?"<span style='color:#FFF'>:</span>":":";
	currentSeconds=eval(currentSeconds*1 +1);
	if(currentSeconds >= 60){ currentSeconds = 0;
	currentMinutes = eval(currentMinutes*1 +1); }
	if(currentMinutes >= 60){ currentMinutes = 0;
	currentHours= eval(currentHours*1 + 1); }
	if(currentHours >= 24){ currentHours = 0; }
	currentMinutes2 = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
	currentSeconds2 = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
	var timeOfDay = ( currentHours*1 >= 12 ) ? "pm" : "am";
	currentHours2 = ( currentHours*1 > 12 ) ? (currentHours - 12) : currentHours;
	currentHours2 = ( currentHours*1 == 0 ) ? 12 : currentHours2;
	jQuery('#timeText1').html(timeOfDay);
	jQuery('#timeText2').html(currentHours2 + sep + currentMinutes2 );
}
jQuery(document).ready(function(){updateClock(); setInterval('updateClock()', 1000 );});
