

function lancia(url, titolo, larghezza, altezza, barre) { 
var w = screen.width; 
var h = screen.height; 
var x = Math.round(w / 2) - Math.round(larghezza / 2); 
var y = Math.round(h / 2) - Math.round(altezza / 2); 
finestra = window.open (url, titolo, 'left=' + x + ',screenX=' + x + ',top=' + y + 'screenY=' + y +',width=' + larghezza + ',height=' + altezza + ',scrollbars=' + barre); 
} 

/*
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
*/

startList = function() {
	if (document.all&&document.getElementById) {
		AKmenRoot = document.getElementById("AKmen");
		for (i=0; i<AKmenRoot.childNodes.length; i++) {
			node = AKmenRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
	//serve per l'editor
	//if(typeof(inizializza)=='undefined'){inizializza=false;}
	//if(inizializza) {initialize();}
}
//window.onload=startList;

////// cambio il background degli input text //////////////////////////////////////////
function getAllTextInputs() {
	
	// input
    var els = document.getElementsByTagName('input');
    for (var i=0; i<els.length; i++) {
        //if (/^text$/.test(els[i].type)) setEventsTo(els[i]);
		if(els[i].type!='button' & els[i].type!='submit') setEventsTo(els[i]);
    }
	
	//textarea
    var areaEls = document.getElementsByTagName('textarea');
    for (var b=0; b<areaEls.length; b++) {
		setEventsTo(areaEls[b]);
    }
	
	//select
    var selEls = document.getElementsByTagName('select');
    for (var d=0; d<selEls.length; d++) {
		setEventsTo(selEls[d]);
    }
	
}

var setEventsTo= function(el) {
    el.onblur= function() {
    this.className = 'unfocused';
    }
    el.onfocus=function() {
    this.className = 'focused';
    }
}
////////////////////////////////////////////////////////////////////////////////////////
/*
Event.observe(window, 'load', startList);
Event.observe(window, 'load', getAllTextInputs);
*/
/*
window.addEvent('load', startList);
window.addEvent('load', getAllTextInputs);
*/
addEve(window, 'load', startList);
addEve(window, 'load', getAllTextInputs);
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////


var h_utile ='';
var w_utile ='';
var page ='';
var myID =0;
var valor =0;
var ajax = 1;

var w_finsetra = 350;
var h_finestra = 150;

function View_div(i) {
	if(document.getElementById(i).style.display=='none') 
	     document.getElementById(i).style.display="";
	else
	     document.getElementById(i).style.display='none'
}


function create_bg(){
	
	h_utile = (document.all && !window.opera) ? document.documentElement.offsetHeight : self.innerHeight;
	w_utile = Math.round(document.body.clientWidth / 2);
	var h_bg = (document.documentElement.scrollHeight > h_utile) ? document.documentElement.scrollHeight : h_utile;
	
	backg = document.createElement("DIV");
	backg.setAttribute("id", "my_bg");
	backg.style.backgroundColor='#000';
	backg.style.zIndex=100;
	backg.style.width=100+'%';
	backg.style.height=h_bg+'px';
	backg.style.position='absolute';
	backg.style.left=0;
	backg.style.top=0;
	backg.style.display='none';
	document.body.appendChild(backg);
	fade('my_bg',0,'piu',80);
	document.getElementById("my_bg").style.display='';
}


function fade(Target,opacity,option,max_fade) {
	            if(max_fade=='undefined') max_fade = 100;
                fadeTarget = document.getElementById(Target);
                if (opacity <= max_fade) {
                        if (fadeTarget.style.MozOpacity!=null) {
                                fadeTarget.style.MozOpacity = (opacity/100);
                        } else if (fadeTarget.style.opacity!=null) {
                                fadeTarget.style.opacity = (opacity/100);
                        } else if (fadeTarget.style.filter!=null) {
                                fadeTarget.style.filter = "alpha(opacity="+opacity+")";
                        }
				
				        if(option!='undefined'){
				            if(option=='piu'){
				               opacity += 10;
				            }else if (option=='meno'){
				               opacity -= 10;
				            }
							var velocity = (navigator.appVersion.indexOf("MSIE")!=-1) ? 1 : 3; 
				            window.setTimeout("fade('"+Target+"',"+opacity+",'"+option+"','"+max_fade+"')", velocity);
				        }
				}else{
					if(ajax==1){
						 open_option();
					}else{
	                     x_new = w_utile - (w_finsetra/2)*1;
                         y_new = Math.round(h_utile / 2) + document.documentElement.scrollTop - (h_finestra/2)*1;
                         document.getElementById("div_reg").style.left = x_new+'px';
                         document.getElementById("div_reg").style.top = y_new+'px';
						 document.getElementById("div_reg").style.display='';
					}
				}
}


function open_option(){
	
	  opt = document.createElement("DIV");
	  opt.setAttribute("id", "option");
	  opt.style.backgroundColor='#fff';
	  opt.style.position='absolute';
	  opt.style.zIndex=110;
	  opt.style.width=w_finsetra+'px';
	  opt.style.height=h_finestra+'px';
	  opt.style.padding=10+'px';
	  x_new = w_utile - (w_finsetra/2)*1;
      y_new = Math.round(h_utile / 2) + document.documentElement.scrollTop - (h_finestra/2)*1;
      opt.style.left = x_new+'px';
      opt.style.top = y_new+'px';
	  document.body.appendChild(opt);
	  
	   Simple_ajax(noCache(page+'?id='+myID+'&value='+valor), 'option', true)

}


function chiudi_box(oopz){
   cRemoveElement('my_bg');
   cRemoveElement('option');
   if(oopz!='undefined'){
	   if(oopz==1) window.location.reload(true);
   }
}

function cRemoveElement(id) {
   var node = document.getElementById(id);
   
   if ((node) && (node.parentNode)) {
     var removed = node.parentNode.removeChild(node); 
     return true;
   }

   return false;
}

function admin_option(id,rich,pages,width,height){

	if(width==null) width = 350;
	if(height==null) height = 150;
	
	w_finsetra = width;
    h_finestra = height;
	myID = id;
	valor = rich;
	page = pages;
	create_bg();
}


function addEve(el, evType, fn, useCapture){
   if (el.addEventListener){
     el.addEventListener(evType, fn, useCapture); 
   } else if (el.attachEvent){
     el.attachEvent('on' + evType, fn);
   } else {
     el['on' + evType] = fn;
   }
}


function noCache(uri){return uri.concat(/\?/.test(uri)?"&":"?","noCache=",(new Date).getTime(),".",Math.random()*1234567)};

function Simple_ajax(url, target, riscrivi) {

	  if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	  } else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  if (req) {
		req.onreadystatechange = function() {
              if (req.readyState == 4) { 
			  
               if (req.status == 200) {
			       if(!riscrivi){
				      document.getElementById(target).innerHTML += execJS(req.responseText); 
				   }else{
					  document.getElementById(target).innerHTML = execJS(req.responseText); 
				   }
			   }
			   
			  }else{
				  if(riscrivi) document.getElementById(target).innerHTML = '<img src="'+path_sito+'/images/loading.gif">';
			  }
         };
		req.open("GET", url, true);
		req.send("");
	  } 
}  

function execJS(t)
{
    var p1 = 0, p2 = 0, p3 = 0, p4 = 0;
    p1 = t.indexOf("<" + "script", 0);
    if(p1 == -1) return t;
    
    p2 = t.indexOf(">", p1 + 7) + 1;
    p3 = t.indexOf("<" + "/script>", p2);
    p4 = p3 + 9;
    
    var c = t.substring(p2, p3);
    var s = document.createElement("script");
    s.type = "text/javascript";
    s.text = c;
    document.getElementsByTagName("head")[0].appendChild(s);
    
    t = t.substring(0, p1) + t.substr(p4);
    return execJS(t);

}

function aggiorna_amici(rich){
	
	var pattern = /<img/i;
	var trovato = pattern.test(document.getElementById('lista_amici').innerHTML); 
	
	if(!trovato) document.getElementById('lista_amici').innerHTML ='';
	
	cRemoveElement('richiedi_'+rich);
	document.getElementById('lista_amici').innerHTML = '<br><br>' + document.getElementById('amico_'+rich).innerHTML + document.getElementById('lista_amici').innerHTML
    cRemoveElement('amico_'+rich);
	
	var numrich = document.getElementById('numRic').innerHTML;
	
	regeXp = new RegExp('<b>(.+)</b>', 'gmi');
    //document.getElementById('numRic').innerHTML = numrich.replace(regeXp,'ciao');
	document.getElementById('numRic').innerHTML = numrich.replace(regeXp,function(x,y){ var numb = (y*1/1-1); if(numb!=0) return "<b>"+numb+"</b>"; else return numb;});
	
	document.getElementById('numRic_menu').innerHTML = document.getElementById('numRic').innerHTML;
	
	//alert(document.getElementById('numRic').innerHTML);
}