function showProps (divId, data) {
  $().stopTime("SEARCHNEWLINES");
  loadSyncroContent(contextPath +'/applications/pataPage/backoffice/ajax/ajaxWidgetProperties.jsp', divId, data);
}

$.fn.updateWidgetScreen= function(divId, objName, data) {
  // verify if any contents has changeg
  if(!$.fn.closeOthersPataContent('') || !$.fn.closeOthersMedia(''))
    return;

  var desc= $(this).find(".widgetDesc").html();
  var imgCode = objName;
  if('CNT_AGR'==objName)  imgCode = "CNT";
  var url= contextPath+"/applications/pataPage/images/pata"+imgCode+".png";
  // remove if present tinyMCE contextualPath
  if($('.mceDropDown'))
    $('.mceDropDown').remove();

  $("#actualWidget .actualWidgetImage").css("background","url("+url+")");
  if(desc)
    $("#actualWidget .actualWidgetDesc").html(desc);
  $("#actualWidget .noWidgetDesc").hide();
  $("#actualWidget .actualWidgetContent").show();
  $("#appWidget").find(".selected").removeClass("selected");
  $(this).addClass("selected");
  if('ppMenu_' + objName != $(this).attr("id"))
    $('#ppMenu_' + objName).addClass("selected");
  data = (data ? data+'&' : '') + 'objName='+objName;
  showData (divId, data );
};

function showData (divId, data) {
  $().stopTime("SEARCHNEWLINES");
  $("#"+divId).slideUp(200,function() {
    loadSyncroContent(contextPath + '/applications/pataPage/backoffice/ajax/ajaxSummary.jsp', divId, data);
    // data glance column is hidden and main container is widened
    if(!$('#dataGlance').is(':hidden')) {
      $('#dataGlance').hide();
      $('#appConts').css('margin-right','0');
    }
  });
}

jQuery.fn.mb_bringToFront= function(){
  var zi=10;
  $('*').each(function() {
    if($(this).css("position")=="absolute" || $(this).css("position")=="fixed"){
      var cur = parseInt($(this).css('zIndex'));
      zi = cur > zi ? parseInt($(this).css('zIndex')) : zi;
    }
  });
  $(this).css('zIndex',zi+=1);
  return $(this);
};


function loadSyncroContent(href, objId, data, showMessages) {
  //  $("#"+objId).html(getContent(href, data));
  $.ajax({
    type: "POST",
    url: href,
    data: data,
    success: function(html){
      if(showMessages)
        showSavingMessage();

      $('#'+objId).html(html);
      //      if ($.browser.msie) $("#"+objId).show();
      //      else $("#"+objId).fadeIn(500);
      $("#"+objId).show();

      if(showMessages)
        hideSavingMessage();
    }
  });
}

function overlay(el, overlayCanNotClose) {
  var overlay = $("<div class='overlay' style='display:none'/>");
  if($('body .overlay').html()==null){
    $("body").append(overlay);
    overlay.show();
  }
  var overlayContent = $(el);

  var isIE_7 = isExplorer && parseFloat($.browser.version)<8;
  if(isIE_7)
    $("body").append(overlayContent);

  overlayContent.css({position:"fixed", zIndex:10000});
  overlayContent.show();

  var closEl= !overlayCanNotClose ? $(".overlay, .overlayClose") : $(".overlayClose");

  closEl.bind("click", function() {
    if(!isExplorer){
      overlay.fadeOut("fast", function() {
        overlay.remove();
      });
      overlayContent.fadeOut("fast");
    } else{
      overlay.remove();
      overlayContent.hide();
    }
  });
  //    overlayContent.mb_bringToFront();
}

function screenPrefiller() {
  // STEP 1: Screen properties
  // Background color
  $('#SCR_BKG_COLOR').val('#FFFFFF');
  $('#SCR_BKG_COLOR_SP').css('background-color','#FFFFFF');
  // Text color
  $('#SCR_TXT_COLOR').val('#000000');
  $('#SCR_TXT_COLOR_SP').css('background-color','#000000');
  // Overlay background color
  $('#SCR_OVER').val('#000000');
  $('#SCR_OVER_SP').css('background-color','#000000');
}

function buttonPrefiller() {
  // STEP 5: Button properties
  // Background color
  $('#BKG_COLOR').val('#000000');
  $('#BKG_COLOR_SP').css('background-color','#000000');
  //Text color
  $('#TXT_COLOR').val('#FFFFFF');
  $('#TXT_COLOR_SP').css('background-color','#FFFFFF');
}

function tryThisButton(objectName){
  var pos= $.browser.msie && $.browser.version<7 ?"absolute":"fixed";
  $(document.body).css({overflow:"hidden"});
  $(document.documentElement).css({overflow:"hidden"});
  var genContainer = $('<div/>').attr("id","genContainer").css({position:pos, top:0,left:0, width:"100%",height:"100%", background:"black url("+contextPath+"/applications/pataPage/images/loading.gif) no-repeat center center"}).hide();
  var toolbar=$("<div/>").attr("id","demoToolbar").css({position:"fixed", bottom:10,right:200});
  var close= $("<a class='button brown noprint'><span style=''>back to your account</span></a>");
  function closeIfr(){
    $("#genContainer").fadeOut(
      1000,
      function(){
        $(this).remove();
        $(document.body).css({overflow:""});
        $(document.documentElement).css({overflow:""});
      })
  }
  close.click(closeIfr);

  $("body").prepend(genContainer);
  var logo=$("#pataLogo").clone();
  var iframe=$("<iframe id='pp_iframe' style='frame-border:none; border:0;display:none; background:white' src='javascript:void(0)'> </iframe> ").hide();
  genContainer.append(iframe);
  genContainer.append(toolbar);
  toolbar.append(close);

  genContainer.fadeIn(1000,function(){
    iframe
      .attr("src",contextPath + '/applications/pataPage/backoffice/ajax/ajaxDemoFileController.jsp' + ( objectName ? '?objName=' + objectName : '') )
      .css({top:0, left:0, position:pos, width:"100%", height:"100%"}).fadeIn(800)
      .mb_bringToFront();

    toolbar.mb_bringToFront();
    logo.click(function(){closeIfr(); return false});
    genContainer.append(logo);
    logo.css({position:"fixed", right:10,bottom:10}).mb_bringToFront();
  }).mb_bringToFront();
}

  $.fn.showHelpForm = function() {
    $('#helpDeskDiv').css({position:'absolute', marginTop:-2, marginLeft:-5, zIndex:'100'});
    $(this).after($('#helpDeskDiv'));
    $('#helpDeskDiv').fadeIn(600);
    $("#infoArea").focus();
  };

