//---------------------------------------------------------------------------
// Проект:      Zoom - 4
//
// Copyright:   "Nota-PI group" 2000г.
//
//---------------------------------------------------------------------------
// Модуль:      wnPopUpRun.js
// Категория:   Вспомогательные процедуры для wnPopUpRun.sub
// Язык:        JavaScript
//
// Описание:    Общие функции
//
// Автор:       Алексей Конюхов
// Разработка:  Морозов Вл.Н.
//              файл создан 15/09/06 - скрипты старые,
//              они просто перенесены из sub (для скорости работы)
//---------------------------------------------------------------------------

function js_StopPopupRunOfHand()
{
	if( arguments.length > 0 )
	alert( "arg="+arguments[0] );
	js_StopPopupRun();
} // end pgm

function js_StopPopupRun()
{
	var b_IsIe = isIe()
	
	g_PopUpTimeCur = g_PopUpTimeStep;
	
    clearInterval(g_PopUpTimer);    
    								//clearTimeout(g_PopUpTimer)
    			  g_PopUpTimer = null ;
    g_oPopBodyRun = null ;

     if( g_sPopUpTimer_EvalOfEnd != "" )
   eval( g_sPopUpTimer_EvalOfEnd );
    	 g_sPopUpTimer_EvalOfEnd = "";
    	 
    g_sPopUpTimer_EvalOfStep= "";

    if( b_IsIe )
    {
    	if( g_oPopupWind != null )
        	g_oPopupWind.hide();
    } else
    {
    	var div = document.getElementById( g_oPopup_DivName ); // all.item
    	if( div != null )
    	    div.style.display='none';
    }

    g_oPopupWind = null ;

    g_PopupH = 0;
    g_PopupW = 164;
        
    g_oPopup_DivName = "popupformRUN"

} // end pgm  js_StopPopupRun


function js_ShowPopupRun()
{
	//alert( "js_ShowPopupRun() start" )
	var b_IsIe = isIe();

	if( b_IsIe )
	{
      if( g_oPopupWind == null )
      {
      
	     g_oPopupWind = window.createPopup();
	  }
	  else
      {
	     //alert( "Otl: [g_oPopupWind] not null by start" )
	     return;
      }

      if( g_oPopupWind == null )
      {
	     //alert( "Otl: [g_oPopupWind] is null" )
	     return;
      }
    } // end if  b_IsIe

   var div = document.getElementById( g_oPopup_DivName ); // all.item
   if( div == null )
   {
	   //alert( "Otl: ["+g_oPopup_DivName+"] is null" )
	   return;
   }


   var oHand = null ;
   try
   {
         oHand = div.getElementById( "Id_StopPopupRunOfHand" ); // all.item
     if( oHand != null )
     {
	   if( g_PopUpTimeMax <= 1000*g_PopUpTimeHand ) // <%' если отображаемое время маленькое, %>
	   {
	    if( b_IsIe )
	      oHand.innerText = "";	  // <%' то ручной останов не нужен%>
	    else
	      oHand.innerContent = "";
	   }
     }
   } // end try
   catch (e) { oHand = null ; }

       //
         div.style.display='block';
g_PopupH=div.clientHeight;
	     

	  if( b_IsIe ) // <%' перенести данные из DIV в окно %>
	  {
	    div.style.display='NONE';
	    g_oPopBodyRun = g_oPopupWind.document.body;
	   try
	   {
        g_oPopBodyRun.style.border = "solid #898fc4 1px";
	    g_oPopBodyRun.style.backgroundColor="#ffffff";
       } // end try
       catch( e ) { }

	    g_oPopBodyRun.innerHTML = div.innerHTML;
	   } // end if

	var img = null; // <% ' найти псевдопрогрессор %>
	if( b_IsIe )
	    img = g_oPopBodyRun.document.getElementById("img_forPopUpRun")
	else
	    img = document.getElementById("img_forPopUpRun")	
	    
	if( img != null )
	{
	    img.style.width = ""+(100/(g_PopUpTimeMax/g_PopUpTimeCur))+"%";
	}

	var nBody = 0;
	if( arguments.length > 0 )
	{

	    var tit = null;
	    if( b_IsIe )
	      tit = g_oPopBodyRun.document.all.item("tit_forPopUpRunId") // all.item
	    else
	      tit = document.getElementById("tit_forPopUpRunId")

	    if( tit != null )
	    if( arguments.length >= 1 )
	    if( typeof( arguments[0] ) == "string" )
	        tit.innerHTML = arguments[0];

	    if( arguments.length == 2 )
	        nBody = (0+arguments[1]);
	} // end if  arguments.length > 0

	
 var bYesEvent = false;
 var xEvent = jsGetEvent();
 
 if( g_oPopup_bYesEvent == true )
   if( xEvent != null ) bYesEvent = true;

 if( bYesEvent == true )
 {
	g_LeftOffset=jsGetEvent_coord("X"); //-g_PopupW;
	g_TopOffset =jsGetEvent_coord("Y");
	
 } else
 {
  //if( g_LeftOffset <= 0 )
  if( nBody == 0 )
  {
	g_LeftOffset=(document.body.offsetWidth-g_PopupW)/2;
	g_TopOffset =(document.body.offsetHeight-g_PopupH)/2;
  } else
  { // nBody != 0
	g_LeftOffset=(window.screen.width-g_PopupW)/2;
	g_TopOffset =(window.screen.height-g_PopupH)/6;
  } // end else
 } // end else
 
 if( !b_IsIe )
    g_TopOffset += document.body.scrollTop;

	//alert(  g_LeftOffset + " / " + g_TopOffset + " / "
	//                + g_PopupW + " / " + g_PopupH);


	if( g_PopupH < 20 ) g_PopupH = 244;

	if( b_IsIe )
	    g_oPopupWind.show(  g_LeftOffset, g_TopOffset ,
	                g_PopupW, g_PopupH,
	                document.body );
	else
	{
		div.style.display='block';
		div.style.left = g_LeftOffset;
		div.style.top  = g_TopOffset;
		//alert( "left="+g_LeftOffset+" top="+g_TopOffset+ " nBody"+nBody )
	}

	js_StartPopUpTimer();
} // end pgm


function js_StartPopUpTimer()
{
	if( g_bPopUpTimer_bYesStart == false ) return;
	g_PopUpTimeCur = g_PopUpTimeStep;
	g_PopUpTimer = setInterval('js_ModPopupRun()',g_PopUpTimeStep);
} // end pgm

function js_ModPopupRun()
{
    if( g_PopUpTimer == null ) return;
    if( g_PopUpTimeCur >= (g_PopUpTimeMax+g_PopUpTimeStep) )
    {
        js_StopPopupRun();
        return;
    } // end if

    g_PopUpTimeCur += g_PopUpTimeStep;

	if( g_oPopBodyRun != null )
	{
	    var img = null; // и id и name
	    if( isIe() )
		    img = g_oPopBodyRun.document.all("img_forPopUpRun")
		else
		    img = document.getElementById("img_forPopUpRun")
		    
		if( img != null )
		{
	    	img.style.width = ""+(100/(g_PopUpTimeMax/g_PopUpTimeCur))+"%";
		}
	}

    if( g_sPopUpTimer_EvalOfStep != "" )
    	eval( g_sPopUpTimer_EvalOfStep );
} // end pgm


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

