function comando(option){
  switch(option){
  case 0:document.getElementById("textArea").value += "<b></b>"; break; 
  case 1:document.getElementById("textArea").value += "<u></u>";break;
  case 2:document.getElementById("textArea").value += "<i></i>";break;
  }

}


function resizeImages(image,width){
  var max_width = width;
  var newWidth;
  var newHeight;
   
  if ( img.width > max_width ){
    var old_width = img.width;
    var old_height = img.height;
    newWidth = max_width;
    newHeight = Math.round(old_height * max_width / old_width);
  }  
  return [newWidth,newHeight];
}


function zoomFoto(url){
  img = new Image;
  img.src = url;

  if (parseInt(navigator.appVersion)>3) {
    if (navigator.appName=="Netscape") {
      winW = window.innerWidth;
      winH = window.innerHeight;
    }
   
    if (navigator.appName.indexOf("Microsoft")!=-1) {
      winW = document.body.offsetWidth;
      winH = document.body.offsetHeight;
    }
  }

  newWidth = winH;
  newHeight = Math.round(img.height * winH / img.width);

  html = '<html>\n<head>\n<title>Foto</title>\n</head>\n<body>\n<center><img src="'+url+'" width="'+newWidth+'" height="'+newHeight+'" border=0></center>\n</body>\n</html>';
  popupImage = window.open('../pages/pdc.php','_blank','toolbar=no, location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,fullscreen=yes');
  popupImage.document.open();
  popupImage.document.write(html);
  popupImage.document.close();
}


function caricaImmagine(){
  popupImage = window.open('../pages/uploadPDC.php','popUpload','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no');
}


function annullaFile(n){
  document.getElementById("input"+n).value= "";
}


function insert(){
  var rv = "";  
  for (var i=1;i<=2;i++) {
    if(document.getElementById("radio"+i).checked) rv= document.getElementById("radio"+i).value;
  }
  
  var urlFoto = document.getElementById("urlPuro").value;
  
  var tagA = '<a href="javascript:zoomFoto(\"'+urlFoto+'\")">';
  var chiusuraTagA =  '")>"';
  
  if(rv == "center"){
    insertAtCursor(window.opener.document.getElementById("textArea"), "<br/>"+ tagA + document.getElementById("url").value + "' align='"+rv+"' class='img'/></a><br/>"); 
  }  
  else{
    insertAtCursor(window.opener.document.getElementById("textArea"), tagA + document.getElementById("url").value + "' align='"+rv+"' class='"+rv+"'/></a>");
  }  
}  


function insertAtCursor(campo, stringa) {
  if (document.selection) {
    campo.focus();
    sel = document.selection.createRange();
    sel.text = stringa;
  }
  else if (campo.selectionStart || campo.selectionStart == '0') {
    var startPos = campo.selectionStart;
    var endPos = campo.selectionEnd;
    campo.value = campo.value.substring(0, startPos)
                  + stringa
                  + campo.value.substring(endPos, campo.value.length);
  } else {
    campo.value += stringa;
  }
}
  
