function	autoUrl(name, dest)
{
	var loc;
	var id_list;

	id_list = document.getElementById(name);
	loc = id_list.options[id_list.selectedIndex].value;
	if (loc != 0)
		location.href = dest+loc;
	return ;
}

function	autoUrlNoList(name, dest)
{
	var loc;

	loc = document.getElementById(name).checked;
	location.href = dest + (loc == true ? 1 : 0);
	return ;
}

/*
** show or hide element e depending on condition show
*/
function toggle(e, show)
{
	e.style.display = show ? '' : 'none';
}

function toggleMultiple(tab)
{
    var len = tab.length;

    for (var i = 0; i < len; i++)
        if (tab[i].style)
            toggle(tab[i], tab[i].style.display == 'none');
}

/**
* Show dynamicaly an element by changing the sytle "display" property
* depending on the option selected in a select.
*
* @param string $select_id id of the select who controls the display
* @param string $elem_id prefix id of the elements controlled by the select
*   the real id must be : 'elem_id'+nb with nb the corresponding number in the
*   select (starting with 0).
*/
function showElemFromSelect(select_id, elem_id)
{
	var select = document.getElementById(select_id);
	for (var i = 0; i < select.length; ++i)
	{
	    var elem = document.getElementById(elem_id + select.options[i].value);
		if (elem != null)
			toggle(elem, i == select.selectedIndex);
	}
}

/**
* Get all div with specified name and for each one (by id), toggle their visibility
*/
function openCloseAllDiv(name, option)
{
	var tab = $('*[name='+name+']');
	for (var i = 0; i < tab.length; ++i)
		toggle(tab[i], option);
}

/**
* Toggle the value of the element id_button between text1 and text2
*/
function toggleElemValue(id_button, text1, text2)
{
	var obj = document.getElementById(id_button);
	if (obj)
		obj.value = ((!obj.value || obj.value == text2) ? text1 : text2);
}

function addBookmark(url, title)
{
	if (window.sidebar)
		return window.sidebar.addPanel(title, url, "");
	else if ( window.external )
		return window.external.AddFavorite( url, title);
	else if (window.opera && window.print)
		return true;
	return true;
}

function writeBookmarkLink(url, title, text, img)
{
	var insert = '';
	if (img)
		insert = writeBookmarkLinkObject(url, title, '<img src="' + img + '" alt="' + escape(text) + '" title="' + escape(text) + '" />') + '&nbsp';
	insert += writeBookmarkLinkObject(url, title, text);
	document.write(insert);
}

function writeBookmarkLinkObject(url, title, insert)
{
	if (window.sidebar || window.external)
		return ('<a href="javascript:addBookmark(\'' + escape(url) + '\', \'' + escape(title) + '\')">' + insert + '</a>');
	else if (window.opera && window.print)
		return ('<a rel="sidebar" href="' + escape(url) + '" title="' + escape(title) + '">' + insert + '</a>');
	return ('');
}

function checkCustomizations()
{
	for (var i = 0; i < customizationFields.length; i++)
		/* If the field is required and empty then we abort */
		if (parseInt(customizationFields[i][1]) == 1 && $('#' + customizationFields[i][0]).val() == '')
			return false;
	return true;
}
//// MY /////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// load remote content
function loadContent(elementSelector, sourceUrl) {
	$(""+elementSelector+"").load(sourceUrl);
}

// check the selected value in a radiogroup
function checkRadio(radioName){
	var radioGrp = eval("document.form1."+radioName);
	for (var i = 0; i< radioGrp.length; i++) {
		if (radioGrp[i].checked) {
		   return str = radioGrp[i].name + "=" + radioGrp[i].value;
			//alert("str " + str);
		}
	}
} 

function resetRadio(obj, id_lang){ 
	nome = obj; 
  	inputs = document.getElementsByName(nome); 
  	var radioLength = inputs.length; 
    for(var i = 0; i < radioLength; i++) { 
		if(inputs[i] != obj) inputs[i].checked = false; 
    } 
	update (id_lang);
}
function resetAllRadio(){
	resetRadio("formato");
	resetRadio("modo");
	resetRadio("caffeina");
	resetRadio("caratteristica");
}
// check all radio and load the content
function update (id_lang){
	var formato = checkRadio("formato");
	var modo = checkRadio("modo");
	var caffeina = checkRadio("caffeina");
	var caratteristica = checkRadio("caratteristica");
	var str = "";
	if(formato) str += formato+"&";
	if(modo) str += modo+"&";
	if(caffeina) str += caffeina+"&";
	if(caratteristica) str += caratteristica;
	str += "&id_lang=" + id_lang;
	loadContent('#find_right', 'find_load.php?'+str);
}
function Apri(immagine, nomeFinestra, larghezza, altezza, bgcolor) {
    newWindow = window.open("", nomeFinestra, "status=no,width="+larghezza+",height="+altezza+"");
    newWindow.document.open();
    newWindow.document.write('<html><title>'+nomeFinestra+'</title><body leftmargin=\"0\" topmargin=\"0\" marginheight=\"0\" marginwidth=\"0\" bgcolor='+bgcolor+' onClick=\"self.close()\">');
    newWindow.document.write('<table width='+larghezza+' border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" height='+altezza+' ><tr><td>');
    newWindow.document.write('<img src=\"'+immagine+'\" width=\"'+larghezza+'\" height=\"'+altezza+'\" alt=\"Chiudi\">');
    newWindow.document.write('</td></tr></table></body></html>');
    newWindow.document.close();
    newWindow.focus();
}

