function CancelEvent(AnEvent){
  if (AnEvent.stopPropagation){
    AnEvent.stopPropagation;
    AnEvent.preventDefault();
  }   
  else{
    AnEvent.cancelBubble = true;
    AnEvent.returnValue = false;
  }  
}
function ChangeProperty(AnEvent,DPN){
  ButtonClicked(AnEvent,DPN);
  document.forms[0].submit();
}

function SubmitForm(AnEvent,DPN){
  ButtonClicked(AnEvent,DPN);
  document.forms[0].submit();
}
function BtnMouseOver(ABtn, AnEvent){
	if (ABtn.tagName != 'BUTTON') ABtn = ABtn.parentElement;
	if (ABtn.contains(AnEvent.fromElement)) return;
	ABtn.style.borderStyle = 'groove';
	
	var AColor = '#F5F5DC';
	if (ABtn.getAttribute('MouseOverColor')) 
	  AColor = ABtn.getAttribute('MouseOverColor');  
	  
	if ((ABtn.getAttribute('NormalImg')) || (ABtn.getAttribute('NosaCaption')))
	  SetButtonNosaCaption(ABtn, ABtn.getAttribute('NosaCaption'),
	    ABtn.getAttribute('MouseOverImg'), AColor);
}


function BtnMouseOut(ABtn, AnEvent){
	
	if (ABtn.tagName != 'BUTTON') ABtn = ABtn.parentElement;
	if (ABtn.contains(AnEvent.toElement)) return;
	ABtn.style.borderStyle = '';
	
	var AColor = '#EEE8AA';
	if (ABtn.getAttribute('NormalColor'))
	  AColor = (ABtn.getAttribute('NormalColor')).toString();
	  
	if ((ABtn.getAttribute('NormalImg')) || (ABtn.getAttribute('NosaCaption')))
	  SetButtonNosaCaption(ABtn, ABtn.getAttribute('NosaCaption'),
	    ABtn.getAttribute('NormalImg'), AColor);
}

function BtnMouseOver(ABtn, AnEvent){
	if (ABtn.tagName != 'BUTTON') ABtn = ABtn.parentElement;
	if (ABtn.contains(AnEvent.fromElement)) return;
	ABtn.style.borderStyle = 'groove';
	
	var AColor = '#F5F5DC';
	if (ABtn.getAttribute('MouseOverColor')) 
	  AColor = ABtn.getAttribute('MouseOverColor');  
	  
	if ((ABtn.getAttribute('NormalImg')) || (ABtn.getAttribute('NosaCaption')))
	  SetButtonNosaCaption(ABtn, ABtn.getAttribute('NosaCaption'),
	    ABtn.getAttribute('MouseOverImg'), AColor);
}


function BtnMouseOut(ABtn, AnEvent){
	
	if (ABtn.tagName != 'BUTTON') ABtn = ABtn.parentElement;
	if (ABtn.contains(AnEvent.toElement)) return;
	ABtn.style.borderStyle = '';
	
	var AColor = '#EEE8AA';
	if (ABtn.getAttribute('NormalColor'))
	  AColor = (ABtn.getAttribute('NormalColor')).toString();
	  
	if ((ABtn.getAttribute('NormalImg')) || (ABtn.getAttribute('NosaCaption')))
	  SetButtonNosaCaption(ABtn, ABtn.getAttribute('NosaCaption'),
	    ABtn.getAttribute('NormalImg'), AColor);
}
function SetBtnCaption(ABtnID,ABtnCaption){
	AnElem = document.getElementById(ABtnID);
	if (AnElem)
	  SetButtonNosaCaption(AnElem, ABtnCaption, AnElem.getAttribute('NormalImg', 0), 
	    AnElem.getAttribute('NormalColor'));
}
function ButtonClicked(AnEvent,ASKind){
	var AnElem;
	AnElem = document.getElementById('DPN');
	if (!AnElem){ 
	CancelEvent(AnEvent);
	return;
	}  
	AnElem.value = ASKind;

}
function SetBtnNosaCaptionByColor(AButton, AMessage, AnImg, AColor,ATextColor){


  AButton.style.backgroundColor = AColor;
  AButton.setAttribute('NosaCaption', AMessage, 0); 
  
  AnHTML = '<center>';  
  if (AnImg)
    AnHTML = AnHTML  + '<img src="' + _ImagePath + AnImg + '" style="vertical-align:middle" />';
  if (AMessage)
    AnHTML = AnHTML + '&nbsp;<font Color="' + ATextColor + '">' + AMessage + '</font>';
  AButton.innerHTML = AnHTML + '</center>';  

}

function SetButtonNosaCaption(AButton, AMessage, AnImg, AColor){
  var ATextColor ;
       
  AButton.style.backgroundColor = AColor;
  AButton.setAttribute('NosaCaption', AMessage, 0); 
  ATextColor = AButton.getAttribute('TextColor');
  if(!ATextColor) ATextColor = 'black'
  
  AnHTML = '<center style="height:19px;margin:0;padding:0;">';  
  if (AnImg)
    AnHTML = AnHTML  + '<img src="' + _ImagePath + AnImg + '" style="vertical-align:middle;" />';
  if (AMessage)
    AnHTML = AnHTML + '&nbsp;<font Color="' + ATextColor + '">' + AMessage + '</font>';
  AButton.innerHTML = AnHTML + '</center>';  
}
 function GetElem(AnEvent, AnElemName){
   var AnElem = document.forms[0].elements[AnElemName];
   if (!AnElem){ 
     CancelEvent(AnEvent);
     return null;
   }  
   return AnElem
 }
 function GoToLoginPage(AnEvent){
    var AnElem;
    
    AnElem=document.getElementById('DPN');
    if(!AnElem){ CancelEvent(AnEvent); return;}
    AnElem.value='LOGIN';

     var AStr = document.forms[0].action;   
//     var re = /SrchDlg/;             
//     document.forms[0].action = AStr.replace(re, "login");    
     document.forms[0].action = _ServerPath + "/login";    
     document.forms[0].submit();
    
  }
  function LatinNumChar(ACh){
    var ACharCode = ACh.charCodeAt(0);
    if ((ACharCode >= 0x06F0) && (ACharCode <= 0x06F9))
      return String.fromCharCode(ACharCode + 48 - 0x06F0);

    if (ACharCode == 47) return '.'
    else return ACh;
  }   

  function LatinNumStr(AStr){
    var Result = '';
    for (i = 0; i < AStr.length; i++) 
      Result = Result + LatinNumChar(AStr.charAt(i));
    return Result;
  }   

   function ResetSimpleSrchPage(AnEvent){
    var AnElem;
    
 
    AnElem = document.getElementById('SearchTextIL') ;
    if(AnElem) AnElem.value = '';

    AnElem = document.getElementById('SearchInLB') ;
    if(AnElem) AnElem.selectedIndex = 0;
    
    AnElem = document.getElementById('FromYearIL') ;
    if(AnElem) AnElem.value = '';
    
    AnElem = document.getElementById('ToYearIL') ;
    if(AnElem) AnElem.value = '';

    AnElem = document.getElementById('LanguageLB') ;
    if(AnElem) AnElem.selectedIndex = 0;
    
    CheckCenterKind(_LocalCenterKind);
       
    AnElem = document.getElementById('AllDBsCB') ;
    if(AnElem) AnElem.checked = true;
    AllDBsCBChange(AnElem);

   }   


  function ResetFullSrchPage(){
    var AnElem;
    
    AnElem = document.getElementById('GeneralIL');
    if(AnElem) AnElem.value = '';         
    AnElem = document.getElementById('TitleIL');
    if(AnElem) AnElem.value = '';     
    AnElem = document.getElementById('AuthorIL');
    if(AnElem) AnElem.value = '';     
    AnElem = document.getElementById('SubjectIL');
    if(AnElem) AnElem.value = '';     
    AnElem = document.getElementById('PublisherIL');
    if(AnElem) AnElem.value = '';     
    AnElem = document.getElementById('CallNumberIL');
    if(AnElem) AnElem.value = '';     
    AnElem = document.getElementById('ISBNIL');
    if(AnElem) AnElem.value = '';     
    
    AnElem = document.getElementById('TitleOpBtn');
    if(AnElem) AnElem.selectedIndex = 0;     
    AnElem = document.getElementById('AuthorOpBtn');
    if(AnElem) AnElem.selectedIndex = 0;     
    AnElem = document.getElementById('SubjectOpBtn');
    if(AnElem) AnElem.selectedIndex = 0;     
    AnElem = document.getElementById('PublisherOpBtn');
    if(AnElem) AnElem.selectedIndex = 0;     
    AnElem = document.getElementById('CallNumberOpBtn');
    if(AnElem) AnElem.selectedIndex = 0;     
    AnElem = document.getElementById('ISBNOpBtn');
    if(AnElem) AnElem.selectedIndex = 0;     
    
    AnElem = document.getElementById('FromYearIL');
    if(AnElem) AnElem.value = '';         
    AnElem = document.getElementById('ToYearIL');
    if(AnElem) AnElem.value = '';         
    
    AnElem = document.getElementById('LanguageLB');
    if(AnElem) AnElem.selectedIndex = 0;     

    CheckCenterKind(_LocalCenterKind);

/*    AnElem = document.getElementById('AllServersCB') ;
    if(AnElem) AnElem.checked = true;
    AllServersCBChange(AnElem);*/
       
    AnElem = document.getElementById('AllDBsCB') ;
    if(AnElem) AnElem.checked = true;
    AllDBsCBChange(AnElem);
    
  }

  function ResetAdvanceSrchPage(){
    var AnElem;
    
    AnElem = document.getElementById('FirstTextIL');
    if(AnElem) AnElem.value = '';  
    AnElem = document.getElementById('SecondTextIL');
    if(AnElem) AnElem.value = '';  
    AnElem = document.getElementById('ThirdTextIL');
    if(AnElem) AnElem.value = '';  

    AnElem = document.getElementById('FirstSrchInLB');
    if(AnElem) AnElem.selectedIndex = 0;  
    AnElem = document.getElementById('SecondSrchInLB');
    if(AnElem) AnElem.selectedIndex = 0;  
    AnElem = document.getElementById('ThirdSrchInLB');
    if(AnElem) AnElem.selectedIndex = 0;  

    AnElem = document.getElementById('FirstOpByRB');
    if(AnElem) AnElem.value = 'AND';  
    AnElem = document.getElementById('SecondOpByRB');
    if(AnElem) AnElem.value = 'AND';  
    AnElem = document.getElementById('ThirdOpByRB');
    if(AnElem) AnElem.value = 'AND';  

    AnElem = document.getElementById('FromYearIL');
    if(AnElem) AnElem.value = '';         
    AnElem = document.getElementById('ToYearIL');
    if(AnElem) AnElem.value = '';         
    
    AnElem = document.getElementById('LanguageLB');
    if(AnElem) AnElem.selectedIndex = 0;     

    CheckCenterKind(_LocalCenterKind);
/*    AnElem = document.getElementById('AllServersCB') ;
    if(AnElem) AnElem.checked = true;
    AllServersCBChange(AnElem);*/
       
    AnElem = document.getElementById('AllDBsCB') ;
    if(AnElem) AnElem.checked = true;
    AllDBsCBChange(AnElem);

  }

  function EditSearchBtnClick(AButton, AnEvent){
    var AnElem=document.getElementById('DPN');
    if(!AnElem){ CancelEvent(AnEvent); return;}
    AnElem.value='';

    if (AButton.getAttribute('HINDEX')) 
      document.forms[0].elements['HINDEX'].value = AButton.getAttribute('HINDEX');
    document.forms[0].action =  _ServerPath + '/SrchDlg';
    document.forms[0].submit();
  }
   function HistoryBtnClick(AButton, AnEvent){
     var AnElem = GetElem(AnEvent, 'DPN');
     if (AnElem) AnElem.value ='HISTORY'; 
     else{
       CancelEvent(AnEvent);
       return false;
     }
  
     document.forms[0].action = _ServerPath + '/History';    
     document.forms[0].submit();
   }

  function GoToCircSys(AnEvent,ADPN){
    var AnElem;
  
    AnElem = document.getElementById('DPN');
    if(!AnElem){
      CancelEvent(AnEvent);
      return;
    }
    AnElem.value = ADPN;
  
    document.forms[0].action = _ServerPath + '/CircPage';
    document.forms[0].submit();
  }
  function NewSearchBtnClick(AButton, AnEvent){
     var AnElem = document.forms[0].elements['DPN'];
     if (!AnElem){ 
       CancelEvent(AnEvent);
       return;
     }  
     
    AnElem.value = 'FSSEARCH';
  
    document.forms[0].elements['HINDEX'].value = 0;
    document.forms[0].action = _ServerPath + '/SrchDlg';    
    document.forms[0].submit();
  }


  function CenterKindClick(ACheckBox){
     var AnElem, ACol, ADisplay, ANodeList;
       
     if(!ACheckBox) return;
     AnElem = document.getElementById('ServersListDiv');  
     if (AnElem){ 
       var ACol = AnElem.childNodes;

       if (ACol){   
         if (ACheckBox.checked)       ADisplay = "";       
         else                         ADisplay = "none";       
         if(!ACol.length){
           if(ACol.id != ACheckBox.CenterID) return;
         
           ACol.style.display = ADisplay;
           ANodeList = ACol.childNodes;
           for (var j = 0; j< ANodeList.length; j++)
             if (ANodeList[j].id == "ServersList")
               ANodeList[j].checked = ACheckBox.checked;
         }
         else
           for (var i = 0; i <ACol.length; i++){
             if(ACol[i].id != ACheckBox.CenterID) continue;
           
             ACol[i].style.display = ADisplay;
             ANodeList = ACol[i].childNodes;
             for (var j = 0; j< ANodeList.length; j++)
               if (ANodeList[j].id == "ServersList")
                 ANodeList[j].checked = ACheckBox.checked;
           }
         
       }    
     }	
  }   

   function CheckCenterKind(ACenterKind){
     var ASrvList, i;
     
     AnElemList = document.forms[0].elements['CenterKindCB'];
     if (AnElemList){
       for ( i = 0; i <AnElemList.length; i++){ 
         if (AnElemList[i].CenterID == ("CenterKind" + ACenterKind))  
           AnElemList[i].checked = true;
         else                                    
           AnElemList[i].checked = false;
           
         CenterKindClick(AnElemList[i]);
       }  
     }          
   }
