var DialogController = new Class.create({

  initialize: function(){

  },

  showDialog: function(html,cfg){
    var dialog = jq$("#dialog-content").dialog({ autoOpen: false });
    if(typeof html=="undefined") return;
    if(typeof cfg=="undefined") cfg = {};
    dialog.dialog( "destroy" );
    jq$("#dialog-content div").html(html);
    dialog.dialog(cfg);
    jq$("#dialog-content").trigger("dialog:created");
  },

  onHcpClick: function(url){
    var message = "<p>The information contained in this section of the site is intended for U.S. healthcare professionals only. Click \"OK\" if you are a healthcare professional.</p>";
    this.showJumpDialog(message,url);
  },

  onThirdPartyClick: function(url){
    var message = "<p>The link you have selected will take you away from this site to one that is not owned or controlled by Genentech, Inc. Genentech, Inc. makes no representation as to the accuracy of the information contained on sites we do not own or control.\n\n Genentech does not recommend and does not endorse the content on any third-party websites. Your use of third-party websites is at your own risk and subject to the terms and conditions of use for such sites.</p>";
    this.showJumpDialog(message,url);
  },

  showJumpDialog: function(msg,url){
    var dialog = jq$("#dialog-content").dialog({ autoOpen: false });
    var message = msg;
  
    var onOk = function(){ 
      if(url.include(contextPath+subPath+"/hcp/") || url.startsWith(subPath+"/hcp/") || url.startsWith("/hcp/")){
        location.href = (!url.include(location.host))?contextPath+url : url;
        site.omniture.omniLinkClick(url);
      }else{
        window.open(url);
      }
      dialog.dialog("close");
    };
  
    var onCancel = function(){
      dialog.dialog("close");
    };
    // becasue IE7 somehow doens't show jquery buttons correctly, needs to create buttons manualy 
    jq$("#dialog-content").one("dialog:created",function(){
      var ok = jq$("<input type='button' class='input-ok' value='ok' />");
      var cancel = jq$("<input type='button' class='input-cancel' value='cancel' />");
      jq$("#dialog-content div").append(ok);
      jq$("#dialog-content div").append(cancel);
      jq$(ok).click(onOk);
      jq$(cancel).click(onCancel);
    });
  
    var cfg = { 
      title: "Avastin.com",
      dialogClass: "hcp-jump"
    };
  
    this.showDialog(message,cfg);
  }
});

