/**
 * Copyright (c) 2008, Andrea La Rosa.
 *
 */
function g(id){if(document.getElementById){return document.getElementById(id);}else if(document.all){return document.all[id];}else if(document.layers){return document.layers[id];}}
function T$(i){return document.getElementById(i)}
function T$$(e,p){return p.getElementsByTagName(e)}
function T$$$(){return document.all?1:0}
var TINY={};
/* text ====*/
function DecToHexa($v){var $newV=parseInt($v).toString(16); if($v<16){$newV="0"+$newV;} return $newV;}
function replaceTxt($str){$str=$str.replace(/&#39;/g,"&lsquo;"); return $str; /*str=str.replace(/&#39;/g,"´"); return str;*/}
function addslashes($str){$str=$str.replace(/\'/g,'\\\''); $str=$str.replace(/\"/g,'\\"'); $str=$str.replace(/\\/g,'\\\\'); $str=$str.replace(/\0/g,'\\0'); return $str;}
function stripslashes($str){$str=$str.replace(/\\'/g,'\''); $str=$str.replace(/\\"/g,'"'); $str=$str.replace(/\\\\/g,'\\'); $str=$str.replace(/\\0/g,'\0'); return $str;}
/* morphing ==== */
function setTimer(fn,time){return window.setTimeout(fn,time);}
function actHeight(id){var h=g(id).clientHeight; if(h==0){h=g(id).offsetHeight;}return h;}
function actWidth(id){width=g(id).clientWidth; if(width==0){width=g(id).offsetWidth;} return width;}
function maxHeight(id){var ids=g(id).style; ids.overflow="hidden"; if(actHeight(id)!=0){return actHeight(id);}else{origdisp=ids.display; origheight=ids.height; origpos=ids.position; origvis=ids.visibility; ids.visibility="hidden"; ids.height=""; ids.display="block"; ids.position="absolute"; height=actHeight(id); ids.display=origdisp; ids.height=origheight; ids.position=origpos; ids.visibility=origvis; return height;}}
function blindUp(id,speed){if(!speed){speed=200;} var acth=actHeight(id); var maxh=maxHeight(id); if(acth==maxh){g(id).style.display="block"; var speedmath=Math.ceil(speed/acth); for(i=0;i<=acth;i++){newh=acth-i; setTimer("g('"+id+"').style.height='"+newh+"px'",speedmath*i);}}}
function blindDown(id,speed){if(!speed){speed=200;}var acth=actHeight(id); if(acth==0){ var maxh=maxHeight(id); g(id).style.display="block"; g(id).style.height="0px"; var speedmath=Math.ceil(speed/maxh); for(i=1;i<=maxh;i++){setTimer("g('"+id+"').style.height='"+i+"px'",speedmath*i);}}}
function toggle(id){if(actHeight(id)==0){blindDown(id);}else{blindUp(id);}}
function opacity(id,da,a,speed){var speed=Math.round(speed/100); var vel=0; if(da>a){for(i=da;i>=a;i--){setTimer("changeOpac("+i+",'"+id+"')",(vel*speed)); vel++;}}else{for(i=da;i<=a;i++){setTimer("changeOpac("+i+",'"+id+"')",(vel*speed)); vel++;}}}
function pulsate(id,num,speed){if(!speed){speed=300;} for(i=1;i<=num;i++){ numx=i*((speed*2)+100)-(speed*2); setTimer("opacity('"+id+"',100,0,"+speed+")",numx); setTimer("opacity('"+id+"',0,100,"+speed+")",numx+speed+100);}}
function changeOpac(valore,id){var ids=g(id).style; ids.opacity=(valore/100); ids.MozOpacity=(valore/100); ids.KhtmlOpacity=(valore/100); ids.zoom=1; ids.filter="alpha(opacity="+valore+")";}
function shiftOpacity(id,_3e){if(g(id).style.opacity<0.5){opacity(id,0,100,_3e);}else{opacity(id,100,0,_3e);}}
function currentOpac(id,a,speed){var da=100; if(g(id).style.opacity<100){da=g(id).style.opacity*100;} opacity(id,da,a,speed);}
function highLight(id,_44,_45,_46){
  if(_44){ milli=_44; }
  else{ milli=900; }
  if(_45){ endcol=_45; }
  else{ endcol="#FFFFFF"; }
  if(_46){ origcol=_46;}
  else{ origcol="#FFFFA6"; }
  colorize(origcol,endcol,id,milli,"high");
}
function textColor(id,_48,_49,_4a){
  if(_4a){ milli=_4a; }
  else{ milli=900; }
  colorize(_48,_49,id,milli,"text");
}
function morphColor(id,_4c,_4d,_4e,_4f,_50,_51,_52){
  if(_52){ milli=_52; }
  else{ milli=900; }
  colorize(_4c,_4d,id,milli,"text");
  colorize(_4e,_4f,id,milli,"back");
  if(_50!=false){ colorize(_50,_51,id,milli,"border"); }
}
function colorize(_53,end,id,_56,_57){
  dr=parseInt(_53.substring(1,3),16);
  dg=parseInt(_53.substring(3,5),16);
  db=parseInt(_53.substring(5,7),16);
  fr=parseInt(end.substring(1,3),16);
  fg=parseInt(end.substring(3,5),16);
  fb=parseInt(end.substring(5,7),16);
  steps=_56/10;
  cr=dr; cg=dg; cb=db;
  sr=(fr-dr)/steps;
  sg=(fg-dg)/steps;
  sb=(fb-db)/steps;
  var zzi=10;
  for(var x=0;x<steps;x++){
    color="#"+DecToHexa(cr)+DecToHexa(cg)+DecToHexa(cb);
    if(x==(steps-1)){
      if(_57=="high"){color="";}else{color=end;}
    }
    mytime=(x);
    if(_57=="back"||_57=="high"){ newfonc="g(\""+id+"\").style.backgroundColor=\""+color+"\";"; }
    else{
      if(_57=="text"){ newfonc="g(\""+id+"\").style.color=\""+color+"\";"; }
      else{
        if(_57=="border"){ newfonc="g(\""+id+"\").style.borderColor=\""+color+"\";"; }
      }
    }
    setTimer(newfonc,zzi);
    cr+=sr; cg+=sg; cb+=sb; zzi+=10;
  }
}
/* vari */
function trim(str){str = str.replace(/&nbsp;$/g, ' '); return str.replace(/^\s*|\s*$/g,'');}
function cambiaSelect(p){this.location.href=p;} // html -> <select onchange="cambiaSelect(this.value)">
function redirectto(newurl){ if(newurl!="") location.href=newurl; }
function changecategory(newcat){g('action').value="change"; g('form').submit();}
/* aperture */
function enlarge(id){var ec=g('content'+id); var et=g('txt'+id); if(ec.className=="acceso"){ec.className="spento"; et.innerHTML='[+]';}else{ec.className="acceso"; et.innerHTML='[-]';}}
function apri(id){g(id).className="acceso";}
function chiudi(id){g(id).className="spento";}
function openMenu(id){for(i=1;i<=qMenu;i++){g(i).className="spento"; if(id==i){g(id).className = "acceso";}}}
function showBoxForm(id){var el=g(id); var elH=g('hidden_'+id); var elL=g('link_'+id); if(el.className=="acceso"){act="spento";}else{act="acceso";}el.className=act; elL.className='arrow_'+act; elH.value=act;}
/* checkbox */
function checkTutti(id,idc){with(g(id)){for(var i=0; i<elements.length; i++){if(elements[i].type=='checkbox' && elements[i].name==idc+"[]"){elements[i].checked=true;}}}}
function uncheckTutti(id,idc){with(g(id)){for(var i=0; i<elements.length; i++){if(elements[i].type=='checkbox' && elements[i].name==idc+"[]"){elements[i].checked=false;}}}}
/* forzature */
function tastoInvia($e){var $key; if(window.event){$key=$e.keyCode;}/* Per IE */else if($e.which){$key=$e.which;}/* Per Firefox/Netscape/Opera */if($key==13){g("loginForm").submit();}}
/* AJAX ===== core ====*/
function XHConn(){
  var xmlhttp;
  try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
  catch(e){try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
  catch(e){try{xmlhttp=new XMLHttpRequest();}
  catch(e){xmlhttp=false;}}}
  if(!xmlhttp){return null;}
  this.connect=function(sURL,sMethod,sVars,fnDone,fnError){
    if(!xmlhttp){return false;}
    sMethod=sMethod.toUpperCase();
    var sTime=new Date().getTime();
    try{
      if(sMethod=="GET"){ sVars = sVars ? '/'+sVars : '' ; xmlhttp.open(sMethod, sURL+sVars+'/stime_'+sTime+_html, true); sVars='';}
      else{
        xmlhttp.open(sMethod, sURL+'/stime_'+sTime+_html, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+'/stime_'+sTime+_html+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length",sVars.length);
        //xmlhttp.setRequestHeader("Connection","close");
      }
      xmlhttp.onreadystatechange=function(){
        if(xmlhttp.readyState==4){
          if(xmlhttp.status==200){fnDone(xmlhttp);}else{fnError(xmlhttp);}
        }};
      xmlhttp.send(sVars);
    }
    catch(z){return false;}
    return true;
  };
  return this;
}
/* costruisci url */
function makeURLstring(nomeForm){
  var s; var form=document.forms[nomeForm];
  var nEl=form.elements.length;
  for(var i=0;i<nEl;i++){ s+=form.elements[i].name+"="+encodeURIComponent(form.elements[i].value); if(i<nEl-1){s +="&";} }
  return s;
}
/* esegui js*/
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 execJSA(id,t,a){
var p1=0,p2=0,p3=0,p4=0;
p1=t.indexOf("<"+"script",0);
if(p1==-1){
  g("script").innerHTML='';
  g(id).innerHTML=t;
  if(a){
    var s=document.createElement("script");
    s.type="text/javascript";
    s.text=a;
    g("script").appendChild(s);
  }
  return true;
}
p2=t.indexOf(">",p1+7) + 1;
p3=t.indexOf("<"+"/script>",p2);
p4=p3+9;
if(a){var add=a}else{var add="";}
var c=add+t.substring(p2,p3);
t=t.substring(0,p1)+t.substr(p4);
return execJSA(id,t,c);
}

/* ============ loadlist = 
// Ritorna il valore dell'elemento <option> selezionato in una lista
function getSelected(select){return select.options[select.selectedIndex].value;} 

function addOption(select,value,text){
	var option = document.createElement("option");
	option.value = value, option.text = text;
	try { select.add(option, null); }
  catch(e) { select.add(option); }// Per Internet Explorer
}

function loadList(url,obg){
  var _n=DynObj.length;
  DynObj[_n] = new ajax();
  DynObj[_n].requestFile = url+'QVobg_'+obg+'.html';
  DynObj[_n].metodo = 'GET';
  DynObj[_n].onCompletion = function(){
    var resp = DynObj[_n].response;
    if(resp){
    	var values = resp.split(';'); // Le coppie di valori nella striga di risposta sono separate da ;
    	var listId = values.shift(); // Il primo elemento è l'ID della lista.
    	var select = g(listId);
    	while (select.options.length) { select.remove(0); } // Elimina i valori precedenti
    	addOption(select, '', '----', 0);
    	var limit = values.length;
    	for(i=0; i < limit; i++){
    		var pair = values[i].split('|');
    		addOption(select, pair[0], pair[1]);
    	}
    }
  };
  DynObj[_n].runAJAX();
}

function loadListMulti(url,obg,tab){
  var _n=DynObj.length;
  DynObj[_n] = new ajax();
  DynObj[_n].requestFile = url+'/tab_'+tab+'/obg_'+obg;
  DynObj[_n].metodo = 'GET';
  DynObj[_n].onCompletion = function(){
    var resp = DynObj[_n].response;
    if(resp){ 
      var values=resp.split('|'); 
      var lista=values[0]; 
      var box=g('from-'+obg+'-'+lista);
      box.innerHTML=values[1];
    }
  };
  DynObj[_n].runAJAX();
}
*/


