//
// PT A FUNCTIONA AI NEVOIE DE dialog_box.css, dialog_box.js si si imaginile din Resources/Image/dialog_box
//[RegisterEasyScript(EasyScriptType.dialog_box)]
//[RegisterEasyStyle(EasyStyleType.Dialog_Box)]
//
//DIALOGUL SUPORTA 4 TIPURI - dialogType:'error','warning','success','prompt'
//


// global variables //
var TIMER = 5;
var SPEED = 10;
var WRAPPER = 'content';

function PopEasyDialog(dialogType,dialogTitle, objId, dialogWidth,sec)
{//dialogType:'error','warning','success','prompt'
    //<a href="javascript:showDialog('Error','You have encountered a critical error.','error',2);">Error</a> | 
    //<a href="javascript:showDialog('Warning','You must enter all required information.','warning');">Warning</a> | 
    //<a href="javascript:showDialog('Success','Your request has been successfully received.','success');">Success</a> | 
    //<a href="javascript:showDialog('Confirmation','Are you sure you want to delete the entry?','prompt');">Prompt</a> - 

    if(typeof(sec) != 'undefined')
        showDialog(dialogType,dialogTitle,objId,dialogWidth,sec);// if (sec == 2) -- dupa 2 secunde se inchide automat
    else
       showDialog(dialogType,dialogTitle,objId,dialogWidth);
       
}
function HideEasyDialog(objId)
{
   var dialogId         = "dialog_" + objId;
   var dialogMaskId      = "dialog_mask_" + objId;
  
   hideDialog(dialogId,dialogMaskId);
}

// build/show the dialog box, populate the data and call the fadeDialog function //
    
function showDialog(type,title,objId,dlgWidth,autohide) 
{
     var childDv = document.getElementById(objId);
     if(childDv != null)
        childDv.style.display = "";


//  if(!type) {
//    type = 'error';
//  }
  var dialog;
  var dialogId      = "dialog_" + objId;
  var dialogMaskId  = "dialog_mask_" + objId;
  var dialogheader;
  var dialogclose;
  var dialogtitle;
  var dialogcontent;
  var dialogmask;
  if(!document.getElementById(dialogId)) {
    dialog = document.createElement('div');
    dialog.className = "main_dialog";
    dialog.id = dialogId;
   
    if(dlgWidth != "")
        dialog.style.width = dlgWidth;
    else//default value
        dialog.style.width = "425px";
    dialogheader = document.createElement('div');
    dialogheader.id = 'dialog-header';
    dialogtitle = document.createElement('div');
    dialogtitle.id = 'dialog-title';
    dialogclose = document.createElement('div');
    dialogclose.id = 'dialog-close';
    dialogcontent = document.createElement('div');
    dialogcontent.id = 'dialog-content';
    dialogcontent.appendChild(childDv);
    
    dialogmask = document.createElement('div');
    dialogmask.id = dialogMaskId;
    dialogmask.className = "dialog-mask"; 
    
    document.body.appendChild(dialogmask);
    document.body.appendChild(dialog);
    dialog.appendChild(dialogheader);
    dialogheader.appendChild(dialogtitle);
    dialogheader.appendChild(dialogclose);
    dialog.appendChild(dialogcontent);;
   
   // dialogclose.setAttribute("onclick","hideDialog()");
   // dialogclose.onclick = hideDialog;
   dialogclose.onclick = function()
                       {
                            var dialog = document.getElementById(dialogId);
                            clearInterval(dialog.timer);
                            dialog.timer = setInterval("fadeDialog(0,'"+ dialogId +"','"+ dialogMaskId +"')", TIMER);
                       
                       };
    
  } 
  else 
  {
    dialog = document.getElementById(dialogId);
    dialogheader = document.getElementById('dialog-header');
    dialogtitle = document.getElementById('dialog-title');
    dialogclose = document.getElementById('dialog-close');
    dialogcontent = document.getElementById('dialog-content');
    dialogmask = document.getElementById(dialogMaskId);
    dialogmask.style.display = "";
    dialog.style.display = "";
  }
  
  
  
  dialog.style.opacity = .00;
  dialog.style.filter = 'alpha(opacity=0)';
  dialog.alpha = 0;
  var width = pageWidth();
  var height = pageHeight();
  var left = leftPosition();
  var top = topPosition();
  var dialogwidth = dialog.offsetWidth;
  var dialogheight = dialog.offsetHeight;
  var topposition = top + (height / 3) - (dialogheight / 2);
  var leftposition = left + (width / 2) - (dialogwidth / 2);
  dialog.style.top = topposition + "px";
  dialog.style.left = leftposition + "px";
  dialogheader.className = type + "header";
  dialogtitle.innerHTML = title;
  dialogcontent.className = type;
  var content = document.getElementById(WRAPPER);
 // dialogmask.style.height = content.offsetHeight +  'px';
  
  dialog.timer = setInterval("fadeDialog(1,'"+ dialogId +"','"+ dialogMaskId +"')", TIMER);
  if(autohide) {
    dialogclose.style.display = "none";
    window.setTimeout("hideDialog('"+dialogId+"','"+ dialogMaskId +"')", (autohide * 1000));
  } else {
    dialogclose.style.display = "";
    
  }
  
 
     
   
}

// hide the dialog box //
function hideDialog(dialogId,dialogMaskId)
 {
  var dialog = document.getElementById(dialogId);
  clearInterval(dialog.timer);
  dialog.timer = setInterval("fadeDialog(0,'"+dialogId+"','"+ dialogMaskId +"')", TIMER);
}

// fade-in the dialog box //
function fadeDialog(flag,dialogId,dialogMaskId) {
  if(flag == null) {
    flag = 1;
  }
  var dialog = document.getElementById(dialogId);
  var value;
  if(flag == 1) {
    value = dialog.alpha + SPEED;
  } else {
    value = dialog.alpha - SPEED;
  }
  dialog.alpha = value;
  dialog.style.opacity = (value / 100);
  dialog.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(dialog.timer);
    dialog.timer = null;
  } else if(value <= 1) {
    
    clearInterval(dialog.timer);
    dialog.style.display = "none";
    document.getElementById(dialogMaskId).style.display = "none";
  }
}


// calculate the current window width //
function pageWidth() {
  return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

// calculate the current window height //
function pageHeight() {
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

// calculate the current window vertical offset //
function topPosition() {
  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

// calculate the position starting at the left of the window //
function leftPosition() {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}
