var numcol = 0
var colori = new Array(15)
colori[0] = "white"
colori[1] = "black"
colori[2] = "navy"
colori[3] = "green"
colori[4] = "red"
colori[5] = "maroon"
colori[6] = "purple"
colori[7] = "olive"
colori[8] = "yellow"
colori[9] = "lime"
colori[10] = "teal"
colori[11] = "aqua"
colori[12] = "blue"
colori[13] = "fuchsia"
colori[14] = "silver"
colori[15] = "gray"

function cambiacol(){
  if (numcol > 14) numcol = 0
  else numcol += 1;
  if (document.all){
//    document.styleSheets[document.styleSheets.length-1].rules[2].style.color = colori[numcol];
//    document.styleSheets[document.styleSheets.length-1].rules[7].style.color = colori[numcol];
//    document.styleSheets[document.styleSheets.length-1].rules[8].style.color = colori[numcol];
  }
  else if(document.getElementById){
    document.styleSheets[1].cssRules[2].style.color = colori[numcol]; // #links
    //document.styleSheets[1].cssRules[7].style.color = colori[numcol]; // .postinfo
    document.styleSheets[1].cssRules[8].style.color = colori[numcol]; // #links a:link
    document.styleSheets[1].cssRules[9].style.color = colori[numcol]; // #links a:visited
  }
}

//var fineanno = new Date("January 1, 2008 00:00:00"); 
var toni_oggi = new Date();
var toni_anno = toni_oggi.getFullYear() + 1;
var fineanno = new Date("January 1, " + toni_anno + " 00:00:00");

var orologio = null;
function AggiornaContoAR() {
  var adesso = new Date();
  if (document.all)
    document.all.conto.innerText = Math.round((fineanno.getTime() - adesso.getTime())/1000);
  else if(document.getElementById)
    document.getElementById('conto').innerHTML = Math.round((fineanno.getTime() - adesso.getTime())/1000);
  orologio = setTimeout("AggiornaContoAR()", 1000);
};

document.write('<body background="http://www.aabo.it/blog/iac/bg-img/dl_test.php" id="toniBG" onLoad="AggiornaContoAR();" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">')

var timBG = null;
timBG = setInterval("cambiaBG()", 300000); //300000
function cambiaBG() {
  if(document.all) // IE4+
    toniBG.background="http://www.aabo.it/blog/iac/bg-img/dl_test.php";
  else
    if(document.getElementById) // IE5+ NN6+
      {
      var cur=Math.round(50*Math.random())
      document.getElementById('toniBG').style.backgroundImage = "url(http://www.aabo.it/blog/iac/bg-img/dl_test.php?"+cur+")";
      //alert(getBGWidth());
//      document.getElementById('toniBG').style.background='url("http://www.aabo.it/blog/iac/bg-img/dl_test.php?'+cur+'")';
//      document.getElementById('toniBG').style.backgroundAttachment = 'fixed';
//      document.getElementById('toniBG').style.backgroundRepeat = 'no-repeat';
//      document.getElementById('toniBG').style.backgroundPosition = 'top left';
//      document.getElementById('toniBG').style.backgroundColor = '#666666';
      }
}

function radio(){
  mplayer=window.open('','radioblog','directories=no,height=300,width=220,location=no,menubar=no,resizable=no,scrollbars=no,status=no')
  mplayer.document.write("<html>\n")
  mplayer.document.write("<head>\n")
  mplayer.document.write("<TITLE>Messiah Radio Blog</TITLE>\n")
  mplayer.document.write("</head>\n")
  mplayer.document.write('<frameset rows="100%,*"><frame noresize frameborder=0 scrolling=no src="http://www.aabo.it/messiah/radio.blog/index.php"></frameset>\n')
  mplayer.document.write("<body>\n")
  mplayer.document.write("</body>\n")
}

// 17/03/2007
// converte i ! in %21 dai permalink di spaces per poterli linkare su phpbb
function convertSpacesLiveURL(val) {
  val = val.replace(/!/gi,"%21");
  document.forms["formSpacesLiveURL"].origval.value = "[URL=" + val + "]link[/URL]";
  document.forms["formSpacesLiveURL"].origval.select();
}

function fix_splinder_lamer_links() {
  // leva www. dai link dei mesi
  for (var i=0; i < document.links.length; i++) {
    var re = /www.iac.splinder/gi; // /stringa/gi g = global i = case-insensitive
    if ( document.links[i].href != document.links[i].href.replace(re,"iac.splinder") ) {
      document.links[i].href = document.links[i].href.replace(re,"iac.splinder");
      document.links[i].innerHTML = document.links[i].innerHTML.replace(re,"iac.splinder");
    }
  }
}


function GoogleVideoChangeIt(val)
{
var state   = "none"
var len     = val.length;
var backlen = len;
var i       = 0;

var newStr  = "";
var frag    = "";
var encval  = "";
var original = val;

if (state == "none") // needs to be converted to normal chars
   {
     while (backlen > 0)
           {
             lastpercent = val.lastIndexOf("%");
             if (lastpercent != -1) // we found a % char. Need to handle
                {
                  // everything *after* the %
                  frag = val.substring(lastpercent+1,val.length);
                  // re-assign val to everything *before* the %
                  val  = val.substring(0,lastpercent);
                  if (frag.length >= 2) // end contains unencoded
                     {
                     //  alert ("frag is greater than or equal to 2");
                       encval = frag.substring(0,2);
                       newStr = frag.substring(2,frag.length) + newStr;
                       //convert the char here. for now it just doesn't add it.
                       if ("01234567890abcdefABCDEF".indexOf(encval.substring(0,1)) != -1 &&
                           "01234567890abcdefABCDEF".indexOf(encval.substring(1,2)) != -1)
                          {
                           encval = String.fromCharCode(parseInt(encval, 16)); // hex to base 10
                           newStr = encval + newStr; // prepend the char in
                          }
                       // if so, convert. Else, ignore it.
                     }
                  // adjust length of the string to be examined
                  backlen = lastpercent;
                 // alert ("backlen at the end of the found % if is: " + backlen);
                }
            else { newStr = val + newStr; backlen = 0; } // if there is no %, just leave the value as-is
           } // end while
   }         // end 'state=none' conversion
else         // value needs to be converted to URL encoded chars
   {
    for (i=0;i<len;i++)
        {
          if (val.substring(i,i+1).charCodeAt(0) < 255)  // hack to eliminate the rest of unicode from this
             {
              if (isUnsafe(val.substring(i,i+1)) == false)
                 { newStr = newStr + val.substring(i,i+1); }
              else
                 { newStr = newStr + convert(val.substring(i,i+1)); }
             }
          else // woopsie! restore.
             {
               alert ("Found a non-ISO-8859-1 character at position: " + (i+1) + ",\nPlease eliminate before continuing.");
               document.forms[0].state.value = "none";
               document.forms[0].enc[0].checked = true; // set back to "no encoding"
               newStr = original; i=len;                // short-circuit the loop and exit
             }
        }

   }
   //GoogleVideourlenc.origval.value = newStr;
	 location.href=newStr;
}

function DownloadYouTube(val)
{
	//http://www.youtube.com/watch?v=dbBfosZoFZs&feature=TopRated&page=1&t=t&f=b
	
	var idx_inizio = val.indexOf("watch?v=") + 8;
	var idx_fine = val.indexOf("&");
	if (idx_fine == -1) idx_fine = val.length;
	var dl_url = "http://youtube.com/get_video.php?video_id=" + val.substring(idx_inizio,idx_fine);
	//alert(dl_url);
	location.href=dl_url;
}

