﻿var cmdName;
 function doSubmit(command){
     cmdName = command; 
    if (getElm('mode') && getElm('mode').value.indexOf('edit')!=-1){
        if (command =='trash'){
            dwsConfirm(culture.term('DoYouWantToDeleteThisRecord'));
        }else
            submit();
   }else{
        var count=0;
        if (setCount)
            count=setCount();
        
        if ((command =='trash'||command =='edit'||command =='approve'||command =='disapprove') && count==0)        
            msgBox(culture.term('YouDoNotSelectAnyRecord'));
        else            
            (command =='itemdelete'||command =='trash'||command =='approve'||command =='disapprove')?dwsConfirm(count+'  '+culture.term('RecordWillBeAffectedDoYouWantToContinue')):submit();
    }
 };
 
function dwsConfirm(message,result){
    result=result==null?submit:result;
    msgBox(message,null,2,true,result);
}
function doJob(action,params,rand,method){
    params = (params == null) ? '' : params;
	getContent(null,"pages/Do.html?action="+action,params,rand,method);
}
 function submit(result){ 
    if (result==null || result==1){
      try{
           if(!validateForm || validateForm(cmdName)){              
              getElm('action').value=cmdName;
              if (document.forms[0].onsubmit){
                 document.forms[0].onsubmit();
              }      
              document.forms[0].submit();              
              return true;
              }
              return false;
         }
         catch(e){
        }    
    }        
 };
 
 function doSort(Col,command){        
    getElm('sortColumn').value=Col;
    return doSubmit(command);
 };
 
 function doSearch(state){
    getElm('Search').value=state;
    return doSubmit('search');        
 }; 
 
function checkAll(name){
    var cbs=document.getElementsByName(name) 
    for (var i=0;i<cbs.length;i++){
        if (cbs[i].checked != getElm('cbCheckAll').checked)
        cbs[i].click();
    }
};

function checkItem(id,name){ 
    var cbs=document.getElementsByName(name);
    for (var i=0;i<cbs.length;i++){
        cbs[i].checked=false; 
    }
    getElm(id).checked=true; 
};

function checkHover(obj,oldClass,type){
    if (type=="in" && obj.className!='selectedListRowS1')
    setClass(obj,'hoverListRowS1'); 
    else if (obj.className!='selectedListRowS1')
    setClass(obj,oldClass); 
};
function checkClick(obj,oldClass){   
    if (!obj.checked){
        setClass(obj.parentNode.parentNode,oldClass);
        getElm('checkedItemsCount').value--;
    }    
    else{
        setClass(obj.parentNode.parentNode,'selectedListRowS1'); 
        getElm('checkedItemsCount').value++;
    }    
};


function setOtherModulesPos(){ 
 var elm=getElm('dvSubMenus');
  var lnk=getElm('lnkSubMenus');
  elm.style.left=(findPosX(lnk)-9)+'px';
  elm.style.top=(findPosY(lnk)+17)+'px';
}
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  
  var showOtherMenusFlag=true;
  
  function lnkMouseOver(){
  var elm=getElm('dvSubMenus');
  otherModulesCounter=0;
  otherModulesCounterStart=false;
  showOtherMenus(true);
  if(otherModulesTimer)
    window.clearTimeout(otherModulesTimer);
  }

function lnkMouseOut(){
  if(!otherModulesCounterStart)
        counterClose();
 
  }
  
  function showOtherMenus(show){
                     
  var elm=getElm('dvSubMenus');
  if (show)
       elm.style.visibility = 'visible';
  else
       elm.style.visibility = 'hidden';

  }
  
  
  var otherModulesCounter=0;
  var otherModulesCounterStart=false;
  var otherModulesTimer;
  
  function counterClose(){
      if(otherModulesCounter<1){
          otherModulesCounterStart=true;
          otherModulesCounter++;
          otherModulesTimer=setTimeout('counterClose();',150);
      
      }else{
          otherModulesCounter=0;
          otherModulesCounterStart=false;
          showOtherMenus(false);
      }
  }
