var strCurrEndDate="";
function setCurrEndDate(strEndDate){strCurrEndDate=strEndDate;}
function getCurrEndDate(){return strCurrEndDate;}

var bSCORMComplete=false;
function setSCORMComplete(){bSCORMComplete=true;}

function setCurrTakenId(strTakenId){
  strCurrTakenId=strTakenId;
}

function setCurrModuleId(strModuleID){
  strCurrModuleId=strModuleID;
  arrParams=getPopupParams().split("|");
  if(arrParams.length>5){
    arrParams[5]=strModuleID;
    strPopupParams=arrParams.join("|");
  }
}

function setPage(strPageName){
  arrParams=getPopupParams().split("|");
  if(arrParams.length>3){
    arrParams[3]=strPageName;
    strPopupParams=arrParams.join("|");
  }
}

function setLang(strLID){
  expdate=new Date();
  expdate.setTime(expdate.getTime()+(365*24*60*60*1000));
  setCookie("dmslang",strLID,expdate);
  form=document.forms['frmSetLang'];
  form.elements['langid'].value=strLID;
  form.submit();
}

function fNew(strModuleID){
  form=document.forms['frmRun'];
  rawform=document.forms['frmRaw'];
  form.elements['mfcisapicommand'].value="IdaRunNew";
  txtLang=rawform.elements['txtDefLang'+strModuleID];
  cmbLang=rawform.elements['cmbLang'+strModuleID];
  if(txtLang){
    if(cmbLang&&cmbLang.style.display=="inline"){
      if(cmbLang.options[cmbLang.selectedIndex].value=="-1"){
        alert(msgSelectLang);
        cmbLang.focus();
        return;
      }else{
        form.elements['language'].value=cmbLang.options[cmbLang.selectedIndex].value;
      }
    }else{
      form.elements['language'].value=txtLang.value;
    }
  }
  form.elements['moduleid'].value=strModuleID;
  form.submit();
}

function fRunPartial(strTakenId,strModuleID){
  form=document.forms['frmRunEnd'];
  form.elements['mfcisapicommand'].value="IdaRunPartial";
  form.elements['takenid'].value=strTakenId;
  form.elements['moduleid'].value=strModuleID;
  form.submit();
}

function fIdxNew(bIsRerun,strModuleID,nTop,nLeft,nWidth,nHeight){
  closeWindows();
  nWidth-=12;
  nHeight-=30;
  nTop=getWinTop(nTop,nHeight);
  nLeft=getWinLeft(nLeft,nWidth);
  rawform=document.forms['frmRaw'];
  strLangID=getIdxLang(strModuleID,bIsRerun);
  if(strLangID=="")
    return;
  if(bAnon){
    strIdxCommand="runNewAnon(\""+HOST_SERVER+DLL_NAME+"\",\""+CONN_CODE+"\",\""+USERNAME+"\",\""+strModuleID+"\",\""+strLangID+"\",\""+strHiddenData+"\")";
  }else{
//    setPage("idxPageFrame.htm");
setPage("idaRunFrameset.htm");
POPUP_TOP=nTop;POPUP_LEFT=nLeft;POPUP_WIDTH=nWidth;POPUP_HEIGHT=nHeight;
    strIdxCommand="runNew(\""+HOST_SERVER+DLL_NAME+"\",\""+CONN_CODE+"\",\""+USERNAME+"\",\""+strModuleID+"\",\""+strLangID+"\")";
  }
  winPopup=window.open(HOST_SERVER+IDA_PATH+"idaPopupTrigger.htm","winPopup","left="+nLeft+",top="+nTop+",width="+nWidth+",height="+nHeight+",resizable=1,scrollbars=0");
  bWinPopup=true;
  try{winPopup.focus();}catch(e){}
}

function fIdxRunPartial(strTakenID,strModuleID,nTop,nLeft,nWidth,nHeight){
  closeWindows();
  nWidth-=12;
  nHeight-=30;
  nLeft=getWinLeft(nLeft,nWidth);
  nTop=getWinTop(nTop,nHeight);
  rawform=document.forms['frmRaw'];
  strLangID=getIdxLang(strModuleID,false);
  if(strLangID=="")
    return;
  if(bAnon) {
    strIdxCommand="runPartialAnon(\""+HOST_SERVER+DLL_NAME+"\",\""+CONN_CODE+"\",\""+USERNAME+"\",\""+strModuleID+"\",\""+strTakenID+"\",\""+strLangID+"\")";
  } else {
//    setPage("idxPageFrame.htm");
setPage("idaRunFrameset.htm");
POPUP_TOP=nTop;POPUP_LEFT=nLeft;POPUP_WIDTH=nWidth;POPUP_HEIGHT=nHeight;
    strIdxCommand="runPartial(\""+HOST_SERVER+DLL_NAME+"\",\""+CONN_CODE+"\",\""+USERNAME+"\",\""+strModuleID+"\",\""+strTakenID+"\",\""+strLangID+"\")";
  }
  winPopup=window.open(HOST_SERVER+IDA_PATH+"idaPopupTrigger.htm","winPopup","left="+nLeft+",top="+nTop+",width="+nWidth+",height="+nHeight+",resizable=1,scrollbars=0");
  bWinPopup=true;
  try{winPopup.focus();}catch(e){}
}

function getIdxLang(strModuleID,bIsRerun){
  strLangID="-1";
  rawform=document.forms['frmRaw'];
  if(rawform){
    txtLang=((bIsRerun)?rawform.elements['txtReDefLang'+strModuleID]:rawform.elements['txtDefLang'+strModuleID]);
    cmbLang=((bIsRerun)?rawform.elements['cmbReLang'+strModuleID]:rawform.elements['cmbLang'+strModuleID]);
    if(txtLang){
      if(cmbLang&&cmbLang.style.display=="inline"){
        if(cmbLang.options[cmbLang.selectedIndex].value=="-1"){
          alert('Please select a language first.');
          cmbLang.focus();
          return "";
        }else{
          strLangID=cmbLang.options[cmbLang.selectedIndex].value;
        }
      }else{
        strLangID=txtLang.value;
      }
    }
  }
  return strLangID;
}

function fNewScorm(strModuleID,nTop,nLeft,nWidth,nHeight){
  closeWindows();
  nWidth-=12;
  nHeight-=30;
  nLeft=getWinLeft(nLeft,nWidth);
  nTop=getWinTop(nTop,nHeight);
  setCurrModuleId(strModuleID);
  setPage("idaScormPopup.htm");
  strIdxCommand="runNew(\""+HOST_SERVER+DLL_NAME+"\",\""+CONN_CODE+"\",\""+USERNAME+"\",\""+strModuleID+"\")";
  winPopup=window.open(HOST_SERVER+IDA_PATH+"idaPopupTrigger.htm","winPopup","left="+nLeft+",top="+nTop+",width="+nWidth+",height="+nHeight+",resizable=1,scrollbars=0");
  bWinPopup=true;
  winPopup.focus();
}

function fScormRunPartial(strTakenID,strModuleID,nTop,nLeft,nWidth,nHeight){
  closeWindows();
  nWidth-=12;
  nHeight-=30;
  nLeft=getWinLeft(nLeft,nWidth);
  nTop=getWinTop(nTop,nHeight);
  setCurrModuleId(strModuleID);
  setPage("idaScormPopup.htm");
  strIdxCommand="runPartial(\""+HOST_SERVER+DLL_NAME+"\",\""+CONN_CODE+"\",\""+USERNAME+"\",\""+strModuleID+"\",\""+strTakenID+"\")";
  winPopup=window.open(HOST_SERVER+IDA_PATH+"idaPopupTrigger.htm","winPopup","left="+nLeft+",top="+nTop+",width="+nWidth+",height="+nHeight+",resizable=1,scrollbars=0");
  bWinPopup=true;
  winPopup.focus();
}

function isScormOpen(){
  if(winPopup&&!winPopup.closed){
    setTimeout("isScormOpen()",1000);
  }else{
    closeScorm(true);
  }
}

function closeScorm(bForceSubmit){
  if(winPopup&&(bForceSubmit||!winPopup.closed)){
    if(strPageName=="idaSkeletonList"&&strDM=="0"&&(strOE==""||strOE=="home")){
      winPopup.close();
      strEndForm=((bSCORMComplete)?"frmRunEnd":"frmRunIncomplete");
      winPopup2=window.open(HOST_SERVER+IDA_PATH+"idaAutoRunEnd.htm","winPopup2","left=0,top=0,width="+(screen.availWidth-10)+",height="+(screen.availHeight-30)+",resizable=1,scrollbars=1");
      bWinPopup2=true;
      winPopup2.focus();
    }else{
      form=((bSCORMComplete)?document.forms['frmRunEnd']:document.forms['frmRunIncomplete']);
      form.elements['moduleid'].value=strCurrModuleId;
      form.elements['takenid'].value=strCurrTakenId;
      form.submit();
      winPopup.close();
    }
  }
}

function idaReport(strFileId,strModuleID,strUserId,strContentType){
  form = document.forms['frmReport'];
  form.action=HOST_SERVER+((strContentType=="6")?"eda.dll":DLL_NAME);
  form.elements['mfcisapicommand'].value="IdaViewReport";
  form.elements['takenid'].value=strFileId;
  form.elements['moduleid'].value=strModuleID;
  form.elements['userid'].value=strUserId;
  form.submit();
}

function fNewWebLink(strModuleID,nTop,nLeft,nWidth,nHeight){
  closeWindows();
  nWidth-=12;
  nHeight-=30;
  nLeft=getWinLeft(nLeft,nWidth);
  nTop=getWinTop(nTop,nHeight);
  setCurrModuleId(strModuleID);
  winWebLink=window.open(HOST_SERVER+IDA_PATH+"idaWebLink.htm","winWebLink","left="+nLeft+",top="+nTop+",width="+nWidth+",height="+nHeight+",resizable=1,scrollbars=1,dependent=1,menubar=1,toolbar=1");
}

function isWebLinkOpen(){
  if(winWebLink&&!winWebLink.closed){
    setTimeout("isWebLinkOpen()",1000);
  }else{
    closeWebLink(true);
  }
}

function closeWebLink(bForceSubmit){
  if(winWebLink&&(bForceSubmit||!winWebLink.closed)){
    if(strPageName=="idaSkeletonList"&&strDM=="0"&&(strOE==""||strOE=="home")){
      winWebLink.close();
      strEndForm="frmRunEnd";
      winPopup2=window.open(HOST_SERVER+IDA_PATH+"idaAutoRunEnd.htm","winPopup2","left=0,top=0,width="+(screen.availWidth-10)+",height="+(screen.availHeight-30)+",resizable=1,scrollbars=1");
      bWinPopup2=true;
      winPopup2.focus();
    }else{
      form=document.forms['frmRunEnd'];
      form.elements['moduleid'].value=strCurrModuleId;
      form.elements['takenid'].value=strCurrTakenId;
      form.submit();
      winWebLink.close();
    }
  }
}

function idxRunEnd(strUsername,strModuleID,strTakenId,bComplete){
  saveCookie(strModuleID,strTakenId);
  if(strPageName=="idaSkeletonList"&&strDM=="0"&&(strOE==""||strOE=="home")){
    strEndForm=((bComplete)?"frmRunEnd":"frmRunIncomplete");
    USERNAME=strUsername;
    strCurrModuleId=strModuleID;
    strCurrTakenId=strTakenId;
    winPopup=window.open(HOST_SERVER+IDA_PATH+"idaAutoRunEnd.htm","winPopup","left=0,top=0,width="+(screen.availWidth-10)+",height="+(screen.availHeight-30)+",resizable=1,scrollbars=1");
    bWinPopup=true;
    winPopup.focus();
  }else{
    if(frames['UtilFrame'])
      frames['UtilFrame'].runEnd(bComplete,HOST_SERVER+DLL_NAME,CONN_CODE,strUsername,strModuleID,strTakenId);
    else{
      form=((bComplete)?document.forms['frmRunEnd']:document.forms['frmRunIncomplete']);
      form.elements['username'].value=strUsername;
      form.elements['moduleid'].value=strModuleID;
      form.elements['takenid'].value=strTakenId;
      form.submit();
    }
    if(bAnon&&bGoBack&&(strOE==""||strOE=="home"))
      history.back();
  }
}

function saveCookie(strModuleID, strTakenId){
  if(bAnon&&bMulti){
    expdate=new Date();
    expdate.setTime(expdate.getTime()+(365*24*60*60*1000));
    setCookie("MID"+strModuleID,strTakenId,expdate);
  }
}

function showPopup(){
  closeWindows();
  nWidth=550;
  nHeight=350;
  if(SHOW_ACTION){
    bEarly=false;
    winPopup=window.open(HOST_SERVER+IDA_PATH+"idaActionTrigger.htm","winPopup","left="+(screen.width-nWidth)/2+",top="+(screen.height-nHeight)/2+",width="+nWidth+",height="+nHeight+",resizable=1,scrollbars=1,dependent=1");
    bWinPopup=true;
  }else if(SHOW_ATTEND){
    winPopup=window.open(HOST_SERVER+IDA_PATH+"idaAttendTrigger.htm","winPopup","left="+(screen.width-nWidth)/2+",top="+(screen.height-nHeight)/2+",width="+nWidth+",height="+nHeight+",resizable=1,scrollbars=1,dependent=1");
    bWinPopup=true;
  }else if(SHOW_WEBFB){
    strPopupParams=HOST_SERVER+DLL_NAME+"|"+CONN_CODE+"|"+USERNAME+"|idaWebFeedback.htm|help\\helpMainList.htm|"+MODULEID+"|"+MODULE_NAME+"|"+FEEDBACK_TEXT+"|"+FEEDBACK_ID+"|"+SHOW_ID+"|"+CUSTOM_TEXT+"|"+DATE;
    winPopup=window.open(HOST_SERVER+IDA_PATH+"idaPopupTrigger.htm","winPropup","left="+(screen.width-nWidth)/2+",top="+(screen.height-nHeight)/2+",width="+nWidth+",height="+nHeight+",resizable=1,scrollbars=1,dependent=1");
    bWinPopup=true;
  }else if(SHOW_IDX){
    if(TAKEN_ID=="0"||TAKEN_ID=="-1")
      fIdxNew(false,MODULEID,POPUP_TOP,POPUP_LEFT,POPUP_WIDTH,POPUP_HEIGHT);
    else
      fIdxRunPartial(TAKEN_ID,MODULEID,POPUP_TOP,POPUP_LEFT,POPUP_WIDTH,POPUP_HEIGHT);
  }
}

function fActionDone(strModuleID){
  closeWindows();
  bEarly=true;
  setCurrModuleId(strModuleID);
  nWidth=550;
  nHeight=350;
  winPopup=window.open(HOST_SERVER+IDA_PATH+"idaActionTrigger.htm","winPopup","left="+(screen.width-nWidth)/2+",top="+(screen.height-nHeight)/2+",width="+nWidth+",height="+nHeight+",resizable=1,scrollbars=1,dependent=1");
  bWinPopup=true;
}

function isEarly(){
  return bEarly;
}

function setAttendance(strAttend,strFeedback,strModuleID,strTakenID){
  form=document.forms['frmAttend'];
  form.elements['attend'].value=strAttend;
  form.elements['feedback'].value=strFeedback;
  if(arguments.length>2){
    form.elements['moduleid'].value=strModuleID
    form.elements['takenid'].value=strTakenID
  }
  form.submit();
}

function openDetailsWin(strModuleID,strEndDate){
  closeWindows();
  setCurrModuleId(strModuleID);
  setCurrEndDate(strEndDate);
  nWidth=600;
  nHeight=325;
  winPopup=window.open(HOST_SERVER+IDA_PATH+"idaDetailsTrigger.htm","winPopup","left="+(screen.width-nWidth)/2+",top="+(screen.height-nHeight)/2+",width="+nWidth+",height="+nHeight+",resizable=1,scrollbars=1,dependent=1");
  bWinPopup=true;
}

function goBoard(strModuleID){
  form=document.forms['frmGoBoard'];
  form.elements['moduleid'].value=strModuleID;
  form.submit();
}

function closeWindows(){
  closePopup();
  closeWebLink();
}

function idxSubFeed(strContentId,strPageId,strFeed,strTakenId){
  form=document.forms['frmIdxFeed'];
  form.elements['contentid'].value=strContentId;
  form.elements['pageid'].value =strPageId;
  form.elements['feedback'].value=strFeed;
  form.elements['takenid'].value=strTakenId;
  form.submit();
}

function showHTDiv(){
/*
  bShow=false;
  if(navigator.cookieEnabled){
    bShow=(getCookie("HOWTO")!="SEEN");
    expdate=new Date();
    expdate.setTime(expdate.getTime()+(365*24*60*60*1000));
    setCookie("HOWTO","SEEN",expdate);
 }
  if(bShow){
    document.getElementById('htdiv').style.left=((screen.width-600)/2);
    document.getElementById('htdiv').style.top=((screen.height-300)/2);
  }
*/
}

function hideHTDiv(){
  document.getElementById('htdiv').style.left= -1000;
}