// JavaScript Document
//F-tmpAdvancedSrch.htm


function ResetFunc() 
{
	form1.reset();
	document.all.form1.TEXT1.focus();
}

//==========================================================
function control() 
{
	document.all.form1.TEXT1.focus();
	document.all.form1.TEXT6.value = '';
	document.all.form1.TEXT8.value = '';
	if (document.form1.ComboSrch != 0)  
	   document.form1.ComboSrch.selectedIndex=0;
	if (document.form1.select18.selectedIndex!=0)  
	    document.form1.select18.selectedIndex=0;
	if (document.form1.Location.selectedIndex!=0)  
	    document.form1.Location.selectedIndex=0;
	if (document.form1.Language.selectedIndex!=0)  
	    document.form1.Language.selectedIndex=0;
	if (document.form1.TotalCenterId !=null)
	    selectedItem('3');
	if (document.form1.check1 !=null){		
	    selectedItem('4');
	}
	document.form1.Attachment.checked=false;	
	document.all.form1.TEXT5.value = '';
	document.all.form1.TAG5.value = '';
	
	document.all.form1.RegNumber.checked=false;
	document.all.form1.TEXT7.value = '';
	document.all.form1.TAG7.value = '';	
}

//=================================================================================
function CheckToSubmitEntry() {
	if ( ( document.form1.TEXT1.value == "" ) &&
         ( document.form1.TEXT2.value == "" ) && 
         ( document.form1.TEXT3.value == "" ) &&  
		 ( document.form1.TEXT4.value == "" ) &&
		 ( document.form1.Language.value == "" ) &&
		 ( document.form1.Location.value == "" ) &&
		 (document.form1.Attachment.checked==false)) 

 	{				
		alert('Please enter your search.');
		control();
		return false;
	}else {    				
		var strText1 = document.all.form1.TEXT1.value;
		var strText2 = document.all.form1.TEXT2.value;
		var strText3 = document.all.form1.TEXT3.value;
		var strChar = "!&:~%";
		var lenChar = strChar.length;
		var lenText1 = strText1.length;
		var lenText2 = strText2.length;
		var lenText3 = strText3.length;
		var isChar;
		var strSearch1="";		
		var strSearch2="";		
		var strSearch3="";		
		// for TEXT1
		for ( i = 0; i < lenText1; i++ ) {
			isChar=0;			
			for ( j = 0; j < lenChar; j++ ){						
				if ((strText1.charAt(i))==(strChar.charAt(j))){					
					isChar=1;
				}			
			}			
			if (isChar==0) {				
				strSearch1=strSearch1+strText1.charAt(i);
			}else if ((i>0) && (i<lenText1) && (strSearch1.charAt(i-1)!=' ') && (strSearch1!='')){
				strSearch1=strSearch1+' ';
			}			
		}		
		// for TEXT2
		for ( i = 0; i < lenText2; i++ ) {
			isChar=0;			
			for ( j = 0; j < lenChar; j++ ){						
				if ((strText2.charAt(i))==(strChar.charAt(j))){					
					isChar=1;
				}			
			}			
			if (isChar==0) {				
				strSearch2=strSearch2+strText2.charAt(i);
			}else if ((i>0) && (i<lenText2) && (strSearch2.charAt(i-1)!=' ') && (strSearch2!='')){
				strSearch2=strSearch2+' ';
			}			
		}		
		//for TEXT3
		for ( i = 0; i < lenText3; i++ ) {
			isChar=0;			
			for ( j = 0; j < lenChar; j++ ){						
				if ((strText3.charAt(i))==(strChar.charAt(j))){					
					isChar=1;
				}			
			}			
			if (isChar==0) {				
				strSearch3=strSearch3+strText3.charAt(i);
			}else if ((i>0) && (i<lenText3) && (strSearch3.charAt(i-1)!=' ') && (strSearch3!='')){
				strSearch3=strSearch3+' ';
			}			
		}		
		
		if ((strSearch1=="") && 
			 (strSearch2=="") && 
			 (strSearch3=="")&&  
			 ( document.form1.TEXT4.value == "" ) &&
			 ( document.form1.Language.value == "" ) &&
		     ( document.form1.Location.value == "" ) && 
			 (document.form1.Attachment.checked==false)){
			alert('Please enter correct word(s).');
			return false;
			
		} 	
		else
		{
			document.all.form1.TEXT1.value=strSearch1;
			document.all.form1.TEXT2.value=strSearch2;
			document.all.form1.TEXT3.value=strSearch3;
			var coll = document.all.tags("option");
			if ( coll != null ) 
			{				
				for ( i = 0; i < coll.length; i++ )
				{		
					if ( coll[i].name == 'radioGroup1' && 
						 coll[i].selected == true ) 
				   {
						switch ( coll[i].value ) 
						{
							case '+':
								document.all.form1.OPERATOR1.value = '+';		
								break;
							case '*':
								document.all.form1.OPERATOR1.value = '*';		
								break;
							case '^':
								document.all.form1.OPERATOR1.value = '^';
								break;
							default :
								break;
						}//EndofSwich
					}//EndofIf
					else if ( coll[i].name == 'radioGroup2' && 
						 coll[i].selected == true ) 
				   {
						switch ( coll[i].value ) 
						{
							case '+':
								document.all.form1.OPERATOR2.value = '+';		
								break;
							case '*':
								document.all.form1.OPERATOR2.value = '*';		
								break;
							case '^':
								document.all.form1.OPERATOR2.value = '^';
								break;
							default :
								break;
						}//EndofSwich
					}//EndofIf
				}//endofFor
				document.all.form1.ROWCOUNT.value =10;			
			}//end of If
			
			if(document.all.form1.Attachment.checked==true){
			   document.all.form1.TEXT5.value= "";
			   document.all.form1.TAG5.value= "";
			   document.all.form1.TEXT5.value = "T";
			   document.all.form1.TAG5.value = "500";
			}
			if(document.all.form1.RegNumber.checked==true){
			   document.all.form1.TEXT7.value= "";
			   document.all.form1.TAG7.value= "";		   
			   document.all.form1.TEXT7.value = "T";
			   document.all.form1.TAG7.value = "100";
			}
			
			if ( document.all.form1.Location.value != "" )
			{
				document.all.form1.TEXT6.value= "";
				document.all.form1.TAG6.value= "";		   
				document.all.form1.TEXT6.value = document.all.form1.Location.value;
				document.all.form1.TAG6.value = "150";
			}
			
			if (document.all.form1.Language.value != "" )
			{
				document.all.form1.TEXT8.value= "";
				document.all.form1.TAG8.value= "";		   			
				document.all.form1.TEXT8.value = document.all.form1.Language.value;
				document.all.form1.TAG8.value = "300";
			}
	//shahriary	 start	
			if (( document.all.form1.LimitDate.value == "" ) &&
				( document.all.form1.FromYear.value != "" )) 
			{
				{		
				  document.all.form1.TEXT9.value = document.all.form1.FromYear.value;
				}
			
			document.all.form1.TAG9.value = "13";
			
			}	
						  
			if ( document.all.form1.LimitDate.value != "" ) 
			{
				if ((( document.all.form1.LimitDate.value == "<" ) ||
					 ( document.all.form1.LimitDate.value == ">" )) &&
					 ( document.all.form1.FromYear.value != "" ))
				{
					document.all.form1.TEXT9.value = document.all.form1.FromYear.value + document.all.form1.LimitDate.value  ;
				}
				else if (( document.all.form1.LimitDate.value == "-" ) &&
						 ( document.all.form1.FromYear.value != "" ) &&
						 ( document.all.form1.ToYear.value != "" ))
				{
					document.all.form1.TEXT9.value = document.all.form1.FromYear.value + document.all.form1.LimitDate.value +                document.all.form1.ToYear.value;
				}
				document.all.form1.TAG9.value = "13";
			}
			SetDbIdsInList_localOtherDB();
			SetIdsInArray_Meta();		
			
			document.all.form1.PAGENAME.value = 'F-tmpAdvancedSrch';		
			return true;
		 }
	}
}
//shahriary end

//=================================================================================
function JustNumber()
{
	var key = window.event.keyCode;
    if  (( key < 48 ) ||
		( key > 57 ))  
	  window.event.keyCode = 0;
}

//=================================================================================
function ComboDateChange()
{
	var strDate = document.all.form1.LimitDate.value;
	if (( strDate == "<" ) || 
	    ( strDate == ">" ))
	{
		document.all.form1.ToYear.value =  "" ;
		document.all.form1.ToYear.disabled = true;
		document.all.form1.FromYear.disabled = false;
	}
	
	else if (strDate == "-" )
	{
		document.all.form1.ToYear.disabled = false;
		document.all.form1.FromYear.disabled = false;
	}
	else if (strDate == "" )
	{
		document.all.form1.ToYear.value = "" ;
		document.all.form1.FromYear.value = ""; 
		document.all.form1.FromYear.disabled = true;
		document.all.form1.ToYear.disabled = true;
	}
}

//=================================================================================
//shahriary start
function showLimitOption(id)
{
	var limitOption='limitOption'+id;
	var picLimit='picLimit'+id;
	//var limit_lbl='limitLbl'+id;

	var coll = document.all.tags("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.all('picLimit1').src = 'image/down.gif';
				  }else if (strid=='limitOption2' ){ 				   
			                selectedItem('2');
					        document.all('picLimit2').src = 'image/down.gif';
				  }else	 if (strid=='limitOption3' ){			  					   				   
						     selectedItem('3');
						     document.all('picLimit3').src = 'image/down.gif';
				  }else  if (strid=='limitOption4' ){					  							 				   
							 selectedItem('4');
							 document.all('picLimit4').src = 'image/down.gif';
				  }				  
			   }																		  
			}					
		}
	}		
	if (document.all(limitOption).style.display ==""){		 
		document.all(limitOption).style.display ="None";
		document.all(picLimit).src = 'image/down.gif';
		selectedItem(id);		
		}

else{
		document.all(limitOption).style.display ="";
		document.all(picLimit).src = 'image/up.gif';
		}
}

//=================================================================================
function selectedItem(num){
    var coll = document.all.tags("input");
	switch (num) 
	{		
		
		case '2':			  			  
			  var strLimit;			   
			  strLimit=document.form1.select18.options[document.form1.select18.selectedIndex].name;
 			  if (document.form1.Language.options[document.form1.Language.selectedIndex].name!='')
         		strLimit=strLimit+','+document.form1.Language.options[document.form1.Language.selectedIndex].name;			  

			  if (document.form1.Location.options[document.form1.Location.selectedIndex].name!='')
			  	strLimit=strLimit+','+document.form1.Location.options[document.form1.Location.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 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 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;
			}
		}			
	}
}
//=================================================================================
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 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
}
//=================================================================================
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;
		}		
	}
	
}

