// JavaScript Document
//F-tmpBasicSrch.htm

function control() 
{
	document.form1.TEXT1.focus();
	if (document.form1.ComboSrch != null)  
	   document.form1.ComboSrch.selectedIndex=0;
	if (document.form1.select3.selectedIndex!=null)  
	    document.form1.select3.selectedIndex=0;
	if (document.form1.TotalCenterId !=null)
	    selectedItem('3');
	if (document.form1.check1 !=null)
	    selectedItem('4');	
}

//=================================================================================
function CheckToSubmitEntry() 
{		

	if ((document.form1.TEXT1.value == "" ) &&
	   (document.form1.TEXT4.value == "" ))
 	{
		alert('Please enter your search.');		 		
		control();			
		return false;
		
	} 	
	else 
    {    				
		var strText = document.form1.TEXT1.value;
		var strChar = "!&:~%";
		var lenChar = strChar.length;
		var lenText = strText.length;
		var isChar;
		var strSearch="";		
		for ( i = 0; i < lenText; i++ ) {
			isChar=0;			
			for ( j = 0; j < lenChar; j++ ){						
				if ((strText.charAt(i))==(strChar.charAt(j))){					
					isChar=1;
				}			
			}			
			if (isChar==0) {				
				strSearch=strSearch+strText.charAt(i);
			}else if ((i>0) && (i<lenText) && (strSearch.charAt(i-1)!=' ') && (strSearch!='')){
				strSearch=strSearch+' ';
			}			
		}		
		
		if ((strSearch=="") &&
	   		( document.form1.TEXT4.value == "" )){
			alert('Please enter correct word(s).');
			return false;
			
		}else{
			document.form1.TEXT1.value=strSearch;
			if ((document.form1.TAG1.value=='TITLE' ) ||
			   (document.form1.TAG1.value=='AUTHOR' ) ||
			   (document.form1.TAG1.value=='SUBJECT' )){
				var act=document.form1.action;
				endStr=act.lastIndexOf("/",act.length);
				if (endStr!=-1){					
					act=act.substring(0,endStr);				
				}
				act=act+'/Browse';
				document.form1.action=act;
				document.form1.ROWCOUNT.value =10;
				if ( document.form1.TEXT1.value != '' ) {
					document.form1.HidTEXT.value = document.form1.TEXT1.value;
					document.form1.HidTYPE.value = document.form1.TAG1.value;
					document.form1.PAGENAME.value = 'F-BrowseDic';				
					return true;
				}
			}else{
					document.form1.ROWCOUNT.value =10; 							
					document.form1.TEXT4.value =document.form1.select3.options[document.form1.select3.selectedIndex].value;
					document.form1.TAG1.value =document.form1.ComboSrch.options[document.form1.ComboSrch.selectedIndex].value; 				
					document.form1.SrchRelatedHidden.value ="44%2%15%3";
					SetDbIdsInList_localOtherDB();
					SetIdsInArray_Meta();								
					document.form1.PAGENAME.value = 'F-tmpBasicSrch';				
					return true;
				  }
			}
		}
}

//=================================================================================
//af from func-Fbasic8.js
function CheckAllCentersLocalOtherDB() 
{
	var coll = document.all.tags("input");
	if ( document.all.TotalCenterId.checked == true )  
	{
		if ( coll != null ) 
		{			
			for ( i = 0; i < coll.length; i++ ) 	
			{		
			    ss=coll[i].name;
				if ( coll[i].type == 'checkbox' && 
					 coll[i].checked == false &&  ss.substring(0,13)=='TotalCenterId') 
					 coll[i].checked = true;
			}//end of for
		}//end of if
	}//end of if
	else 
	{
		if ( coll != null ) 
		{
			for ( i = 0; i < coll.length; i++ ) 	
			{		
			    ss=coll[i].name;
				if ( coll[i].type == 'checkbox' && 
					 coll[i].checked == true && ss.substring(0,13)=='TotalCenterId' ) 
					coll[i].checked = false;
			}//end of for
		}//end of if
	}//end of else
}

//=================================================================================
//af from func-Fbasic8.js
function CheckAllCentersMeta() 
{
	var coll = document.all.tags("input");
	if ( document.all.CheckAllMeta.checked == true )  
	{
		if ( coll != null ) 
		{
			for ( i = 0; i < coll.length; i++ ) 	
			{			
				ss=coll[i].name;
				if ( coll[i].type == 'checkbox' && 
					 coll[i].checked == false  &&   ss.substring(0,5)=='check') 
				  {										
					   coll[i].checked = true;
				  }
			}//end of for
		}//end of if
	}//end of if
	else 
	{
		if ( coll != null ) 
		{
			for ( i = 0; i < coll.length; i++ ) 	
			{	
			    ss=coll[i].name;	
				if ( coll[i].type == 'checkbox' && 
					 coll[i].checked == true && ss.substring(0,5)=='check'  ) 
					coll[i].checked = false;
			}//end of for
		}//end of if
	}//end of else
}
//=================================================================================
//af from func-Fbasic8.js
function SetDbIdsInList_localOtherDB() 
{
	var strS, iLen;
	var coll = document.all.tags("input");
	if ( coll != null ) 
	{		
		document.all.form1.hidDbList.value = '';		
		for ( i = 0; i < coll.length; i++ ) 	
		{		
			strName=coll[i].name;
			if ( coll[i].type == 'checkbox' && 
			     coll[i].checked == true  &&
				 strName != 'TotalCenterId' && strName.substring(0,13)=='TotalCenterId' )  
			{
				strS = coll[i].value;
				if ( document.all.form1.hidDbList.value == '' )  
					document.all.form1.hidDbList.value = strS;
                else 
					document.all.form1.hidDbList.value = document.all.form1.hidDbList.value +'*'+ strS;
			}
		}					 
	}
}

//=================================================================================
//af: from func-Fbasic8.js
//This function calles before submitting the page. It puts checkbox's id in a hidden text that
// is/are selected.
function SetIdsInArray_Meta() 
{
	var strS, iLen, strSub,HostID,flag;
	var coll = document.all.tags("input");	
	flag=0;
	if ( coll != null ) 
	{
		document.all.form1.hidIPList.value = '';
		document.all.form1.hidHostId.value = '';
		for ( i = 0; i < coll.length; i++ ) 	
		{					
			strName=coll[i].name;
			if ( coll[i].type == 'checkbox' && 
			     coll[i].checked == true && 
				 strName != 'CheckAllMeta' && strName.substring(0,5)=='check' ) 
			{
				if (flag==0) {
					if ( document.all.form1.hidDbList.value != '')
	                    document.all.form1.hidDbList.value = document.all.form1.hidDbList.value+'*Meta';
					flag=1;	
				}
				
				strS   = coll[i].name;
				iLen   = strS.length;
				HostID = strS.substring(5,iLen);				
				if ( document.all.form1.hidHostId.value == '')
				    document.all.form1.hidHostId.value = HostID;
				else
				    document.all.form1.hidHostId.value = document.all.form1.hidHostId.value+'*'+HostID;				
				strSub = coll[i].value ;
				
				if ( document.all.form1.hidDbList.value == '' )  
					document.all.form1.hidDbList.value ='Meta*'+strSub;
				else 
					document.all.form1.hidDbList.value = document.all.form1.hidDbList.value+'*'+strSub;
			}
		}
	}	
}
//=================================================================================
//af: from func-Fbasic8.js
function ShowGroup(id)
{
	var tdList = document.getElementsByTagName("td");
	for (var i=0;i<tdList.length;i++) 
			if (tdList[i].className == id) {		
				if(tdList[i].style.visibility == "visible") {
					tdList[i].style.visibility = "hidden";
					tdList[i].style.display = "none";
				}
				else {
					tdList[i].style.visibility = "visible"; 
					tdList[i].style.display = "block"; 
				}
			}
	var imgList = document.getElementsByTagName("img");
	for (var i=0;i<imgList.length;i++) 
			if (imgList[i].id == id) {	
				var s = new String();
				s = imgList[i].src;
				var index =s.lastIndexOf("/");
				var str = s.substring(index+1, s.length).toLowerCase();	
				if(str =="plus2.gif") 
				{
					imgList[i].src =s.substring(0,index+1)+"minus2.gif";	
				}
				else if(str =="minus2.gif") 
				{
					imgList[i].src =s.substring(0,index+1)+"plus2.gif";
				}
			}
}

//=================================================================================
function selectedItem(num){
    var coll = document.all.tags("input");
	switch (num) 
	{		
		case '1':
			  document.getElementById('feildSrch1').innerHTML=document.form1.ComboSrch.options[document.form1.ComboSrch.selectedIndex].name;  
	          document.getElementById('limitOption1').style.display = "none";
			  document.getElementById('picLimit1').src = 'image/down.gif';
			 
			break;
		case '2':
			  var strLimit;
			  strLimit=document.form1.select3.options[document.form1.select3.selectedIndex].name;
			  if (document.form1.Attachment.checked==true)	      
				  strLimit=strLimit+' , &#1605;&#1606;&#1575;&#1576;&#1593; &#1583;&#1740;&#1580;&#1740;&#1578;&#1575;&#1604; &#1583;&#1575;&#1585;&#1583;';
			  if (document.form1.RegNumber.checked==true)	      
				  strLimit=strLimit+' , &#1605;&#1608;&#1580;&#1608;&#1583;&#1740; &#1583;&#1575;&#1585;&#1583;'; 		  
			   document.getElementById('feildSrch2').innerHTML=strLimit;
			break;
		case '3':						
			  if (document.form1.TotalCenterId !=null){
				  var count=0;
				  if (document.form1.TotalCenterId !=null){
					  if (document.all.TotalCenterId.checked == true){
						  document.getElementById('feildSrch3').innerHTML='&#1607;&#1605;&#1607; &#1605;&#1608;&#1575;&#1585;&#1583';
					  }else{
						  if ( coll != null ) 
						  {
							   for ( i = 0; i < coll.length; i++ ) 	
							   {	
								   strName=coll[i].name;	
								   if ( coll[i].type == 'checkbox' && 
										   coll[i].checked == true && strName != 'TotalCenterId' && 
										   strName.substring(0,13)=='TotalCenterId'  ) 
									   count=count+1;
							   }//end of for
							   if (count==0){
								   document.getElementById('feildSrch3').innerHTML='&#1607;&#1740;&#1670; &#1705;&#1583;&#1575;&#1605;';		
							   }else{
								   document.getElementById('feildSrch3').innerHTML='(&#1578;&#1593;&#1583;&#1575;&#1583; &#1576;&#1575;&#1606;&#1705; &#1575;&#1606;&#1578;&#1582;&#1575;&#1576; &#1588;&#1583;&#1607; ('+count+' &#1576;&#1575;&#1606;&#1705;'; 	
							   }			   
						  }//end of if   
					  }
				  }
	
			  }			    			
			break;
		case '4':						
			  if (document.form1.check1 !=null){
				  var count=0;
				  if (document.all.CheckAllMeta.checked == true){
					  document.getElementById('feildSrch4').innerHTML='&#1607;&#1605;&#1607; &#1605;&#1608;&#1575;&#1585;&#1583';
				  }else{
					  if ( coll != null ) 
					  {
						   for ( i = 0; i < coll.length; i++ ) 	
						   {	
							   strName=coll[i].name;	
							   if ( coll[i].type == 'checkbox' && 
										coll[i].checked == true && strName != 'CheckAllMeta' && 
										strName.substring(0,5)=='check'  ) 
								   count=count+1;
						   }//end of for
						   if (count==0){
							   document.getElementById('feildSrch4').innerHTML='&#1607;&#1740;&#1670; &#1705;&#1583;&#1575;&#1605;';		
						   }else{
							   document.getElementById('feildSrch4').innerHTML='(&#1578;&#1593;&#1583;&#1575;&#1583; &#1605;&#1585;&#1705;&#1586; &#1575;&#1606;&#1578;&#1582;&#1575;&#1576; &#1588;&#1583;&#1607; ( '+count+' &#1605;&#1585;&#1705;&#1586;'; 	
						   }			   
					  }//end of if   
				  }	  
			  }			    		
			break;	
	}
}

//=================================================================================
function showLimitOption(id)
{
	var limitOption='limitOption'+id;
	var picLimit='picLimit'+id;

	var coll = document.getElementsByTagName("tr");
	if ( coll != null ) 
	{
		for ( i = 0; i < coll.length; i++ ) 	
		{		
			strid=coll[i].id;
			if (strid.substring(0,11)=='limitOption'){
			   if ( strid!=limitOption && coll[i].style.display ==""){
			      coll[i].style.display ="None";				  
				  if (strid=='limitOption1' ){ 
				      selectedItem('1');
					  document.getElementById('picLimit1').src = 'image/down.gif';
				  }else if (strid=='limitOption2' ){ 				   
			                selectedItem('2');
					        document.getElementById('picLimit2').src = 'image/down.gif';
				  }else	 if (strid=='limitOption3' ){			  					   				   
						     selectedItem('3');
						     document.getElementById('picLimit3').src = 'image/down.gif';
				  }else  if (strid=='limitOption4' ){					  							 				   
							 selectedItem('4');
							 document.getElementById('picLimit4').src = 'image/down.gif';
				  }				  
			   }																		  
			}					
		}
	}	

	if (document.getElementById(limitOption).style.display ==""){		 
		document.getElementById(limitOption).style.display ="None";
		document.getElementById(picLimit).src = 'image/down.gif';
		selectedItem(id);					
	}
	else{
		document.getElementById(limitOption).style.display ="";
		document.getElementById(picLimit).src = 'image/up.gif';		
	}
}

//=================================================================================
function deselectAllChechBox(id){
	strName=document.getElementById(id).name;	
	if (strName.substring(0,5)=='check' ){	 // for meta checkboxes
	    var countFalse=0;
		if (document.getElementById(id).checked==false && document.all.CheckAllMeta.checked==true ){
		    document.all.CheckAllMeta.checked=false;
		}else if (document.getElementById(id).checked==true && document.all.CheckAllMeta.checked==false ){
		    var coll = document.all.tags("input");		   		 		   
		     if ( coll != null ) 
		     {			
				 for ( i = 0; i < coll.length; i++ ) 	
				 {		
					 strName=coll[i].name;
					 if ( coll[i].type == 'checkbox' && 
						      coll[i].checked == false && strName != 'CheckAllMeta' && 
							  strName.substring(0,5)=='check') 
						  countFalse =countFalse+1;
				 }//end of for
			  }//en of if
			  if (countFalse==0) document.all.CheckAllMeta.checked=true;
		}
	}else{	// for centers checkboxes	
		var countFalse=0;
		if (document.getElementById(id).checked==false && document.all.TotalCenterId.checked==true ){
		    document.all.TotalCenterId.checked=false;
		}else if (document.getElementById(id).checked==true && document.all.TotalCenterId.checked==false ){
		     var coll = document.all.tags("input");		   		 		   
		     if ( coll != null ) 
		     {			
				 for ( i = 0; i < coll.length; i++ ) 	
				 {		
					 strName=coll[i].name;
					 if ( coll[i].type == 'checkbox' && 
						      coll[i].checked == false && strName != 'TotalCenterId' && 
							  strName.substring(0,13)=='TotalCenterId') 
						  countFalse =countFalse+1;
				 }//end of for
			  }//en of if
			  if (countFalse==0) document.all.TotalCenterId.checked=true;
		}		
	}
	
}
