var PopupGenerator = {
  open: function(options)
  {
    this.options = {
      url: '#',
      width: 600,
      height: 500,
      name:"_blank",
      location:"no",
      menubar:"no",
      toolbar:"no",
      status:"yes",
      scrollbars:"yes",
      resizable:"yes",
      left:"",
      top:"",
      normal:false
    }
    Object.extend(this.options, options || {});

    if (this.options.normal){
        this.options.menubar = "yes";
        this.options.status = "yes";
        this.options.toolbar = "yes";
        this.options.location = "yes";
    }

    this.options.width = this.options.width < screen.availWidth?this.options.width:screen.availWidth;
    this.options.height=this.options.height < screen.availHeight?this.options.height:screen.availHeight;
    var openoptions = 'width='+this.options.width+',height='+this.options.height+',location='+this.options.location+',menubar='+this.options.menubar+',toolbar='+this.options.toolbar+',scrollbars='+this.options.scrollbars+',resizable='+this.options.resizable+',status='+this.options.status
    if (this.options.top!="")openoptions+=",top="+this.options.top;
    if (this.options.left!="")openoptions+=",left="+this.options.left;
    window.open(this.options.url, this.options.name,openoptions );
    
    return false;
  }
}

function addTag(tag,el){
  var taglist = $(el);
  taglist.value = taglist.value + tag + ",";
}

Event.observe(window,'load',initUserInfo);

function initUserInfo(){
    userInfoWindow = new Popup('userInfo',null,{modal:true,duration:.2,position:'centerVert'});
    
}
function getUserInfo(id) {

    target = "userInfoContent";
    params = "userId="+id;
    url = "getUser.do";
    userInfoUpdater = new Ajax.Updater(target,url,{method:'post',parameters:params,onComplete:function (){tinyMCE.init({
        mode: "textareas",
        theme: "simple",
        editor_deselector: "mceNoEditor"
    });
    $('userInfo').popup.show();
    $('mailUserID').value = id;
    //Event.observe('sendMessage','click',sendMessage);
    }});
}
function getUserListInfo(){
    //alert("Here");
    target ="userInfoContent";
    params="";
    url = "getList.do";
    userInfoUpdater = new Ajax.Updater(target,url,{method:'post',parameters:params,onComplete:function (){tinyMCE.init({
        mode: "textareas",
        theme: "simple",
        editor_deselector: "mceNoEditor"
    });
    $('userInfo').popup.show();
    //$('mailUserID').value = id;
    //Event.observe('sendMessage','click',sendMessage);
    }});
}

function sendMessage(){
    //tinyMCE.triggerSave();
    //alert($F('mailUserID'));
    //alert($F('mailMessageSubject'));
    //alert($F('mailMessageBody'));
    sendMessageUpdater=new Ajax.Updater('sendMailSuccess','sendMessage.do',{method:'post',parameters:
        {userId: $F('mailUserID'), subject: $F('mailMessageSubject'), body: $F('mailMessageBody')}, onComplete:function(){
        alert("Your message is sent");
        $('messageSent').popup.hide()}});

}
function sendMessageToAll(){

    sendMessageUpdater=new Ajax.Updater('sendMailSuccess','sendMessageToAll.do',{method:'post',parameters:
        {toIDs: $F('mailUserID'), subject: $F('mailMessageSubject'), body: $F('mailMessageBody')}, onComplete:function(){
        alert("Your message is sent");
        $('messageSent').popup.hide()}});

}

function getMiniBio(id) {

    target = "miniBioContent";
    params = "userId="+id;
    //alert(params);
    url = "getMiniBio.do";
    userInfoUpdater = new Ajax.Updater(target,url,{method:'post',parameters:params,onComplete:function (){

    $('miniBio').popup.show();}});
}

function getColleague(e) {
    var data = $A(arguments);
    id=data.shift();
    
    target = "addColleagueContent";
    params = "action=addColleague&userId="+id;
    //alert(params);
    url = "getUser.do";
    userInfoUpdater = new Ajax.Updater(target,url,{method:'post',parameters:params,onComplete:function (){

    $('addColleague').popup.show();
}});


}

function openWindow(e){
        var data = $A(arguments);
        data.shift();

        window.open(this.href, data[0], data[1]);

        Event.stop(e);
    }