// JavaScript Document
//F-tmpMetaSearch.htm
//af copy of func-Fmain3.js

function control() 
{
	document.all.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.check1 !=null)
	    selectedItem('4');
}

//=================================================================================
function CheckToSubmitEntry() 
{		
	
	if (( document.all.form1.TEXT1.value == ""  ) &&
	   (  document.all.form1.select3.value == "" ))
 	{
		alert('Please enter your search.');		 			
		return false;		
	} 	
	else 
    {    						
		if (checkForOneCenter()==false){
		 	alert('Please select at least one center.');	
			return false;
		}else{
			document.all.form1.ROWCOUNT.value =10; 						
			document.all.form1.TEXT4.value =document.all.form1.select3.options[document.all.form1.select3.selectedIndex].value;
			document.all.form1.TAG1.value =document.form1.ComboSrch.options[document.form1.ComboSrch.selectedIndex].value; 				
			document.all.form1.SrchRelatedHidden.value ="44%2%15%3";				
			SetIdsInArray_Meta();												
			document.all.form1.PAGENAME.value = 'F-tmpMetaSearch';					
			return true;
		}
	 }	 
}

//=================================================================================
//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 = '';
		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 != 'CheckAllMeta' && strName.substring(0,5)=='check' ) 
			{								
				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 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
}

//=================================================================================
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;
		}		
	}
	
}

//========================================================================
function checkForOneCenter(){
	var coll = document.all.tags("input");
	var hasChecked=false;
	if ( document.all.CheckAllMeta.checked == false )  
	{
		if ( coll != null ) 
		{
			for ( i = 0; i < coll.length; i++ ) 	
			{							
				if ( coll[i].type == 'checkbox' && 
					 coll[i].checked == true  &&   coll[i].id !='CheckAllMeta') 
				  {										
					   hasChecked = true;
				  }
			}//end of for
		}//end of if
	}else{
		hasChecked = true;
	}//end of if
	return hasChecked;
}

