function importPopup(uid) {
/* 
   url= location.protocol + '//' + location.host + '/podcast/import_media?uid=' +
         uid + '&session_id=' + sid;
  newWin=window.open(url,'importMedia','height=175,width=505,scrollbars,resizable');
  if (newWin.focus) { newWin.focus(); }
  */
 $('import_box').style.display='block';
/* Effect.Appear($('import_box')); */
}
function undoImport(){
 $('import_box').style.display='none';
}

/* create a popup window with the delete media form */
function deletePopup(id,plus) {
  url=location.protocol+'//'+location.host+'/podcast/delete/'+id+'&session_id='+sid;
  height=400;
  width=505;
  if (plus) {
    height=175;
    width=505;
  }
  newWin=window.open(url,'deleteShow','height='+height+',width='+width+',scrollbars=yes');
  if (newWin.focus) { newWin.focus(); }
}


function changePlayerText(id, name) {
  var text = $(id);
  if ( text != null ) {
    text.innerHTML = name;
  }
}


function updateCommentsCount(count, span_id) {
  try {
    window.opener.setCommentsCount(count, span_id)
  } catch (e) {
    /* do nothing for now */
  }
}

function setCommentsCount(count, span_id) {
  $( span_id ).innerHTML = count;
}

var messageText = ''
function setText(newText) {
  /* alert( "setting text to" + newText ); */
  messageText = newText;
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return $(movieName);
  }
}

function sendMessageIE(lcId, fileName, id) {
  var flashMovie = getFlashMovieObject( lcId );
  var text = flashMovie.GetVariable( 'messageText' );

  sendMessage( text, fileName, id );
}

function sendMessage(text, fileName, id){
  /* setMessageHidden(); */
  if (fileName != null && id != null) {
    setRecordedHidden(fileName, id);
  }
  document.podcast_form.onsubmit();
  document.podcast_form.submit();
}

function setRecordedHidden(filename,id){
  var e_id=$('recorded_id');
  var e_fn=$('recorded_fn');
  e_id.setAttribute('value',id);
  e_fn.setAttribute('value',filename);
  
}


function setMessageHidden(){
  $('podcast_body').setAttribute('value',messageText);
}

function setHiddens(fn, tmp, doc){
  doc.getElementById('cast').setAttribute('value',fn);
}


function flash(message, doc, uid) {
  if (! doc) { doc=document; }
  doc.getElementById('flash').innerHTML=message;

}

var flashProxy = null;
function setFlashName(name, uid) {
  flashProxy = new FlashProxy( uid, '/flash/JavaScriptFlashGateway.swf' );
  flashProxy.call( 'setImportFile', name );
} 


function selectAudio(uid) {
  var name=$('podcast_cast').value;
  var message='The media '+name+' will be included in this podMail.';
  setHiddens(name,false,window.opener.document);

  window.opener.setFlashName( name, uid );

  window.close();
}

function selectUploaded(name, uid){
  var message='The media '+name+' will be included in this episode.';

  movie = $("recorder" );
  if ( movie != null ) {
    movie.SetVariable( "importText", message );
    movie.GotoFrame( 4 );
  }
  setHiddens(name,false,window.opener.document);
  window.opener.setFlashName( name, uid );
  window.close();
}

function showTT(obj_id) {
  $(obj_id).style.display='block';
  document.onmousedown=function() { $(obj_id).style.display='none'; document.onmousedown=function(){}; }
}

function goToMixOmatic() {
  window.location.href='/mix?d=p';
}

function subscribe(event, name, feed, title, home, div_id) {
  var text = document.getElementById( div_id + '_flash' );
  text.innerHTML = name;

  showToolTip( div_id, captureMousePosition( event || window.event ) );

  // have to do a subs request, get the base req, the params, and call Request
  var req = '/queuesub/create';
  var params = 'queuesub[feed]=' + feed + '&queuesub[title]=' + title + 
    '&queuesub[home]=' + home;

  new Ajax.Request( req, { parameters: params } );
}

function podAmigoRPC(URL) {
  var IFrameObj; // our IFrame object

  if (!document.createElement) {return true};
  var IFrameDoc;
  if (!IFrameObj && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time 
    // callToServer() is called
    try {
      var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id','RSIFrame');
      tempIFrame.style.border='0px';
      tempIFrame.style.width='0px';
      tempIFrame.style.height='0px';
      IFrameObj = document.body.appendChild(tempIFrame);

      if (document.frames) {
        // this is for IE5 Mac, because it will only
        // allow access to the document object
        // of the IFrame if we access it through
        // the document.frames array
        IFrameObj = document.frames['RSIFrame'];
      }
    } catch(exception) {
      // This is for IE5 PC, which does not allow dynamic creation
      // and manipulation of an iframe object. Instead, we'll fake
      // it up by creating our own objects.
      iframeHTML='\<iframe id="RSIFrame" style="';
      iframeHTML+='border:0px;';
      iframeHTML+='width:0px;';
      iframeHTML+='height:0px;';
      iframeHTML+='"><\/iframe>';
      document.body.innerHTML+=iframeHTML;
      IFrameObj = new Object();
      IFrameObj.document = new Object();
      IFrameObj.document.location = new Object();
      IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
      IFrameObj.document.location.replace = function(location) {
        this.iframe.src = location;
      }
    }
  }
}

function getPodcastUser() {
  return(document.location.hostname.split('.',2)[0]);
}
