/* ------------------------------------------------------------------------------
 * SITE-WIDE FUNCTIONS
 * ------------------------------------------------------------------------------*/

function loginUser() {
	setTimeout("window.location = 'login.php'", 500);
}


/* trim()
 * ------------------------------------------------------------------------------*/
function trim(str) {
    var trimmed = str.replace(/^\s+|\s+$/g, '') ;
    return trimmed;
}

/* replaceString()
 * ------------------------------------------------------------------------------*/
function replaceString(sString, sReplaceThis, sWithThis) { 
    if (sReplaceThis != "" && sReplaceThis != sWithThis) {
      var counter = 0;
      var start = 0;
      var before = "";
      var after = "";
      while (counter<sString.length) {
        start = sString.indexOf(sReplaceThis, counter);
        if (start == -1){
         break;
         } else {
           before = sString.substr(0, start);
           after = sString.substr(start + sReplaceThis.length, sString.length);
           sString = before + sWithThis + after;
           counter = before.length + sWithThis.length;
          }
        }
      }
   return sString;
  }

/* openEquityURL()
 * Redirect to external site with ticker symbol, in new window (used on Ticker Trigger page)
 * ------------------------------------------------------------------------------*/
function openEquityURL(url){
	try {
		// replace XXX with the symbol from toolbar
		var e = document.ticker_tools.om_symbol;
		var symbol = e.value;
		if ( trim(symbol) == '' || trim(symbol) == 'enter symbol') {
			alert("Please enter a ticker symbol");
			e.style.backgroundColor = "#BF190D";
			e.value = "";
			e.focus();
		} else {
			var newurl = replaceString( url, 'XXX', symbol );
			window.open(newurl);
		}
	} catch(err) {
		txt = "There was an error on this page:\n\n"
		txt += err.description + "\n\n"
		txt += "Click OK to continue\n\n"
		alert(txt)
	}
}

/* openThirdPartyURL()
 * Redirect to external site in new window (used on Options Tools page)
 * ------------------------------------------------------------------------------*/
function openThirdPartyURL(url){
	try {
		window.open(url);
	}
	catch(err) {
		txt = "There was an error on this page:\n\n"
		txt += err.description + "\n\n"
		txt += "Click OK to continue\n\n"
		alert(txt)
	}
}

/* getSymbolLookup()
 * Open new window for ticker symbol lookup via QuoteMedia
 * ------------------------------------------------------------------------------*/
function getSymbolLookup(url, winName, winWidth, winHeight) {
	var screenw = screen.width;
	var screenh = screen.height;
	var centerw = ((screenw - winWidth) / 2);
	var centerh = ((screenh - winHeight) / 2);
	var winprops = 'height=' + winHeight + ',width=' + winWidth + ',top=' + centerh + ',left=' + centerw +
	',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1';
	win = window.open(url, winName, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

/* getToolsData()
 * Redirect to target page with ticker symbol
 * ------------------------------------------------------------------------------*/
function getToolsData(tool) {
	try {
		var e = document.ticker_tools.om_symbol;
		var rnd = 1 + Math.floor(Math.random()*99999);
		var symbol = e.value;
		if ( trim(symbol) == "" || trim(symbol) == "enter symbol") {
			alert("Please enter a ticker symbol");
			e.style.backgroundColor = "#BF190D";
			e.focus();
		} else {
		    var url = "http://" + document.location.host;
			switch (tool) { 
			  case "Options Chain" : 
				url += "/quotes/options_chain.jsp?nc=" + rnd + "&symbol=" + symbol;
				break;
			  case "Detailed Quote" : 
				url += "/quotes/detailed.jsp?nc=" + rnd + "&symbol=" + symbol;
				break;
			  case "Ticker Trigger" : 
				url += "/resources/ticker_trigger.jsp?symbol=" + symbol;
				break;
			  default : 
				url += "/quotes/options_chain.jsp?nc=" + rnd + "&symbol=" + symbol;
		    }
			window.location.href = url; 
		}
	} catch(err) {
		txt = "There was an error on this page:\n\n"
		txt += err.description + "\n\n"
		txt += "Click OK to continue\n\n"
		alert(txt)
	}
}

/* reverseDisplay()
 * Toggle on/off (use with NASD tool bar charts)
 * ------------------------------------------------------------------------------*/
function reverseDisplay(d) {
	if(document.getElementById(d).style.display == "none") { 
		document.getElementById(d).style.display = "block"; 
	}
	else { 
		document.getElementById(d).style.display = "none"; 
	}
}

/* ------------------------------------------------------------------------------
 * FORM VALIDATION FUNCTIONS
 * ------------------------------------------------------------------------------
 * Various functions to check fields identified within the calling FORM tag for
 * non-blank values, email and password formats, and comparisons such as
 * 'password' and 'confirm password' fields.
 *
 * Use the following FORM tag syntax to validate/check fields.
 * Modify the onsubmit event handler to include the name of each form  
 * field to be checked, as well as the corresponding message to display
 * if the field is blank.

 *  <form name="lookup" method="POST" action="/cgi/processing-script.jsp" 
 *		  onSubmit="this.name.required = true;
 *					this.name.message = 'Your name';
 *					this.email.required = true;
 *					this.email.message = 'Your email address';
 *					this.email.checkEmail = true;
 *					this.password.checkPassword = true;
 *					this.password.compareFields = this.confirm_password;
 *					this.confirm_password.required = true;
 *					this.confirm_password.message = 'Your password confirmation';
 *					return validateForm(this);">
 * ------------------------------------------------------------------------------*/

// BEGIN FORM VALIDATION FUNCTIONS

// Check email input for proper format:  a@a.aa
function validateEmail(e) {
	var error = "";
	var usEmail = true;
	var str = e.value;
	var lenSuffix = (usEmail) ? 3 : 3;
	var goodAddr = false;
	var ndxAt = ndxDot = 0;

	ndxAt	= str.indexOf("@");
	ndxDot	= str.indexOf(".");
	ndxDot2	= str.lastIndexOf(".");

	// Test field if non-blank continuous character string only
	if (str != "") {
		if ( (str != trim(str)) || (ndxDot < 0) || (ndxAt < 0) || (ndxAt < 1) || ((ndxDot2 - 1) <= ndxAt) || ( str.length < (ndxDot2 + lenSuffix)) ) {
			error = "<br \/> - Please enter a valid email address";
		}
	}
	return error; 
}

// Validate state and zip code fields as appropriate for US / Canada / all other countries
function validateUSFields(formName, countryField, stateField, postalField) {
	if (document.forms[formName].elements[countryField].options[document.forms[formName].elements[countryField].selectedIndex].value == 'us') {
		document.forms[formName].elements[stateField].required = true;
		document.forms[formName].elements[stateField].message = 'Your state';
		document.forms[formName].elements[postalField].required = true;
		document.forms[formName].elements[postalField].message = 'Your zip code'; 	
		document.forms[formName].elements[postalField].checkZipCode = true;
	} else if (document.forms[formName].elements[countryField].options[document.forms[formName].elements[countryField].selectedIndex].value == 'ca') {
		document.forms[formName].elements[stateField].required = true;
		document.forms[formName].elements[stateField].message = 'Your province';
		document.forms[formName].elements[postalField].required = true;
		document.forms[formName].elements[postalField].message = 'Your postal code'; 	
		document.forms[formName].elements[postalField].checkZipCode = false;				
	} else {
		document.forms[formName].elements[stateField].required = false;
		document.forms[formName].elements[postalField].required = false;
		document.forms[formName].elements[postalField].checkZipCode = false;				
	}
}

// Check password input for proper format:  7-15 characters, a-zA-Z0-9 with at least one 0-9
function validatePassword(e) {
    var error = "";
	var pwd = e.value;
	var illegalChars = /[\W_]/; // allow only letters and numbers 
 
 	if (!isblank(pwd)) {
		if ( ((pwd.length < 7) || (pwd.length > 15)) ) {
	        error = "<br \/> - The password must contain 7 to 15 characters (letters and numbers only)";
	    } else if (illegalChars.test(pwd)) {
	    	error = "<br \/> - The password contains illegal characters (use uppercase and lowercase letters and at least one number)";
	    } else if (!( ((pwd.search(/[a-z]+/) > -1) || (pwd.search(/[A-Z]+/) > -1)) && (pwd.search(/[0-9]+/) > -1))) {
		  	error = "<br \/> - The password must contain at least one uppercase or lowercase letter, and one number";
		}
	}
	return error;
}  
  
// Check input fields for blank entries (called by 'verify' function)
function isblank(s) {
	for (var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) {
			return false;
		}
	}
	return true;
}

// Check if phone format matches us phone
function isPhoneNumber(s) {
      var error="";
      var objRegExp = new RegExp(/^(\+*\d*\s*[-\/\.]?)?(\((\d{3})\)|(\d{3}))\s*([\s-./\\])?([0-9]*)([\s-./\\])?([\s*0-9]*)$/);

      if (s != "") {
            if (!objRegExp.test(s)) {
                  error = "<br \/> - Please enter a valid phone number";
            }
      }
      return error;
}


function validateUSZip(s) {
	var error = "";
	// var reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/); 
	// var reZip = new RegExp(/(^\d{5}$)|(^\d{6}$)|(^\d{7}$)|(^\d{8}$)|(^\d{9}$)/);
	// var reZip = new RegExp(/(^\d{5}$)|(^\d{9}$)/);
	var reZip = new RegExp(/^\d{5}([\-]\d{4})?$/);
	if (!reZip.test(s)) {
		error = "<br \/> - Zip code format must be XXXXX or XXXXX-XXXX";
	}
	return error;
}

function validateSecCode(s) {
	var error = "";
  	if( s.match(/^\d\d\d$/) == null && s.match(/^\d\d\d\d$/) == null ) {
  		error = "<br \/> - Credit card security code must be 3 or 4 digits";
  	}
 	return error;
}

// Check all form fields listed in onSubmit handler
function validateForm(f) {
	var msg;
	var empty_fields = "";
	var typeCC = "";
	var month = "";
	var year = "";
	
	for (var i = 0; i < f.length; i++) {
		var e = f.elements[i];

		if (e.required) {
		
			if ( (e.value == null) || (e.value == "") || (isblank(e.value))  
			     || (e.type == "checkbox" && !e.checked) || (e.type == "radio" && !e.checked) 
			     || e.selectedIndex == "" || e.selectedIndex == 0 ) {

				empty_fields += "<br \/> - " + e.message;
			}
		}

		if (e.checkEmail) {
			empty_fields += validateEmail(e);
		}
		
		if (e.checkPassword) {
			empty_fields += validatePassword(e);
		}

		if (e.name == "credit_card_type"){
	    	typeCC = e.value;
		}
		
		if (e.checkCreditCard) {
			// empty_fields += checkCard(e.value, typeCC);
			empty_fields += checkCardValidation(e.value, typeCC);
		}	
		
		if (e.checkCCSecCode) {		
			empty_fields += validateSecCode(e.value);
		}
		
		if (e.checkPhone) {
			empty_fields += isPhoneNumber(e.value);
		}	

		if (e.checkZipCode) {
			empty_fields += validateUSZip(e.value);
		}	
				
		if (e.name == "pp_expMonth"){
	    	month = e.value;
		}
		if (e.name == "pp_expYear"){
	    	year = e.value;
		}
		
		if (e.checkExpDate) {
			empty_fields += ValidCCExpDate(month, year);
		}	
		
		if (e.compareFields) {
			if (e.value != e.compareFields.value) {
				empty_fields += "<br \/> - " + e.message + " confirmation does not match";
			}
		}
	}	

	// if required fields all validate correctly, then return and submit form
	if (isblank(empty_fields)) {
		document.getElementById("form_status").innerHTML = "<i>Submitting form...</i>";
		document.getElementById("form_status").style.display = "block";
		return true;
	} else {
		msg = "<b>Please complete the following:</b>" + empty_fields + "<br \/>";
    }

	// alert user
	document.getElementById("form_status").innerHTML = msg;
	document.getElementById("form_status").style.display = "block";
	window.scrollTo(0,document.getElementById('form_status').offsetTop-10);

// stop form submission
	return false;
}

// encrypt password 
function ncrypt9(strin) {
	var temp = 0;
	var strout = "";
	var offset = 9;
	for (var i=0; i<strin.length; i++) {
		temp = strin.charCodeAt(i) + offset;
		if (temp<100) {
			temp = "0" + temp;
		}
		strout += temp;
	}
	return strout;
}

function isCreditCard(CC) {
// alert("credit c: " + CC.value.length);
	if (CC.length > 19)
		return (false);
	
	sum = 0; 
	mul = 1; 
	l = CC.length;
	for (i = 0; i < l; i++) {
		digit = CC.substring(l-i-1,l-i);
		tproduct = parseInt(digit ,10)*mul;
		if (tproduct >= 10)
			sum += (tproduct % 10) + 1;
		else
			sum += tproduct;
		if (mul == 1)
			mul++;
		else
			mul--;
	}
	if ((sum % 10) == 0)
		return true;
	else
		return false;
}

function isVisa(cc) {
	if( (cc.substring(0,1) == 4) && (cc.length == 16) || (cc.length == 13) ) {
		return isCreditCard(cc);
	}
	return false;
}

function isMC(cc) {
	if( (cc.length == 16) && (cc.substring(0,2) == 51)
		|| (cc.substring(0,2) == 52) || (cc.substring(0,2) == 53)
		|| (cc.substring(0,2) == 54) || (cc.substring(0,2) == 55) )
	{
		return isCreditCard(cc);
	}
	return false;
}

function isAmex(cc) {
	if( (cc.length == 15) && (  (cc.substring(0,2) == 34) || (cc.substring(0,2) == 37)  ) )
	{
		return isCreditCard(cc);
	}
	return false;
}

function isDiscover(cc) {
	if( (cc.length == 16) && (cc.substring(0,4) == 6011)) {
		return isCreditCard(cc);
	}
	return false;
}


function checkCard(cc, typeCC) {
	var error = "";
	// if ( (cc.length == 0) || (e.value == "") || (isblank(e.value)) )  
	//	error = " number is empty";	
	if (!isCreditCard(cc)) {
		return "<br \/> - Your credit card number is incorrect";
	}
	// if (cc == "4111111111111111")
	//	error = "";	
	if (typeCC == "Amex" && !isAmex(cc)) { 
	    if (cc == "4111111111111111") {
			error = "";	
		}
		error = " - You have an incorrect American Express card number";
	}
	if (typeCC == "Discover" && !isDiscover(cc)) { 
		if (cc == "4111111111111111") {
			error = "";	
		}
		error = " - You have an incorrect Dicover card number";
	}
	if (typeCC == "MasterCard" && !isMC(cc)) { 
		if (cc == "4111111111111111") {
			error = "";	
		}
		error = " - You have an incorrect MasterCard number";
	}
	if (typeCC == "Visa" && !isVisa(cc)) { 
		if (cc == "4111111111111111") {
			error = "";	
		}
		error = " - You have an incorrect Visa card number";
	}
	return error;
}

function checkCardValidation(cc, typeCC) {
    var error = "";	
	if (!isCreditCard(cc) && cc != "4111111111111111") {
		error = "<br \/> - Your credit card number is incorrect";
	}
	if (cc == "4111111111111111") {
		error = "";	
	}
	if (typeCC == "Amex" && !isAmex(cc) && cc != "4111111111111111") { 
		error = "<br \/> - You have an incorrect American Express card number";
	}
	if (typeCC == "Discover" && !isDiscover(cc) && cc != "4111111111111111") { 
		error = "<br \/> - You have an incorrect Discover card number";
	}
	if (typeCC == "MasterCard" && !isMC(cc) && cc != "4111111111111111") { 	
		error = "<br \/> - You have an incorrect MasterCard number";
	}
	if (typeCC == "Visa" && !isVisa(cc) && cc != "4111111111111111") { 	
		error = "<br \/> - You have an incorrect Visa card number";
	}
	return error;
}

function ValidCCExpDate(month , year) {
	var error = "";
	var expired = false;	
	var month = parseInt(month,10);
	var year = parseInt(year,10);
	
    if (year.length == 2) {
    	year += 2000;
	}
	var now = new Date();
	var nowMonth = now.getMonth() + 1;
	var nowYear = now.getFullYear();

    expired = (nowYear > year) || ((nowYear == year ) && (nowMonth > month));
    
    // result = allDigits(elems[0]) && (month > 0) && (month < 13) &&
    //                   allDigits(elems[1]) && ((elems[1].length == 4));

    if (expired) {
 		error = "<br \/> - The credit card has expired";
	}
    return error;
}

function clearErrorMsg() {
	document.getElementById('form_status').style.display='none';
}

/* ------------------------------------------------------------------------------
 * COOKIE FUNCTIONS
 * ------------------------------------------------------------------------------*/
/*	USAGE:
 *	// setCookie parameters:  name, value, expires, path, domain, secure
 *	setCookie( 'test', 'it works', '', '/', '', '' );
 *	if (getCookie('test')) alert(getCookie('test'));
 *
 *	// deleteCookie parameters:  name, path, domain
 *	// (use the same parameters in setCookie and deleteCookie)
 *	deleteCookie('test', '/', '');
 *	(getCookie('test')) ? alert(getCookie('test')) : 
 *	alert('it is gone');
 * ------------------------------------------------------------------------------*/

function setCookie( name, value, expires, path, domain, secure ) {
//	set time in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

/*	if the expires variable is set, make the correct expires time, 
	the current script below will set it for x number of days, 
	to make it for hours, delete * 24, for minutes, delete * 60 * 24  */
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function getCookie(check_name) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for (i = 0; i < a_all_cookies.length; i++) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if (cookie_name == check_name) {
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 ) {
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if (!b_cookie_found) {
		return null;
	}
}				

function deleteCookie(name, path, domain) {
	if (getCookie(name)) document.cookie = name + "=" +
	( (path) ? ";path=" + path : "") +
	( (domain) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function noAutoComplete() {
	if (document.loginForm.password.value != "") {
		document.getElementById('password_label').style.display='none';
	}
} 

// Used for login 'remember me' checkbox
function getEmailCookieValue(f) {
	if (getCookie("user_name") != null && getCookie("user_name") != "") {
		f.username.value = getCookie("user_name");
		f.username.style.color='#000000';
		if (f.remember) {
			f.remember.checked = true;
		}
	}
}	

// Also used for login 'remember me' checkbox
function setEmailCookieValue(f) {
	if (f.username.value != '' && f.remember.checked) {
		setCookie('user_name', f.username.value, '120', '/', '', '');
	} else if (!f.remember.checked && getCookie("user_name") != null && getCookie("user_name") != "") {
		setCookie('user_name', '', '0', '/', '', '');
	}
}

function refreshIOPage() {
	new Ajax.Updater('content', '/premium/io/index_content.jsp', {method: 'post'});
}

function go(url) {
	window.location.href = url;
}

function cancelErrorMsg() {
	document.getElementById('form_status').style.display='none';
}

function goToBrokerageMsg() {
    var leaveSite = window.confirm("The web site you have chosen, trade MONSTER, is a licensed broker-dealer. trade MONSTER and optionMONSTER are separate but affiliated companies. This web link between the two companies is not an offer or solicitation to trade in securities or options, which can be speculative in nature and involve risk. If you wish to go to trade MONSTER, click 'OK'. If you do not, click 'Cancel'.");
    if (leaveSite) {
        go("/trademonster/");
    }
}

function selectGoTo(e) {
	var url = e.options[e.selectedIndex].value;
	if (url != null && url != "") {
		window.location.href = url;
	}
}

function validateSearch(f) {
	if (trim(f.keywords.value) =='') {
		document.getElementById('search_status').innerHTML = '<b>Search</b> - <i style="color:#c00">Enter a keyword or ticker symbol</i><br />';
		return false;
	}
	document.getElementById('search_status').innerHTML = '<b>Search</b><br />'; 
	return true;
}

function validateSearchForm(f) {
    var msg;
    var fieldResponse = "";
    
    if (f.keywords.value == null || trim(f.keywords.value) == '') {
        fieldResponse += "<br \/> - Enter at least one keyword";
    }     

    for (var i = 0; i < f.length; i++) {
        var e = f.elements[i];
        if (e.name == "keywords" && e.value != "" && e.value.length > 30) {
            fieldResponse += "<br \/> - \"Limit keywords to 30 characters";     
        }
        
        if (e.name == "toDate" && e.value != "mm/dd/yyyy") {
           if (!isDate(e.value)) {
                fieldResponse += "<br \/> - \"To Date\" field format is wrong";     
           }
        }
        
        i
    }
    
    // if required fields all validate correctly, then return and submit form
    if (isblank(fieldResponse)) {
        document.getElementById("form_status").innerHTML = "<i>Submitting form...</i>";
        document.getElementById("form_status").style.display = "block";
        return true;
    } else {
        msg = "<b>Please complete the following:</b>" + fieldResponse + "<br \/>";
    }

    // alert user
    document.getElementById("form_status").innerHTML = msg;
    document.getElementById("form_status").style.display = "block";
    window.scrollTo(0,document.getElementById('form_status').offsetTop-10);

// stop form submission
    return false;
}

function isDate(sDate) {
   var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/
   if (re.test(sDate)) {
      var dArr = sDate.split("/");
      var d = new Date(sDate);
      return d.getMonth() + 1 == dArr[0] && d.getDate() == dArr[1] && d.getFullYear() == dArr[2];
   }
   else {
      return false;
   }
}

function toggleIONewsBox(source) {
	var on = 'io_news_toggle';
	var off = 'om_news_toggle';
	if (source == 'IO') {
		document.getElementById('om_news_feed').style.visibility = 'hidden';
		document.getElementById('io_counter').style.visibility = 'visible';
	} else {
		on  = 'om_news_toggle';
		off = 'io_news_toggle';	
		document.getElementById('io_counter').style.visibility = 'hidden';
		document.getElementById('om_news_feed').style.visibility = 'visible';
	}
	document.getElementById(on).style.padding = '8px 6px 4px 6px';
	document.getElementById(on).style.backgroundColor = '#de9231';
	document.getElementById(on).style.color = '#000';
	document.getElementById(on).style.border = '1px solid #333';
	document.getElementById(on).style.borderBottom = '1px dotted #666';

	document.getElementById(off).style.padding = '4px 6px 4px 6px';
	document.getElementById(off).style.backgroundColor = '#777';
	document.getElementById(off).style.color = '#ddd';
	document.getElementById(off).style.border = '1px dotted #999';
	document.getElementById(off).style.borderBottom = '1px solid #333';
}

function loadBoxMessage(text) {
	var footerCode = "<br />";
	var styleCode = "<style type=\"text/css\">\n#page_header {font-size:16px; font-weight:bold; color:#376c98; height:18px; margin:0 0 12px 0;}\n</style>\n\n";
	styleCode += "<a href=\"#productMessage\" onclick=\"closeBox();\"><img src=\"/includes/images/close.gif\" alt=\"close this box\" style=\"float:right; margin:-3px -5px 0 2px; border:none; display:inline;\" /></a>\n";
	document.getElementById('overlay').style.display='block';
	document.getElementById('lightbox').innerHTML = styleCode + text + footerCode;
	document.getElementById('lightbox').style.display='block';
}

function closeBox() {
	document.getElementById('overlay').style.display = 'none';
	document.getElementById('lightbox').style.display = 'none';
	document.getElementById('lightbox').innerHTML = '';
}

/* getQueryStringParameters()
 * - Precede with array definition: 
 *      var qsParameters = new Array();
 * - Call with:
 *      qsParameters['name_of_parameter'] 
 */
function getQueryStringParameters() {
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParameters[key] = val;
		}
	}
} 