// -- Generic functions --------------------------------------------------
function $(id) {
	return document.getElementById(id);
}

// used for the markets stock symbol look up form
function checkSymbolForm(){
	//var obj = document.lookitup.symb;
	var obj = $("mt_stock_quote_lookup");
	if (obj.value == ""){
		alert("Please enter a valid stock ticker symbol");
		obj.focus();
		return false;
	} else {
		return true;
	}
}

// generic popup window
function pop_me_up(pURL,name,features){
	new_window = window.open(pURL,name,features);
	new_window.focus();
}

// open form submission in popup window
function form2pop(formID, w, h) {
	var myForm = document.getElementById(formID);
	var attribStr = 'width=' + w + ',height=' + h;
	var popup = window.open(myForm.action, myForm.target, attribStr);
	myForm.submit();
}

// google ----------------------------------------------------------------
// Displays the google ad results.
function google_ad_request_done(google_ads) {
	// Proceed only if we have ads to display!
	if (google_ads.length == 0){
		return;
	// only display text ads
	} else {
        var str = '<div id="ad_google">\n';
        str += '<div id="ad_google_header">Ads by Google</div>\n';
        
        var textstyle = "";
    	if (google_ads[0].bidtype == "cpm"){
    		textstyle = "text2_google_cpm";
    	} else {
    		textstyle = "text2_google";
    	}
        
        // For text ads, display each ad in turn.
    	if (google_ads[0].type == 'text') {
    		for (var i = 0; i < google_ads.length; i++) {
                str += '<div class="ad_google_item">\n';
                str += '\t<div class="ad_google_item_title"><a href="' +  google_ads[i].url + '">' + google_ads[i].line1 + '</a></div>\n';
                str += '\t<div class="' + textstyle + '">' + google_ads[i].line2 + ' ' + google_ads[i].line3 + '</div>\n';
                str += '\t<div><a href="' + google_ads[i].url + '">' + google_ads[i].visible_url + '</a></div>\n';
                str += '</div>\n';
            }
        }        
        str += '</div>\n';
        document.write(str);
	}		
}

// text resize functions -------------------------------------------------
var currentTextSize = null;
var currentLineHeight = null;
// check for cookie
if (get_text_cookie("ihtfontsize")) {
    currentTextSize = parseInt(get_text_cookie("ihtfontsize"));
} else {
    currentTextSize = 13;
    createCookie("ihtfontsize",currentTextSize,1000);
}
currentLineHeight = currentTextSize + 5;

// creates a cookie with the given parameters
function createCookie(name,value,days){
        if (days){
                var date = new Date();
                date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
                var expires = "; expires=" + date.toGMTString();
        } else {
                var expires = "";
        }
        document.cookie = name + "=" + value + expires + "; path=/";
}

function textSize(dir) {
    if (dir == 'up') {
        if (currentTextSize <= 17) {
            currentTextSize += 2;
        }
    } else if (dir == 'down') {
        if (currentTextSize >= 11) {
            currentTextSize -= 2;
        }
    }
    currentLineHeight = currentTextSize + 5;
    document.getElementById('bodyText').style.fontSize = currentTextSize + 'px';
    document.getElementById('bodyText').style.lineHeight = currentLineHeight + 'px';
    // write/rewrite cookie
    createCookie("ihtfontsize",currentTextSize,1000);
}

function get_text_cookie ( cookie_name )
{
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

  if ( results ) {
    return ( unescape ( results[1] ) );
  }
  else { return null; }
}

// -- Window onload functions --------------------------------------------
/*************************************************************
 * The woms array holds all of the functions you wish to run
 * when the page loads.
 *************************************************************/
var woms = new Array();

/*************************************************************
 * The womOn() function will set the window.onload function to
 * be womGo() which will run all of your window.onload
 * functions.
 *************************************************************/
function womOn(){
	window.onload = womGo;
}

/*************************************************************
 * The womGo() function loops through the woms array and
 * runs each function in the array.
 *************************************************************/
function womGo(){
	if ((woms.length != 0 ) && (woms.length != null)) {
		for(var i = 0;i < woms.length;i++)
			eval(woms[i]);
	}
}

/*************************************************************
 * The womAdd() function will add another function to the woms
 * array to be run when the page loads.
 *************************************************************/
function womAdd(func){
	woms[woms.length] = func;
}



