/*******************************************************************/
function nl_popupWindow(url,target,width,height,opts)
/*
	Returns: (nothing)

	Required parameters:
	·	url: address of page to load in popup window, usually: this.href
	·	target: the name to give to the new window (for reusing windows)

	Optional parameters:
	·	width: (integer) only used if height is also specified
	·	height: (integer)
	·	opts: (string) specify which elements to display in the window:
			l - location (or address) bar
			m - menu bar (useful for access to the file menu for printing)
			r - resizable (usually this should be specified)
			s - scroll bars (usually this should be specified)
			t - tool bar (back, forward, reload, stop, etc)
			x - status bar

			e.g. 'mrs' means display menu bar, allow window to be resized
			and display scrollbars if content is too big for window
********************************************************************/
{
	var p = null;
	if (width == null || height == null) {
		p = null
	}
	else if (opts == null) {
		p = "width="+width+",height="+height
	}
	else
	{
		p = "width="+width+",height="+height

		opts = opts.toString().toLowerCase();

		if (opts.indexOf("l") >= 0) p += ",location=1"
		if (opts.indexOf("m") >= 0) p += ",menubar=1"
		if (opts.indexOf("r") >= 0) p += ",resizable=1"
		if (opts.indexOf("s") >= 0) p += ",scrollbars=1"
		if (opts.indexOf("t") >= 0) p += ",toolbar=1"
		if (opts.indexOf("x") >= 0) p += ",status=yes"
	}

	var x = window.open(url,target,p)
	if (x.focus) x.focus();
}
/*******************************************************************/

function openHowItWorksWindow(url) { nl_popupWindow(url,'howitworks',545,385,'x'); }
function nl_popupEmailAFriend(lang,url) { nl_popupWindow(url,'emailafriend',450,300,'rs'); }
function nl_popupContactUs(lang,url) { nl_popupWindow(url,'contactus',530,450,'rs'); }
function nl_popupNewsletter(lang,url) { nl_popupWindow(url,'newsletter',530,400,'rs'); }
function nl_popupPurchase(lang,url) { nl_popupWindow(url,'purchase',620,450,'mrlsx'); return false; }

/********************************************************************
	Opens a popup window to display scorm content:
    lang:				the language of the sample course pages (to determine in which language to display the interface in)
    scormID:		the ID of the scorm package to display
    levelName:	the title bar text, normally the level of the course
    courseType:	the type of course, used by the player to display different interfaces (defaults to a standard English player)
*/
function nl_popupSample(lang,scormID,levelName,courseType) {
	// jump to new version for GE
	if (scormID.substring(0,7) == "en-gen-") {
		scormID = "en-ge-" + scormID.substring(7,scormID.length);
		return nl_popupNewSample(lang,scormID,levelName,courseType);
	}
	if (scormID.substring(0,6) == "en-ge-") return nl_popupNewSample(lang,scormID,levelName,courseType);

	var windowWidth = 900;
	var windowHeight = 540;
	var url = document.location.href;
	url = url.substring(0,url.indexOf("/information/"));

	// Have to hard code this until constants.asp is available on all mirror sites
	if (document.location.hostname == "sol") {
		url = "http://sol";
	}else {
		url = "http://www.netlanguages.com";
	}

	url += "/information/player/start.htm";
	url += "?sco=" + scormID;

	// guess the name of the course from the scormID if level name is not supplied
	if (levelName == null) {
		if (scormID == "vyl-a-sample") {
			url += "&interface=vyl";
			windowWidth = 940;
			windowHeight = 680;
		} else if (scormID.indexOf("es-gen-l1-") == 0) {
			url += "&level=PreElemental";
		} else if (scormID.indexOf("es-gen-l2-") == 0) {
			url += "&level=Elemental";
		} else if (scormID.indexOf("es-gen-l3-") == 0) {
			url += "&level=Intermedio Bajo";
		} else if (scormID.indexOf("es-gen-l4-") == 0) {
			url += "&level=Intermedio";
		} else if (scormID.indexOf("es-gen-l5-") == 0) {
			url += "&level=Intermedio Alto";
		} else if (scormID.indexOf("es-gen-l6-") == 0) {
			url += "&level=PreAvanzado";
		} else if (scormID.indexOf("es-gen-l7-") == 0) {
			url += "&level=Avanzado";
		}
	} else {
		url += "&level=" + levelName;
	}

	url += "&logout=&returnto="; // is a sample so pass these empty to ensure these links just close the window
	if (lang == "es") {
		url += "&lang=es&sample=Material%20de%20muestra";
	} else {
		url += "&sample=Sample%20Material";
	}
//	url += "&topimage="; // deprecated
	url += "&root=samples";
	url += "&path=/information/"; // the location within the URL where the root of the scorm content can be found

	if (courseType == null) {
		// use the id of the SCORM sample to guess the top image required
		if (scormID.indexOf("efd-") == 0) {
			// English for Doctors
			url += "&topimage=englishfordoctors.jpg";
		} else if (scormID.indexOf("ge-") == 0) {
			// General English
			url += "&topimage=ge.jpg";
		} else if ((scormID.indexOf("vocpt-") == 0) || (scormID.indexOf("grpt-") == 0) || (scormID.indexOf("lspt-") == 0) || (scormID.indexOf("prpt-") == 0)) {
			// Practice Courses
			url += "&topimage=practicecourses.jpg";
		}
	} else {
		switch(courseType) {
			case "practicecourse":
				url += "&topimage=practicecourses.jpg";
				break;
		}
	}

//alert(url);
	nl_popupWindow(url,'sample',windowWidth,windowHeight,'rsx')
}
/********************************************************************
	Opens a popup window to display scorm content:
    lang:				the language of the sample course pages (to determine in which language to display the interface in)
    scormID:		the ID of the scorm package to display
    levelName:	the title bar text, normally the level of the course
    courseType:	the type of course, used by the player to display different interfaces (defaults to a standard English player)
*/
function nl_popupNewSample(lang,scormID,levelName,courseType) {
	var windowWidth = 900;
	var windowHeight = 540;
	var url = document.location.href;
	url = url.substring(0,url.indexOf("/information/"));
	var rootStr,pathStr

	// Do something different if on dev server
	if (document.location.hostname == "sol") {
		url = "http://discovia/discovia";
		rootStr = "samples"
		pathStr = "/samples/"
	}else {
		url = "http://sample.netlanguages.com/sample";
		rootStr = "samples"
		pathStr = "/samples/"
	}

	url += "/samples/player/start.htm";
	url += "?sco=" + scormID;

	// guess the name of the course from the scormID if level name is not supplied
	if (levelName == null) {
		if (scormID == "vyl-a-sample") {
			url += "&interface=vyl";
			windowWidth = 940;
			windowHeight = 680;
		} else if (scormID.indexOf("es-gen-l1-") == 0) {
			url += "&level=PreElemental";
		} else if (scormID.indexOf("es-gen-l2-") == 0) {
			url += "&level=Elemental";
		} else if (scormID.indexOf("es-gen-l3-") == 0) {
			url += "&level=Intermedio Bajo";
		} else if (scormID.indexOf("es-gen-l4-") == 0) {
			url += "&level=Intermedio";
		} else if (scormID.indexOf("es-gen-l5-") == 0) {
			url += "&level=Intermedio Alto";
		} else if (scormID.indexOf("es-gen-l6-") == 0) {
			url += "&level=PreAvanzado";
		} else if (scormID.indexOf("es-gen-l7-") == 0) {
			url += "&level=Avanzado";
		}
	} else {
		url += "&level=" + levelName;
	}

	url += "&logout=&returnto="; // is a sample so pass these empty to ensure these links just close the window
	if (lang == "es") {
		url += "&lang=es&sample=Material%20de%20muestra";
	} else {
		url += "&sample=Sample%20Material";
	}
//	url += "&topimage="; // deprecated
	url += "&root=" + rootStr;
	url += "&path=" + pathStr; // the location within the URL where the root of the scorm content can be found

	if (courseType == null) {
		// use the id of the SCORM sample to guess the top image required
		if (scormID.indexOf("efd-") == 0) {
			// English for Doctors
			url += "&topimage=englishfordoctors.jpg";
		} else if (scormID.indexOf("ge-") == 0) {
			// General English
			url += "&topimage=ge.jpg";
		} else if ((scormID.indexOf("vocpt-") == 0) || (scormID.indexOf("grpt-") == 0) || (scormID.indexOf("lspt-") == 0) || (scormID.indexOf("prpt-") == 0)) {
			// Practice Courses
			url += "&topimage=practicecourses.jpg";
		}
	} else {
		switch(courseType) {
			case "practicecourse":
				url += "&topimage=practicecourses.jpg";
				break;
		}
	}

//alert(url);
	nl_popupWindow(url,'sample',windowWidth,windowHeight,'rsx')
}

var rolloverCurrent = undefined;
function rolloverWriteStyles() {
	if (!document.getElementById) return;
	document.write('<style type="text/css" media="screen">\n');
	document.write('.rollover-section {\n');
	document.write('display:none;\n');
	document.write('margin: 30px 0px 0px 0px;\n');
	document.write('}\n');
	document.write('</style>\n');
}

function rolloverSectionOver(s)
{
	if (!document.getElementById) return;

	if (rolloverCurrent != undefined) rolloverCurrent.style.display = "none";
	rolloverCurrent = document.getElementById(s);
	document.getElementById(s).style.display = "block";
}

function rolloverSectionOut(s)
{
	return;

	if (!document.getElementById) return;

	if (rolloverCurrent != undefined) rolloverCurrent.style.display = "none";
	rolloverCurrent = undefined;
}

function selectedLanguage(s)
{
	if (s.selectedIndex != 0)
	{
		document.location = s.options[s.selectedIndex].value;
	}
}

function writeLanguageSelecter(lang)
{
	var s;
	switch(lang) {
		case "spanish":
			s = "seleccionar idioma...";
			break;
		default:
			s = "select language..."
	}
	document.write('<form>');
	document.write('<img src="../images/header_bullet.gif" width="10" height="11" hspace="5">');
	document.write('<select onchange="selectedLanguage(this)" class="formulario">');
	document.write('<option value="">'+s+'</option>');
	document.write('<option value="../english/index.htm">English</option>');
	document.write('<option value="../spanish/index.htm">Espa&ntilde;ol</option>');
/*	document.write('<option value="../french/index.htm">Fran&ccedil;ais</option>');
	document.write('<option value="../italian/index.htm">Italiano</option>');
	document.write('<option value="../russian/index.htm">&#1056;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081;</option>');
	document.write('<option value="../chinese/index.htm">&#20013;&#25991;</option>');
*///	document.write('<option value="../czech/index.htm">Czech</option>');
	document.write('</select>');
	document.write('</form>');
}



function writeLanguageList(lang)
{
	document.write('<ul class="indent">');
	document.write('<li><a href="../english/index.htm">English</a></li>');
	document.write('<li><a href="../spanish/index.htm">Espa&ntilde;ol</a></li>');
/*	document.write('<option value="../french/index.htm">Fran&ccedil;ais</option>');
	document.write('<option value="../italian/index.htm">Italiano</option>');
	document.write('<option value="../russian/index.htm">&#1056;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081;</option>');
	document.write('<option value="../chinese/index.htm">&#20013;&#25991;</option>');
*///	document.write('<li><a href="../czech/index.htm">Czech</a></li>');
	document.write('</ul>');
}



function nl_frameMePlease(lang,title)
{
//	return;
	var newURL;

	if (parent != self)
	{
//		alert("Already framed");
		return;
	}
//	alert("Framing...");

	var pathToLang = document.location.href;

	if (pathToLang.indexOf("/information/") >= 0) {
		pathToLang = pathToLang.substring(0,pathToLang.lastIndexOf("/information/"+lang+"/"));
		pathToLang += "/information/"+lang

	} else if (pathToLang.indexOf("/level-tests/") >= 0) {
		pathToLang = pathToLang.substring(0,pathToLang.lastIndexOf("/level-tests/"));
		pathToLang += "/information/"+lang

	} else {
		return;

	}

//alert(pathToLang);
	var html =
		'<html>'+
		'<head>'+
		'<title>'+title+'</title>'+
		'</head>'+
		'<frameset rows="*,22" border="0" framespacing="0" frameborder="NO">' +
		'<frame src="'+document.location.href+'" frameborder="NO" name="content">' +
		'<frame src="'+pathToLang+'/popup/copyright.htm" frameborder="NO" name="copyright" noresize scrolling="NO">' +
		'</frameset>'+
		'</html>';

//	alert(html);
//	return;

	newURL = pathToLang + "/popup/index.htm?l="+escape(document.location)+"&t="+escape(document.title);
	document.location = newURL;

//	document.open();
//	document.write(html);
//	document.close();
}

// Event Binding Code
function nl_onLoad() {
  if (null == document.nl_config) { alert("General initialisation failed!  Please contact webteam@netlanguages.com."); return; }
  if (null == document.nl_config.onload) { alert("ONLOAD initialisation failed!  Please contact webteam@netlanguages.com."); return; }
  eval (document.nl_config.onload);
  document.nl_config.loaded = true;
}
function nl_onUnload() {
  if (null == document.nl_config) { alert("General initialisation failed!  Please contact webteam@netlanguages.com."); return; }
  if (null == document.nl_config.onunload) { alert("ONUNLOAD initialisation failed!  Please contact webteam@netlanguages.com."); return; }
  eval (document.nl_config.onunload);
}
function nl_wrap(nl_code) {
  if (null == document.nl_config) { alert("General initialisation failed!  Please contact webteam@netlanguages.com."); return; }
  if (! document.nl_config.loaded) { alert("Please wait until the page has finished loading before doing the exercises!"); return; }
  eval(nl_code);
}
function _addEvent(ev,code) {
  if (ev.toLowerCase() == "onload") this.onload += code + ";\n ";
  else if (ev.toLowerCase() == "onunload") this.onunload += code;
  else alert("Event '"+ev+"' not supported\nCould not bind '"+code+"'.");
}
document.nl_config = new Object();
document.nl_config.loaded=false; document.nl_config.onload="";
document.nl_config.onunload=""; document.nl_config.add = _addEvent;
window.onload=nl_onLoad;
window.onunload=nl_onUnload;
// End of Event Binding Code
