function checkNewsletter(titolo) {
    var tmpValue = document.getElementById(titolo).value;
    tmpValue = tmpValue.replace(/^\s+|\s+$/g, "");
    if(tmpValue == "") {
	alert("Devi inserire il titolo della newsletter");
	return false;
    }
    return true;
 }

//FUNZIONI PER NEXT IMAGE NELLA BARRA
var firstImageBar = 0;
var lastImageBar = 4; //Parto da 0 quindi 4
var numImageBar = 0;

function prevImageBar() {
    if (firstImageBar>0) {
	firstImageBar--;
	if (document.getElementById("img_"+firstImageBar)) document.getElementById("img_"+firstImageBar).style.display = "inline";
	if (document.getElementById("img_"+lastImageBar)) document.getElementById("img_"+lastImageBar).style.display = "none";
	lastImageBar--;
    }
}

function nextImageBar() {
    if (lastImageBar < numImageBar-1) {
	if(document.getElementById("img_"+firstImageBar)) document.getElementById("img_"+firstImageBar).style.display = "none";
	firstImageBar++;
	lastImageBar++;
	if (document.getElementById("img_"+lastImageBar)) document.getElementById("img_"+lastImageBar).style.display = "inline";
    }
}

//FUNZIONI PER UPLOAD IMAGE
var numFoto = 0;
var maxFoto = 8;
//Carica l'URL
function loadYouTubeLink(youtube) {
    objImg = document.createElement('img'); 
    objImg.id = document.getElementById('h_foto').value; 
    //Estraiamo ID youtube
    youTubeID = "";
    urlTube = youtube.value;
    pos = urlTube.indexOf("?");
    if (pos>=0) {
	urlTube = urlTube.substring(pos+1);
    }
    //Splittiamo su &
    urlTube = urlTube.split("&");
    for(var ii=0; ii<urlTube.length; ii++) {
	if (urlTube[ii]=="") continue;
	parTmp = urlTube[ii].split("=");
	if (parTmp[0]=="v") {
	    youTubeID = parTmp[1];
	    break;
	}
    } 
    objImg.src = "http://i1.ytimg.com/vi/"+youTubeID+"/default.jpg?"+youtube.value; 
    objImg.width='150'; 
    objImg.height='150';

    document.getElementById('foto'+document.getElementById('h_foto').value).appendChild(objImg);
    fotoH = "h_foto"+document.getElementById('h_foto').value;
    document.getElementById(fotoH).value = objImg.src;
    document.getElementById("saveButton").disabled = false;

    return true;
}

//Controlliamo che abbia inserito qlks per evitare di inserire paragrafi vuoti
function checkInfoParagrafo() {
    var atLeastOne = false;
    //Controlliamo che abbia inserito il titolo del paragrafo
    var tmpValue = document.getElementById('titolo_paragrafo').value;
    //Trim
    tmpValue = tmpValue.replace(/^\s+|\s+$/g, "");
    if (tmpValue != "") {
	document.forms[0].submit();
	return true;
    }
    tmpValue = document.getElementById('articolo').value;
    //Trim                                                                                                                                                                                           
    tmpValue = tmpValue.replace(/^\s+|\s+$/g, "");
    //Controlliamo che abbia inserito la descrizione
    if (tmpValue != "") {
	document.forms[0].submit();
        return true;
    }
    //Controlliamo che abbia inserito almeno una foto
    if(document.getElementById("h_foto1").value != "") {
	document.forms[0].submit();
	return true;
    }
    alert("Devi inserire almeno un dato per gruppo di video/foto.");
    return false;
}

//Fa l'upload del file
function uploadFoto(youTubeName, uploadNome) {
  document.getElementById("saveButton").disabled=true;
  var upload_field = document.getElementById(uploadNome);
  var youtube_field = document.getElementById(youTubeName);

  //var re_text = /\.txt|\.xml|\.zip|\.jpg|\.gif|\.jpeg/i;
  var re_text = /\.jpg|\.gif|\.jpeg|\.png/i;
  var filename = upload_field.value;
  
  /* Checking file type */
  if ((filename.search(re_text) == -1) && (youtube_field.value=="") && (youtube_field.value.indexOf("youtube")==-1)) {
    alert("File don't have image(jpg, gif, jpeg, png) extension or no youtube link.");
    upload_field.form.reset();
    document.getElementById("saveButton").disabled=false;
    return false;
  }
  
  if (numFoto >= maxFoto) {
    alert ("Raggiunto il massimo numero di foto per questo Paragrafo.");
    upload_field.form.reset();
    document.getElementById("saveButton").disabled=false;
    return false;
  } else {
    //lanciamo la funzione uploadFile....
    document.getElementById('formModified').value=1;
    numFoto++;
    document.getElementById('h_foto').value = numFoto;
    var pippo=youtube_field.value;
    //Controlliamo che non abbiamo inserito link youtube, in questo caso il percorso &egrave; diversi
    if ( (pippo != "") && (pippo.indexOf("youtube")>=0)) {
	//Percorso alternativo
	return loadYouTubeLink(youtube_field);
    }
    var pluto = upload_field.form;
    pluto.submit();
    pluto.reset();
    return true;
  }
}

function uploadFoto2(youTubeName, uploadNome) {
  document.getElementById("saveButton").disabled=true;
  var upload_field = document.getElementById(uploadNome);
  var youtube_field = document.getElementById(youTubeName);

  //var re_text = /\.txt|\.xml|\.zip|\.jpg|\.gif|\.jpeg/i;
  var re_text = /\.jpg|\.gif|\.jpeg|\.png/i;
  var filename = upload_field.value;
  
  /* Checking file type */
  if ((filename.search(re_text) == -1) && (youtube_field.value=="") && (youtube_field.value.indexOf("youtube")==-1)) {
    alert("File don't have image(jpg, gif, jpeg, png) extension or no youtube link.");
    upload_field.form.reset();
    document.getElementById("saveButton").disabled=false;
    return false;
  }
  
  if (numFoto >= maxFoto) {
    alert ("Raggiunto il massimo numero di foto per questo Paragrafo.");
    upload_field.form.reset();
    document.getElementById("saveButton").disabled=false;
    return false;
  } else {
    //lanciamo la funzione uploadFile....
    document.getElementById('formModified').value=1;
    numFoto++;
    document.getElementById('h_foto').value = numFoto;
    var pippo=youtube_field.value;
    //Controlliamo che non abbiamo inserito link youtube, in questo caso il percorso &egrave; diversi
    if ( (pippo != "") && (pippo.indexOf("youtube")>=0)) {
	//Percorso alternativo
	return loadYouTubeLink(youtube_field);
    }
    var pluto = upload_field.form;
    pluto.submit();
    //pluto.reset();
    return true;
  }
}

function delFotoGallery(indexFoto) {
    var delObj = document.getElementById("h_foto"+indexFoto).value;    
    if (numFoto<=0 || !delObj || delObj== "") return false;
    if(confirm('Sicuro di voler cancellare la foto: '+delObj+' ?')){
	for (i=indexFoto; i<maxFoto; i++) {
	    document.getElementById("foto"+i).innerHTML = document.getElementById("foto"+(i+1)).innerHTML;
            document.getElementById("h_foto"+i).value = document.getElementById("h_foto"+(i+1)).value;
	}
	document.getElementById("foto"+maxFoto).innerHTML = "";
        document.getElementById("h_foto"+maxFoto).value = "";
	numFoto--;
	var delObjSub = document.getElementById("delFoto");
	delObjSub.value = delObj;
	delObjSub.form.submit();
    }
}

function delFotoOLD(indexFoto) { 
    var delObj = document.getElementById("h_foto"+indexFoto).value;
    if (numFoto<=0 || !delObj || delObj== "") return false;
    if(confirm('Sicuro di voler cancellare la foto: '+delObj+' ?')){    
	for (i=indexFoto; i<maxFoto; i++) {
	    document.getElementById("foto"+i).innerHTML = document.getElementById("foto"+(i+1)).innerHTML;
	    document.getElementById("h_foto"+i).value = document.getElementById("h_foto"+(i+1)).value;
	}
	document.getElementById("foto"+maxFoto).innerHTML = "";
	document.getElementById("h_foto"+maxFoto).value = "";
	
	numFoto--;
	
	var delObjSub = document.getElementById("delFoto");
	delObjSub.value = delObj;
	delObjSub.form.submit();
    }
}

function riempiForm(idParagrafo) {
  numFoto = 0;
  document.getElementById("titolo_paragrafo").value = document.getElementById(idParagrafo+"_titolo").value;
  document.getElementById("articolo").value = document.getElementById(idParagrafo+"_paragrafo").value;
  document.getElementById("h_paragrafo").value = idParagrafo;
  document.getElementById("new").value = 0;
  urls = document.getElementsByName(idParagrafo+"_url");
	
  for (i=0; i<8; i++) {
      document.getElementById("foto"+(i+1)).innerHTML = "";
      document.getElementById("h_foto"+(i+1)).value = "";
  }

  for (i=0; i<urls.length; i++) {
      //Cotrolliamo che sia youtube
      if(urls[i].value.indexOf("youtube")>=0) {
	  document.getElementById("foto"+(i+1)).innerHTML = "<img src='"+urls[i].value+"' >"; //gestire preview AB
	  document.getElementById("h_foto"+(i+1)).value = urls[i].value;	  
      } else {
	  document.getElementById("foto"+(i+1)).innerHTML = "<img src='/"+urls[i].value+"'  onClick='previewImg(\"/"+urls[i].value+"\");'>";
	  var urlss = (urls[i].value).split("/"); //AB
	  document.getElementById("h_foto"+(i+1)).value = urlss[1];
      }
  }
  numFoto = urls.length;
}

function previewImg(imgName) {
  var sVet = imgName.split("/");
  new_window = open("","displayTagWindow","resizable=1,scrollable=1,width=930,height=700,left=10,top=10");
  new_window.document.open();
  new_window.document.writeln("<html><head><title>Preview IMG</title></head>");
  urlTmp = "";
  if (sVet.length>=3)
      urlTmp = sVet[2];
  else
      urlTmp = sVet[1];
  urlTmp = urlTmp.replace("tAB_", "");
  new_window.document.writeln("<body><br><br><div align='center'>Preview per la foto: <b>"+urlTmp+"</b><br><br><br>");
  //Togliamo tAB_ e mostriamo quella gAB_
  imgName = imgName.replace("tAB_","gAB_");
  new_window.document.writeln("<img src='"+imgName+"' border=0><br></div>");    
  new_window.document.writeln("</body></html>");
  new_window.document.close();
}

//Inserisce rigo nella tabella dei paragrafi
function addRow(nomeTabella, id, nome, articolo) {
  var tabella = parent.document.getElementById(nomeTabella);
	
  //Rigo del titolo paragrafo
  var rigo = parent.document.createElement('tr');
  var colonna0 = parent.document.createElement('td');
  colonna0.innerHTML = "&nbsp;";
  rigo.appendChild(colonna0);
  var colonna1 = parent.document.createElement('td');
  colonna1.innerHTML = nome;
  rigo.appendChild(colonna1);
  var colonna2 = parent.document.createElement('td');
  var imgUpd = parent.document.createElement('img');
  imgUpd.src = 'images/edit.gif';
  imgUpd.alt = "Anteprima"; 
  imgUpd.title = "Modifica"; 
  colonna2.appendChild(imgUpd);
  rigo.appendChild(colonna2);
  var colonna3 = parent.document.createElement('td');
  var imgUpd = parent.document.createElement('img');
  imgUpd.src = 'images/delete.png';
  imgUpd.alt = "Cancella"; 
  imgUpd.title = "Cancella";
  colonna3.appendChild(imgUpd);
  rigo.appendChild(colonna3);
  tabella.appendChild(rigo);
	
  //Rigo del contenuto del paragrafo
  var rigo2 = parent.document.createElement('tr');
  var colonna0 = parent.document.createElement('td');
  colonna0.innerHTML = "&nbsp;";
  rigo2.appendChild(colonna0);
  var colonna2 = parent.document.createElement('td');
  colonna2.innerHTML = articolo;
  rigo2.appendChild(colonna2);
  var colonna0 = parent.document.createElement('td');
  colonna0.innerHTML = "&nbsp;";
  rigo2.appendChild(colonna0);
  var colonna0 = parent.document.createElement('td');
  colonna0.innerHTML = "&nbsp;";
  rigo2.appendChild(colonna0);
  tabella.appendChild(rigo2);
	
  //Righe con le foto
  var rigo3 = parent.document.createElement('tr');
  var colonna0 = parent.document.createElement('td');
  colonna0.innerHTML = "&nbsp;";
  rigo3.appendChild(colonna0);
	
  var colonna0 = parent.document.createElement('td');
	
  //Creiamo sottotabella...
  var tab = parent.document.createElement('table');
  var rigo11 = parent.document.createElement('tr');
  var col11 = parent.document.createElement('td');
  if ((fotos[1] != "") && (fotos[1] != undefined) ) {
    var imgUpd = parent.document.createElement('img');
    imgUpd.src = "/img_articoli/"+fotos[1];
    imgUpd.width = "120";
    imgUpd.height = "120";
    col11.appendChild(imgUpd);	
  } else {
    col11.innerHTML = "&nbsp;";
  }
  rigo11.appendChild(col11);
  tab.appendChild(rigo11);
	
  var col11 = parent.document.createElement('td');
  if ((fotos[2] != "") && (fotos[2] != undefined) ) {
    var imgUpd = parent.document.createElement('img');
    imgUpd.src = "/img_articoli/"+fotos[2];
    imgUpd.width = "120";
    imgUpd.height = "120";
    col11.appendChild(imgUpd);	
  } else {
    col11.innerHTML = "&nbsp;";
  }
  rigo11.appendChild(col11);
  tab.appendChild(rigo11);
	
  var col11 = parent.document.createElement('td');
  if ((fotos[3] != "") && (fotos[3] != undefined) ) {
    var imgUpd = parent.document.createElement('img');
    imgUpd.src = "/img_articoli/"+fotos[3];
    imgUpd.width = "120";
    imgUpd.height = "120";
    col11.appendChild(imgUpd);	
  } else {
    col11.innerHTML = "&nbsp;";
  }
  rigo11.appendChild(col11);
  tab.appendChild(rigo11);
	
  var col11 = parent.document.createElement('td');
  if ((fotos[4] != "") && (fotos[4] != undefined) ) {
    var imgUpd = parent.document.createElement('img');
    imgUpd.src = "/img_articoli/"+fotos[4];
    imgUpd.width = "120";
    imgUpd.height = "120";
    col11.appendChild(imgUpd);	
  } else {
    col11.innerHTML = "&nbsp;";
  }
  rigo11.appendChild(col11);
  tab.appendChild(rigo11);
  //Secondo rigo foto
  var rigo11 = parent.document.createElement('tr');
  var col11 = parent.document.createElement('td');
  if ((fotos[5] != "") && (fotos[5] != undefined) ) {
    var imgUpd = parent.document.createElement('img');
    imgUpd.src = "/img_articoli/"+fotos[5];
    imgUpd.width = "120";
    imgUpd.height = "120";
    col11.appendChild(imgUpd);	
  } else {
    col11.innerHTML = "&nbsp;";
  }
  rigo11.appendChild(col11);
  tab.appendChild(rigo11);
	
  var col11 = parent.document.createElement('td');
  if ((fotos[6] != "") && (fotos[6] != undefined) ) {
    var imgUpd = parent.document.createElement('img');
    imgUpd.src = "/img_articoli/"+fotos[6];
    imgUpd.width = "120";
    imgUpd.height = "120";
    col11.appendChild(imgUpd);	
  } else {
    col11.innerHTML = "&nbsp;";
  }
  rigo11.appendChild(col11);
  tab.appendChild(rigo11);
	
  var col11 = parent.document.createElement('td');
  if ((fotos[7] != "") && (fotos[7] != undefined) ) {
    var imgUpd = parent.document.createElement('img');
    imgUpd.src = "/img_articoli/"+fotos[7];
    imgUpd.width = "120";
    imgUpd.height = "120";
    col11.appendChild(imgUpd);	
  } else {
    col11.innerHTML = "&nbsp;";
  }
  rigo11.appendChild(col11);
  tab.appendChild(rigo11);
	
  var col11 = parent.document.createElement('td');
  if ((fotos[8] != "") && (fotos[8] != undefined) ) {
    var imgUpd = parent.document.createElement('img');
    imgUpd.src = "/img_articoli/"+fotos[8];
    imgUpd.width = "120";
    imgUpd.height = "120";
    col11.appendChild(imgUpd);	
  } else {
    col11.innerHTML = "&nbsp;";
  }
  rigo11.appendChild(col11);
  tab.appendChild(rigo11);
	
  colonna0.appendChild(tab);
  rigo3.appendChild(colonna0);
  //FINE Creiamo sottotabella...
	
  var colonna0 = parent.document.createElement('td');
  colonna0.innerHTML = "&nbsp;";
  rigo3.appendChild(colonna0);
  var colonna0 = parent.document.createElement('td');
  colonna0.innerHTML = "&nbsp;";
  rigo3.appendChild(colonna0);
  tabella.appendChild(rigo3);
	
	
  //parent.document.getElementById("tableUpload").innerHTML ='<tr class="left">	<td>1)</td><td><div id="idFoto1" style="visibiliy:hidden"></div> <div id="foto1"> </div></td><td><span onClick="delFoto(1);">Del</span> &nbsp;&nbsp;</td><td>2)</td><td><div id="idFoto2"></div> <div id="foto2"> </div></td><td><span onClick="delFoto(2);">Del</span></td></tr><tr class="left"><td>3)</td><td><div id="idFoto3" style="visibiliy:hidden"></div> <div id="foto3"> </div></td><td><span onClick="delFoto(3);">Del</span> &nbsp;&nbsp;</td><td>4)</td><td><div id="idFoto4" style="visibiliy:hidden"></div> <div id="foto4"> </div></td><td><span onClick="delFoto(4);">Del</span></td></tr><tr class="left"><td>5)</td><td><div id="idFoto5" style="visibiliy:hidden"></div> <div id="foto5"> </div></td><td><span onClick="delFoto(5);">Del</span> &nbsp;&nbsp;</td><td>6)</td><td><div id="idFoto6" style="visibiliy:hidden"></div> <div id="foto6"> </div></td><td><span onClick="delFoto(6);">Del</span></td></tr><tr class="left">	<td>7)</td><td><div id="idFoto7" style="visibiliy:hidden"></div> <div id="foto7"> </div></td><td><span onClick="delFoto(7);">Del</span> &nbsp;&nbsp;</td>	<td>8)</td><td><div id="idFoto8" style="visibiliy:hidden"></div> <div id="foto8"> </div></td><td><span onClick="delFoto(8);">Del</span></td></tr>'; 
  parent.document.getElementById("idFoto1").innerHTML = "";
  parent.document.getElementById("idFoto2").innerHTML = "";
  parent.document.getElementById("idFoto3").innerHTML = "";
  parent.document.getElementById("idFoto4").innerHTML = "";
  parent.document.getElementById("idFoto5").innerHTML = "";
  parent.document.getElementById("idFoto6").innerHTML = "";
  parent.document.getElementById("idFoto7").innerHTML = "";
  parent.document.getElementById("idFoto8").innerHTML = "";
  parent.document.getElementById("foto1").innerHTML = "";
  parent.document.getElementById("foto2").innerHTML = "";
  parent.document.getElementById("foto3").innerHTML = "";
  parent.document.getElementById("foto4").innerHTML = "";
  parent.document.getElementById("foto5").innerHTML = "";
  parent.document.getElementById("foto6").innerHTML = "";
  parent.document.getElementById("foto7").innerHTML = "";
  parent.document.getElementById("foto8").innerHTML = "";
  parent.document.getElementById("h_foto1").value = "";
  parent.document.getElementById("h_foto2").value = "";
  parent.document.getElementById("h_foto3").value = "";
  parent.document.getElementById("h_foto4").value = "";
  parent.document.getElementById("h_foto5").value = "";
  parent.document.getElementById("h_foto6").value = "";
  parent.document.getElementById("h_foto7").value = "";
  parent.document.getElementById("h_foto8").value = "";
	
  parent.numFoto = 0;
  parent.document.getElementById('h_foto').value = '1';
}

function stampa() {
  window.print();
}




function makePreview(var_img_preview,crid,isFlash,larghezza,altezza) {
  var id;
  if (crid == null) {
    if (navigator.userAgent.indexOf("Mac",1) < 1) {
      // I am a non-mac
      newStr = var_img_preview.replace(/\\/g, '/');
      newStr = var_img_preview.replace(/:/, '|');
      newStr = "file:///" + newStr;
    } else {
      // I am a mac
      if (navigator.appName=="Netscape") {
	newStr = "file://" + (var_img_preview);
      } else {
	newStr = "file://" + unescape(var_img_preview);
	newStr = newStr.replace(/\+/g, '%20');
      }
    }
  } else{
    var subdir = crid % 1000;
    if( crid > 0){
      id = crid;
    } else if( document.forms[0].cloned_from.value > 0){
      id = document.forms[0].cloned_from.value;
      subdir=id % 1000;
    }
    newStr="/img_uploads/" + subdir + "/" + id + "_" + var_img_preview;
  }

  new_window = open("","displayWindow","resizable=1,width=" + (larghezza + 40) + ",height=" + (altezza+50) + ",left=10,top=10");
  new_window.document.open();
  new_window.document.writeln("<html><head><title>img preview</title>");
  new_window.document.writeln("<scr" + "ipt language=\"javascript\">");
  new_window.document.writeln("var arrTemp=self.location.href.split(\"?\");var picUrl = (arrTemp.length>0)?arrTemp[1]:\"\";var NS = (navigator.appName==\"Netscape\")?true:false;");
  new_window.document.writeln("function FitPic() {iWidth = (NS)?window.innerWidth:document.body.clientWidth;iHeight = (NS)?window.innerHeight:document.body.clientHeight;iWidth = document.images[0].width - iWidth;iHeight = document.images[0].height - iHeight;iWidth = iWidth + 120;iHeight = iHeight + 180;window.resizeBy(iWidth, iHeight);self.focus();};</scri" + "pt></head>");
  if (isFlash==1) {
    new_window.document.writeln("<body bgcolor=\"#FFFFFF\">");
  } else {
    new_window.document.writeln("<body onload=\"FitPic();\" bgcolor=\"#FFFFFF\">");
  }
  new_window.document.writeln("<center>");
  new_window.document.writeln("<br><br>");

  if (isFlash==1) {
    new_window.document.writeln('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
    new_window.document.writeln('codebase="http://active.macromedia.com/flash/cabs/swflash.cab#version=5,0,0,0"');
    new_window.document.writeln('id="fban" width="' + larghezza + '" height="' + altezza + '">');
    new_window.document.writeln('<param name="movie" value="' + newStr + '">');
    new_window.document.writeln('<param name="quality" value="autohigh">');
    new_window.document.writeln('<param name="menu" value="false">');
    new_window.document.writeln('<param name="scale" value="exactfit">');
    new_window.document.writeln('<param name="wmode" value="opaque">');
    new_window.document.writeln('<embed src="' + newStr + '" name="fban"');
    new_window.document.writeln('  width="' + larghezza + '" height="' + altezza + '" swLiveConnect=true');
    new_window.document.writeln(' quality="autohigh" menu="false" scale="exactfit" wmode="opaque"');
    new_window.document.writeln(' type="application/x-shockwave-flash"');
    new_window.document.writeln(' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');
    new_window.document.writeln('</embed>');
    new_window.document.writeln('</object>');
  } else {
        
    new_window.document.writeln("<img name=\"newImage\" src=\"" + newStr + "\" border=1>");
  }	
  new_window.document.writeln("</body></html>");
  new_window.document.close();

  return true;
}
     
function preview(type, sizew, sizeh, foto) {
  var w = sizew;
  var h = sizeh;
  filename = document.getElementById(foto).value

    
    var pview_string = '<div style="text-align:center; width:'+w+'px; height:10px"><img src="/images/preview.gif"><img src="/images/close.gif" onClick="hidePreview();"></div>'; 

  if (type=="swf") {
    //  pview_string += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + w + '" height="' + h + '" id="swfpreview" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + filename + '" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="' + filename + '?callurl=' + link + '" quality="high" bgcolor="#ffffff"  width="' + w + '" height="' + h + '" name="swfpreview" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';

  } else if (type=="img") {
    pview_string += '<img src="' + filename + '" width="' + w  + '" height="' + h  +  '">';
  }
  alert(filename);
  divp = document.getElementById("divpreview");
  divp.style.width = w+20;
  divp.style.height = h+30;
  divp.innerHTML = pview_string;
  divp.style.visibility="visible";
}

function hidePreview() {
  divp = document.getElementById("divpreview");
  divp.style.visibility="hidden";
}

