
/*
 * CODE : Document Object Model
 * DEPENDS : code-base.js, lib-jquery.js, lib-jqueryui.js, lib-floatobject.js
 */

/* JQuery Extensions */
jQuery.fn.exists = function(){return jQuery(this).length>0;}

/* style initialization */

function InitLight()
{
  var maxScreenHeight = Math.max($(document).height(), $(window).height(), document.documentElement.clientHeight);
  $("#lightout").css({ opacity: 0.9 });
  $("#lightout").css("width", "100%");
  $("#lightout").height(maxScreenHeight);
}

/* DOM actions */

function BaseOpenGadget(strUrl)
{
  window.open(strUrl, '_blank', 'status=0,toolbar=0,menubar=0,directories=0,resizable=0,scrollbars=1,width=770,height=470');
}

function BaseOpenGadgetSmall(strUrl)
{
  window.open(strUrl, '_blank', 'status=0,toolbar=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=468,height=400');
}

function BaseOpenGadgetMiddle(strUrl)
{
  window.open(strUrl, '_blank', 'status=0,toolbar=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=468,height=460');
}

function BaseOpenGadgetSpec(strUrl,iWidth, iHeight)
{
  window.open(strUrl, '_blank', 'status=0,toolbar=0,menubar=0,directories=0,resizable=0,scrollbars=1,width='+iWidth.toString()+',height='+iHeight.toString()+'');
}

function BaseOpenVideo(strUrl)
{
  window.open(strUrl, '_blank', 'status=1,toolbar=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=468,height=411');
}

function BaseOpenNews(strUrl)
{
  window.open(strUrl, '_blank', 'status=1,toolbar=1,location=1,menubar=0,directories=0,resizable=1,scrollbars=1,width=960,height=560');
}

function ShowLight()
{
  $("#lightout").css("display", "block");
}

function RemoveLight()
{
  $("#lightout").css("display", "none");
}

function ShowAlert(alertWidth, alertHeight, alertContent, shakeIt, floatIt)
{
  var varScreenWidth = $(window).width();
  $("#popalert").width(alertWidth);
  $("#popalert").height(alertHeight);
  
  if (!(floatIt))
  {
    $("#popalert").css("left", (Math.round((varScreenWidth-alertWidth)/2)).toString()+"px" );
    $("#popalert").css("top", "30px");
  }
  
  $("#popalert").html(alertContent);
  $("#popalert").css("display", "block");
  ShowLight();
  
  if (shakeIt) { $("#popalert").effect("shake", { times:4 }, 30); }
  if (floatIt) { $("#popalert").makeFloat( { x : Math.round((varScreenWidth-alertWidth)/2) , y : 30 }, 'fast' ); }
  
  if ($("#popalertad").exists())
  {
    $("#popalertad").css("left", (Math.round((varScreenWidth-$("#popalertad").width())/2)).toString()+"px" );
    $("#popalertad").css("top", (30+alertHeight-$("#popalertad").height()-12).toString()+"px");
    $("#popalertad").css("display", "block");
  }
}

function ShowAlertPrep(alertTitle, alertText)
{
  var strDivContent = "";
  strDivContent += "<h3 class=\"hebtext\">"+alertTitle+"</h3>";
  strDivContent += "<p class=\"hebtext\">"+alertText+"</p>";
  
  var strAlert = "<div class=\"alertprep hebtext\">"+ strDivContent +"</div>";
  strAlert = BaseReplace(strAlert, "\n", "</p><p class=\"hebtext\">");
  
  ShowAlert(400, 300, strAlert, true, false);
}

function ShowAjax(strUrl, typeGetPost, strData, iWidth, iHeight)
{
  $.ajax(
    {
      type: typeGetPost,
      url: strUrl,
      data: strData,
      success: function(strContent)
      {
        ShowAlert(iWidth, iHeight, strContent, false, true);
      },
      error: function(strError)
      {
        ShowAlertPrep("אופס, אירעה שגיאה", "שגיאה התרחשה בעת טעינת הדף.\nאנא נסו שוב בעוד מספר דקות.")
      }
    }
  );
} 

function CloseAlert()
{
  $("#popalert").fadeOut(1000);
  RemoveLight();
  $("#popalert").html("");
  $("#popalert").css("width", "auto");
  $("#popalert").css("height", "auto");
}

/* events */

$(document).ready(
  function() 
  {
    InitLight();
  } 
);

