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.focus();}

    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);
    
    AnElem = document.getElementById('DocHasERSpecificCB');
    if (AnElem){ 
      AnElem.checked = false;
      DocHasERChanged(document, event);
    }
  }   
   
  function ResetERSrchPage(){
    var AnElem;
     
    AnElem = document.getElementById('ERFullTextIL') ;
    if(AnElem) {AnElem.value = ''; AnElem.focus();}
    AnElem = document.getElementById('ERDescIL') ;
    if(AnElem) AnElem.value = '';
    AnElem = document.getElementById('ERKeywordIL') ;
    if(AnElem) AnElem.value = '';
    AnElem = document.getElementById('ERFileNameIL') ;
    if(AnElem) AnElem.value = '';
    AnElem = document.getElementById('ERFormatIL') ;
    if(AnElem) AnElem.value = '';
    AnElem = document.getElementById('ERSizeFromIL') ;
    if(AnElem) AnElem.value = '';
    AnElem = document.getElementById('ERSizeToIL') ;
    if(AnElem) AnElem.value = '';
    AnElem = document.getElementById('ERNoteIL') ;
    if(AnElem) AnElem.value = '';
    AnElem = document.getElementById('ERBiblioQueryIL') ;
    if(AnElem) AnElem.value = '';     
    AnElem = document.getElementById('ERBiblioFieldLB') ;
    if(AnElem) AnElem.selectedIndex = 0;
    AnElem = document.getElementById('ERBiblioR') ;
    if(AnElem) AnElem.checked = true;
     
    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.focus();}
    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('AllDBsCB') ;
    if(AnElem) AnElem.checked = true;
    AllDBsCBChange(AnElem);
    
    AnElem = document.getElementById('DocHasERSpecificCB');
    if (AnElem){ 
      AnElem.checked = false;
      DocHasERChanged(document, event);
    }
  }

  function ResetAdvanceSrchPage(){
    var AnElem;
    
    AnElem = document.getElementById('FirstTextIL');
    if(AnElem) {AnElem.value = '';  AnElem.focus();}
    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';  
*/

   var ACol = document.forms[0].elements['FirstOpByRB'];
   if (ACol){ 
      for (var i = 0; i < ACol.length; i++)
        if (ACol[i].value == 'AND')   ACol[i].checked = true;
   }

   var ACol = document.forms[0].elements['SecondOpByRB'];
   if (ACol){ 
      for (var i = 0; i < ACol.length; i++)
        if (ACol[i].value == 'AND')   ACol[i].checked = true;
   }
 

    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);
    
    AnElem = document.getElementById('DocHasERSpecificCB');
    if (AnElem){ 
      AnElem.checked = false;
      DocHasERChanged(document, event);
    }
  }
  // omid : if ERSearch Called From ExternalUser for Back to serach Page "DPN" Must Set From IsFarsi 
  function SetDoFullERSearch()
  {
    var AnElem=document.getElementById('SPN');
    if(!AnElem) return false;
    var AIsDoFullPage = (AnElem.value=='DOFULL');
    if (!AIsDoFullPage) return false;
    
    AnElem=document.getElementById('ISFARSI');
    if(!AnElem) return true;
    var AIsFarsi = (AnElem.value=='1')
    
    AnElem=document.getElementById('DPN');
    if(!AnElem) return true;
    if (AIsFarsi) AnElem.value = 'FERSEARCH';
    else          AnElem.value = 'LERSEARCH';
    return true;
  }

  function EditSearchBtnClick(AButton, AnEvent){
    var AnElem=document.getElementById('DPN');
    if(!AnElem){ CancelEvent(AnEvent); return;}
// omid: MainVerion    AnElem.value='';  
// omid    if (!SetDoFullERSearch()) AnElem.value='';
    SetDoFullERSearch();

    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';
  
    AnElem = document.forms[0].elements['HINDEX'];
     if (AnElem)    AnElem.value = 0;

    document.forms[0].action = _ServerPath + '/SrchDlg';    
    document.forms[0].submit();
  }

//*************************************************
  function CenterAllKindClick(ACheckBox){
     var AnElem, AnAllChBoxElem;
       
     if(!ACheckBox) return;
     
     var AName = ACheckBox.getAttribute('AllCheckBoxID');
     AnAllChBoxElem = document.getElementById(AName);
     if(!AnAllChBoxElem) return;
     
     AnAllChBoxElem.disabled = (!ACheckBox.checked);
     AnAllChBoxElem.checked = ACheckBox.checked;

  }   

  function CanKindClick(ACheckBox){
     var AnElem, ACol, Adisabled, ANodeList, ACenterID;
       
     if(!ACheckBox) return;
     
     ACenterID = ACheckBox.getAttribute('AllBoxCenterID');
     
     AnElem = document.getElementById('ServersListDiv');  
     if (AnElem){ 
       var ACol = AnElem.childNodes;

       if (ACol){   
         if (ACheckBox.checked)      Adisabled = true;       
         else                        Adisabled = false;       
         
         if(!ACol.length){
           
           if(ACol.id != ACenterID) return;
         
           ANodeList = ACol.childNodes;
           
           for (var j = 0; j< ANodeList.length; j++)
             if (ANodeList[j].id == "ServersList"){
               ANodeList[j].checked = ACheckBox.checked;
               //ANodeList[j].disabled = Adisabled;
             }
         }
         else
           for (var i = 0; i <ACol.length; i++){
             if(ACol[i].id != ACenterID) continue;
           
             ANodeList = ACol[i].childNodes;
             for (var j = 0; j< ANodeList.length; j++)
               if (ANodeList[j].id == "ServersList")
               {
                 ANodeList[j].checked = ACheckBox.checked;
                 //ANodeList[j].disabled = Adisabled;
               }  
           }
         
       }    
     }	
  }   
//*************************************************
  function CenterKindClick(ACheckBox){
     var AnElem, ACol, ADisplay, ANodeList, ACenterID;
       
     if(!ACheckBox) return;
     CenterAllKindClick(ACheckBox);
     
     ACenterID = ACheckBox.getAttribute('CenterID');
     
     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 != ACenterID) 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 != ACenterID) 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, ACenterID;
     
     AnElemList = document.forms[0].elements['CenterKindCB'];
     if (AnElemList){
       for ( i = 0; i <AnElemList.length; i++){ 
         AnIndex = AnElemList[i].CenterID.indexOf("CenterKind"); 
         if(AnIndex == -1) continue;
         
         ACenterID = AnElemList[i].CenterID.substring(AnIndex + 10, AnElemList[i].CenterID.length);  		
         
         if ((ACenterID & ACenterKind) != 0)  
           AnElemList[i].checked = true;
         else                                    
           AnElemList[i].checked = false;
           
         CenterKindClick(AnElemList[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]);
       }  
     }          */
   }

   function ShowOtherSearchPage(AnEvent, ASrchKind){
     var AnElem = GetElem(AnEvent, 'DPN');
     if (!AnElem) return false;
     
     AnElem.value = ASrchKind;
     document.forms[0].submit();
   }

   function InitNosaButtons(AnElem, ACaption){
     if (AnElem){ 
       var AColor = '#EEE8AA';
       if (AnElem.getAttribute('NormalColor'))
       AColor = (AnElem.getAttribute('NormalColor')).toString();
       SetButtonNosaCaption(AnElem, ACaption, AnElem.getAttribute('NormalImg', 0), 
         AColor);
     }       
   }

   function SetWaitToSearchMsgState(document, ShowMsg){
     AnElem = document.getElementById('PageDiv');
     if(AnElem)
       if (ShowMsg)  AnElem.style.display = 'none';  
       else          AnElem.style.display = '';  

     AnElem = document.getElementById('WaitToSearchMsgDiv');
     if(AnElem)
       if (ShowMsg)  
       {
         AnElem.style.display = '';     
         window.status = "Loading ..."; 
         DoProgress(true);  
       }else
       {
         AnElem.style.display = 'none'; 
         DoProgress(false); 
       }
   }
   
   function DocHasERChanged(document, AnEvent){
     ADocHasER = GetElem(AnEvent, 'DocHasERSpecificCB');
     if(!ADocHasER) return;
     AnERKinds = document.forms[0].elements['ERKind'];
     if(!AnERKinds) return;
     
     for(var Idx = 0; Idx < AnERKinds.length; Idx++)
     {
       AnERKinds[Idx].checked = ADocHasER.checked;
       AnERKinds[Idx].disabled = ADocHasER.checked;
     }
   }
   
   function CheckServerListSelection(){
     var Result = false;
     
     var ACol = document.forms[0].elements;
     var ServerCount = 0;
     if (ACol){ 
       for (var i = 0; i < ACol.length; i++){
         if (ACol[i].id == 'ServersList')      
           if (ACol[i].checked) ServerCount++;
       }  
       if (ServerCount != 0)    Result = true;       
     } 
     
     return Result;     
   }
   
   function CheckDBListSelection(){
     var Result = false;
   
     var ACol = document.forms[0].elements['DBsList'];
     var DBCount = 0;
     if (ACol){ 
       for (var i = 0; i < ACol.length; i++)
         if (ACol[i].checked) DBCount++;
       if (DBCount != 0)  Result = true;
     }  
     return Result;     
   }
   
   function SubmitSearchRequest(AnEvent){
     var AStr = document.forms[0].action;   
     var re = /SrchDlg/;             
     document.forms[0].action = AStr.replace(re, "Search");    
     
     AnElem = GetElem(AnEvent, 'DPN');
     if (!AnElem) return;
     AnElem.value = 'DONEWSRCH';

     SetWaitToSearchMsgState(document, true);
     
     document.forms[0].submit();   
   }
   
   function AllDBsCBChange(ACheckBox){
     AnElem = document.getElementById('DBsListDiv');  
     if (AnElem){ 
       var ACol = document.forms[0].elements['DBsList'];
       if (ACol){ 
         for (var i = 0; i < ACol.length; i++)
           ACol[i].checked = ACheckBox.checked;
       }    
     }	
   }
  
   function DBsListClicked(){
     AnElem = document.forms[0].elements['AllDBsCB'];  
     if (AnElem)
       AnElem.checked = false;
   } 

