var txtControlId=null,globalCursorPos=0,timingTextboxIndex,getSelect,GlossaryWindow,VerbChartWindow,TutorialWindow,eBookWindow,CharFlag=false,temp=0,ResourceBarConst=1;
var strControls="txtHours,txtMinutes,txtEstMinutes,txtEstHours,txtMaxScore,txtHeight,txtWidth,txtTolerenceX,txtTolerenceY,txtWrongAnswerScore,ucPreference_txtMinutes,ucPreference_txtSeconds,txtNoOfRows,txtNoOfColumns,txtMinChoice,txtMaxChoice,txtinCorrect,txtScore,txtinRange,txtScoreCorrect,txtWrongScore,txtNumberOfLines,txtthreshold,txtAssessmentHours,txtAssessmentTiming,txtNoOfQuestions,txtAttemptsallowed,txtBuzzerTime,txtNoQues,txtAllowAttempts,txtMin,txtHour,txtNumOfQuestion,txtDurHH,txtDurMM,txtThreshHoldScore,txtCorrectAnswer,txtRangeMinus,txtRangePlus,txtScore,txtIncr,txtScoreYes,txtScoreNo,txtNumberOfWords,ucPreference_txtMinutes,ucPreference_txtSeconds,txthours,txtmins,txtRandomQnsNo,txtThresholdScore,txtFromHrs,txtFromMins,txtToHrs,txtToMins,txtOtherScore,txtNumberofAssessmentAttemps,txtNumberOfAttemptsperQuestion,txtFromHur,txtToHur,txtURL,txtweight,TxtUrl,txtTofield,txtCCfield,txtBCCfield,fontname,fontsize,txtStartDate,txtEndDate,txtNewVal,txtassmt,txtassessment,_ctl0_ContentHolderArea_txteBook,_ctl0_ContentHolderArea_txtHour,_ctl0_ContentHolderArea_txtMin,txtEstimatedAssessmentHours,txtEstimateAssessmentTiming,txtSecNoOfQues,txtNoofQuestions,txtMaxQuestions,txtMoveToNextSectionAfter,txtqnsincluded1,_ctl0:ContentHolderArea:txtFolderLevelScore";
var RegExpArray = new Array(/dgdOutCome__ctl\d{1,2}_txtScoreCorrect/,/dgdOutCome__ctl\d{1,2}_txtScoreWrong/,/dgdChoice__ctl\d{1,2}_txtScoreCorrect/,/dgdChoice__ctl\d{1,2}_txtScoreWrong/,/dgdAnswer__ctl\d{1,2}_txtScore/,/dgdChoice__ctl\d{1,2}_txtScore/,/dgdChoice__ctl\d{1,2}_txtScoreCorrect/,/dgdChoice__ctl\d{1,2}_txtScoreWrong/,/dtgOutCome__ctl\d{1,2}_txtScore/,/dgdChoices__ctl\d{1,2}_txtScore/,/dtgOperand__ctl\d{1,2}_txtMin/,/dtgOperand__ctl\d{1,2}_txtMax/,/dtgChoice__ctl\d{1,2}_txtScore/,/dgdChoices__ctl\d{1,2}_txtScore/,/dtgChoice__ctl\d{1,2}_txtScore/,/dtgOperand__ctl\d{1,2}_txtMin/,/dtgOperand__ctl\d{1,2}_txtMax/,/dgdSlider__ctl\d{1,2}_txtScore/,/dgdKeyWords__ctl\d{1,2}_txtScore/,/dtgOperand__ctl\d{1,2}_txtMin/,/dtgOperand__ctl\d{1,2}_txtMax/,/dtgChoice__ctl\d{1,2}_txtCorectScore/,/dtgChoice__ctl\d{1,2}_txtWrongScore/,/dgdBlanks__ctl\d{1,2}_txtScoreCorrect/,/dgdBlanks__ctl\d{1,2}_txtScoreWrong/,/txtTotal\d{1,2}/,/txtKnowledge\d{1,2}/,/txtEasy\d{1,2}/,/txtModerate\d{1,2}/,/txtDifficult\d{1,2}/,/txtComprehension\d{1,2}/,/txtApplication\d{1,2}/,/txtAnalysis\d{1,2}/,/txtSynthesis\d{1,2}/,/txtEvaluation\d{1,2}/,/dtgLines__ctl\d{1,2}_txtScoreCorrect/,/dtgOutcome__ctl\d{1,2}_txtScore/,/dgdOutcome__ctl\d{1,2}_txtScoreCorrect/,/dgdOutcome__ctl\d{1,2}_txtScoreWrong/,/dtgChoice__ctl\d{1,2}_txtCorrectScore/,/dgdKeywords__ctl\d{1,2}_txtScore/,/txtqnsincluded\d{1,2}/,/dtgSetAnswer__ctl\d{1,2}_txtAnswerScore/,/dtgAnswer__ctl\d{1,2}_txtAnswerScore/,/txtTotal\d{1,2}/,/dtgOperand__ctl\d{1,2}_txtEqual/,/txtedit\d{1,12}/,/txteditMS\d{1,2}/);

function ele(objId)
{
	var obj=document.getElementById(objId);
	return obj;
}
function eletag(objId)
{
	var obj=document.getElementsByTagName(objId);
	return obj;
}
function txtgetCursorPos()
{ 
    try
    {
        if(navigator.appName=="Netscape")
        {  
            txtControlId=this.id;	
            var txtObj=ele(txtControlId);            
            globalCursorPos=txtObj.selectionStart;
            parent.globalCursorPos=txtObj.selectionStart;
            get_Selection(); 
        }
        else
        {
            parent.txtControlId=this.id;
            txtControlId=this.id;	
            var txtObj=ele(txtControlId);
            var len=txtObj.value.length;
            var i=len+1;
            if (txtObj.createTextRange)
            {
                theCaret = document.selection.createRange().duplicate();
                while (theCaret.parentElement()==txtObj && theCaret.move("character",1)==1) --i;
            }
            globalCursorPos=i-1;
            parent.globalCursorPos=i-1;
            get_Selection();       
        }
    }
    catch(ex)
    {}
}
function txtareagetCursorPos()
{
    try
    {
        if(navigator.appName=="Netscape")
        {   
            txtControlId=this.id;	
            var txtObj=ele(txtControlId);            
            globalCursorPos=txtObj.selectionStart;
            parent.globalCursorPos=txtObj.selectionStart;
            get_Selection();    	 
        }
        else
        {
            txtControlId=this.id;	
            var txtObj=ele(txtControlId);
            var len=txtObj.value.length;
            var i=len+1;	
            var c=0,k;
            if (txtObj.createTextRange)
            {
                theCaret = document.selection.createRange().duplicate();
                while (theCaret.parentElement()==txtObj && theCaret.move("character",1)==1) --i;
                for(k=0;k<len;k++)
                {
                    if(txtObj.value.charAt(k)=='\n')               
                    c++;                
                }		
            }
            globalCursorPos=i-c;
            parent.globalCursorPos=i-c;		
            get_Selection();
        }
    }
    catch(Exception)
    {}
}
function insertString(stringToInsert)
{ 
    try
    {				
        if(txtControlId!=null)
        {
            if(navigator.userAgent.indexOf("Mac")!=-1)
            {		   
                var txtControlObj=ele(txtControlId);		
                if(txtControlObj==null)
                {    			   
                    txtControlObj=window.frames[0].ele(txtControlId);    				
                    var len=txtControlObj.value.length;
                    var maxlen=txtControlObj.maxLength;								
                }			    
                var len=txtControlObj.value.length;
                var maxlen=txtControlObj.maxLength;	    			
                if((maxlen==undefined || maxlen==0 || maxlen==-1) & (txtControlObj.readOnly != true))
                {
                    var firstPart = txtControlObj.value.substring(0, globalCursorPos);
                    var secondPart = txtControlObj.value.substring(globalCursorPos, txtControlObj.value.length);
                    txtControlObj.value = firstPart + stringToInsert + secondPart;
                    globalCursorPos=parseInt(globalCursorPos)+1;
                }
                else if(txtControlObj.readOnly != true & txtControlObj.disabled==false & len<maxlen)
                {	
                    var firstPart = txtControlObj.value.substring(0, globalCursorPos);
                    var secondPart = txtControlObj.value.substring(globalCursorPos, txtControlObj.value.length);
                    txtControlObj.value = firstPart + stringToInsert + secondPart;
                    globalCursorPos=parseInt(globalCursorPos)+1; 
                }
            }
            else if(navigator.userAgent.indexOf("Firefox")!=-1)
            {
                var txtControlObj=document.getElementById(txtControlId);	
                var x = txtControlObj.selectionStart;
                var y = txtControlObj.selectionEnd;
                var firstPart = txtControlObj.value.substring(0, x);
                var secondPart = txtControlObj.value.substring(y, txtControlObj.value.length);
                txtControlObj.value = firstPart + stringToInsert + secondPart;
            }
            else
            {	   
                var txtControlObj=ele(txtControlId);					
                if(txtControlObj==null)
                {
                    txtControlObj=window.frames[0].ele(txtControlId);							
                }			
                if(txtControlObj!=null && (txtControlObj.type=="text" || txtControlObj.type=="password" || txtControlObj.type=="textarea"))
                {				    			
                    if(txtControlObj.createTextRange) 
                    {				
                        parent.getSelect.text=stringToInsert;   
                        var range = txtControlObj.createTextRange();   
                        range.move("character", globalCursorPos);   
                        range.select();  
                        get_Selection();
                    }
                }			
            }		
        }
    }
    catch(Exception)
    {}	
}
function addEvents()
{
    try
    {
        var varInputControls=eletag("INPUT");
        var varTextareaControls=eletag("TEXTAREA");
        var varImgControls=eletag("IMG");
        var varAnchorControls=eletag("A");
        var i,j;	
        for(i=0;i<varImgControls.length;i++)
        {
            varImgControls[i].onfocus=NullFunction;
        }	
        for(i=0;i<varAnchorControls.length;i++)
        {
            varAnchorControls[i].onfocus=NullFunction;
        }		
        for(i=0;i<varInputControls.length;i++)
        {				
            if(varInputControls[i].type=="text" || varInputControls[i].type=="password")
            {	
                timingTextboxIndex=strControls.search(varInputControls[i].id);
                if(timingTextboxIndex==-1)
                {
                    for(j=0;j<RegExpArray.length;j++)
                    {
                        if((varInputControls[i].id).match(RegExpArray[j])== null )
                        {
                            varInputControls[i].onfocus=FocusedFunction;
                            varInputControls[i].onkeyup=txtgetCursorPos;												
                            varInputControls[i].onchange=txtgetCursorPos;						  
                            varInputControls[i].onclick=txtgetCursorPos;
                            varInputControls[i].onmouseup=get_Selection;			
                        }					
                        else
                        {
                            varInputControls[i].onfocus=NullFunction;
                            varInputControls[i].onchange=null;					
                            varInputControls[i].onclick=null;	
                            varInputControls[i].onkeyup=null;
                            varInputControls[i].onmouseup=null;	
                            break;
                        }
                    }
                }
                else
                {
                    varInputControls[i].onfocus=NullFunction;
                } 
            }
            else
            {
                varInputControls[i].onfocus=NullFunction;
            }		
        }	
        for(i=0;i<varTextareaControls.length;i++)
        {
            if(varTextareaControls[i].readOnly!=true)
            {	
                varTextareaControls[i].onfocus=FocusedFunction;	
                varTextareaControls[i].onkeyup=txtareagetCursorPos;	
                varTextareaControls[i].onchange=txtareagetCursorPos;			 
                varTextareaControls[i].onclick=txtareagetCursorPos;	
                varTextareaControls[i].onmouseup=get_Selection;	
            }
        }	
        var objBody=eletag("BODY");
        objBody[0].onmouseup=BodyOnClickFunction;				
    }
    catch(ex){}
}

function BodyOnClickFunction(objEvent) 
{
    try
    {     
        if(navigator.appName=="Netscape")
        {   
            var tag=objEvent.target.tagName;//For FireFox
            var obj=objEvent.target;
        }
        else
        {
            var tag=event.srcElement.tagName;
            var obj=event.srcElement;
        }
        if(tag=="INPUT" || tag=="TEXTAREA")
        {
            if((obj.disabled) || (obj.readOnly))
            {			
                NullFunction();
            }
            CharFlag=false;
        }
        else 
        {		
            var tdId=obj.id;
            var ind=tdId.lastIndexOf("_");
            var subId=tdId.substring(ind+1,ind+14);
            if(subId!="tdCharPalette" && subId!="imgCapsLock")
            {	
                if(navigator.appName=="Netscape")
                {    		
                    var gettext=window.document.getSelection();
                }
                else
                {
                    var gettext=document.selection.createRange();
                }
                if(gettext.text=="")
                    NullFunction();						
            }						
        }
    }
    catch(Exception)
    {}	
}
function NullFunction()
{	
	try 
	{
	    parent.txtControlId=null;
	    txtControlId=null;
    }
	catch(Exception)
	{}
}
function FocusedFunction()
{	   
	CharFlag=true;
	parent.txtControlId=this.id;
	txtControlId=this.id;	
	get_Selection();	
}
function get_Selection()
{
    try
    {
        var myField=ele(txtControlId);	
        if(navigator.appName=="Netscape")
        {
            if(window.getSelection)
            {
                var len=myField.value.length;
                var maxlen=myField.maxLength;				
                //myField.focus();		
                getSelect = window.document.getSelection();	
                parent.getSelect= window.document.getSelection();
                if(len!=maxlen || maxlen==undefined || maxlen==0)
                {
                    globalCursorPos=globalCursorPos+1;
                }		    
            }
        }
        else
        {
            if(document.location.pathname.indexOf("frmPeerAssessmentContents.aspx")!=-1 || document.location.pathname.indexOf("frmAssessmentTestDetails.aspx")!=-1)
            {
                if(document.selection.type.toLowerCase() == "none")
                return;     
            }
            if(document.selection)
            {
                var len=myField.value.length;
                var maxlen=myField.maxLength;	
                if(myField.focus!=true)			
                    myField.focus();
                getSelect = document.selection.createRange();	
                parent.getSelect=document.selection.createRange();
                if(len!=maxlen || maxlen==undefined || maxlen==0)
                {
                    globalCursorPos=globalCursorPos+1;			
                }		
            }
        }
    }
    catch(Exception)
    {}
}
function openGlossary()
{
    if(GlossaryWindow)GlossaryWindow.close();
	GlossaryWindow=window.open(strAppPathForResToolbar+"/Modules/MySpanishLab/Glossary.aspx","","width=600,height=400,top=175,left=125,status=yes,scrollbars=no");	
}
function openVerbChart()
{   
	if(VerbChartWindow)VerbChartWindow.close();
	VerbChartWindow=window.open(strAppPathForResToolbar+"/Modules/MySpanishLab/VerbChart.aspx","","width=600,height=570,top=75,left=125,status=yes,scrollbars=yes");
}
function openeBook()
{
   if(eBookWindow) eBookWindow.close();
    eBookWindow=window.open(strAppPathForResToolbar+"/Modules/MySpanishLab/Ebook.aspx?mode=1","Ebook","width=600,height=550,top=75,left=125,status=yes,scrollbars=yes,resizable=yes");
}
function openTutorial()
{
    if(TutorialWindow) TutorialWindow.close();    
    TutorialWindow=window.open(strAppPathForResToolbar+"/Modules/MySpanishLab/Ebook.aspx?mode=2","Tutorial","width=600,height=550,top=75,left=125,status=yes,scrollbars=yes,resizable=yes");   
}

function closeWindow_RT()
{ 
 
    var SelectedDay='';
    if(TutorialWindow)
    {
        TutorialWindow.close(); 
    }
    if(eBookWindow)
    {
        eBookWindow.close();
    }
    if(VerbChartWindow)
    {
        VerbChartWindow.close();
    }
    if(GlossaryWindow)
    {
        GlossaryWindow.close();
    }           
    if($(assessmentHolderValue + "hdnSelectedDay").length > 0)
    {
        SelectedDay = $(assessmentHolderValue + "hdnSelectedDay").val();
    } 
     try
     {
           if(SelectedDay !='')
            {        
                if(window.opener)
                {
                     if(window.opener.document)
                     {
                            var strPath = '';                
                                strPath = window.opener.document.location.href;
                                
                            if(strPath != '')
                            {
                                if(strPath.indexOf("frmInstructorPresentation.aspx")==-1 && strPath.indexOf("frmStudentPresentation.aspx")==-1 && document.getElementById(assessmentHolderValue + "hdnFrom").value!="GB" && strPath.indexOf("frmDRTDefault.aspx")==-1 && strPath.indexOf("frmAdaptiveTest.aspx")==-1)
                                {
                                   parent.opener.location.href = selectedDay(strPath);
                                    
                                }
                            }                    
                       }  
                 }	    
            } 
      }
      catch(ex)
      {
         objLogger.LogAll(objLogger.Error,ex);
      }        
}

//For DropDown Menu Closing
function closeDropDownMenu()
{
    try
    { 
        if(navigator.appName=="Microsoft Internet Explorer")
        {
            for(var i=0;i<=parent.window.document.getElementById("divTable1").parentElement.parentElement.children.length-1;i++)
            {
                parent.window.document.getElementById("divTable1").parentElement.parentElement.children[i].children[1].style.display='none';           
            }   
        }
        else
        { 
            for(var i=0;i<=window.parent.document.getElementById("divTable1").parentNode.parentNode.cells.length-1;i++)
            {
                window.parent.document.getElementById("divTable1").parentNode.parentNode.cells[i].lastChild.style.display='none';
            }              
        }             
    }
    catch(e){}
}  
//START - For Scroll in Course Content SubNavigation
function hideImgScroll(obj)
{
    var subobj;
    if(obj == 1)
        subobj=document.getElementById("imgbtnContent1");
    else
        subobj=document.getElementById("imgbtnContent2");
    
    if(subobj.style.display=="" || subobj.style.display=="block")
        subobj.style.display="none";
}
function showImgScroll(obj)
{
    var subobj;
    if(obj == 1)
        subobj=document.getElementById("imgbtnContent1");
    else
        subobj=document.getElementById("imgbtnContent2");

    if(subobj.style.display=="none")
        subobj.style.display="";
}
var IsLegendAvail=0;
var k;
function RTBhideSubNavigationTab(chkString)
{
    var j=0;
    if(document.getElementById("imgbtnContent")) // IsLegendAvail is setted to '0' if 'LegendIcon' is not available in the subnavigation bar.
        IsLegendAvail = 1;
    else        
        IsLegendAvail = 0; 
            
    k = document.getElementsByName("ancSubNavigationTab").length; // k contains total tabs in subnavigation bar(i.e anchor tag in table - tblSubNavigationTab).

    k = k - IsLegendAvail;   
    k = k - 2 ;   // k - 2  is done b'cos 2 tabs in table tblSubNavigationTab are image buttons.now k  contains the number of subnaviagtion tabs .

  for (var i =1; i<= k;i++)
    {
        if(chkString == document.getElementsByName("ancSubNavigationTab")[i].innerHTML)
        {
        j =  i ;
        }
        if(j != 0 && j <= 5 && i > 5 )
        {
            document.getElementsByName("ancSubNavigationTab")[i].parentNode.style.display ="none" ;   
        }
        else if(j > 5)
        {
            if(j == k)
                  hideImgScroll(2);
                        
            showImgScroll(1);
            var s ;
            s = i +1; // s contains the tab position which has to be hide.
             
            if(s > k) // if tab to be hidden is greater than the tab in subnavigation table(s > k) i.e if 7th tab selected then 8,1,2 tabs must be hidden.
             {
                s = 1; // 1st and 2nd tab wil be hidden if 7th tab is selected
                while(1) 
                 {
                    document.getElementsByName("ancSubNavigationTab")[s].parentNode.style.display ="none";
                    j = j - 1;
                    if(j == 5)
                    break;
                    else
                    s= s + 1;
                 }
             }
            else
             {
             document.getElementsByName("ancSubNavigationTab")[s].parentNode.style.display ="none";
             }                          
         }
    }
}
// now 8 tabs are ther in courescontent subnavigation and onpage load 3 tabs will be hidden . z is setted to 3 if 8 tabs exists in Coursecontent.
function newHideorDisplayTab2(obj)
{
  showImgScroll(1);
  var z;
    z = k - 5;
        
    for (var s=6;s <=k;s++ )
    {
        if(document.getElementsByName("ancSubNavigationTab")[s].parentNode.style.display =="none" )
        {
         document.getElementsByName("ancSubNavigationTab")[s].parentNode.style.display ="";  
         if(s == k)
            hideImgScroll(2);
         break;
        }
    }
     for (var s=1;s <=z;s++ )
    {
        if(document.getElementsByName("ancSubNavigationTab")[s].parentNode.style.display =="" )
        {
         document.getElementsByName("ancSubNavigationTab")[s].parentNode.style.display ="none";   
         break;
         }
    }
}
function newHideorDisplayTab1(obj)
{
showImgScroll(2);

var z;
    z = k - 5;
        
    for (var s=k;s >= 6;s--)
    {
        if(document.getElementsByName("ancSubNavigationTab")[s].parentNode.style.display =="" )
        {
         document.getElementsByName("ancSubNavigationTab")[s].parentNode.style.display ="none"; 
         break;
         }
    }
     for (var s=z;s >= 1;s--)
    {
        if(document.getElementsByName("ancSubNavigationTab")[s].parentNode.style.display =="none" )
        {
         document.getElementsByName("ancSubNavigationTab")[s].parentNode.style.display ="";
            if(s == 1)
            hideImgScroll(1); 
         break;
         }
    }
}
// END - For Scroll in Course Content SubNavigation