/**
 * @author Benjamin Sterling
 * @email bsterling@informationexperts.com
 * @version 1.0
 */

/**
 * @purpose	this file is needed for all functions to work
 * so core.js looks for this file before doing anything 
 */
var $presets = true;

var wbt = {};
 
/**********************************************************
 *		Start item that can be changed
 *********************************************************/
var isDynamic = false;
var isFramed = false;

var isRestricted = false;


var contentUrlFramed = '/util/page.ashx?id={[id]}';
var contentUrl = '/modules/{[id]}/';

var tocXmlFramed = "/ajax/buildXML.aspx?id={[id]}";
var tocXml =  'common/xml/{[id]}.xml';

var glossaryXMLFramed = '/ajax/buildGlossary.aspx';
var glossaryXML = 'common/xml/glossary.xml';

/**
 * Set to true if you want to restict to a certain domain
 */
var restictToDomain = false;

/**
 * domain to restrict to
 */
var domainToRestrictTo = "localhost";
 
/**
 * @purpose	turns logger on and off
 * set to false to turn debuging off
 */
var DEBUG = false;

/**
 * @purpose	for dev purpose
 * set to true to put limitations back into play
 */
var $live = false;

/**
 * @purpose	set to false if topic menu is not grouped with lesson menu
 */
var $groupedMenu = true;

/**
 * @purpose	sets the percetage to pass by
 */
var percentageToPassBy = 80;

/**
 * @purpose	sets random questions for quiz
 */
var randomQuestionQuiz = true;

/**
 * @purpose	sets random answer for quiz
 */
var randomAnswerQuiz = false;

/**
 * @purpose	set how many end of lessons questions to grab
 * set to -1 if you want all questions
 */
var totalQuestionsQuiz = -1;

/**
 * @purpose	sets random questions for test
 */
var randomQuestionTest = false;

/**
 * @purpose	sets random answer for test
 */
var randomAnswerTest = false;

/**
 * @purpose	set how many end of lessons questions to grab
 * set to -1 if you want all questions
 */
var totalQuestionsTest = -1;

/**
 * @purpose	Custom pass and fail messages
 */
var FAILEDTESTMESSAGE = "<h3>Quiz Summary</h3><p>You have answered {correct} out of {count} questions correctly and therefore have not met the minimal requirements to pass this module. Below are the questions you answered incorrectly. Please take a moment to review the summary information then click on the Retake button to repeat the questions you missed.  You may also print this summary information by clicking on the Print button.</p>";

var PASSEDTESTMESSAGE = "<h3>Quiz Summary</h3><p>Congratulations! You have scored 80% or better and have successfully completed the test for this module! Any questions you may have missed are listed below. You may want to review these sections of the lesson again.</p><p>To receive your certificate, click on the Print Certificate button below. Note that you will need to select <strong>landscape</strong> within your printer options to correctly print the certificate.</p>";

var PRETESTMESSAGE = "<img src='common/img/quiz.png' class='floatRight' alt='Quiz Icon'/><h3>Quiz Directions</h3><p>You are about to begin the end of lesson quiz. Please review the following directions before you begin.<br/><br/>Once you begin the quiz, you will need to continue forward and answer all quiz questions before receiving your score. If you exit the quiz before answering all of the questions, your responses will be lost and you will need to retake the quiz again from the first question.<br/><br/>You cannot go back to review a question once you have selected an answer. To receive a certificate for this lesson you will need to score 80% or better. You can retake missed questions as many times as needed.<br/><br/>Click the Take Quiz button to begin.<br/><br/>Good Luck!</p>";


/**
 * @purpose	set to true if there are going to be a need to check for
 * multiple sizes, ie. a design for 990 and a design for 800
 */
var $multipleSizes = false;

//  if $use is set to cookie, this variable will be used for the cookie name
var $cookieName = 'dummyData';

//  if $use is set to cookie, this variable will be used for the cookie params
var $cookieParams = {expires: 7};

/**
 * @purpose	Set what page to redirect to
 * URL to redirect to if there is no hash present on the 
 * module.asp/.htm /.php page
 */
var $redirectUrl = "index.htm";

/**
 * @purpose	example document.location + '#m-1000'
 */
var $redirectUrlNoHash =	'index.htm#m-1000';

var defaultModuleID = 1000;

/**
 * @purpose	set this to any other the follow to control 
 * where data collection is saved to.  
 *		null:  No data collection
 *		db: for database collection, must set $ajaxURL
 *		cookie: set to cookie collection
 *		scorm: set to scorm collection
 */
var $use = null;

/**
 * @purpose	set to true if you want to set a time out
 */ 
var $timeOut = false;

//  set (in milliseconds) the time till the app times out
var $timeOutTime = null;

//	if $multipleSizes is set to true, then use this class
var $800Class = "smallArea800";

// show (true) / hide (false) end of test helper text
var $showTestHelperText =  true;

//	set to the url of the server side page that will execute any db calls
var $ajaxURL = null;

/**
 * @purpose  For the pagination text; {[p]} is for current
 * page number and {[t]} is for total page number Other 
 * example: Page {[p]}/{[t]} or You are on page {[p]} of {[t]}
 */
var $paginationText = "<strong>Page {[p]}</strong> of {[t]}";
var $quizPaginationText = "<strong>Question {[p]}</strong> of {[t]}";

/**
 * @purpose	set below if there will be static menu items
 */
var $staticMenuItems = Array();
		$staticMenuItems.push({'txt':'Home','url':'index.htm'});
		$staticMenuItems.push({'txt':'Help','url':'help.htm'});
		
/**
 * @purpose set to true if persons data must be retrieved and validated
 *				for site structure is loaded
 */
var preloadValidate = false;

var domainToRestrictToMsg = 'Must set domainToRestrictTo if you set restictToDomain to true';

/**********************************************************
 *		End item that can be changed
 *********************************************************/

/**********************************************************
 *		Start layout/theme specific selectors
 *********************************************************/
/*
This is a list of IDs that will be used through out the code to append
data to

#moduleName // module name gets appended to this
#lessonName // lesson Name
#topicName // topic name gets appended to this
#pageName // page name gets appended to this
#bodyText // imported page gets appended to this

#lessonMenu // a list of lesson items get appended to this
#topicMenu // a list of topic items get appended to this
#pageMenu // a list of page items get appended to this
#tabs	// tab menu
#staticMenu // most likely the home link and log out link
#welcomeName // the welcome name
#pagination // page number holder
#nxtprvContainer // next previous holder

.answers // used to hide answers when they come up
*/

var SelectorTabs = '#tabs';
var SelectorStaticMenu = '#staticMenu';
var SelectorNxtprvContainer = '#nxtprvContainer';
var SelectorBodytext = '#bodyText';
var SelectorLessonMenu = '#lessonMenu';
var SelectorTopicMenu = '#topicMenu';
var SelectorWelcomeName = '#welcomeName span:first';
var SelectorLessonName = '#lessonName span:eq(1)';
var SelectorModuleName = '#moduleName span:first';
var SelectorPagination = '#pagination';
var SelectorTopicName = '#topicName span:eq(1)';
var SelectorNext = '#next';
var SelectorPrev = '#prev';

// close button can be an html element
var SelectorClose = '#getClosed';

//	items to help with selector speeds
var jqtabs = null;
var jqstaticMenu = null;
var jqwelcomeName = null;
var jqnxtprvContainer = null;
var jqbodytext = null;
var jqlessonMenu = null;
var jqlessonName = null;
var jqtopicMenu = null;
var jqtopicName = null;
var jqpagination = null;
var jqmoduleName = null;

//	jQuery object holding all the links to unbind the click event for.
var $aUnbindLinks;

//	a list of links you done want to remove the default click event for
var $aNotUnbindLinks = '.leaveAlone,.a_tab1,.a_tab2,.a_tab3,#iLoggerClose,#iLoggerClear,#iLoggerToggle,#iLogger_dbcall,#iLogger_TODO,#iLogger_testing,#iLogger_notice,#iLogger_warning,#iLogger_error,.a_close_tabs';


/**********************************************************
 *		End layout/theme specific selectors
 *********************************************************/


/**********************************************************
 *		Start helper variables to be used thru out course
 *********************************************************/

/**
 * @desc	stores xml files that get pulled in
 */
var docXML = Array();

/**
 * @desc	stores variables that are most used
 */
var vars = {};

/**
 * @purpose	holds currently access questions
 */
var totalQuestionsQuizAccessed = Array();


/**
 * @purpose	holds currently access questions
 */
var totalQuestionsTestAccessed = Array();

/**
 * @purpose	holds currently passed questions
 */
var totalQuestionsTestPassed = Array();

var totalQuestionsHolder = Array();

/**
 * @desc	variables that get set when user logs on
 */
var testNumOfAttempts = 0;

/**
 * @desc	helps to check if user is logged on in js
 */
var isLoggedIn = false;

/**
 * @desc	holds information on the pop up window
 */
var win=null;

//	helps keep track of users location
var $locationMarker = null;
var $globalMarker = null;
//	items to text and othe misc variables
var $MODULENAME = null;
var $MODULEID = null;
var logoutTimeout = null;
var tempDataArray = Array();

/**********************************************************
 *		End helper variables to be used thru out course
 *********************************************************/


/********************************************************/
/********************************************************/
/*		more clean up needed							*/
/********************************************************/
/********************************************************/



/**
 * @purpose	current location
 */
var curTotalLessons = null;
var curTotalTopics = null;
var curTotalPages = null;

/**
 * @desc	used to see if test is passed.
 */
var bPassed = 0;

/**
 * @desc	used to see if test is passed.
 */
var bContentComplete = 0;

var now = new Date();
var dDateStart = now.getFullYear()+'/'+now.getMonth() + "/" + now.getDate();
var dDateEnd = now.getFullYear()+'/'+now.getMonth() + "/" + now.getDate();

var month = now.getMonth() + 1;
var day = now.getDate();
var year = now.getFullYear();
/**
 * @desc	used for inline quizzes to test for how many tries
 */
var inlinequiztmp = 0;

var iInlineQuizCount = 0;
var sInlineQuiz = '';
var bIsDone = 0;
var np = null;


/*
 * added August 08, 2007
 */
/*************************************************************************
**************************************************************************
*************************************************************************/



								



//	holds needed site data
var $sitedata = {
				i : 'init',
				fn:null,// first name
				ln:null,// last name
				m: { // module
					p: null, // passed test
					c: null, // completed content
					na: null, // number of attempts
					ds: month + "/" + day + "/" + year,//"6/25/2007", date started
					de: null, // date ended
					tt: Array(), // test taken
					tp: Array(), // test passed
					sPageViewed: null
				},
				l:{// lesson
					_0_0:{
						iLessonRef: 0, 
						iTopicRef: 0, 
						bIsDone: 0, 
						sInlineQuiz: '0', 
						sPageRef: 0 
					}
				}
			};
/*
var $sitedata = {
				index : 'init',
				'fname':null,
				'lname':null,
				moduleLevel: {
					bPassed: null, 
					bContentComplete: null, 
					iNumAttempts: null, 
					dDateStart: month + "/" + day + "/" + year,//"6/25/2007", 
					dDateEnd: null, 
					sTestTaken: Array(), 
					sTestPassed: Array(), 
					sPageViewed: null
				},
				lessonLevel:{
					_0_0:{
						iLessonRef: 0, 
						iTopicRef: 0, 
						bIsDone: 0, 
						sInlineQuiz: '0', 
						sPageRef: 0 
					}
				}
			};
*/