function sniffBrowser()
{
	var bWin, bMSIE, bMSIE55, bMSIE6, bMSIE7, bMSIE8;
	var ua = window.navigator.userAgent;

  bWin = (ua.indexOf("Windows") != -1);
  bMSIE = (ua.indexOf("MSIE") != -1);
	if (bWin && bMSIE)
  {
    bMSIE55 = (ua.indexOf("MSIE 5.5") != -1);
    bMSIE6 = (ua.indexOf("MSIE 6.0") != -1);
    bMSIE7 = (ua.indexOf("MSIE 7.0") != -1);
    bMSIE8 = (ua.indexOf("MSIE 8.0") != -1);
    if (!bMSIE55 && !bMSIE6 && !bMSIE7 && !bMSIE8)
			alert(getTranslate("cxt2410000PmNtUnsupportedIE"))
	}
  else
		alert(getTranslate("cxt2410000PmNtOnlyMicrosoftIE"))
}


function validateData(form)
{
	var password = form.Password.value;
  var length = password.length;
  var uFlag = false;
  var pFlag = false;
	   
  if (form.UserName.value != "")
  {      
    if (checkInvalidChars(form.UserName.value))
    {
			uFlag = true;
		}
		else
		{
      fixElement(form.UserName, getTranslate("cxt00LgMsNtUseLettersNumbers"));
			form.UserName.value = "";
			return uFlag;
		}	
  }
	else
	{
    fixElement(form.UserName, getTranslate("cxtCoLgNtUserName"));
		form.UserName.value = "";
		return uFlag;
	}	

  if (password != "")
  {      
    if (length <= 4)
    {
      fixElement(form.Password, getTranslate("cxtMfMsNt5Characters"));
			form.Password.value = ""
    }      
    else
    {      
      if (checkInvalidChars(password))
      {
				pFlag = true;
			}
			else
			{
			  fixElement(form.Password, getTranslate("cxtMfMsNtUseLetters"));
				form.Password.value = "";
			}	
    }
  }
	else
	{
    fixElement(form.Password, getTranslate("cxtCoLgNtPassword"));
		form.Password.value = "";
	}

  if (form.Loc != null && form.Loc.value == "")
  {
		fixElement(form.Loc, "Please select your location.");
		//fixElement(form.Loc, getTranslate(""));
		return false;
	}	
	return uFlag && pFlag;
} 

function checkInvalidChars(string) 
{     
	if (/\W/.test(string))
		return false;
	else
		return true;
}   

function fixElement(element, message)
{
	alert(message);
	element.focus();
}
	
function switchBG(btnType, trId)
{
	var elem = document.getElementById(trId);
	switch (btnType)
	{
		case "title":
			if (elem.className == "homeBarButtonT")
				elem.className = "homeBarButtonTH";
			else
				elem.className = "homeBarButtonT";
		break;
			
		case "common":
			if (elem.className == "homeBarButtonI")
				elem.className = "homeBarButtonIH";
			else
				elem.className = "homeBarButtonI";
		break;
			
		case "last":
			if (elem.className == "homeBarButtonILast")
				elem.className = "homeBarButtonILastH";
			else
				elem.className = "homeBarButtonILast";
		break;
	}
}

function setFocus() 
{
  document.getElementById("UserName").focus();
}	  
  
function getLastActivity() 
{
	document.frames("lastAct").document.location = "../getLastActivity.asp";
}	  

function getGBVersion() 
{
	if (getCompositeCookie("Student", "GB") == "1")
	{
		if (getCompositeCookie("Student", "GBVer") == null)
		{
			var url = "../GrammarBook/getGBVersion.asp";
			loadData(url, processGBVResponse);
		}
	}
}
	
function plannerFrame(height)
{
	var obj = document.getElementById("plannerFrame");
	if (obj != null)
		obj.height = height;
}

function buildBanner(id, width, height, loaderName, movie, path)
{
	w('<object id="'+id+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+width+'" height="'+height+'">')
		w('<param NAME="movie" VALUE="Banners/'+loaderName+'.swf?flashFileArr='+movie+'&flashFilePath='+path+'">')
		w('<param NAME="quality" VALUE="high">')
		w('<param NAME="bgcolor" VALUE="#FFFFFF">')
		w('<div STYLE="text-align:center;white-space:nowrap;color:#ff0000;font-weight:bold;font-size:1.3em">')
			w('ActiveX control failed to load!<br>Please check browser security settings.')
		w('</div>')
	w('</object>')
}

function buildCorner(id, width, height, movie, varsRoot, cornerPlace)
{
	w('<object id="'+id+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+width+'" height="'+height+'">')
		w('<param NAME="movie" VALUE="'+movie+'?myVarsRoot='+varsRoot+'/myColors.txt&myCorner='+cornerPlace+'">')
		w('<param NAME="quality" VALUE="high">')
		w('<param NAME="bgcolor" VALUE="#FFFFFF">')
		w('<div STYLE="text-align:center;white-space:nowrap;color:#ff0000;font-weight:bold;font-size:1.3em">')
			w('ActiveX control failed to load!<br>Please check browser security settings.')
		w('</div>')
	w('</object>')
}

function doBanner(bannerCode)
{
	switch (bannerCode)
	{
		case "1":
			if (IID == "5230520")
				showRPDemo();
			else
			showGuidedTour();
			break;
		case "2":
			break;
	}
}

function keyboardHandler(e)
{
	if (!e) e = window.event;
	if (e.keyCode == 13)
		processForm()
}

function processForm()
{
	var form = document.getElementById("passwordForm");
	if (validateData(form))
		form.submit();
}

function setIfrSrc(strDivName){
	var crtDiv = document.getElementById(strDivName);
	if(crtDiv){
		var tblColl = crtDiv.all.tags("Table") ;
		for(var i = 0 ; tblColl != null && i < tblColl.length ; i ++){
			var strTbN = tblColl[i].getAttribute("id");
			if(strTbN && strTbN.indexOf("cstobj_IFR") > -1){
				var crtIFR  = tblColl[i].all.tags("IFRAME") ;
				if(crtIFR){
					crtIFR[0].setAttribute("src",crtIFR[0].getAttribute("value"));
					if(IID == "5230520"){
						if(crtIFR[0].parentNode){
							var prntTD = crtIFR[0].parentNode ;
							while(prntTD != null && prntTD.tagName != "DIV")
								prntTD = prntTD.parentNode ;
							
							if(prntTD != null){
								prntTD.style.width = 480 ;
								prntTD = prntTD.parentNode ;
								while(prntTD != null && prntTD.tagName != "TD")
									prntTD = prntTD.parentNode ;
								if(prntTD != null){
									prntTD.width = 480 ;
									
									while(prntTD != null && prntTD.tagName != "TR")
										prntTD = prntTD.parentNode ;
									if(prntTD && prntTD.cells){
										for(var jj = prntTD.cells.length - 1 ;jj > 1 ;jj--)
											prntTD.deleteCell(jj) ;
									}
								}
								
							}

						}				
					}
				}
			}
		}
	}
}

function setNodeVisibility(el,bVisible){
	if(el){
		var arrEl = el.length ? el : new Array(el);
		for(var i = 0 ; i < arrEl.length ; i ++){
			if(arrEl[i] && arrEl[i].style)
				arrEl[i].style.display = bVisible == "True" ? "block" : "none" ;
		}
	}
}

function displayRigth(bArrRh, strArrTbl) {
	for(var i = 0; strArrTbl != null && i < strArrTbl.length; i++){
		for(var j = 0; strArrTbl[i] != null && j < strArrTbl[i].length; j++){
			setNodeVisibility(document.getElementById(strArrTbl[i][j]), bArrRh[i]);
		}
	}
	var tbl = document.getElementById("tbl_DHPMainArea");
	if(tbl)tbl.style.display = "block";
}

function setMsgImages(strImgObj, strTMsgDspl, strMsgDspl){
	var strArrISrc = new Array(Root+"Runtime/Context/"+strTMsgDspl, Root+"Runtime/Context/"+strMsgDspl);
	for(var i = 0; i < strImgObj.length; i++){
		var el = document.getElementById(strImgObj[i]);
		if(el){
			el.src = strArrISrc[i];
		}
	}
}

function switchBGB(){ switchBGCell("homeBarButtonTH","homeBarButtonT"); }

function switchBGN(){ switchBGCell("homeBarButtonIH","homeBarButtonI"); }

function switchBGCell(strHLG,strNRM){
	var trId = event.srcElement ;
	if(trId.tagName != "TD"){
		while(trId != null && trId.tagName != "TD")
			trId = trId.parentNode ;
	}
	if(trId == null)return ;
	trId.className = event.type == "mouseout" ? strNRM : strHLG ;
}

function showAssesment() 
{
	gotoTMS("Ast");
}
						      
function showResources() 
{
	gotoTMS("Res");
}
						 
function showServices()
{
	gotoTMS("Ser");
}      

function showMP3()
{
	var URL = Root + "Runtime/Window.asp?Width=790&Height=450&Title="+"Download Audio"+"&Feature="+"Download Audio"+"&Source=" + Root + "Runtime/audio/code/downloadPage.asp";
	window.open(URL, "MP3", "width=800,height=505,left=0,top=0,resizable=1,scrollbars=0")		
}      

function showDemo(){
	var placementLang = getCompositeCookie("Community", "PLTLanguage");
	var URL = Root + "Runtime/Localization/Demo/" + language + "/demoBG.htm?Lang=" + language + "&forguided=" + placementLang + "&resPath=" + resPath
	window.open(URL, "Demo", "width=562,height=373,left=200,top=200,resizable=no,scrollbars=no,status=yes")		
}

function showGuidedTour(){
	var placementLang = getCompositeCookie("Community", "PLTLanguage");
	var URL = Root + "Runtime/Localization/GuidedTour/" + language + "/guidedTour.htm?Lang=" + placementLang + "&forDemo=" + language;
	window.open(URL, "GuidedTour", "width=796,height=549,left=0,top=0,resizable=no,scrollbars=no,status=yes")		
}

function showPlacementTest(){
	var placementLang = getCompositeCookie("Community", "PLTLanguage");
	var URL = Root + "Runtime/PlacementTest/PlacementIntro.asp?pOnline=true&language=" + placementLang + "&studentId=" + studentId;
	window.open(URL, "PlacementTest", "title=no,status=no,scrollbars=no,toolbar=no,fullscreen=yes")
}

function showAboutED(){
	var lang = getContextLanguage();
	var URL = Root + "Runtime/Window.asp?Width=790&Height=545&Title=cxt00NbBtHome&Feature=cxtHoMnOtLearnAbout&Source=" + Root + "Runtime/Localization/AboutED/" + lang + "/AboutED.asp";
	window.open(URL, "AboutED", "width=800,height=600,left=0,top=0,resizable=no,scrollbars=no")
}

function getCustHPObj(elPrn){
	while(elPrn != null){
		if(elPrn.tagName == "TABLE" && elPrn.getAttribute("id") && elPrn.getAttribute("id").indexOf("eduobj_") > -1)
			break ;
		elPrn = elPrn.parentNode;
	}
	return elPrn ;
}

function openHLink(){
	var elPrn = getCustHPObj(event.srcElement);
	if(elPrn){
		switch(elPrn.getAttribute("id")){
			case	"eduobj_SelfReg":
				register();			
				break ;
		}
	}
}

function replaceTemplateTxt(strTxt,arSeach,arRepl){
	if (strTxt && arSeach){
		for(var i = 0; i < arSeach.length; i ++)
			strTxt = strTxt.replace(new RegExp(arSeach[i],"g"),arRepl[i])
	}
	return strTxt;
}
