
/**
 * qTip parametres
 */
var qtborderdefault = {width:  5, radius: 5};
var qtstyledefault =
{
  border: qtborderdefault,
  width: {mini: 300, max: 300},
  padding:   5,
  textAlign: 'left',
  tip:       true,                      // Give it a speech bubble tip with automatic corner detection
  name:      'cream'                    // Style it according to the preset 'cream' style ('dark',green','light','red','blue')
};
var qtpositiondefault =
{
  corner:
  {
     target:  'topMiddle',              // ...and opposite corner
     tooltip: 'bottomMiddle'            // Use the corner...
  }
};

/**
 * pause function
 **/
function pausecomp(millis)
{
    var date = new Date();
    var curDate = null;

    do {curDate = new Date();}
    while(curDate-date < millis);
}

/**
 * Show the wait view, use for waiting the ajax loading view
 */
function waitViewPage(pTargetTag, pWaitMsg)
{
    $(pTargetTag).html('<p>&nbsp;</p><br/><img src="/images/global/ajax-loader.gif" alt=""/><br/><p><br/><br/>'+pWaitMsg+'.</p>');
}

/**
 * Show the wait line, use for waiting the ajax submit by button
 */
function waitViewLine(pTargetTag, pWaitMsg)
{
    if(!inset(pWaitMsg))
        pWaitMsg = '';
    $(pTargetTag).html('&nbsp;<img src="/images/global/ajax-loader.gif" alt=""/>&nbsp;&nbsp;&nbsp;&nbsp;'+pWaitMsg);
}

function errorViewPage(pTargetTag, pErrorMsg)
{
    $(pTargetTag).html('<div class="ui-state-error ui-corner-all ui-yb-form-error-alert"><p><span><strong>ATTENTION</strong></span></p><p class="ui-yb-form-error-alert-message">'+pErrorMsg+'</p></div>');
}


// ***********
// * Use into dialog form
// ***********
function setInstallFormField(pFormName)
{
    $(pFormName+' [help]').each(function()
    {
        $(this).qtip(
        {
            content: $(this).attr('help'),
            position: qtpositiondefault,
            style: {border: qtborderdefault, padding: 5, textAlign: 'left', tip:  true, name: 'cream'}, // Style it according to the preset 'cream' style ('cream','dark',green','light','red','blue')
            show: {effect: {type: 'fade', length: 200}},
            hide: {effect: {type: 'fade', length: 50}}
        });
    });
}

function setErrorFormFieldAllReset(pFormName)
{
    $(pFormName + ' .ui-widget-content').removeClass('ui-state-error');

    $(pFormName +' .ui-yb-form-error').each(function()
    {
        $(this).html("");
        $(this).hide();
    });
}

function setErrorFormField(pFieldName, pMessage)
{
    var nameField = pFieldName;

    $(nameField + " .ui-widget-content").addClass('ui-state-error');

    $(nameField + " .ui-yb-form-error").each(function()
    {
        $(this).html(pMessage);
        $(this).show();
    });

}

// ***********
// * Use into page form
// ***********

function setFormFieldError(pFieldName, pMessage)
{
    $(pFieldName+' .ui-widget-content').addClass('ui-state-error');

    var tmpObj = $(pFieldName);

    tmpObj.qtip('destroy');
    tmpObj.qtip(
        {
            content: pMessage,
            position: qtpositiondefault,
            style: {border: qtborderdefault, padding: 5, textAlign: 'left', tip:  true, name: 'red'}, // Style it according to the preset 'cream' style ('cream','dark',green','light','red','blue')
            show: {effect: {type: 'fade', length: 200}},
            hide: {effect: {type: 'fade', length: 50}}
        });
}


function setFormFieldInstall(pFormName)
{
    $(pFormName+' *[id][help]').each(function()
    {
        $(this).qtip(
        {
            content: $(this).attr('help'),
            position: qtpositiondefault,
            style: {border: qtborderdefault, padding: 5, textAlign: 'left', tip:  true, name: 'cream'}, // Style it according to the preset 'cream' style ('cream','dark',green','light','red','blue')
            show: {effect: {type: 'fade', length: 200}},
            hide: {effect: {type: 'fade', length: 50}}
        });
    });
}

function setFormFieldReset(pFormName)
{
    $(pFormName+' *[id][help]').each(function()
    {
        $(this).qtip('destroy');
        $(this).qtip(
        {
            content: $(this).attr('help'),
            position: qtpositiondefault,
            style: {border: qtborderdefault, padding: 5, textAlign: 'left', tip:  true, name: 'cream'}, // Style it according to the preset 'cream' style ('cream','dark',green','light','red','blue')
            show: {effect: {type: 'fade', length: 200}},
            hide: {effect: {type: 'fade', length: 50}}
        });

        $(this).qtip('updateStyle', 'cream');
        $(this).qtip('updateContent', $(this).attr('help'));
    });
    $('.ui-widget-content').removeClass('ui-state-error');
}

function uninstallTips(pJqXpath)
{
    $(pJqXpath).each(function() { $(this).qtip('destroy'); });
}

$(document).ready(function()
{
    // -----
    // preferences buttons
    // -----
    $('.ui-button')
        .hover(function(){ $(this).addClass("ui-state-hover"); }, function(){ $(this).removeClass("ui-state-hover"); } )
        .mousedown(function(){ $(this).addClass("ui-state-active"); })
        .mouseup(function(){ $(this).removeClass("ui-state-active"); });
})


