'use strict';  
/* Common code for front end in both EntryWizard and  EWZ-Rating */
    
/* To stop IE from generating errors if a console.log call was left in */
function fixConsole()
{
    if (console === undefined)
    {
        console = {}; // define it if it doesn't exist already
    }
    if (console.log === undefined)
    {
        console.log = function() {
        };
    }
    if (console.dir === undefined)
    {
        console.dir = function() {
        };
    }
}

function ewz_alert( alert_id, msg, pnum ){
    var title = '** Notice **';
    return jQuery('<div class="alertDiv' + alert_id + '"></div>').html('[' + alert_id + '] &nbsp; ' +  msg ).dialog({
            title: title,
        resizable: true,
       classes: {"ui-dialog": "ewz-dialog ui-corner-all"},
       closeText: "",
            minWidth: 200,
            modal: true,
            buttons:[ {
                        text:"Ok",
                        id: "ewz_alert" + pnum.toString(),
                        click: function(){
                                  jQuery( this ).dialog( "close" );
                               }
                      }
                    ]
        });
}

function ewz_alert_and_reload( alert_id, msg, pnum){
    var title = '** Notice **';
    return jQuery('<div></div>').html('[' + alert_id + '] &nbsp; ' + msg).dialog({
        title: title,
        resizable: true,
       classes: {"ui-dialog": "ewz-dialog ui-corner-all"},
       closeText: "",
         minWidth: 200,
        modal: true,
        buttons:[ {
                    text:"Ok",
                    id: "ewz_alert" + pnum.toString(),
                    click: function(){
                              document.location.reload(true);                              
                           }
                  }
                ]
    });
}

function ewz_confirm(  msg, truefunc, falsefunc, pnum ){
    var title = 'Please Confirm';

    return jQuery('<div></div>').html(msg).dialog({
        title: title,
        resizable: true,
         minWidth: 200,
       classes: {"ui-dialog": "ewz-dialog ui-corner-all"},
       closeText: "",
       modal: true,
        buttons:[ {
                      text: "Yes, Go Ahead",
                      id: "ewz_confirm" + pnum.toString(),
                      click: function(){ 
                                          if (typeof truefunc == 'function') {
                                              setTimeout(truefunc, 50);
                                          }                 
                                          jQuery(this).dialog('close');
                                       }
                  },
                  {
                      text: "No, Cancel",
                        id: "ewz_cancel" + pnum.toString(),
                      click: function(){
                                          if (typeof falsefunc == 'function') {
                                              setTimeout(falsefunc, 50);
                                          }
                                          jQuery(this).dialog('close');
                                       }
                 }
               ]
    });
}

function isblank(string)
{
   if ( string === undefined) {
      return true;
   }
   if (null == string) {
      return true;
   }
   var blankre = /^\s*$/;
   return (blankre.test(string));
}
