function ricercaSempliceTermine(theForm,theType){
if(!theForm['theTerm'].disabled){
	if(trim(theForm['theTerm'].value) == '' && trim(theForm['[?SEL]'].value) == ''){
		alert('Attenzione:\nInserire almeno un termine di ricerca');theForm['theTerm'].focus();return false;
	}
	if(trim(theForm['theTerm'].value.length) < 3 && trim(theForm['[?SEL]'].value.length) < 3){
		alert('Attenzione:\nIl termine di ricerca deve essere di almeno tre caratteri');theForm['theTerm'].focus();return false;
	}
	re = /\*/gi;re2 = /\?/gi
	if((trim(theForm['theTerm'].value).replace(re,'')).replace(re2,'').length < 3 && trim(theForm['[?SEL]'].value.length) < 3){
		alert('Attenzione:\nLa radice del termine di ricerca deve essere di almeno tre caratteri');theForm['theTerm'].focus();return false;
	}
	for(i=0;i<theForm.length;i++){
		if(theForm.elements[i].checked){break}
		if(i == theForm.length-1){alert('Attenzione:\nSelezionare almeno una tipologia di archivio');return false;}
	}
	if(theType == '' || theType == undefined || theType == '/'){
		ricercaInCorso(true);
	}else{
		analisiInCorso(true);
	}
return true
}else{
return false
}

}

function voc(obj,theTipology){
	theInput = obj.parentNode.getElementsByTagName('input')[0]
	theArchAlias = "";
	returnField = theInput.name;
	theKey = returnField;
	theTerm = trim(theInput.value)
	start = "";
	if(theTipology == 'double'){
		start = "%20"+theTerm;
		
	}else{
	if(theTipology == 'one'){
		start = theTerm;
		if(start == '')
			start = "a";
	}}
		

	re = /\[/gi;
	theKey = theKey.replace(re,'');
	re = /\]/gi;
	theKey = theKey.replace(re,'');
	
	if(theTerm.indexOf("\"")>-1){
		re = /\"/gi;
		theTerm = theTerm.replace(re,'');
	}
	if(theTerm.indexOf(" or ")>-1){
		re = / or /gi;
		theTerm = theTerm.replace(re,') or (');
		theTerm = "("+theTerm+")"
	}
	else{
	if(theTerm.indexOf(" ")>-1){
		re = / /gi;
		theTerm = theTerm.replace(re,' and ');
	}
	}
	findCine = false;
	findFoto = false;	
	findPartner = false;	
	findOnly = false;		
	
	for(i=0;i<document.theForm.length;i++){
		if(document.theForm.elements[i].checked && document.theForm.elements[i].name == 'findCine'){
			findCine = true;
		}else{	if(document.theForm.elements[i].checked && document.theForm.elements[i].name == 'findFoto'){
			findFoto = true;
		}else{	
			if(document.theForm.elements[i].checked && document.theForm.elements[i].name == 'findPartner'){
				findPartner = true;
			}else{if(document.theForm.elements[i].checked && document.theForm.elements[i].name == 'findOnly'){
				findOnly = true;
			}
			}
			}
		
		}
	
	}
	if(document.theForm != null){
 

		for(i=0;i<document.theForm.length;i++){
			ilNome = document.theForm.elements[i].name;
			ilValore =  document.theForm.elements[i].value;
			if(document.theForm.elements[i].checked && ilNome.indexOf("archivio")==0){
					if(ilValore.indexOf("fotografico")==0 && (findFoto || findOnly))
						theArchAlias+=	";"+document.theForm.elements[i].value
					if(ilValore.indexOf("cinematografico")==0 && (findCine || findOnly))
						theArchAlias+=	";"+document.theForm.elements[i].value
					if(ilValore.indexOf("partner")==0 && (findPartner || findOnly))
						theArchAlias+=	";"+document.theForm.elements[i].value
								
				}
		}
	}
		
		//alert(theArchAlias)
		if(theArchAlias == ''){
		alert('Attenzione:\nSelezionare almeno un archivio')
		return;
		}
	



	
	
	if(document.ricercaSemplice != null){
		theArchAlias = document.ricercaSemplice.theArchAlias.value
	}
	
	theArchAlias = theArchAlias.substring(1);
	
	
	percorso='/archivio/Vocabolario?urlAfterSave=/jsp/ricerca/vocabolario.jsp&urlErrorPage=/jsp/error.jsp&vocabolario_alias='+theKey+'&vocabolario_maxresult=20&vocabolario_up_down=up&vocabolario_start_param='+start+'&vocabolario_return_id='+returnField+'&vocabolario_tipology='+theTipology+'&vocabolario_phrase=&theArch='+theArchAlias
	parent.analisiInCorso(true);
	urlOpener(percorso,'vocabolarioFrame')

	 if(document.getElementById('vocabolarioFrame')!=null)
		document.getElementById('vocabolarioFrame').style.display='';
	
	 if(document.getElementById('theForm')!=null)
	 	document.getElementById('theForm').style.display='none';
	
	return false;
	
}

 

function vocLookUp(db,theInput,theXPath,thePath){
 voc(theInput,'double')
	return false
	theArchAlias = "";
	theTerm = trim(theInput.value)
	returnField = theInput.name
 
	if(theTerm.indexOf("\"")>-1){
		re = /\"/gi;
		theTerm = theTerm.replace(re,'');
	}
	if(theTerm.indexOf(" or ")>-1){
		re = / or /gi;
		theTerm = theTerm.replace(re,') or (');
		theTerm = "("+theTerm+")"
	}
	else{
	if(theTerm.indexOf(" ")>-1){
		re = / /gi;
		theTerm = theTerm.replace(re,' and ');
	}
	}
 
 
 
	if((theInput.value).indexOf("*")>-1 || (theInput.value).indexOf("?")>-1){
		re = /\*/gi;re2 = /\?/gi
		if((trim(theInput.value).replace(re,'')).replace(re2,'').length < 3){
			alert('Attenzione:\nLa radice del termine deve essere di almeno tre caratteri');theInput.focus();return false;
		}
	}
	if(document.theForm != null){
		for(i=0;i<document.theForm.length;i++){
			if(document.theForm.elements[i].checked){
				break;
				}
			if(i == document.theForm.length-1){alert('Attenzione:\nSelezionare almeno un archivio');return false;}
		}
		for(i=0;i<document.theForm.length;i++){
			if(document.theForm.elements[i].checked){
					theArchAlias+=	";"+document.theForm.elements[i].value
				}
		}

	}
	if(document.ricercaSemplice != null){
		theArchAlias = document.ricercaSemplice.theArchAlias.value
	}
	
	theArchAlias = theArchAlias.substring(1);
	
//	parametri = 'db='+db+'&theTerm='+theTerm+'&theXPath='+theXPath+'&thePath='+thePath+'&theArchAlias='+theArchAlias;
//alert('db='+db+'&theTerm='+theTerm+'&theXPath='+theXPath+'&thePath='+thePath+'&theArchAlias='+theArchAlias)
	document.vocForm.laLocation.value = document.location.href;
	document.vocForm.db.value = db;
	document.vocForm.theTerm.value = theTerm;
	document.vocForm.theXPath.value = theXPath;
	document.vocForm.thePath.value = thePath;
	document.vocForm.returnField.value = returnField;
	document.vocForm.theArchAlias.value= theArchAlias;
	document.vocForm.action = 'vocLookUp.jsp';
	document.vocForm.submit();

	

}
function fillOnLoad(leVoci,ilCampo,theArchAlias){
	theArchAliasArray = theArchAlias.split(";");
	leVociArray = leVoci.split("[@@]");
	leVoci ="";
	for(i=0;i<document.theForm.length;i++){
		if(document.theForm.elements[i].name.indexOf("archivio") == 0 && document.theForm.elements[i].type == 'checkbox'){
				if(theArchAlias.indexOf(document.theForm.elements[i].value)==-1)
					document.theForm.elements[i].checked = false;
				else
					document.theForm.elements[i].checked = true;
			}
	}
	for(i=0;i<leVociArray.length;i++){
		if(leVociArray[i].length>0)
			leVoci+= '"'+unescape(leVociArray[i])+'" or ';
	}
	leVoci = leVoci.substring(0,leVoci.length-4)
	document.theForm[ilCampo].value = leVoci;
	return true;
}

var optionIframe,returnPath;

function moreSearchOption(ilForm,theIframe,parametri){
	if(!ilForm['theTerm'].disabled){
		ilValore = ilForm['theTerm'].value;
		if(ilForm['theTerm']!=null)
			ilForm['theTerm'].style.visibility = 'hidden';
		if(document.getElementById('submit')!=null)
			document.getElementById('submit').style.visibility = 'hidden';
		if(document.getElementById('imgRicerca')!=null)
			document.getElementById('imgRicerca').style.visibility = 'hidden';
		if(document.getElementById('opzioniRicerca')!=null)
			document.getElementById('opzioniRicerca').style.visibility = 'hidden';		
		optionIframe = theIframe;
		if(returnPath != theIframe.src)
			returnPath = theIframe.src; 
		theIframe.src = '/archivio/jsp/ricerca/moreOption.jsp?'+parametri;
		parent.analisiInCorso(true);
	}
	else{
		searchOptionBack(parent.ricerca)
		ilForm['theTerm'].disabled = false;
	}
}
function searchOptionBack(){
	parent.analisiInCorso(false);
	if(document.ricercaSemplice['theTerm']!=null)	
		document.ricercaSemplice['theTerm'].style.visibility = '';
	if(document.getElementById('submit')!=null)
		document.getElementById('submit').style.visibility = '';
	if(document.getElementById('imgRicerca')!=null)
		document.getElementById('imgRicerca').style.visibility = '';
	if(document.getElementById('opzioniRicerca')!=null)
		document.getElementById('opzioniRicerca').style.visibility = '';		
	if(optionIframe!=null && returnPath != null)
		optionIframe.src = returnPath;
	return true;
}
