function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/**
* Execute url encoding
*/
function myUrlEncode(string) {if (self.encodeURIComponent) {string = string.replace(/'/g,"%27"); return encodeURIComponent(string);} else {return escape(string);}}

/**
* Reverse a string
*/
function strrev(string) { return string.split("").reverse().join("");}

function check_search(prefix)
{
	var cosa = trim(Element('category').value).toLowerCase();
	var dove = trim(Element('key').value).toLowerCase();
	if (cosa == 'cosa') cosa = '';
	if (dove == 'dove') dove = '';
	
	if ((cosa == '') && (dove == ''))
	{
		alert('Scegli dal menù "cosa" o "dove"');
		return false;
	}
	
	var action = "/"+prefix+"/";
	if (cosa != "")
		action += cleanKey(cosa)+"/";
	else
		action += "top/";
	if (dove != "")
		action += cleanKey(dove)+"/";

	Element('search').action = action.substring(0, action.length-1) + "-1.html";
	
	if (cosa == "")
		Element('category').value = '';
	if (dove == "")
		Element('key').value = '';
	
	return true;
}

function cleanKey(key)
{
	if (!key)
		return "";
	var tmp = key.toLowerCase();
	tmp = tmp.replace(/[_\s+]+/g, "-");
	tmp = tmp.replace(/\-+/g,"-");
	tmp = myUrlEncode(tmp);
	return tmp
}

function check_search_fot(prefix)
{
	var cosa = trim(Element('categoryfot').value).toLowerCase();
	var dove = trim(Element('keyfot').value).toLowerCase();
	if (cosa == 'cosa') cosa = '';
	if (dove == 'dove') dove = '';
	
	if ((cosa == '') && (dove == ''))
	{
		alert('Scegli dal menù "cosa" o "dove"');
		return false;
	}
	
	var action = "/"+prefix+"/";
	if (cosa != "")
		action += cleanKey(cosa)+"/";
	else
		action += "top/";
	if (dove != "")
		action += cleanKey(dove)+"/";

	Element('searchfot').action = action.substring(0, action.length-1) + "-1.html";
	
	if (cosa == "")
		Element('categoryfot').value = '';
	if (dove == "")
		Element('keyfot').value = '';
	
	return true;
}

function addBookmark() {
	if (window.sidebar)
		window.sidebar.addPanel(document.title, location.href, '');		// versione FF
	else if (window.external)
		window.external.AddFavorite(location.href, document.title);	// versione IE
}

function getTimeZone()
{
	var localTime = new Date();
	//var ms = localTime.getTime() + (localTime.getTimezoneOffset() * 60000);
	var ms = localTime.getTime();
	var time =  new Date(ms);
	var hour = time.getHours();
	var minute = time.getMinutes();
	var second = time.getSeconds();
	var curTime = "" + ((hour > 12) ? hour - 12 : hour);
	if (hour==0) curTime = "12";
	curTime += ((minute < 10) ? ":0" : ":") + minute;
	curTime += ((second < 10) ? ":0" : ":") + second;
	curTime += (hour >= 12) ? " PM" : " AM";
	return curTime;
}
function Element(id)
{
	return document.getElementById(id);
}

function add_bookmark() {
	if (window.sidebar)
		window.sidebar.addPanel(document.title, location.href, '');		// versione FF
	else if (document.all)
		window.external.AddFavorite(location.href, document.title);		// versione IE
	else if (window.opera)												// versione Opera
	{
		var a = document.createElement("A");
		a.rel = "sidebar";
		a.target = "_search";
		a.title = document.title;
		a.href = location.href;
		a.click();
	}
}

function set_homepage(obj)
{
	obj.style.behavior = 'url(#default#homepage)';
	if (isIE())
		obj.setHomePage(location.href);
	else
		MM_openBrWindow('index.php5?op=static&page=c2V0aG9tZXBhZ2UudG1wbA==','','scrollbars=yes,resizable=yes,width=400,height=300')
	return false;
}

function trim(inputString)
{
	if (typeof inputString != "string") return inputString;
	var retValue = inputString;
	var ch = retValue.substring(0, 1);

	while (ch == " ") {
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length - 1, retValue.length);

	while (ch == " ") {
		retValue = retValue.substring(0, retValue.length - 1);
		ch = retValue.substring(retValue.length - 1, retValue.length);
	}

	while (retValue.indexOf("  ") != -1) {
		retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ") + 1, retValue.length);
	}
	return retValue;
}

function isIE() {
	return (navigator.userAgent.indexOf("MSIE") > -1);
}

function opzioni_show(id, min, max)
{
	var element = document.getElementById(id);
	if (!element.pippo)
		element.pippo = 0;

	if (element.pippo==0)
	{
		element.style.display = 'block';
		element.timer = setInterval("opzioni_resize('"+id+"',"+min+","+max+")",10);

		element.pippo = 1;
	} else
	{
		element.timer = setInterval("opzioni_resize('"+id+"',"+max+","+min+")",10)
		element.pippo = 0;
	}
}

function opzioni_resize(id, from, to)
{
	var element = document.getElementById(id);
	var tmp = element.style.height;
	tmp = (tmp.replace(/px$/, ""))*1;
	if (from>to)
	{
		if (tmp<=to)
		{
			clearInterval(element.timer);
			element.style.display = 'none';
		} else
		{
			tmp = tmp-2;
			element.style.height = tmp+"px";
		}
	} else
	{
		if (tmp>=to)
		{
			clearInterval(element.timer);
		} else
		{
			tmp = tmp+2;
			element.style.height = tmp+"px";
		}
	}
}

function centerImg(what,clientWidth, clientHeight)
{
	return;
	
	if (typeof(window.innerWidth) == 'number')
	{
		// Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else
	{
		if (document.documentElement &&
		   (document.documentElement.clientWidth || document.documentElement.clientHeight))
	    {
			// IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		}
		else
		{
			if (document.body && (document.body.clientWidth || document.body.clientHeight))
			{
				// IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}
		}
   }
	
	
	var cheight = what.naturalHeight;
	var cwidth = what.naturalWidth;
	var reduxHeight = myHeight/cheight;
	var reduxWidth = myWidth/cwidth;
	var redux = Math.max(reduxHeight,reduxWidth);

	what.style.height = (redux*cheight)+'px';
	what.style.width = (redux*cwidth)+'px';


	what.style.left = (((redux*cwidth)-myWidth)/2)*-1+'px';
	what.style.top = (((redux*cheight)-myHeight)/2)*-1+'px';
}