function popup(link){
msg=open(link,"winpopup","toolbar=no,directories=no,menubar=no,width=430,height=500,resizable=no,scrollbars=yes,left=10,top=10");
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
   endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr)).replace("+"," ");
}

  function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var none = '';
   var i = 0;
   while (i < clen) {
    var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
        return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
  }
 return none;
}


function tagging(id,ide){

 var e = document.getElementById(id);
 var a = document.getElementById(ide);
 
 //Supporto Internet Explorer
 if(document.selection){
   sel = e.document.selection.createRange();
   if (sel.text.length > 0) {
			sel.text = '[' + a.value + ']' + sel.text + '[/' + a.value + ']';
   }else{
    if(a.value == ide){
    e.value += '[' + ide + ']';
    a.value = '/' + ide;
 }else{
    e.value += '[/' + ide + ']';
    a.value = ide;
 }
   
   }
 }else{
 //Da qui per il resto del mondo...
 var st = e.selectionStart;
 var en = e.selectionEnd;

 if(e.value.substring(st, en) != 0){
   if(st != en){
  e.value = e.value.substring(0, st)
             + '[' + a.value + ']' 
             + e.value.substring(st, en) 
             + '[/' + a.value + ']' 
             + e.value.substring(en, e.value.length);
   }
 }else{
 
 if(a.value == ide){
    e.value += '[' + ide + ']';
    a.value = '/' + ide;
 }else{
    e.value += '[/' + ide + ']';
    a.value = ide;
 }
 }
}
}

function controlcomment(){
 with(document.comments){
  if(commento.value == ""){
    a = "Il campo commento e' obbligatorio";
  }else{
    a = "";
  }

  if(commento.value == ""){
  alert('Sono stati riscontrati i seguenti errori:\n\n' + a);
  
  return false;
  }
  
  if(autore.value == ""){
    agree = confirm("Inviare il commento come utente Anonimo?");
    
      if (agree){
	return true ;
     }else{
	return false ;
     }
  }
  
  if(captcha.value != 'carciofo'){
    alert('Devi scrivere \'carciofo\' per farmi capire che sei umano :-)');
    
    return false;
  }
 }
}

function addedcom(id){
  if(myReq.readyState == 4 && myReq.status == 200){
     close('loader');
   if(myReq.responseText.indexOf("Spiacente, ma i commenti non sono abilitati per questo articolo") != -1 || 
      myReq.responseText.indexOf("Il campo commento e' obbligatorio") != -1 ||
      myReq.responseText.indexOf("Errore nell'inserimento della parola di controllo") != -1 ||
      myReq.responseText.indexOf("Se sei un utente registrato devi loggarti prima di postare") != -1){
    alert(myReq.responseText);
  }else{ 
    opacity_IN(id,0,1000); 
    setTimeout("document.getElementById('"+id+"').innerHTML += myReq.responseText;", 200);
    document.getElementById('commento').value = '';
  }
  setTimeout("enable('submit')", 3000);
 } 
}

function addcomment(id,lod){
  PreparaDati('comments');
  disable('submit');
  loader(lod,'<span style="color:#ccc; font-size:18px;">Attendere Prego...</span><br />','http://www.davidonzo.com/include/ajax/loader.gif');
    setTimeout("AJAXReq('POST','http://www.davidonzo.com/include/ajax/ajax.php?act=comments',true,function (){addedcom('"+id+"')},stringa);", 1000);
} 

function showprev(id){
  var div = document.getElementById(id);
  if(myReq.readyState == 4 && myReq.status == 200){
   div.innerHTML = '';
   if(myReq.responseText.indexOf("Spiacente, ma i commenti non sono abilitati per questo articolo") != -1 || 
      myReq.responseText.indexOf("Il campo commento e' obbligatorio") != -1 ||
      myReq.responseText.indexOf("Errore nell'inserimento della parola di controllo") != -1 ||
      myReq.responseText.indexOf("Se sei un utente registrato devi loggarti prima di postare") != -1){
    alert(myReq.responseText);
  }else{ 
    opacity_IN(id,0,1000); 
    div.innerHTML = myReq.responseText;
  }
 } 
}

function preview(id){
  PreparaDati('comments');
  loader(id,'<span style="color:#ccc; font-size:18px;">Attendere Prego...</span><br />','http://www.davidonzo.com/include/ajax/loader2.gif');
  setTimeout("AJAXReq('POST','http://www.davidonzo.com/include/ajax/ajax.php?act=preview',true,function (){showprev('"+id+"')},stringa);", 1000);
}

function close(id){
  var div = document.getElementById(id);
  div.style.visibility = 'hidden';
  div.style.display = 'none';
}

function rand_banner(){
  var mybanner = new Array();
  mybanner[0] = '<a href="http://www.securityside.it" target="_blank" title="Security Side. IT - Servizi di sicurezza informatica"><img src="bn/1.png" alt="securityside" /></a>';
  mybanner[1] = '<a href="http://www.digitalside.it" target="_blank" title="Digital Side. IT - Servizi di web developing"><img src="bn/0.png" alt="digitalside" /></a>';
  res = Math.round(Math.random());
  document.getElementById('mybanner').innerHTML = mybanner[res];
}

window.onload = rand_banner;
