﻿if(document.all && !document.getElementById) {
    document.getElementById = function(id){
         return document.all[id];
    }
}

function GetParam(name) {
    var start = location.search.indexOf("?" + name + "=");
    if (start < 0) start = location.search.indexOf("&" + name + "=");
    if (start < 0) return '';
    start += name.length + 2;
    var end = location.search.indexOf("&", start) - 1;
    if (end < 0) end = location.search.length;
    var result = location.search.substring(start, end);
    var result = '';
    for (var i = start; i <= end; i++) {
        var c = location.search.charAt(i);
        result = result + (c == '+' ? ' ' : c);
    }
    return unescape(result);
}

var $j = jQuery.noConflict();

$j(function() {
    $j('.HelpButton').click(function() {
        $j(".CommonHelp").slideToggle("slow");
    });

    $j(".CommonHelpClose").click(function() {
        $j(".CommonHelp").slideUp('slow');
    });

    setTimeout('LoadSnapShotImages()', 2000);
});

function LoadSnapShotImages() {
    $j(".snapshot_chartimage").each(function() {
        var symbol = $j(this).attr('alt');
        var width = $j(this).css('width');
        if (width == "auto") width = "";
        var height = $j(this).css('height');
        if (height == "auto") height = "";
        var interval = $j(this).attr('interval');
        if (interval == undefined) interval = "";
        $j(this).attr('src', '/community/controls/chartimage.aspx?symbol=' + symbol + '&interval=' + interval + '&w=' + width + '&h=' + height);
    });
}


function LaunchLightWaveWeb(url) {
    window.open(url, 'player', 'width=1000,height=700,scrollbars=1,resizable=1');
}

function LaunchPlayer(c)
{
    window.open("http://mbtsoftware.com/player/?mini=true&ch=3&c=" + c, "player", "width=1000,height=700,scrollbars=1,resizable=1");
}

function LaunchAlerts(c) {
    window.open("http://www.livemarketalerts.com/?c=" + c, "alerts", "width=1000,height=700,scrollbars=1,resizable=1");
}

function LaunchNews(c) {
    window.open("http://mbtsoftware.com/news/?c=" + c, "news", "width=1000,height=700,scrollbars=1,resizable=1");
}

function LaunchRMC(c) {
    window.open("http://mbtsoftware.com/rmc/?c=" + c, "rmc", "width=900,height=700,scrollbars=1,resizable=1");
}

function LaunchGL(c) {
    window.open("/community/strategies/Gainers.aspx?asset=All&c=" + c, "gl", "width=900,height=700,scrollbars=1,resizable=1");
}

function LaunchMBTIdeas(c,userid) {
    location.href = '/vote/?c=' + c + '&user=' + userid, 'mbti';
}

function LoginCallBack(result)
{
    //alert(result);
    if(result == 'CreateScreenName')
        location.href = './CreateScreenName.aspx?ReturnUrl=' + location.href;
    else
        location.href = location.href;
}

//CT - My Trades Page
function confirmSS_On()
{
	var agree=confirm("Are you sure you want to stop this strategy? \nIf this strategy has two sides, both sides will be stopped.");
	if (agree){
		return true;
	}else{
		return false;
	}
}

function confirmSS_InTrade()
{
	var agree=confirm("You are currently stopping a strategy that is in trade.  \nPlease be aware that the strategy will be removed and \nyou will need to manually exit your position.  Are \nyou sure you want to stop this strategy?");
	if (agree){
		return true;
	}else{
		return false;
	}
}

// Used with CustomValidator
function CheckPhoneLength(Src, Args){
    element = document.getElementById(Src.controltovalidate);
    formatNumber(element);
    Args.IsValid = (element.value.length >= 10);
}

function formatNumber(element){
    var val = element.value;
    val = replace(val,"-","");
    val = replace(val,".","");
    val = replace(val," ","");
    element.value = val;
}

function replace(string,oldtext,newtext) {
    var strLength = string.length, txtLength = oldtext.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(oldtext);
    if ((!i) && (oldtext != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + newtext;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),oldtext,newtext);

    return newstr;
}

function show(id){
    try{
        document.getElementById(id).style.visibility = 'visible';
        document.getElementById(id).style.display = 'block';
    }
    catch(err){}
    return false;
}

function hide(id){
    try{
        document.getElementById(id).style.visibility = 'hidden';
        document.getElementById(id).style.display = 'none';
    }
    catch(err){}
    return false;
}

function setTitleAndStatus(newTitle, id){
	var tsText
	if(id == "0"){
		tsText = newTitle;
	}else{
		tsText = newTitle + '|' + id;	
	}
	
	
	window.status = tsText;
	window.document.title = tsText;
}