// popup was blocked, inform user
function popupNotice()
{
	var msg = "Sorry, it appears your settings have blocked a window from popping up.\nWould you like to visit our popup info page which gives instructions on changing your settings?"
	var info_path = "../folder_demo/popup_info.html"
	//var fRet; 
	//fRet = confirm(msg);
	//if (fRet)
	//{
		//if(parent.opener) { parent.opener.location = info_path; top.close(); }
		if(parent.opener) { parent.opener.location = info_path; }
		else window.location = info_path;
	//}
}

// launches a new window centrally on screen
function popUpWindow()
{
	a = arguments;
	var xPos = (screen.availWidth - a[2]) / 2;
	var yPos = (screen.availHeight - a[3]) / 2;
	var openMe = window.open(a[0],a[1],"width="+a[2]+","+"height="+a[3]+",screenX="+xPos+",screenY="+yPos+",left="+xPos+",top="+yPos+",resizable=yes");

	// check if the popup window was allowed (avoids openMe is null debug message when window is blocked)
	if (openMe == null || openMe == "undefined") popupNotice();
	else openMe.focus();
}

// redirect to login checker function - avoided modifying all launch location links!!!
function launchCourse(courseChoice)
{
	openLoginChecker(courseChoice);
}

function openLoginChecker(courseChoice)
{
	var xPos = (screen.availWidth - 400) / 2;
	var yPos = (screen.availHeight - 450) / 2;
	var file = "../folder_demo/check_login.asp?" + courseChoice;
	openMe = open(file,'loginwin',"width=400,height=450,screenX="+xPos+",screenY="+yPos+",left="+xPos+",top="+yPos+",resizable=no");
	
	// check if the popup window was allowed (avoids openMe is null debug message when window is blocked)
	if (openMe == null || openMe == "undefined") popupNotice();
	else openMe.focus();
}

// actual course launch function
function launchCourseFromChecker(courseChoice)
{
	var xPos = (screen.availWidth - 780) / 2;
	var yPos = (screen.availHeight - 480) / 2;

	var aicc_sid = "aicc_sid=123456";
	var aicc_url = "aicc_url=none";
	var lms = "trainercd";
	var invoker = "../folder_demo/balance_courses/balance/html/launch.html";

	var dimensionChoice = "knowledge_dimension";
	var courseChoice = courseChoice.split(":");
	var languageChoice = "enus";

	if (courseChoice[3]) var menuFile = "demo_menu_"+courseChoice[3]+".asp";
	else var menuFile = "demo_menu.asp";

	var userDetail = "user_detail=" + document.forms.userData.userEmail.value + "|" + courseChoice[2]+"_"+languageChoice;
	
	var menuLink = menuFile + "?" + userDetail;
	var path = "course="+dimensionChoice+"/"+courseChoice[0]+"/html/"+menuLink+"&coursePath=/"+courseChoice[1]+"/"+courseChoice[2]+"_"+languageChoice;
	var fullPath = invoker + "?" + aicc_sid + "&" + aicc_url + "&" + path + "&trainer=demotrainer@democompany.com&lms=" + lms;

	//var fullPath = unescape(escapedFullPath)
	openMe = open(fullPath,'coursewin',"width=780,height=480,screenX="+xPos+",screenY="+yPos+",left="+xPos+",top="+yPos+",resizable=yes");

	// check if the popup window was allowed (avoids openMe is null debug message when window is blocked)
	if (openMe == null || openMe == "undefined") { popupNotice(); return false; }
	else { openMe.focus(); return true; }
}

// open login.asp in popup
function openLoginWindow()
{
	var xPos = (screen.availWidth - 400) / 2;
	var yPos = (screen.availHeight - 450) / 2;
	openMe = open("../folder_demo/login.asp",'loginwin',"width=400,height=450,screenX="+xPos+",screenY="+yPos+",left="+xPos+",top="+yPos+",resizable=no");

	// check if the popup window was allowed (avoids openMe is null debug message when window is blocked)
	if (openMe == null || openMe == "undefined") popupNotice();
	else openMe.focus();
}

function initTip()
{
	return;
}

function checkFields()
{
	if(document.forms[0].username.value=="")
	{
		alert('Please enter your user name');
		document.forms[0].username.focus();
		return false;
	}
	else if (document.forms[0].userpwd.value=="")
	{
		alert('Please enter your password');
		document.forms[0].userpwd.focus();			
		return false;
	}
	else return true;
}
