var inputType        = (userType == "Internal") ? "checkbox"            : "hidden";
var debugTxt         = (userType == "Internal") ? "Debug Mode"          : "";
var debugBehaviorTxt = (userType == "Internal") ? "Debug Behavior"      : "";
var reviewerTxt      = (userType == "Internal") ? "Reviewer Mode"       : "";
var editShowTextTxt  = (userType == "Internal") ? "Edit Show Text Mode" : "";
var rma508Txt        = (userType == "Internal") ? "RMA Mode"            : "";
//var pathToRoot       = "../";
var pathToRoot       = "";
var wndw;

function launchCurrent() {
	var tgtURL = dfltModulePath + "module.htm" + getModeParamString();
//alert("1. tgtURL " + tgtURL);
	var startPt = (startPoint == undefined) ? "default" : startPoint;
	if (startPt == "LastVisitedModule") {
		tgtURL = getLastVisitedURL(tgtURL);
//alert("2. tgtURL " + tgtURL);
	}
	launchURL(tgtURL);
}


function launchGuidedTour() {
	var tgtURL = "guidedtour/module.htm" + getModeParamString();
	launchURL(tgtURL);
}

function launchNew() {
	startRefreshMovie();

	var startPt = (startPoint == undefined) ? "default" : startPoint;

	if (startPt == "LastVisitedModule") {
		clearStatusForAllModules();
	}
	else {
		clearStatusForModule();
	}

	//  Open the module in the refresh window.
	setTimeout("redirectRefreshWindow();", 3000);
}

function launchBrowserTest() {
	launchURL(pathToRoot + "common/cw/htm/browsertest.htm");
}

function launchURL(url) {
//alert("launching " + url);
	var wndwFeatures = "width=" + flashwidth + ",height=" + flashheight + ",resizable=0,status=0,scrollbars=0";
	wndw = window.open(url, 'content', wndwFeatures);
	wndw.focus();
}

function redirectRefreshWindow() {
	wndw.location.href = dfltModulePath + "module.htm" + getModeParamString();
	wndw.focus();
}

function getLastVisitedURL(dfltStartPt) {
	var cookieName  = getParameterCookieName();
//alert("cookieName = " + cookieName);
	var paramcookie = readCookie(cookieName);
//alert("paramcookie = " + paramcookie);
	if (paramcookie == false) {
		return dfltStartPt;
	}
	var idx1 = paramcookie.indexOf("LastVisitedModule=");
	if (idx1 < 0) {
		return dfltStartPt;
	}
	var idx2 = paramcookie.indexOf("&", idx1);

	var lastVisitedModule = paramcookie.substring((idx1 + "LastVisitedModule=".length), idx2);
	return pathToRoot + lastVisitedModule + "/module.htm" + getModeParamString();
}

function clearStatusForModule() {
	var cookieName = getParameterCookieName();
//alert("1. delete cookie: " + cookieName + ", peth: " + cookiePath);
	deleteCookie(cookieName, cookiePath);

	//  Need to clear the thisAU portion of the links cookie also.
	cookieName = getParameterCookieName();
	var cookieValue = readCookie(cookieName);
	if (!cookieValue) {
		return;
	}

	var idx1 = cookieValue.indexOf(thisAU + "=");
	if (idx1 < 0) {
		return;
	}

	var idx2 = cookieValue.indexOf("&", idx1);
	if (idx2 < 0) {
		return;
	}

	var newValue = cookieValue.substring(0, idx1) + cookieValue.substring((idx2 + 1));
	setCookie(cookieName, newValue);
}

function clearStatusForAllModules() {
	var linkCookieName  = getParameterCookieName();
	var cookieValue = readCookie(linkCookieName);
//alert("2. delete cookie: " + linkCookieName + ", cookieValue: " + cookieValue);
	if (!cookieValue) {
		return;
	}

//alert("1. Clear all modules: " + linkCookieName + " = " + cookieValue);
	var aus = cookieValue.split("&");
	for (var i = 0; i < aus.length; i++) {
		var idx = aus[i].indexOf("=");
		if (idx > 0) {
			var auCookieName = aus[i].substring(0, idx) + "_Params";
//alert("2. Clearing module " + auCookieName);
			deleteCookie(auCookieName, cookiePath);
		}
	}

	deleteCookie(linkCookieName, cookiePath);
}

function startRefreshMovie() {
//alert(thisAU);
	var refreshURL = pathToRoot + "common/controller/htm/refresh.htm?thisAU=" + thisAU + "&flashwidth=" + flashwidth + "&flashheight=" + flashheight;
	launchURL(refreshURL);
}

function validateShell() {
	var scriptURL = "http://venusii.teamcarney.com/cgi-bin/verifyShell.pl?tgtDir=" + window.location.href;
	var wndwFeatures = "width=1200,height=550,resizable=yes,status=0,scrollbars=yes";
	resultsWndw = window.open(scriptURL, 'scriptResults', wndwFeatures);
	resultsWndw.focus();
}

function getModeParamString() {
	var paramStr = getURLParamsString();

	var frm = document.forms[0];
	if (frm.debugMode.checked) {
		paramStr +="debugMode=1&";
	}
	if (frm.debugBehavior.checked) {
		paramStr +="debugBehavior=1&";
	}
	if (frm.reviewerMode.checked) {
		paramStr +="reviewerMode=1&";
	}
	if (frm.showTextEditMode.checked) {
		paramStr +="showTextEditMode=1&";
	}
	if (frm.accessibilityMode.checked) {
		paramStr +="accessibilityMode=1&";
		paramStr +="debug508=1&";
	}
	return (paramStr == "") ? "" : "?" + paramStr;
}

//  This function is used to ensured that all parameters passed into
//  this page are relayed to module.htm.
function getURLParamsString() {
	var paramStr = "";
	for (var paramName in urlParams) {
		paramStr = paramStr + paramName + "=" + urlParams[paramName] + "&";
	}
	return paramStr;
}

function writeLaunchPage() {
	document.write('<HTML>');
	document.write('<HEAD>');
	document.write('  <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>');
	document.write('  <STYLE type="text/css">');
	document.write('    td {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #000000}');
	document.write('  </STYLE>');
	document.write('  <TITLE>' + title + '</TITLE>');
	document.write('</HEAD>');
	document.write('<BODY bgcolor="#cccccc" text="#000000">');
	document.write('    <NOSCRIPT>');
	document.write('        Your browser does not support JavaScript. JavaScript is required to view this course.');
	document.write('    </NOSCRIPT>');
	document.write('    <TABLE WIDTH="750" BORDER="0" CELLSPACING="1" CELLPADDING="0" ALIGN="center" BGCOLOR="#666666">')
	document.write('      <tr>');
	document.write('        <td bgcolor="#FFFFFF">');
	document.write('          <IMG height=150 src="' + pathToRoot + 'common/cw/images/launchPgImage.jpg" width=750> ');
	document.write('          <br>&nbsp;&nbsp;');
//	document.write('          <TABLE BORDER="0" width = "735" align="center">');
//	document.write('            <tr>');
//	document.write('              <td>You are about to view the alpha lesson for <b>Principles of Automotive Air Conditioning</b>. This alpha lesson consists of a presentation screen that focuses on the air conditioning system\'s compressor and demonstrates graphics, animation, popups, and rollovers as well as 2 checks on learning.  Prior to viewing the compressor screens, students will have had an overall review of the A/C cycle and an introduction to the A/C components in vehicles. This alpha lesson will take approximately 5-10 minutes to complete. To start the alpha lesson, select "Launch New Principles of Automotive Air Conditioning Alpha Lesson". ');
//	document.write('              </td>');
//	document.write('            </tr>');
//	document.write('          </table>');
	//document.write('        </A>');
	document.write('		<br>&nbsp;&nbsp;<A href="javascript:launchGuidedTour();">');
	document.write('		Launch Guided Tour');
	document.write('		</A>');
	document.write('        <BR>&nbsp;&nbsp;');
	document.write('        <br>&nbsp;&nbsp;');
	document.write('        <A href="javascript:launchNew();">');
	document.write('          Launch New <B>' + shortTitle + '</B>');
	document.write('        </A>');
	document.write('        <BR><BR>&nbsp;&nbsp;');
	document.write('        <A href="javascript:launchCurrent();">');
	document.write('          Continue Current <B>' + shortTitle + '</B>');
	document.write('        </A>');
	document.write('        <BR><BR>&nbsp;&nbsp;');
	document.write('        <FORM>');
	document.write('          &nbsp;&nbsp;');
	document.write('          <INPUT type=' + inputType  +' name=debugMode>'         + debugTxt         + '&nbsp;&nbsp;');
	document.write('          <INPUT type=' + inputType  +' name=debugBehavior>'     + debugBehaviorTxt + '&nbsp;&nbsp;');
	document.write('          <INPUT type=' + inputType  +' name=reviewerMode>'      + reviewerTxt      + '&nbsp;&nbsp;');
	document.write('          <INPUT type=' + inputType  +' name=accessibilityMode>' + rma508Txt        + '&nbsp;&nbsp;');
	document.write('          <INPUT type=' + inputType  +' name=showTextEditMode>'  + editShowTextTxt  + '&nbsp;&nbsp;');
	document.write('        </FORM>');
	document.write('      </td>');
	document.write('    </tr>');
	document.write('  </table>');
	document.write('</BODY>');
	document.write('</HTML>');
}


