function processLogin() {
	// Retrieve login values
	var username = document.getElementById("userid");
	var password = document.getElementById("password");
	
	// Check for valid input
	//if (!username.value || username.value == 'Enter User Name') { alert("Please enter a valid user name."); return false; }
	//if (password.value == "Enter password") { alert("Please enter a password."); return false; }

	// Track the login event
	var loginTrackingVars = {
		"omniturePageName" : "investools:user signed in",
		"linkTrackEvents" : "event11",
		"parameters" : {
			"prop1" : "investools.com:login",
			"eVar1" : "customer: has cookie",
			"events"	: "event11"
		}
	}
	omnitureTracking(loginTrackingVars);
	return true;
}

function sendZip(zip) {
	if (zip.length >= 5 && zip.length <= 7 && zip.indexOf("'") < 0) {
        url = getORCUrl( zip );
	    window.open( '/popups/popupRedirect.swim?redirect=' + url,'po','width=800,height=800,toolbar=yes,scrollbars=yes,resizable=yes,right=6,top=6');
		var freeClassSearchTrackingVars = {
			"omniturePageName" : "investools:free class search",
			"parameters" : {
				"eVar5"		: zip.toLowerCase()
			}
		}
		omnitureTracking(freeClassSearchTrackingVars, true);
	} else {
		alert("Please enter a valid zip code and try again.");
	}
	return false;
}

function getORCUrl( zip ) {
     mediaCode = 'INVESTOOLS_HOME';
     keyCode = 'INVESTOOLS_HOME';

     if( document.getElementById("media_code") )
         mediaCode = document.getElementById("media_code").value;

     if( document.getElementById("key_code") )
         keyCode = document.getElementById("key_code").value;

	var url = encodeUrl('http://ied.onlineregistrationcenter.com/registerlist.asp?m=155&it=1&da=1&s=8&sb=2&dsd=0&p=3&zip=' + zip + '&pas_mcd=' + mediaCode + '&pas_kcd=' + keyCode);
	return url;
}

function encodeUrl(url) {
	return url.replace(/:/gi,"%3A").replace(/\//gi,"%2F").replace(/\?/gi,"%3F").replace(/\&/gi,"%26").replace(/\=/gi,"%3D");
}

// Removes leading whitespaces
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}

// Returns the document object of the passed iframe.
function getIFrameDocument(oIframe) {
  var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
  if (oDoc.document) oDoc = oDoc.document;
  return oDoc;
}

function getParameter( queryString, parameterName ) {
	// Add "=" to the parameter name (i.e. parameterName=value)
	var parameterName = parameterName + "=";
	if ( queryString.length > 0 ) {
		// Find the beginning of the string
		begin = queryString.indexOf ( parameterName );
		// If the parameter name is not found, skip it, otherwise return the value
		if ( begin != -1 ) {
			// Add the length (integer) to the beginning
			begin += parameterName.length;

			// Multiple parameters are separated by the "&" sign
			end = queryString.indexOf ( "&" , begin );
			if (end == -1) {
				end = queryString.length
			}
			// Return the string
			return unescape ( queryString.substring ( begin, end ) );
		}
		// Return "null" if no parameter has been found
		return null;
	}
}

function saveCookie(name, value, days) {
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000)); // days * number of milliseconds in a day
	var expires = "expires=" + date.toGMTString();
	document.cookie = name + "=" + value + ";" + expires + "; path=/";
}


function getPos(obj) {
	function getX(objX) {
		return objX.offsetLeft + (objX.offsetParent ? getX(objX.offsetParent) : objX.x ? objX.x : 0);
	}
	function getY(objY) {
		return objY.offsetParent ? objY.offsetTop + getY(objY.offsetParent) : objY.y ? objY.y : 0;
	}
	return {
		x: getX(obj),
		y: getY(obj)
	}
}

function greaterThanIE6() {
	return typeof document.body.style.maxHeight != "undefined";
}

function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}

function changeInputType(
		oldElm, // a reference to the input element
		iType, // value of the type property: 'text' or 'password'
		iValue, // the default value, set to 'password' in the demo
		blankValue, // true if the value should be empty, false otherwise
		noFocus, // set to true if the element should not be given focus
		firstTime) { // used to fix a bug in firefox where the focus event fires twice the first time you call this function
	if(!oldElm || !oldElm.parentNode || (iType.length<4) || 
		!document.getElementById || !document.createElement) return;
	var newElm = document.createElement('input');
	newElm.type = iType;
	if(oldElm.name) newElm.name = oldElm.name;
	if(oldElm.id) newElm.id = oldElm.id;
	if(oldElm.className) newElm.className = oldElm.className;
	if(oldElm.size) newElm.size = oldElm.size;
	if(oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
	if(oldElm.accessKey) newElm.accessKey = oldElm.accessKey;
	newElm.onfocus = function(){return function(){
		if(this.hasFocus) return;
		var newElm = changeInputType(this,'password',iValue,
			this.value.toLowerCase()==iValue.toLowerCase());
		if(newElm) newElm.hasFocus=true;
	}}();
	newElm.onblur = function(){return function(){
		if(this.hasFocus)
		if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
			changeInputType(this,'text',iValue,false,true);
		}
	}}();
	// hasFocus is to prevent a loop where onfocus is triggered over and over again
	newElm.hasFocus=firstTime;
	oldElm.parentNode.replaceChild(newElm,oldElm);
	if(!blankValue) {
		newElm.value = iValue;
	}
	if(!noFocus || typeof(noFocus)=='undefined') {
		window.tempElm = newElm;
		setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
	}
	return newElm;
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

var toggle = {
	show : function(obj) {
		$(obj).style.display = ($(obj).style.display != 'none' ? 'none' : '' );
	},
	hide : function(obj) {
		for ( i=0; i < arguments.length; i++ ) {
			$(arguments[i]).style.display = 'none';
		}
	}
};