﻿function loadHtml( containerName, loaderURL, params ){
	var container = document.getElementById( containerName );
	if( container != null ){
		addSpinner( containerName );
		// now, load the rss using ajax updater
		var url = loaderURL;
		
		if( params == null || trimString( params ).length == 0 ){
		    params = location.search.substring(1);
		}
		// Make sure that quote page does not do "ALL"
		params = ensureStkQuoteParams( params );
		//
		// Dependent upon prototype js lib
		// 
		var htmlAjax = new Ajax.Updater(
			containerName,
			url,
			{
				method: 'get',
				parameters: params,
				onComplete: reportLoadComplete,
				onSuccess: reportLoadSuccess,
				onFailure: reportLoadError
			}
		);
	}
}

function ensureStkQuoteParams( params ){
    // special condition if on the Quote page
	if( location.href.indexOf( "Quote" ) > 0 ){
	    if( params.indexOf( "s=" ) < 0 ){
	        if( params.length > 0 ){
	            params += "&";
	        }
	        params += "s=NO_SYMBOL";
	    }
	}
	return params;
}

function trimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

function reportLoadComplete( request )
{
	// don't do anything here, ie does not recognize this
	//alert( 'load complete' );
}
function reportLoadSuccess( request )
{
	// don't do anything here, ie recognizes this
	//alert( 'load success' );
}
    
function reportLoadError( request )
{
	// the client should handle this
	//alert( 'load failed' );
}

function addSpinner( containerName ){
	// Try to add the spinner img
	try{
		var spinnerDivName = containerName + '_spinner';
		var spinnerDiv = document.getElementById( spinnerDivName );
		// create the spinner image (div) if it doesn't exist
		if( spinnerDiv == null ){
			spinnerDiv = document.createElement( 'div' );
			spinnerDiv.setAttribute( 'id', containerName + '_spinner' );
			spinnerDiv.setAttribute( 'class', 'spinner' );
			spinnerDiv.setAttribute( 'className', 'spinner' );
			var containerObject = document.getElementById( containerName );
			containerObject.appendChild( spinnerDiv );
		}
	}
	catch( err ){
	}
}

function removeSpinner( containerName ){
	// Try to remove the spinner img
	try{
		var spinnerDivName = containerName + '_spinner';
		var spinnerDiv = document.getElementById( spinnerDivName );
		var containerObject = document.getElementById( containerName );
		containerObject.removeChild( spinnerDiv );
	}
	catch( err ){
	}
}


function doQuoteOnEnter( e, quoteFieldName ) {

    if( !e ){
        e = window.event;
    }
    if( e && e.keyCode == 13 ){
        doQuote( quoteFieldName );
        return false;
    }
}

function doQuote( quoteFieldName ){
    location.href='Quote.aspx?s=' + document.getElementById( quoteFieldName ).value;
}

/*
function showChart( imgElementName, symbol ){
    var img = document.getElementById( imgElementName );
    if( img ){
//        if( symbol && symbol.lengh > 0 ){
            img.src="http://bigcharts.marketwatch.com/charts/big.chart?symb=" + symbol + "&compidx=aaaaa%3A0&ma=0&maval=9&uf=0&lf=1&lf2=0&lf3=0&type=2&size=2&state=8&sid=3291&style=320&time=8&freq=1&nosettings=1&rand=4515&mocktick=1&rand=6477";
//        }
//        else{
//            img.src="";
//        }
    }       
}
*/