//if (top.frames.length!=0) top.location=self.document.location;

function ss(el){
if (window.RegExp && window.encodeURIComponent) {
	var qe=encodeURIComponent(document.c.s.value);
	if (el.href.indexOf("s=")!=-1) {
		el.href=el.href.replace(new RegExp("s=[^&$]*"),"s="+qe);} 
	else {
		el.href+="&s="+qe;}
}return 1;
}


//** Tab Content script- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Last updated: Nov 8th, 06

var enabletabpersistence=0; //enable tab persistence via session only cookies, so selected tab is remembered?

////NO NEED TO EDIT BELOW////////////////////////
var tabcontentIDs=new Object()

function expandcontent(linkobj){
var ulid=linkobj.parentNode.parentNode.id //id of UL element
var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents
for (var i=0; i<ullist.length; i++){
ullist[i].className=""  //deselect all tabs
if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents
}
linkobj.parentNode.className="selected"  //highlight currently clicked on tab
document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content
saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))
}

function expandtab(tabcontentid, tabnumber){ //interface for selecting a tab (plus expand corresponding content)
var thetab=document.getElementById(tabcontentid).getElementsByTagName("a")[tabnumber]
if (thetab.getAttribute("rel"))
expandcontent(thetab)
}

function savetabcontentids(ulid, relattribute){// save ids of tab content divs
if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet
tabcontentIDs[ulid]=new Array()
tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute
}

function saveselectedtabcontentid(ulid, selectedtabid){ //set id of clicked on tab as selected tab id & enter into cookie
if (enabletabpersistence==1) //if persistence feature turned on
setCookie(ulid, selectedtabid)
}

function getullistlinkbyId(ulid, tabcontentid){ //returns a tab link based on the ID of the associated tab content
var ullist=document.getElementById(ulid).getElementsByTagName("li")
for (var i=0; i<ullist.length; i++){
if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel")==tabcontentid){
return ullist[i].getElementsByTagName("a")[0]
break
}
}
}

function initializetabcontent(){
for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off
setCookie(arguments[i], "")
var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
var ulobj=document.getElementById(arguments[i])
var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
for (var x=0; x<ulist.length; x++){ //loop through each LI element
var ulistlink=ulist[x].getElementsByTagName("a")[0]
if (ulistlink.getAttribute("rel")){
savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
ulistlink.onclick=function(){
expandcontent(this)
return false
}
if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
expandcontent(ulistlink) //auto load currenly selected tab content
}
} //end inner for loop
if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value
var culistlink=getullistlinkbyId(arguments[i], clickedontab)
if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value
expandcontent(culistlink) //auto load currenly selected tab content
else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)
expandcontent(ulist[0].getElementsByTagName("a")[0]) //just auto load first tab instead
}
} //end outer for loop
}
function getCookie(Name){ 
var re=new RegExp(Name+"=[^;]+", "i");
if (document.cookie.match(re))
return document.cookie.match(re)[0].split("=")[1]
return ""
}
function setCookie(name, value){
document.cookie = name+"="+value
}


function showHide(eId)
{
	if(typeof(eId) == "object")
	{
		var o = eId;
		if(o){ if(o.style.display == 'none' || o.style.display == '') o.style.display = 'block';	else o.style.display = 'none';}
	}
	else
	{
		if(document.getElementById)
		{
			var o = document.getElementById(eId)
			if(o) {	if(o.style.display == 'none' || o.style.display == '') o.style.display = 'block'; else o.style.display = 'none'; }
		}
	}
}

//formattazione emoticon
function formatta(startTag,defaultText,endTag,replace)
{
	if(document.getElementsByTagName)
	{
		elements = document.getElementsByTagName("textarea")
			
		if(elements.length == 1)
		{
			//alert(startTag);
			//alert(defaultText);
			//alert(endTag);
	
			t = elements[0];
			//debug(t);
			if(t.createTextRange) 
			{
				t.focus(t.caretPos);
				t.caretPos = document.selection.createRange().duplicate();
				if(t.caretPos.text.length>0) 
				{
					var sel = t.caretPos.text;
					var fin = '';
					while(sel.substring(sel.length-1, sel.length)==' ') 
					{
						sel = sel.substring(0, sel.length-1)
						fin += ' ';
					}
					if(replace) t.caretPos.text = startTag + sel + endTag + fin;
					else t.caretPos.text = sel + fin + startTag + defaultText + endTag;
				} 
				else 
				{
					t.caretPos.text = startTag+defaultText+endTag;
				}
			}
			else 
			{
				//MOZILLA/NETSCAPE support
				if (t.selectionStart || t.selectionStart == "0") 
				{
					var startPos = t.selectionStart;
					var endPos = t.selectionEnd;

					if (startPos != endPos) 
					{
						if(startTag.length > 0)
						{
							t.value = t.value.substring(0, startPos)
			              		+	startTag
					            + t.value.substring(startPos, endPos) 
				              	+ endTag
				              	+ t.value.substring(endPos, t.value.length);
						}
						else
						{
							t.value = t.value.substring(0, endPos)
				              + endTag
				              + t.value.substring(endPos, t.value.length);
						}
					}
					else
					{
						t.value = 	t.value.substring(0, startPos)
									+ endTag
									+ t.value.substring(endPos, t.value.length);
	
						t.selectionStart = (t.value.substring(0, startPos) + endTag).length;
						t.selectionEnd = (t.value.substring(0, startPos) + endTag).length;
					}
				} 
				else 
				{
					t.value += startTag+defaultText+endTag;
				}
			}
		}
	}
}

/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
function bookmarksite(title,url){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

function openWin(_url, _name, _w, _h)
{
	var _leftPos = (screen.availWidth-_w)/2, _topPos = (screen.availHeight-_h)/2;
	var _args = new Array();
	_args[0] = "alwaysRaised=1";
	_args[1] = "dependent=1";
	_args[2] = "height=" + _h;
	_args[3] = "width=" + _w;
	_args[4] = "top=" + _topPos;
	_args[5] = "left=" + _leftPos;
	_args[6] = "screenY=" + _topPos;
	_args[7] = "screenX=" + _leftPos;
	_args[8] = "menubar=0";
	_args[9] = "resizable=0";
	_args[10] = "status=0";
	_args[11] = "titlebar=0";
	_args[12] = "toolbar=0";
	_args[13] = "scrollbars=1";
	var _win;
	_win = window.open(_url, _name, _args);
	
	/*
	if(window.focus())
		_win.focus();
	*/
}

function doAjax(url, containerid)
{
	if (!document.getElementById)
		return;
	var _div = document.getElementById(containerid);
	if(!_div)
		return;

	showHide(containerid);
	
	if(_div.style.display == 'block')
	{
		_div.innerHTML = "<div class='attendere'><img src='images/clessidra.gif' align='absmiddle' alt='Attendere prego' border='0'>&nbsp;Caricamento in corso...</div>";
		ajaxpage(url, containerid);
	}
}