/*----------------------------------------------------------------------*/
/* FUNCTION:	apri													*/
/* DESCRIPTION: apre popup con analitico gruppo							*/
/* PARAMETERS :	grpId		id del gruppo (RT_CATEGORIE.RTCT_ID)		*/
/*			  :	kart		codice articolo	(usato solo se grpId == 0)	*/
/*----------------------------------------------------------------------*/
function apri(grpId, kart)
{
	var parameter
	if (!grpId)
		parameter = 'kart=' + kart
	else
		parameter = 'GrpID=' + grpId
	var popup = window.open("bf_analiticoCat.asp?" + parameter,"navigazione","width=785,height=500,location=0,menubar=0,resizable=1,scrollbars=yes,status=0,titlebar=0,toolbar=0,z-lock=0,screenX=0,screeny=0,left=0,top=0");
	popup.focus();
}
/*--------------------------------------------------------------*/
/* FUNCTION:	chiudi								            */
/* DESCRIPTION: chiude il popup con analitico gruppo			*/
/*--------------------------------------------------------------*/
function chiudi()
{
	var popup = window.open("","navigazione","width=1,height=1,top=5000,left=5000,screenX=5000,screenY=5000")
	popup.close()
	return true
}


/*----------------------------------------------------*/	
/* FUNCTION     : Trim		   	                      */
/* DESCRIPTION  : esegue il trim della stringa		  */
/* PARAMETERS										  */
/*----------------------------------------------------*/
function Trim(str)
{
	while(str.substr(0,1)==' ')
		str=str.substr(1)
		
	while(str.substr(str.length-1)==' ')
		str=str.substr(0,str.length-1)	
	return str
}

/*--------------------------------------------------------------*/
/* FUNCTION:	Cerca								            */
/* DESCRIPTION: Lancia la pagina di ricerca	                    */
/*--------------------------------------------------------------*/

	function Cerca()
{
	var SearchKey
	SearchKey=Trim(document.frmCat.KEY.value)
	var words, i, wordOk, numCar
	i = 0
	wordOk = false
	numCar = 3
	
	if (SearchKey.replace(/ /gi,'').length < numCar)	{
		alert('Inserire almeno tre caratteri da ricercare')
		document.frmCat.KEY.focus();
	}
	else {
		while (SearchKey.indexOf('  ')!=-1)
			SearchKey = SearchKey.replace(/  /gi,' ')
		words = SearchKey.split(' ')
		while (words[i]) {
			if (words[i].length >= numCar) {
				wordOk = true
				break
			}
			i++
		}
		if (!wordOk) {
			alert('Inserire una parola di almeno tre caratteri')
			document.frmCat.KEY.focus();
		}
		else
			document.location="bf_Search.asp?CatSearch=" + escape(SearchKey)
	}

}
