// Charset: utf8 (αινσϊ)

/*******************************************************************/
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();
}
/*******************************************************************/

/********************************************************************
	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);
	} else if (scormID.substring(0,5) == "ielts") {
		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 if (document.location.hostname == "dev.office.netlanguages.com") {
		url = "http://discovia.office.netlanguages.com:2000/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')
}


function nl_popupPurchase(url) { nl_popupWindow(url,'purchase',620,450,'mrlsx'); }
function nl_popupContactUs(url) { nl_popupWindow(url,'contactus',650,650,'rs'); }
function nl_popupNewsletter(url) { nl_popupWindow(url,'newsletter',530,400,'rs'); }
function nl_popupTestYourComputer(url) { nl_popupWindow(url,'technical',650,640,'rs'); }
function nl_popupPrivacyPolicy(url) { nl_popupWindow(url,'privacy',650,400,'rs'); }
function nl_popupLevelTest(url) { nl_popupWindow(url,'newsletter',650,795,'rs'); }
function nl_popupSampleSelector(url) { nl_popupWindow(url,'sample',950,600,'rs'); }
