// global variables //
var TIMER = 5;
var SPEED = 10;
//var WRAPPER = 'content';

// calculate the current window width //

// calculate the current window height //

// calculate the current window vertical offset //

// calculate the position starting at the left of the window //

//////////////* Code for dilog middle position by Kamlesh Kumar *////////////////
// Find Browser Width////////////////////////////////////////////////////////////
 function BrowserWidth()
 {
    var myWidth = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    }
  return myWidth;
 }
// Find Browser Hight ////////////////////////////////////////////////////////////
 function BrowserHeight()
 {
    var myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
   
    myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
   
    myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
   
    myHeight = document.body.clientHeight;
    }  
  return myHeight;
 }

// Show the dialog box, populate the data and call the fadeDialog function //
function showDialog(title,message,type,autohide,url) 
{
    if(!type) 
    {
    type = 'error';
    }
      var dialog;
     // var dialogheader;
      var dialogclose;
      var dialogtitle;
      var dialogcontent;
      var dialogmask;
    if(!document.getElementById('dialog')) 
    {
    dialog = document.createElement('div');
    dialog.id = 'dialog';
    
    dialogtitle = document.createElement('div');
    dialogtitle.id = 'dialog-title';
    dialogclose = document.createElement('div');
    dialogclose.id = 'dialog-close'
    dialogcontent = document.createElement('div');
    dialogcontent.id = 'dialog-content';
    dialogmask = document.createElement('div');
    dialogmask.id = 'dialog-mask';
    document.body.appendChild(dialogmask);
    document.body.appendChild(dialog);
    
    dialog.appendChild(dialogcontent);

    } 
    else 
    {
    dialog = document.getElementById('dialog');
   
    dialogtitle = document.getElementById('dialog-title');
    dialogclose = document.getElementById('dialog-close');
    dialogcontent = document.getElementById('dialog-content');
    dialogmask = document.getElementById('dialog-mask');
    dialogmask.style.visibility = "visible";
    dialog.style.visibility = "visible";
  }
  dialog.style.opacity = .00;
  dialog.style.filter = 'alpha(opacity=0)';
  dialog.alpha = 0;

  var dialogwidth = dialog.offsetWidth;
  var dialogheight = dialog.offsetHeight;
  var topposition =  BrowserHeight()/2;
  var leftposition =  BrowserWidth()/4;

  dialog.style.top = topposition + "px";
  dialog.style.left = leftposition + "px";
//Load content in Dialog  
  dialogtitle.innerHTML = title;
  dialogcontent.className = type;
  dialogcontent.innerHTML = message;
//Set timer for interval  
  dialog.timer = setInterval("fadeDialog(1)", TIMER);

  if(autohide) {
    dialogclose.style.visibility = "hidden";
    window.setTimeout("hideDialog('"+url+"')", (autohide * 1000));
  } else {
    dialogclose.style.visibility = "visible";
  }
}

// hide the dialog box //
function hideDialog(url) {
  var dialog = document.getElementById('dialog');
  clearInterval(dialog.timer);
  dialog.timer = setInterval("fadeDialog(0)", TIMER);
  window.open(url,'_self');
}

// fade-in the dialog box //
function fadeDialog(flag) {
  if(flag == null) {
    flag = 1;
  }
  var dialog = document.getElementById('dialog');
  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) {
    dialog.style.visibility = "hidden";
    document.getElementById('dialog-mask').style.visibility = "hidden";
    clearInterval(dialog.timer);
  }
}