var $ = jQuery.noConflict();

function customAlert( title, message, width ) {
    if ( title == "" ) {
        title = globalvar_pagetitle;
    }
    var nWidth;
    if (width != undefined) { nWidth = width; }
    if (nWidth < 300) { nWidth = 300; }
    
    $("<div title='" + title + "'>" + message + "</div>").dialog( {
        width: nWidth,
        buttons: {
            "Ok": function() {
                $(this).dialog("close");
            }
        }
    });
}

function getDialogButtonArray( pText, pClickFunction ) {
  return  {
    text: pText,
    click: pClickFunction    
  };
}

function dialogLoadContent( pTitle, pUrl, pWidth, pHeight, pButtons ) {

  var divDialog = $("<div title='" + pTitle + "'></div>");
  
  divDialog.html('');
  divDialog.load( pUrl );
  divDialog.dialog( {
    width : pWidth,
    height: pHeight,
    buttons:  pButtons,
    close: function() {
      $(this).remove();
    }
  });
  
  return divDialog;
}


function customConfirm( title, message, yesFunction, noFunction ) {
    if ( title == "" ) {
        title = globalvar_pagetitle;
    }
    
    $("<div title='" + title + "'>" + message + "</div>").dialog( {
        buttons: [
            {
                text: globalvar_lang.algemeen_lang_ja,
                click: function() {
                    if ( yesFunction !== undefined ) {
                        yesFunction();
                    }
                    $(this).dialog("close");
                }
            },
            {
                text: globalvar_lang.algemeen_lang_nee,
                click: function() {
                    if ( noFunction !== undefined ) {
                        noFunction();
                    }
                    $(this).dialog("close");
                }
            }]
    });
}

/**
* Info popup
* @param string selector met popup content
* @param object custom options
*/
function customPopup(holder, options) {
  $(holder + ":ui-dialog").dialog("destroy");
  
  var currentDialog = $(holder);
  var settings = {
    height: "auto",   
    width: 300,
    modal: true,
    buttons: {
      Ok: function() {
        currentDialog.dialog("close");
      }
    }
  };
  if (options !== undefined){ 
    $.extend(settings, options);
  }
  currentDialog.dialog(settings);
}
