function searchIt()
{
	preLoad();
    var chars = document.searchf.elements['rs_display_name'].value;
    var tot = chars.length;
    if ( !chars )
	{
        document.searchf.elements['rs_display_name'].focus();
		preLoad('off');
        return false;
    }
    if ( tot < 2 )
	{
        document.searchf.elements['rs_display_name'].focus();
		preLoad('off');
        return false;
    }

	var loc="";
	if(document.searchf.sect.options[document.searchf.sect.selectedIndex].value)
		loc = '/'+document.searchf.sect.options[document.searchf.sect.selectedIndex].value;
	if(document.searchf.sect.options[document.searchf.sect.selectedIndex].value != 'ringtones')
		loc += "/find/";
	else
		loc+="/";
	chars=cleanWord(chars);
	loc+=chars+"/";
	if(document.searchf.sect.options[document.searchf.sect.selectedIndex].value == 'ringtones')
		loc+="/";
	document.location.href = 'http://'+document.location.host+loc;
    return false;
}

function searchRingtones()
{
	preLoad();
	if(document.searchr)
	{
		var title = document.searchr.elements['title'].value;
		var author = document.searchr.elements['author'].value;
		if(title == 'Titolo')
			title = '';
		if(author == 'Cantante')
			author = '';
		author=cleanWord(author);
		title=cleanWord(title);
		if(title.length > 1 || author.length > 1)
		{
			var type = document.searchr.elements['type'].options[document.searchr.elements['type'].selectedIndex].value;
			var loc = "/suonerie/"+author+"/"+title+'/'+type+"/";
			document.location.href = 'http://'+document.location.host+loc;
		}
		else
			preLoad('off');
	}
	else
		preLoad('off');
	return false;
}

function cleanWord(word)
{
	var w="";
	for(var i = 0; i < word.length; i++)
		w += word.substr(i,1).replace("/"," ");
	return escape(w);	
}

function searchRingtonesInit()
{
	if(document.searchr)
	{
		var tmp = document.location.href.split("/");
		if((tmp[3] == 'suonerie' || tmp[3] == 'ringtones') && (tmp[4] || tmp[5]))
		{
			document.searchr.elements['author'].value="";
			document.searchr.elements['title'].value="";
			if(tmp[4])
				document.searchr.elements['author'].value = unescape(tmp[4]);
			if(tmp[5])
				document.searchr.elements['title'].value = unescape(tmp[5]);
			if(tmp[6])
			{
				for(var i = 0; i < document.searchr.elements['type'].options.length ; i++)
				{
					if( document.searchr.elements['type'].options[i].value == tmp[6] )
						document.searchr.elements['type'].options[i].selected = true;
				}
			}
		}
	}
}

function searchItInit()
{
	if(document.searchf && document.searchf.sect && document.searchf.sect.type == 'select-one')
	{
		
		if(SECT == 'mobi_ringtones')
			SECT = 'ringtones';
		for(var i = 0; i < document.searchf.sect.options.length ; i++)
		{
			if( document.searchf.sect.options[i].value == SECT )
				document.searchf.sect.options[i].selected = true;
		}
		var loc = document.location.href;
		if(loc.match(/\/find\//))
		{
			var tmp = loc.split("/");
			var key = '';
			for(var i = 0 ; i<tmp.length;i++)
			{
				if(tmp[i] == 'find')
					key = unescape(tmp[i+1]);
			}
			document.searchf.rs_display_name.value = key;
		}
	}
}

function preLoad(c)
{
	var el = document.getElementById('loader'); 
	if(el)
	{
		if(c == 'off')
			el.style.display='none';
		else
			el.style.display='block';
	}
}

