// JavaScript Document

function OpenWindow(url,windowName,features)
{
	(window.open(url,windowName,features)).focus();
}

function OpenWindowNoFocus(url,windowName,features)
{
	window.open(url,windowName,features);
}

function openJobWindow(link)
{
	window.open(link, "_blank", "toolbar=no, location=no, menubar=yes, resizable=yes, width=600, height=400");
} 

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function ScrollTo(ElementName)
{
		var el = document.all(ElementName)
		if(el !=null)
		{
			document.body.scrollTop= findPosY(el)
		}//if not null
}//ScrollTo
/*------------------------- DreamWaver support function -------------------------*/

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

//********************************Session Cookie**************************************/
//-------------------------------GetCookieValue()----------------------
function GetCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}
//-------------------------------TestSessionCookie()----------------------
function TestSessionCookie () {
 
  document.cookie ="SessionCookie=ok";
  el = document.all("SessionEnabled");
  if (GetCookieValue ("SessionCookie")!="ok")
  {
	if(el!=null)
		el.value = "false";
	alert("Warning: Unable to set cookie. To log on to our system, please set your browser to allow cookie.\n\nFor more information, please click on [Help] in the menu above then click on [Log on Questions] in the submenu at left. If you have any question, please contact us.");   
  }
  else
  {
	if(el!=null)
		el.value = "true";
   
  }
}

/**************************** Test Pages Start *************************************/
function LoadPageToFrame(url,frameName)
{
	var frame = document.all(frameName)
	//check if frameName is valid
	if(frame !=null)
	{
		frame.src = url;
	}//if frame not null
}//LoadPageToFrame


function ShowChapter(chapterPath)
{
	
	document.all("ifrMaterial").src=chapterPath;	
	document.all("chapterURL").value=chapterPath;	
	
}

function ShowChapterWithinIframe(linkInsideFrame)
	{	
		if(parent.document.all("chapterURL"))
			parent.document.all("chapterURL").value=linkInsideFrame.href;	
	}
function IsAllQuestionAnswered(totalQuestions)
{
	arr = document.getElementsByTagName("input")
	var cnt=0;
	for(var i = 0;i<arr.length;i++)
	{
		if(arr[i].type=="radio")
			if(arr[i].checked)
				cnt++
	}
	if(cnt < totalQuestions)
	{
		alert("You have not answered all questions. Please verify and submit again.")
		return false;
	}
	return true;
}
/**************************** Test Pages End *************************************/

/**************************** Course *************************************/

function WriteCourseChapters(chapterCnt,currentChapter)
	{

		history.forward();
		var currentUrl = window.location.href;
		var courseName ="";
		var rootPath = "";
		var strLink="";
		//write chapter links
		document.write("<table width=\"100%\" cellpadding=\"3px\" border=\"0\">");
		document.write("<tr>");
		document.write("<td class='CourseMaterialIndexText' width=\"100px\">Chapter(s):</td>");
		rootPath = currentUrl.substring(0,currentUrl.lastIndexOf('/')+1);
		courseName = currentUrl.substring(currentUrl.lastIndexOf('/')+1,currentUrl.lastIndexOf('_'));
				
		for(var i=1;i<=chapterCnt;i++)
		{
			
				if(currentChapter==i)
				{
					strLink ="<td class=\"CourseMaterialIndexText\" width=\"2%\">" +i + "</td>"
				}
				else
				{
					strLink = "<td class=\"CourseMaterialIndexText\" width=\"2%\"><a href=\"" + rootPath + courseName +"_chapter"+ i + ".htm\" onclick=\"ShowChapterWithinIframe(this);\">" + i +"</a> </td>"			
				}
				
				document.write(strLink)
		}
		//write content
		if(currentChapter=="content")
			strLink ="<td class=\"CourseMaterialIndexText\" width=\"2%\">Content</td>"
		else
			strLink = "<td class=\"CourseMaterialIndexText\" width=\"2%\"><a href=\"" + rootPath + courseName +"_content.htm\" onclick=\"ShowChapterWithinIframe(this);\">Content</a></td>"			
		document.write(strLink)
		document.write("<td>&nbsp;</td>")
		
		//write Print Material link
		strLink = "<td width=\"250px\" align=\"right\"><img height=\"30\" src=\"../../images/printer_dark.jpg\" width=\"30\">&nbsp;&nbsp;";
		strLink += "<a class=\"CourseMaterialIndexText\" href=\"javascript:;\" onclick=\"OpenWindowNoFocus('" + rootPath+ courseName +"_print.pdf','_blank','width=550,height=600,resizable,scrollbars');\">Print Material</a></td>"			

		document.write(strLink)
		document.write("</tr></table>");

	}


var font_size = "1em;" //follow up later, may not need this var
function gobig(){

	var elementList = document.getElementsByName("text"), fs = 16;
	for (i=0;i<elementList.length;i++){
		el = elementList[i]
		if (el != null){
			fs = el.style.fontSize;
			if (fs.indexOf("px") > -1){
				fs = fs.substr(0,fs.indexOf("px"));
				fs = parseFloat(fs) + 1;
			}else fs = 16;
		el.style.fontSize = fs + "px";
		}
	}
	
}
function gosmall(){

	var elementList = document.getElementsByName("text"), fs = 14;
	for (i=0;i<elementList.length;i++){
		el = elementList[i]
		if (el != null){
			fs = el.style.fontSize;
			if (fs.indexOf("px") > -1){
				fs = fs.substr(0,fs.indexOf("px"));
				fs = parseFloat(fs) - 1;
			}else fs = 14;
			el.style.fontSize = fs + "px";
		}
	}
}

/**************************** End Course *************************************/
//-----------------------------CheckListBoxSelect()----------------------------
function CheckListBoxSelect(name)
{
	el 			= document.all(name);
	retVal  	= true;
	isShowAll	= false;
	isNonShowAll= false;
	
	if(el != null)
	{
		for(var i =0;i<el.length;i++)
		{
			if(el.options[i].selected)
			{
				if(el.options[i].value==0)
					isShowAll=true;
				if(el.options[i].value!=0)
					isNonShowAll=true;
			}
		}
		if(isShowAll && isNonShowAll)
		{
			if(confirm("You've selected <Show All> and one or more different Seminar Areas. Do you want to show seminars in ALL cities?"))
				retVal=true
			else
				retVal = false
		}
	}//if list exists
	return retVal;
}//CheckListBoxSelect()


/************************************* Midas ********************************************/
//--------------------------------- Begin MProfile -----------------------------------
function DistEmpYes_onClick(distEmpNoID)
{
	/*
	if (confirm("This will remove all of your entered information on questions 4, 5, 6, 8, 9, and 10. \r\n\r\nAre you sure?"))
		return true;
	else
	{
		document.getElementById(distEmpNoID).checked = true;
		return false;
	}
	*/
	
	alert("Please skip questions 4, 5, 6, 8, 9, and 10. These questions are optional to Midas distributor's employee.");
	
	return true;	
}

//--------------------------------- End MProfile -----------------------------------






