//****************************************************************
//****************************************************************
//	Defensive Driver On-line
//	Copyright 1998, Vertex Software
//
//****************************************************************
//****************************************************************
var browserName = navigator.appName;
var browserVer = parseInt(navigator.appVersion);
var win = null;
var gCourseWindow = null;
var gVideoViewer = null;
var gPlayerWindowName = "Player";
var gIsExplorer = (browserName.indexOf( "Explorer" ) > -1);
var gIsWindows = (navigator.appVersion.indexOf( "Win" ) > -1);
var gIsNetscape = (browserName.indexOf( "Netscape" ) > -1);
var gIsThreeOhBrowser = (browserVer <= 4);
var gIsFourOhBrowser = (browserVer >= 4);
var gIsAnimationQuestion = 0;
var gPlayerCount = 0;
var version = "no";
var gDocumentURL = "" + document.location;
var gPageTurned = null;
var gViewedVideo = false;
var gSubmitTimeout = 10;
var gClickedPic = "";
var gTimer = null;
var gViewedVideo = false;
var gPageContentTimer = null;

if (browserName == "Netscape" && browserVer >=3) version = "yes";
if (browserName == "Microsoft Internet Explorer" && browserVer >=4) version = "yes";

//****************************************************************
//	PreloadImage
//****************************************************************
function PreloadImage( url ) {
	var preload = new Image();
	preload.src = url;
	}


//****************************************************************
//	LoadImages
//****************************************************************
function LoadImages() {
	PreloadImage( "img/nextc.GIF" );
	PreloadImage( "img/previousc.GIF" );
	PreloadImage( "img/logoffc.GIF" );
	PreloadImage( "img/browc.GIF" );
	PreloadImage( "img/glossc.GIF" );
	PreloadImage( "img/refreshc.GIF" );
	PreloadImage( "img/bckcoursec.GIF" );	
	}

		
//****************************************************************
//	Testing
//****************************************************************
function Testing() {
	if (!document.forms[0].testing) return false;
	if ((typeof document.forms[0].testing.value) == "number" || (typeof document.forms[0].testing.value) == "string") {
		if (document.forms[0].testing.value == 1) return true;
		}
	return false;
	}


//****************************************************************
//	HandleUnload
//****************************************************************
function HandleUnload() {
	CloseVideoViewer();
	if (!WasPageSubmitted()) {
		//
		if (gTimer > 0) window.clearTimeout( gTimer );
		gTimer = 0;
		if (document.forms[0].sid ) {
			Logoff();
			}
		}
	}


//****************************************************************
//	HandleLoad
//****************************************************************
function HandleLoad() {
	if (document.forms[0]) {
		LoadImages();
		gViewedVideo = false;
		var elements = document.forms[0].elements
		var index = 0;
		if (document.forms[0].minimized) {
			UpdateContentTimer();
			return;
			}
		for (index=0; index<elements.length; index++) {
			if (elements[index].type != "hidden") {
				elements[index].focus();
				break;
				}
			}
		}
	}



//****************************************************************
//	HandleKeyDown
//****************************************************************
function HandleKeyDown() {
	if (document.forms[0].ptype && document.forms[0].ptype.value != "Q" && document.forms[0].ptype.value != "K") {
		if (window.event.keyCode == 39) {
			if (document.all( "next" )) GoToNextPage();
			}
		else if (window.event.keyCode == 37) {
			if (document.all( "previous" )) GoToPreviousPage();
			}
		}
	}
	


//****************************************************************
//	HandleSubmit
//****************************************************************
function HandleSubmit() {
	if (document.activeElement != null) {
		if (document.activeElement.tagName == "INPUT") {
			if (gIsExplorer) {
				if (window.event.keyCode == 13) {
					Submit();
					}
				}
			else {
				if (window.event.which == 13) {
					Submit();
					}
				}
			}
		}
	}




//****************************************************************
//	Logoff
//****************************************************************
function Logoff() {
	return;
	if (document.forms[0].sid && !Testing() ) {
		var logoffWindow = null;
		var windowprops = "height=100,width=100";	
		var url = "logoff.html?sid=" + document.forms[0].sid.value;
		//alert( "Please use the 'log off' button to exit the course." );
		window.open(url, "DDOLOGOFF", windowprops );
		}
	}
	
	
//****************************************************************
//	Reload
//****************************************************************
function Reload() {
	document.forms[0].direction.value = "x";
	document.forms[0].ptype.value = "C";
	//window.location.reload();
	Submit('refresh');
	}
	

//****************************************************************
//	CancelExpressMail
//****************************************************************
function CancelExpressMail(server) {
	document.forms[0].action = server + "certificaterequest.html";
	Submit( 'previous' );
	}
	
	
//****************************************************************
//	Submit
//****************************************************************
function Submit(clickedPic) {
	if (!WasPageSubmitted()) {
		if (clickedPic) {
			picClick( clickedPic );
			}
		gTimer = window.setTimeout( "ResetPic();", gSubmitTimeout*1000 );
		gPageTurned = new Date();
		document.forms[0].submit();
		}
	else {
		picClick( clickedPic );
		}
	}


	
//****************************************************************
//	WasPageSubmitted
//	Returns true if teh page was submitted within the last 
//	gSubmitTimeout seconds.
//****************************************************************
function WasPageSubmitted() {
	if (gPageTurned == null) {
		return false;
		}
	else {
		var now = new Date();
		return ((now.getTime() - gPageTurned.getTime()) / 1000.00) < gSubmitTimeout;
		}
	}


//****************************************************************
//	IsDirectionValid
//****************************************************************
function IsDirectionValid() {
	// NO LONGER USED 
	// Was apparently used to prevent tey user from clicking a button more than once.
	// Now handled by WasPageSubmitted call.
	return (document.forms[0]) && (document.forms[0].direction) && (document.forms[0].direction.value=='x')
	}


//****************************************************************
//	SetSelectValue
//****************************************************************
function SetSelectValue( selectName, valueText ) {
	if (valueText.length > 0) {
		var select = eval( "document.forms[0]." + selectName );
		var index = 0;
		if (select) {
			for (index=0; index<select.options.length; index++) {
				if (select.options[index].value == valueText) {
					select.selectedIndex = index;
					break;
					}
				}
			}
		}
	}


//****************************************************************
//	SetRadioButton
//****************************************************************
function SetRadioButton( name, valueText ) {
	if (valueText.length > 0) {
		var radioButton = eval( "document.forms[0]." + name );
		var index = 0;
		if (radioButton) {
			for (index=0; index<radioButton.length; index++) {
				if (radioButton[index].value == valueText) {
					radioButton[index].checked = true;
					break;
					}
				}
			}
		}
	}



//****************************************************************
//	GoToPage
//****************************************************************
function GoToPage(id) {
	document.forms[0].ptype.value = "R";
	document.forms[0].point.value = id
	Submit();
	}

	
//****************************************************************
//	GoToPreviousPage
//****************************************************************
function GoToPreviousPage() {
	//if (IsDirectionValid()) {
		TurnPage('prev');
	//	}
	}


//****************************************************************
//	GoToNextPage
//****************************************************************
function GoToNextPage() {
	//if (IsDirectionValid()) {
		TurnPage('next');
	//	}
	}


//****************************************************************
//	picSwitch
//****************************************************************
function picSwitch(name) {
	try {
		var pic = document[ name ]
		if (pic) {
			if (pic.src.indexOf("c.GIF") > -1) {
				// DOn't change
				}
			else if (pic.src.indexOf("a.GIF") == -1) {
				pic.src = pic.src.substring(0,pic.src.length-5)+"a.GIF"
				} 
			else {
				pic.src = pic.src.substring(0,pic.src.length-5)+"b.GIF"
				}
			window.status = pic.src
			}
		}
	catch (error) {
		}	
	}


//****************************************************************
//	picClick
//****************************************************************
function picClick(name) {
	if (name == 'prev') name = "previous";
	var pic = eval( "document." + name );
	if (pic) {
		gClickedPic = name;
		pic.src = pic.src.substring(0,pic.src.length-5)+"c.GIF"
		}
	}


//****************************************************************
//	ResetPic
//****************************************************************
function ResetPic(clickedPic) {
	if (!clickedPic) clickedPic = gClickedPic;
	if (clickedPic == 'prev') clickedPic = "previous";
	if (clickedPic.length > 0) {
		var pic = eval( "document." + clickedPic );
		if (pic) {
			pic.src = pic.src.substring(0,pic.src.length-5)+"a.GIF"
			}
		}
	}


//****************************************************************
//	courseRedirect
//****************************************************************
function courseRedirect(page) {
	if (WasPageSubmitted()) return;
	if (page == "browse.html" ) {
		document.forms[0].ptype.value="B"
		document.forms[0].action = "course.html?trace=B.0.0";
		picClick( "brow" );
		}
	if (page == "browse.html?browseFromExam=1" ) {
		document.forms[0].ptype.value="B"
		document.forms[0].action = "course.html?trace=B.0.0&browseFromExam=1";
		picClick( "brow" );
		}
	if (page == "glossary.html" ) {
		document.forms[0].ptype.value="G"
		document.forms[0].action = "course.html?trace=G.0.0";
		picClick( "gloss" );
		}
	if (page == "help.html" ) {
		var helpWindow = window.open("help.html?incourse=1", "DDOHELP" );
		helpWindow.focus();
		return;
		}
	if (page == "logoff.html" ) {
		document.forms[0].action = "logoff.html"
		picClick( "logoff" );
		}
	Submit();
	}



//****************************************************************
//	makeSearchString
//	FROM: http://devedge.netscape.com/viewsource see 
//		  "Passing Data Between Pages via URL's"
//****************************************************************
function makeSearchString() {
	var args = makeSearchString.arguments
	var searchString = "?"
	var onePair
	for (var i = 0; i < args.length; i++) {
		onePair = escape(args[i++]) + "="
		onePair += escape(args[i])
		searchString += onePair + "&"
		}
	return searchString
	}



//****************************************************************
//	TurnPage
//****************************************************************
function TurnPage(way) {
	if (!CheckTime(way)) return;
	if (!CheckAnswers(way)) return;
	if (WasPageSubmitted()) return;
	document.forms[0].direction.value = "" + escape(way)
	Submit(way);
	}	


//****************************************************************
//	NetscapeRealPlayerCheck
//****************************************************************
function NetscapeRealPlayerCheck() {
	if (gIsNetscape) {
		numPlugins = navigator.plugins.length;
		for (i = 0; i < numPlugins; i++) {
			plugin = navigator.plugins[i];
			if (plugin.name.substring(0,10) =="RealPlayer") {
				return true;
				}
			}
		}
	else if (navigator.userAgent.indexOf("Window") >= 0) {
		return true;
		}
	alert("You must install RealPlayer Plug-in in order to take the course!");
	return false;
	}


//****************************************************************
//	VerifyWarningCheck
//****************************************************************
function VerifyWarningCheck() {
	if (document.forms[0].warning.value == 1) {
		alert( "Because you did not respond to the verification question within one minute or you logged off without answering the verification, the system recorded an incorrect answer. Please click the next button and answer the verification question." );
		}
	}


//****************************************************************
//	VideoVerifyPassed
//****************************************************************
function VideoVerifyPassed() {
	if (!Testing()) {
		alert( "Your answer to the question concerning the video was correct! You may now proceed with the course." );
		}
	}


//****************************************************************
//	VideoVerifyWarningCheck
//****************************************************************
function VideoVerifyWarningCheck() {
	alert( "Your answer to the question concerning the video was incorrect. Please watch the video again before moving on." );
	}


//****************************************************************
//	NoEmail
//****************************************************************
function NoEmail() {
	document.forms[0].email.value='no e-mail';
	}

	
//****************************************************************
//	CourtLater
//****************************************************************
function CourtLater() {
	document.forms[0].court.value='enter at the end of course';
	}


//****************************************************************
//	NoCourt
//****************************************************************
function NoCourt() {
	document.forms[0].court.value='NA';
	}


//****************************************************************
//	HasPaid
//****************************************************************
function HasPaid() {
	if (document.forms[0].hasPaid.value == 1) {
		alert( "Our records indicate that you have already paid. There is no need to pay again." );
		ClearTrap();
		document.location = "login.html";
		}
	return false;
	}


//****************************************************************
//	AlreadyHasCert
//****************************************************************
function AlreadyHasCert(   ) {
	alert( "Our records indicate that you have already been issued a cert." );
	document.location = "login.html";
	return false;
	}
	

//****************************************************************
//	PreCheckCreditCardInfo
//****************************************************************
function PreCheckCreditCardInfo() {
	var todaysDate = new Date();
	var todaysYear = todaysDate.getYear();
	var selectedYear = document.forms[0].expYear.options[ document.forms[0].expYear.selectedIndex].value;
	if (HasPaid()) return false;
	if (selectedYear == todaysYear) {
	    var todaysMonth = todaysDate.getMonth();
		if (document.forms[0].expMonth.selectedIndex < todaysMonth) {
			alert( "The expiration date entered for the credit card is invalid. Please enter a different date." );
			return false;
			}
		}
	return true;
	}
	

//****************************************************************
//	CheckEvaluationAnswers
//****************************************************************
function CheckEvaluationAnswers() {
	if (WasPageSubmitted()) return;
	var question = 0;
	var option = 0;
	var radioButton = null;
	var checked = false;
	// Remove but save since TEA changes their mind daily
	//for (question=1; question<13; question++) {
	//	checked = false;
	//	for (option=0; option<5; option++) {
	//		checked = checked || eval( "document.forms[0].q" + question + "[" + option + "].checked" );
	//		}
	//	if (!checked) {
	//		alert( "You must first answer all of the questions before you can proceed." );
	//		return;
	//		}
	//	}
	Submit();
	}


//****************************************************************
//	CheckIfDeclined
//****************************************************************
function CheckIfDeclined() {
	if (document.forms[0].contractDeclined.value == 1) {
		alert( "You can not continue with the course until you accept the terms of the contract. Please read the contract and click the 'Accept' button below." )
		}
	}
	

//****************************************************************
//	ConfirmDecline
//****************************************************************
function ConfirmDecline( declineAction ) {
	if ( confirm("Are you sure you want to decline the contract?") ) {
		ClearTrap();
		self.location = declineAction;
		}
	}

	
//****************************************************************
//	CheckPaymentOptions
//****************************************************************
function CheckPaymentOptions() {
	if (WasPageSubmitted()) return;
	if (document.forms[0].payMethod[0].checked) {
		document.forms[0].action = document.forms[0].ccFormAction.value
		}
	else if (document.forms[0].payMethod[1].checked) {
		document.forms[0].action = document.forms[0].chFormAction.value
		}
	else {
		alert( "You must first select a payment method before you can proceed." );
		return;
		}
	Submit( 'next' );
	}


//****************************************************************
//	CheckTime
//****************************************************************
function CheckTime(way) {
	var valid = true;
	if (way == 'next' && document.forms[0].timeRequired) {
		if (parseInt( document.forms[0].timeRequired.value ) > 0) {
			alert( "Sorry, you must remain on this page for another " + document.forms[0].timeRequired.value + " seconds before proceeding." );
			ResetPic();
			valid = false;
			}
		}
	return valid;
	}


//****************************************************************
//	CheckAnswers
//****************************************************************
function CheckAnswers(direction) {
	var pageType = document.forms[0].ptype.value;
	if ((pageType == 'Q' || pageType == 'K') && direction == 'next') {
		var index;
		for (index=0; index<document.forms[0].answer.length; index++) {
			if (document.forms[0].answer[index].checked) {
				return true;
				}
			}
		alert( "You must answer the question before you can proceed." );
		}
	else if (pageType == 'EV') {
		
		}
	else if (pageType == 'CHECK') {
		if (!gViewedVideo && !Testing() ) {
			alert( "You must first click the 'test video' button in Step 3 before you can proceed." );
			}
		else {
			return true;
			}
		}
	else if ((document.forms[0].animFolder || document.forms[0].videoID) && direction == 'next' && !Testing() ) {
		var pointCheck = document.forms[0].pointCheck.value;
		var currentPoint =  pointCheck.substring( pointCheck.indexOf( " " ) + 1  );
		// Only alert the first time the user comes to this page
		if ( (currentPoint == document.forms[0].maxPoint.value) || (document.forms[0].videoID && document.forms[0].videoID.value == "test") ) {
			if (gVideoViewer) {
				// The PlayerWindow sets the window's name to
				// pass back status. We do this since the player
				// window can be closed and then we have no way
				// to check the result.
				if (window.name == gPlayerWindowName + "closed") {
					// Window was closed before view viewed
					}
				else if (window.name == "complete" || gViewedVideo) {
					// Window was closed after viewing video
					return true;
					}
				}
			else if (document.forms[0].courseVersion.value == "2") {
				gViewedVideo =  true;
				}
			if (gIsAnimationQuestion) {
				alert( "You must first view the animation and answer the question before you can proceed." );
				}
			else if (document.forms[0].videoID ) {
				if (!gViewedVideo) {
					alert( "You must first view the video before you can proceed." );
					}
				else {
					return true;
					}
				}
			else {
				alert( "You must first view the animation before you can proceed." );
				}
			}
		else {
			return true;
			}
		}
	else {
		return true;
		}
	ResetPic( direction );
	return false;
	}
	

//****************************************************************
//	CloseVideoViewer
//****************************************************************
function CloseVideoViewer() {
	if (gVideoViewer) {
		// Not set anymore due to bugs in AOL 5.0
		//if (window.name != (gPlayerWindowName + "closed")) {
			if (!gVideoViewer.closed) { 
				gVideoViewer.close();
				}
		//	}
		gVideoViewer = null;
		if (!Testing()) window.name = "DDO";
		}
	}


//****************************************************************
//	OpenRealPlayer
//****************************************************************
function OpenRealPlayer(URL, useNewWindow) {
	gViewedVideo = true;
	if (!URL) URL=document.forms[0].videoSource.value;
	if ( navigator.appVersion.indexOf( "MSIE 5.5" ) > -1 ) {
		var windowprops = "height=30,width=40,location=no, scrollbars=no, menubars=no, toolbars=no, resizable=no";	
		window.open(URL, "VideoViewer", windowprops);
		}
	else {
		ClearTrap();
		document.location.href = URL;
		}
	}
	
	
//****************************************************************
//	playStreamingVideo
//****************************************************************
function playStreamingVideo() {
	var URL;
	var form = document.forms[0];
	var windowLocation = "";
	var animPause = -1;
	var animScriptBFrame = -1;
	var animScriptCFrame = -1;
	var windowprops = "height=373,width=480,location=no, scrollbars=no, menubars=no, toolbars=no, resizable=no";	
	gIsAnimationQuestion = 0;
	// only works on IE
	if (window.screenTop) {
		var windowTop = window.screenTop + 10;
		var windowLeft = window.screenLeft + 50;
		windowprops = windowprops + ", top=" + windowTop + ", left=" + windowLeft;
		}
	if (form.animPause) animPause = form.animPause.value;
	if (form.animScriptBFrame) animScriptBFrame = form.animScriptBFrame.value;
	if (form.animScriptCFrame) animScriptCFrame = form.animScriptCFrame.value;
	URL = "streamingvideoviewer.html" + makeSearchString( 
		"videoSource", form.videoSource.value, 
		"videoLength", form.videoLength.value,
		"sid", form.sid.value );
	CloseVideoViewer();
	// Need to make sure that every time a player is opened,
	// it is given a different name. Otherwise, attempts to re-open
	// the browser will try to use the previous window with the same
	// name. If it was already closed, an error occurs.
	gPlayerWindowName = "Player" + gPlayerCount;
	gVideoViewer = window.open(URL, gPlayerWindowName, windowprops);
	if (!Testing()) window.name = "DDO";
	gPlayerCount++;
	if (!gVideoViewer.opener) gVideoViewer.opener = self;
	}


//****************************************************************
//	playVideo
//****************************************************************
function playVideo() {
	var URL;
	var form = document.forms[0];
	var windowLocation = "";
	var animPause = -1;
	var animScriptBFrame = -1;
	var animScriptCFrame = -1;
	var windowprops = "height=325,width=480,location=no, scrollbars=no, menubars=no, toolbars=no, resizable=no";	
	// only works on IE
	if (window.screenTop) {
		var windowTop = window.screenTop + 10;
		var windowLeft = window.screenLeft + 50;
		windowprops = windowprops + ", top=" + windowTop + ", left=" + windowLeft;
		}
	if (form.animPause) animPause = form.animPause.value;
	if (form.animScriptBFrame) animScriptBFrame = form.animScriptBFrame.value;
	if (form.animScriptCFrame) animScriptCFrame = form.animScriptCFrame.value;
	URL = "videoviewer.html" + makeSearchString( 
		"animFolder", form.animFolder.value, 
		"animFrames", form.animFrames.value,
		"animBFrames", form.animBFrames.value,
		"autoPlay", form.autoPlay.value,
		"animwrongFrame", form.animwrongFrame.value,
		"animCop", form.animCop.value,
		"animPause", animPause,
		"animScriptBFrame", animScriptBFrame,
		"animScriptCFrame", animScriptCFrame );
	gIsAnimationQuestion = (form.autoPlay.value != "yes" || form.autoPlay.value != "Yes");
	CloseVideoViewer();
	// Need to make sure that every time a player is opened,
	// it is given a different name. Otherwise, attempts to re-open
	// the browser will try to use the previous window with the same
	// name. If it was already closed, an error occurs.
	gPlayerWindowName = "Player" + gPlayerCount;
	gVideoViewer = window.open(URL, gPlayerWindowName, windowprops);
	if (!Testing())  window.name = "DDO";
	gPlayerCount++;
	if (!gVideoViewer.opener) gVideoViewer.opener = self;
	}


	
//****************************************************************
//	SubmitValidation
//****************************************************************
function SubmitValidation() {
	if (WasPageSubmitted()) return false;
	var questionType = document.forms[0].questionType.value;
	if (window.event) {
		if (window.event.keyCode != 13 && window.event.keyCode > 0) return true;
		}
	if (TestQuestion(questionType)) {
		if ((questionType == 2) || (questionType == 5)) {
			document.forms[0].answer.value = ConcatAnswer( questionType );
			}
		Submit('next');
		// MUST RETURN FALSE otherwise you get a double-sumbit
		//return true;
		return false;
		}
	return false;
	}


//****************************************************************
//	SubmitValidationNoReturn
//****************************************************************
function SubmitValidationNoReturn() {
	SubmitValidation();
	}


//****************************************************************
//	TestQuestion
//****************************************************************
function TestQuestion (questionType) {
	if (questionType == 0) {		// project.kQuestionTypeRadio CHECK
		for (i=0; i < document.forms[0].answer.length; i++){
			if (document.forms[0].answer[i].checked) {
				return true
				}
			}
		WarnInvalid (questionType);
		return false
		}
	else if (questionType == 1 ) {		// project.kQuestionTypeSelect CHECK
		if (document.forms[0].answer.options[document.forms[0].answer.selectedIndex ].value != "") {
			return true
			}
		WarnInvalid(questionType);
		return false
		}
	else if (questionType == 2) {		// project.kQuestionTypeDate CHECK
		if (document.forms[0].answer1) {
			if (document.forms[0].answer1.options[document.forms[0].answer1.selectedIndex].value == ""){
				WarnInvalid (questionType);
				return false
				}
			}
		if (document.forms[0].answer2) {
			if (document.forms[0].answer2.options[document.forms[0].answer2.selectedIndex].value == ""){
				WarnInvalid (questionType);
				return false
				}
			}
		if (document.forms[0].answer3) {
			if ((document.forms[0].answer3.value == "") || (document.forms[0].answer3.value.length != 4) || (!(CheckNumericClient(document.forms[0].answer3.value)))) {
				WarnInvalid (questionType);
				return false
				}
			}
		return true
		}
	else if ( questionType == 3 ) {		// project.kQuestionTypeText CHECK
		if (document.forms[0].answer.value != ""){
			return true
			}
		WarnInvalid (questionType);
		return false
		}
	else if ( questionType == 4) {		// project.kQuestionTypeNumeric CHECK
		if ((document.forms[0].answer.value != "") && (document.forms[0].answer.value.length == document.forms[0].qOptions.value) && (CheckNumericClient(document.forms[0].answer.value))) {
			return true
			}
		WarnInvalid (questionType);
		return false
		}
	else if (questionType == 5 ) {		// project.kQuestionTypePhone CHECK
		if (((document.forms[0].answer1.value != null) && (document.forms[0].answer1.value.length == 3)) && ((document.forms[0].answer2.value != null) && (document.forms[0].answer2.value.length == 3)) && ((document.forms[0].answer3.value != null) && (document.forms[0].answer3.value.length == 4)) && (CheckNumericClient(document.forms[0].answer1.value)) && (CheckNumericClient(document.forms[0].answer2.value)) && (CheckNumericClient(document.forms[0].answer3.value))){
			return true;
			}
		WarnInvalid (questionType);
		return false;
		}
	return false;
	}



//****************************************************************
//	ConcatAnswer
//****************************************************************
function ConcatAnswer( questionType ) {
	var ansDelimitor = "";
	var answer = "";
	var answer1 = "";
	var answer2 = "";
	var answer3 = "";
	if (questionType == 2) {
		if (document.forms[0].answer1 && document.forms[0].answer2 && document.forms[0].answer3) ansDelimitor = "/";
		if (document.forms[0].answer1) {
			answer1 = "" + document.forms[0].answer1.options[document.forms[0].answer1.selectedIndex].value;
			}
		if (document.forms[0].answer2) {
			answer2 = "" + document.forms[0].answer2.options[document.forms[0].answer2.selectedIndex].value;	
			}
		if (document.forms[0].answer3) {
			answer3 = "" + document.forms[0].answer3.value;
			}
		}
	else if (questionType == 5) {
		answer1 = document.forms[0].answer1.value;
		answer2 = document.forms[0].answer2.value;
		answer3 = document.forms[0].answer3.value;
		}
	answer = answer1 + ansDelimitor +  answer2 + ansDelimitor + answer3;
	return answer;
	}
	
	
//****************************************************************
//	CheckNumericClient
//****************************************************************
function CheckNumericClient(InString) {
	for (i = 0; i < InString.length; i++) {
		var c = InString.charAt(i);
		if (!isDigit(c)){
			return false;
			}
   		}	
	 return true;
	 }
		 
		 
//****************************************************************
//	isDigit
//****************************************************************
function isDigit(c) {   
	return ((c >= "0") && (c <= "9"))
	}

		 
//****************************************************************
//	WarnInvalid
//****************************************************************		 
function WarnInvalid(questionType) {
	if (questionType == 0) {		// project.kQuestionTypeRadio CHECK
		alert('You must choose an item before you can proceed.');
		}
	else if ( questionType == 1 ) {		// project.kQuestionTypeSelect CHECK
		alert('You must choose an item before you can proceed.');
		}
	else if ( questionType == 2 ) {		// project.kQuestionTypeDate CHECK
		alert('You did not set the month and/or day field(s) or you did not enter or properly format the year field (yyyy).');
		}
	else if ( questionType == 3 ) {		// project.kQuestionTypeText CHECK
		alert('You must enter an answer before you can proceed.');
		}
	else if ( questionType == 4 ) {		// project.kQuestionTypeNumeric CHECK
		alert( "You must enter integers like (123456789) and you need to enter " + document.forms[0].qOptions.value + " integers." );
		}
	else if ( questionType == 5 ) {		// project.kQuestionTypePhone CHECK
		alert('Invalid phone number. A phone number can only contain the numbers one through ten and must have 10 digits (xxx-xxx-xxxx).');
		}
	}



//****************************************************************
//	HandleBlur
//****************************************************************		 
function HandleBlur( ) {
	return;
	var form = document.forms[0];
	window.status = "HandleBlur"
	if (!document.layers && document.activeElement && document.activeElement.tagName != "BODY") {
		window.focus();
		return;
		}
	if (form && form.minimized) {
		if (form.minimized.value == -1) {
			UpdateContentTimer();
			alert( "blured" );
			//alert( typeof document.embeds[0] )
			window.focus();
			}
		else {
			form.minimized.value = 1; 
			}
		}	
	else {
		window.status = "B"
		}
	}



//****************************************************************
//	HandleFocus
//****************************************************************		 
function HandleFocus( ) {
	return;
	var form = document.forms[0];
	if (form && form.minimized) form.minimized.value = 0; 
	window.status = "HandleFocus"
	}




//****************************************************************
//	UpdateContentTimer
//****************************************************************		 
function UpdateContentTimer( ) {
	var form = document.forms[0];
	var timeRequiredElement = form.timeRequired;
	var timeRequiredDisplay = form.timeRequiredDisplay;
	var seconds = parseInt( timeRequiredElement.value ) - 1;
	if (form.minimized.value == -1) form.minimized.value = 0; 
	if (form.minimized.value == 0 ) { 
		if (seconds < 0 ) seconds = 0; 
		timeRequiredElement.value = seconds;
		timeRequiredDisplay.value = seconds;
		}
	gPageContentTimer = window.setTimeout( "UpdateContentTimer();", 1000 );
	}


//****************************************************************
// PopupWindow
//****************************************************************
function PopupWindow( URL, name, height, width, resizeable, scrollbars, windowTop, windowLeft, menubars, toolbar, location) {
	resizeable = (resizeable ? ",resizable=yes" : ",resizable=no" );
	scrollbars = (scrollbars ? ",scrollbars=yes" : ",scrollbars=no" );
	menubars = (menubars ? ",menubars=yes" : ",menubars=no" );
	toolbar = (toolbar ? ",toolbar=yes" : ",toolbar=no" );
	location = (location ? ",location=yes" : ",location=no" );
	var windowprops = "height=" + height + ",width=" + width + resizeable + scrollbars + menubars + toolbar + location;	
	// only works on IE
	if (window.screenTop) {
		windowTop = (windowTop ? window.screenTop + windowTop :  window.screenTop + 10 );
		windowLeft = (windowLeft ?  window.screenLeft + windowLeft : window.screenLeft + 50 );
		windowprops = windowprops + ",top=" + windowTop + ",left=" + windowLeft;
		}
	var newWin = window.open(URL, name, windowprops);
	newWin.focus()
	}


//****************************************************************
// SetTrap
//****************************************************************
function SetTrap( trapURL, springTrap ) {
	try {
		if (!springTrap) {
			window.onunload = function() { 				
				SetTrap( trapURL, true);
				return "Please don't leave us!!!!";
				};
			// using onload problematic since used elsewhere
			window.setTimeout( FixLinks, 300 );
			if (typeof document.all == "undefined") window.onbeforeunload = window.onunload; 
			}
		if (springTrap && trapURL) {
			//alert("springTrap: " + [document.location.href,trapURL] );
			window.location.href = trapURL;
			}
		}
	catch (error) {
		alert( "SetTrap: " + error.description);
		}
	}


//===========================================================
// ClearTrap
//===========================================================
function ClearTrap( ) {
	window.onbeforeunload = window.onunload = null;
	}




//===========================================================
// FixLinks
// Adds onlcikc handlers to all links to they bypass trap
//===========================================================
function FixLinks( ) {
	try {
		window.status = ( "FixLinks" );
	    $("*[onclick]").filter(function(index) {
			var currentHandler = this.onclick;
	        if (currentHandler) {
			    this.onclick = function() {
				    ClearTrap();
				    currentHandler();
				    }
	            }
	        } );
	    $("*[onchange]").filter(function(index) {
			var currentHandler = this.onchange;
	        if (currentHandler) {
			    this.onchange = function() {
				    ClearTrap();
				    currentHandler();
				    }
	            }
	        } );
	    $("a,area").filter( function(index) {
			if (this.onclick || this.target.match(/blank/i)) return;
			this.onclick = function() {
				ClearTrap()
				if (this.href.match(/javascript/i)) {
					eval(this.href.replace("javascript:", "") )
					}
				else { 
					document.location.href = this.href;
					}
				}
	          } );
	    $("select,").filter( function(index) {
			var currentHandler = this.onchange;
			if (!currentHandler) return;
			this.onchange = function() {
				ClearTrap();
				if (currentHandler) currentHandler();
				}
	          } );
		}
	catch (error) {
		alert( "FixLinks: " + error.description  );
		}
	}



//===========================================================
// Initialize
//===========================================================
function Initialize( ) {
	try {
        $(document).ready(function(){
            try {
				if (document.referrer.match(/defensivedriving.com\//i) && document.location.href.match(/ddo\/register\.html/gi)) return;
				// 30APR2008 RFM - reduced to credit card payment only per Kent via MMac
				//if (document.location.href.match(/\/ddo\/(paymentoptions|courseunpaid|register|registered|contract_accepted|creditcard|decline|contract2)\.html/gi)) {
				if (document.location.href.match(/\/ddo\/(creditcard)\.html/gi)) {
					SetTrap( "/ddo/leave.html" );
					}
	            }
            catch (error) {
	            }
          });
		}
	catch (error) {
		
		}
	}


// 09SEP2008 RFM - Removed since no longer needed with price change
//Initialize();