

                           // JScript main page source code
  
  var m_aAsyncLoad = new Array();
  var bIsSafe_AS_Store = true;
  //-----------------------------------------------------------------
  
  function CAsyncLoadObject (oXmlhttp, oCallBack)
  //       ~~~~~~~~~~~~~~~~
  {
    this.AS_Xmlhttp = oXmlhttp;
    this.fCallBack = oCallBack;
  }
  //-----------------------------------------------------------------
  
  function AS_UpdateData(sUrl, sTextData, fCallBack)
  //       ~~~~~~~~~~~~~
  {     
    // First, locate a free async handle
    var nHandle = 0;
    while (m_aAsyncLoad[nHandle] != null)
      nHandle++;
      
    AS_Xmlhttp = new ActiveXObject("Microsoft.Xmlhttp");
    AS_Xmlhttp.open("Post" ,sUrl , false);
    AS_Xmlhttp.setRequestHeader("Content-Type", "charset=utf-8")
    
    m_aAsyncLoad[nHandle] = new CAsyncLoadObject(AS_Xmlhttp , fCallBack);
    AS_Xmlhttp.onreadystatechange = Function("AS_OnAsyncLoadComplete( " + nHandle + " );" );
    
    AS_Xmlhttp.send(sTextData); 
    
    //if(sUrl.indexOf('InsertAspx') == -1) 
    //  location.href = sUrl
  }
  //----------------------------------------------------------------------------
  
  function AS_OnAsyncLoadComplete (nLoadHandle)
  //       ~~~~~~~~~~~~~~~~~~~
  {
    var oAsyncLoad = m_aAsyncLoad[nLoadHandle];
    
    try
    {
      if (oAsyncLoad.AS_Xmlhttp.readyState != 4)
        return;
    }
    catch(e) {return;}
    //alert(AS_Xmlhttp.responseText);
    if (oAsyncLoad.fCallBack != null)
      oAsyncLoad.fCallBack(AS_Xmlhttp.responseText);
   
    m_aAsyncLoad[nLoadHandle] = null;
  }    
  //----------------------------------------------------------------------------
 
  function AS_UpdateEditor(sContent,nResourceID,sUrl,nAddedResource,sAddedContent)
  //       ~~~~~~~~~~~~~~~~
  { 
    if(sContent.value != "" )
        AS_DisableMandatoryBlock(nResourceID)
    var sConcatSign = ((sUrl.indexOf('?') > 1) ? '&' : '?')
    sUrl = sUrl.replace("&nResourceID=", "&sVoid=") // cancel old resource if any 
    sUrl = sUrl + sConcatSign + "nResourceID=" + nResourceID ;
    bIsSafe_AS_Store = false;
    AS_UpdateData(sUrl,sContent);   
    
    if(nAddedResource != null && nAddedResource != '')
      AS_UpdateEditor(sAddedContent,nAddedResource, sUrl + "&bFeedback=1", null, null);
  }
  //---------------------------------------------------------------------
  
  function AS_UpdateTextBox(nResourceID,sUrl,nAddedResource)
  //       ~~~~~~~~~~~~~~~~
  {       
    var oControl = document.getElementById('EditText' + nResourceID);
    if(oControl.value != "" )
        AS_DisableMandatoryBlock(nResourceID)
    var sUrlChane = ((sUrl.indexOf('?') > 1) ? '&' : '?')
    sUrl = sUrl.replace("&nResourceID=", "&sVoid=") // cancel old resource if any
    sUrl = sUrl + sUrlChane + "nResourceID=" + nResourceID ;
    bIsSafe_AS_Store = false;
    AS_UpdateData(sUrl,oControl.value);
    
    if(nAddedResource != null && nAddedResource != '')
      AS_UpdateTextBox(nAddedResource, sUrl + "&bFeedback=1", null);
  }
  //---------------------------------------------------------------------
  function AS_UpdateRadioButton(nResourceID,sUrl,sValue)
  //       ~~~~~~~~~~~~~~~~~~~~~
  { 
    sUrl = sUrl + "?nResourceID=" + nResourceID ;
    bIsSafe_AS_Store = false;
    AS_UpdateData(sUrl,sValue);
  }
  //---------------------------------------------------------------------
  
  function AS_UpdateSelect(nResourceID,sUrl,sValue)
  //       ~~~~~~~~~~~~~~~~~~~~~~~
  { 
    sUrl = sUrl + "?nResourceID=" + nResourceID ;
    bIsSafe_AS_Store = false;
    if(sValue != "")
      AS_DisableMandatoryBlock(nResourceID)
    AS_UpdateData(sUrl,sValue);
  }
  //---------------------------------------------------------------------
  function AS_UpdateCheckBox(nResourceID,sUrl)
  //       ~~~~~~~~~~~~~~~~~~
  { 
    var oMandatoryBlock = document.getElementById("OnFailFeedback" + nResourceID);
    var oControl = document.getElementById('CheckBox' + nResourceID);
    
    if(oControl.checked != "" && oMandatoryBlock != null)
        oMandatoryBlock.style.display = "none";
    
    sUrl = sUrl + "?nResourceID=" + nResourceID  ;
    bIsSafe_AS_Store = false;
    var sValueToSave = '';
    if(oControl.checked.toString() == 'true')
      sValueToSave = oControl.checked.toString();
    AS_UpdateData(sUrl,sValueToSave);
  }
  //----------------------------------------------------------------------------
  
  function AS_UpdateRecordSound(nResourceID,sFileName,sTitle,sDescription,nDuration,sUrl)
  //       ~~~~~~~~~~~~~~~~~~~~
  {
     
    sDescription = encodeURIComponent(sDescription);
    sTitle = encodeURIComponent(sTitle);// decodeURIComponent
    sUrl = sUrl + "?nResourceID=" + nResourceID + "&sFileName=" + sFileName +"&sTitle=" + sTitle +"&sDescription=" + sDescription + "&bIsSound=1" ;
    bIsSafe_AS_Store = false;
    //alert(sUrl);
    AS_UpdateData(sUrl,nDuration + 0);
  }
  //--------------------------------------------------------------------------------
  
  function AS_LockForm(nHeight,nWidth,sUrl)
  //       ~~~~~~~~~~~
  { 
    var oBody = document.body;
    var oFrame = document.all.AS_iFrame;
    var oMask = document.all.AS_Mask;
   
    if (nHeight != null)
       oFrame.style.height = nHeight;
    if (nWidth != null)
       oFrame.style.width = nWidth;
    if (sUrl != null)
       oFrame.src = sUrl;
    oMask.style.width = oBody.scrollWidth;
    oMask.style.height = oBody.scrollHeight;//
    oMask.style.top = 0;
    oMask.style.left = 0;
    oMask.style.display = "";
    var nTop;
    if(oBody.clientHeight <= 500)
    {
     nTop = oBody.scrollTop + (oBody.clientHeight - oFrame.offsetHeight) / 2;
    }
    else
    {
    nTop = oBody.scrollTop + (500 - oFrame.offsetHeight)/2;
    }    
    var nLeft = (oBody.clientWidth - oFrame.offsetWidth) / 2;
    oFrame.style.top = nTop;
    oFrame.style.left = nLeft;
    oFrame.style.visibility = "visible";
  }
  //-----------------------------------------------------------------------------------------
  
  function AS_UpdateForm(nResourceID,sFileName,nDuration)
  //       ~~~~~~~~~~~~~
  { 
    var oImage = document.getElementById("AS_Image" + nResourceID);
    var oFileLink = document.getElementById("AS_FileLink" + nResourceID);
    var oFileName = document.getElementById("AS_FileName" + nResourceID);
    var oFlash = document.getElementById("AS_Flash" + nResourceID)
    AS_DisableMandatoryBlock(nResourceID);
    
    if(oImage)
    {
       var sUrl = oImage.src + "&" + Math.random();
       oImage.src = sUrl;
    } 
    if(oFileLink)
    {
       var sUrl = oFileLink.href + "&" + Math.random();
       oFileLink.href = sUrl;
    } 
    if(oFlash)
       AS_UpdateFlashVars(oFlash,nResourceID,nDuration);
    if(oFileName)
       oFileName.innerText  = sFileName;
  }
  //----------------------------------------------------------------------
  
  function AS_UpdateFlashVars(oFlash,nResourceID,sDuration)
  { 
    //inserting new Duration to FlashVars    
    for (i = 0; i < oFlash.childNodes.length; i++)
    {
      if(oFlash.childNodes[i].name == "FlashVars")
      {
        var sFlashVars = '';
        var sParam = '';
        arrParams = oFlash.childNodes[i].value.split('&');  
        for (var j=0; j < arrParams.length-1; j++)
        {  
          var sPramSpliter = '$$';
          if(arrParams[j].indexOf('nFileID') != -1)
            sParam = arrParams[j].split('=')[1] + '=' +  arrParams[j].split('=')[2] + '&' + Math.random();
          else if(arrParams[j].indexOf('.mp3') != -1)
            sParam = arrParams[j].split('=')[1] + Math.random();
          else if(arrParams[j].indexOf('=') != -1)                        
             sParam = arrParams[j].split('=')[1];
          else
             continue;
          sFlashVars = sFlashVars + sParam + sPramSpliter; 
       }
       sFlashVars = sFlashVars + sDuration;
       oFlash.setVariable('sData',sFlashVars);
       break;
      }
    }
  } 
  //----------------------------------------------------------------------
       
  function AS_EnableDataBlock(bEnable,nResourceID)
  //       ~~~~~~~~~~~~~~~~~~
  {              
   // var oDataBlock = document.getElementById('AS_IfDataBlock' + nResourceID); document.getElementsByName("");
    var oDataBlock = document.getElementsByName('AS_IfDataBlock' + nResourceID);
    var oNoDataBlock = document.getElementById('AS_NoDataBlock' + nResourceID );
    var oRemoveBtn = document.getElementById('AS_RemoveBtn' + nResourceID );
    var oUploadBtn = document.getElementById('AS_UploadBtn' + nResourceID );
    var oChangeBtn = document.getElementById('AS_ChangeBtn' + nResourceID );
    
    if(bEnable > 0 )
    {
//      
//        oDataBlock[i].style.display = "";
      if(oDataBlock)
        for(var i = 0 ; i < oDataBlock.length; i++)
          oDataBlock[i].style.display = "";
      if(oRemoveBtn)
        oRemoveBtn.style.display = "";
      if(oChangeBtn)
        oChangeBtn.style.display = "";
          
      if(oNoDataBlock)
        oNoDataBlock.style.display = "none";
      if(oUploadBtn)
        oUploadBtn.style.display = "none";
    }
    else
    {
      if(oDataBlock)
        for(var i = 0 ; i < oDataBlock.length; i++)
          oDataBlock[i].style.display = "none";
      if(oRemoveBtn)
        oRemoveBtn.style.display = "none";
      if(oChangeBtn)
        oChangeBtn.style.display = "none";
          
      if(oNoDataBlock)
        oNoDataBlock.style.display = "";
      if(oUploadBtn)
        oUploadBtn.style.display = "";
    }
  }
   //----------------------------------------------------------------------
  function AS_DisableMandatoryBlock(nResourceID)
  //       ~~~~~~~~~~~~~~~~~~~~~~~~
  { 
    var sName = "OnFailFeedback" + nResourceID;
    var oMandatoryBlock = document.getElementById(sName);
    if(oMandatoryBlock)
      oMandatoryBlock.style.display = "none";
  }
  //----------------------------------------------------------------------------
  
  function AS_NavOnValidate(sUrl)
  //       ~~~~~~~~~
  {
    if (AS_Validate())
      document.location.href = sUrl; 
  }    
  //----------------------------------------------------------------------------

  function AS_OnConfirmDelete (ret ,sUrl)
  //       ~~~~~~~~~~~~~~~
  {
    if(ret)
    {
      var nResourceID;
      if(sUrl.length > 0)
      {
         var aUrlParts = sUrl.split('=');
         if(aUrlParts.length > 1)
         {
          var aResourceIDParts = aUrlParts[1].split('&');
          if(aResourceIDParts.length > 1)
             nResourceID = aResourceIDParts[0];
         }
      }
      var oFrame = document.getElementById("AS_IFrameTarget");
      if (sUrl != null)
        oFrame.src = sUrl;
      AS_UpdateForm(nResourceID,'');
      AS_EnableDataBlock(0,nResourceID)
    }
  }
  //---------------------------------------------------------------------------
  function AS_OnUploadEnd (sParams,nFileID)
  //       ~~~~~~~~~~~~~
  {
    //alert(sParams + ',nFileID=' + nFileID);
    var nResourceID;
    var sFileName;
    var nDuration;
    var sTitle;
    var sDescription;
    var sUrl;
    
    if(sParams  && sParams.length > 0)
    {
       var arParams = sParams.split(',');
       
       if(arParams.length >= 3)
       {
         nResourceID = arParams[0];
         sFileName = arParams[1];
         nDuration = arParams[2];
         sTitle = arParams[3];
       }
       if(arParams.length >= 5)
       {
         sDescription = arParams[4];
         if(arParams.length > 5)
           sUrl = arParams[5];
       }
       
       if(sUrl != null)
       {
         AS_UpdateRecordSound(nResourceID,sFileName,sTitle,sDescription,nDuration,sUrl);
         nDuration = new Number(nDuration)*1000;
       }
       else
         nDuration = new Number(nDuration);
       
       AS_UpdateForm(nResourceID,sFileName,nDuration);
       AS_EnableDataBlock(1,nResourceID);
    }
  }
   //---------------------------------------------------------------------------
  function AS_OnSelect (oFileInfo,nFileID)
  //       ~~~~~~~~~~ 
  { 
    if(nFileID && oFileInfo)
    {
      var sUrl = "/Common/AspxStore/UpdateData.aspx?nFileID=" + nFileID;
      //alert(s);
      AS_UpdateData(sUrl,oFileInfo.nResourceID);
      AS_UpdateForm(nFileID,oFileInfo.sFileName,oFileInfo.nMediaDuration);
      AS_EnableDataBlock(1,nFileID);
    }
   // else
   // {
     
      //AS_EnableDataBlock(0,nFileID);
  //  }
  }
  
  //---------------------------------------------------------------------------
  function AS_RemoveFile(nWinWidth,nWinHeigth,sUrlConfirm,sUrlRemove)
  //       ~~~~~~~~~~~~~
  {
    if(sUrlRemove.length > 0)
    {
       var aUrlParts = sUrlRemove.split('=');         //sUrlRemove 
       if(aUrlParts.length > 1)
        nResourceID = aUrlParts[1].split('&')[0];
    }
    eval('cRemoveDlg' + nResourceID).Show(nWinWidth,nWinHeigth,sUrlConfirm ,sUrlRemove + '&' + Math.random());
  }
  //---------------------------------------------------------------------------
  function AS_UploadFile(nResourceID,nWinWidth,nWinHeigth)
  //       ~~~~~~~~~~~~~
  {
    if(nResourceID != 0)
      eval('cUploadDlg' + nResourceID).Show(nWinWidth,nWinHeigth,null,nResourceID);
  }
  //-----------------------------------------------------------------------------------------------------------------
  
  function AS_SavePackage(sUrl)
  //       ~~~~~~~~~~~~~
  {
   // alert(sUrl);
    eval('cSaveDlg').Show(null,null,null,sUrl);
  }
  //---------------------------------------------------------------------------
  function AS_LoadPackage(nResourceID)
  //       ~~~~~~~~~~~~~
  {
    eval('cFileDlg').Show(null,null,null,nResourceID);
  }
  //---------------------------------------------------------------------------
  function AS_OnSaveDialogEnd(oFileInfo ,sUrl)
  //       ~~~~~~~~~~~~~~~
  {
    if(oFileInfo)
    {
      var sContextPage = document.URL.replace("http://" + document.domain , "");
      
      nPos = sContextPage.indexOf("?");
      if (nPos != -1)
        sContextPage = sContextPage.substring(0 ,nPos)

      sUrl = sUrl + "?nFileID=" + oFileInfo.FileID + "&sTitle=" + encodeURIComponent(oFileInfo.Title) + "&sDescription=" + encodeURIComponent(oFileInfo.Description);
      sUrl += "&sContextPage=" + encodeURIComponent(sContextPage);
      sUrl += "&sPackageContentType=" + encodeURIComponent(oFileInfo.sPackageContentType);
      sUrl += "&cIDtoDisplay=" + encodeURIComponent(oFileInfo.cIDtoDisplay);
      var oFrame = document.getElementById("AS_IFrameTarget");
      if (sUrl != null)
        oFrame.src = sUrl;
      var olblDescription = parent.document.getElementById("asDescription");
      if(olblDescription)
        olblDescription.innerText = oFileInfo.Description;
      var olblTitle = parent.document.getElementById("asTitle");
      if(olblTitle)
        olblTitle.innerText =  oFileInfo.Title;
    }
  }
  //---------------------------------------------------------------------------//---------------------------------------------------------------------------

  function AS_OnSelectDialogEnd(oFileInfo)
  //       ~~~~~~~~~~~~~~~~~~~~
  {
    if(oFileInfo && oFileInfo.nFileID)
    {
      var sUrl = document.location.href;
      var aUrlParts = sUrl.split('?');
      // alert(aUrlParts[0] + "?nPackageID=" + oFileInfo.nFileID);
      document.location.href = aUrlParts[0] + "?nPackageID=" + oFileInfo.nFileID + "&sContext=" + ParsePageQueryString('sContext'); 
    }
  }
  //==================================================================
  var qsParm ; 
  function ParsePageQueryString(sKey) 
  // ~~~~
  { 
    if(!qsParm)
    {
      qsParm = new Array(); 
      var query = window.location.search.substring(1); 
      var parms = query.split('&'); 
      for (var i=0; i<parms.length; i++) 
      {
        var pos = parms[i].indexOf('=');
        if (pos > 0)   
        {
          var key = parms[i].substring(0,pos);
          var val = parms[i].substring(pos+1);
          qsParm[key] = val;
        }
       }
    } 
    return qsParm[sKey]; 
  } 
