// global variables //
var TIMER = 5;
var SPEED = 10;
var WRAPPER = 'content';
var PAGE = '';
// ADDED BY LEVC::::::::::::::::14-05-2009
var OPTEXTBOX = 'False';
var TYPEDIALOG = '';
//::::::::::::::::::::::::::::::::::::::::

// 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;
}

// build/show the dialog box, populate the data and call the fadeDialog function //
function showDialog(title,message,type,page,autohide,optxt) 
{
   if(!type) 
  {
    type = 'error';
  }
  PAGE = page;
  //ADDED BY LEVC:::::::::::::::::::::::14-05-2009
  OPTEXTBOX = optxt;
  TYPEDIALOG = type;
  //::::::::::::::::::::::::::::::::::::::::::::::
  if(!document.getElementById('dialog')) 
  {
    var dialog = document.createElement('div');
    dialog.id = 'dialog';
    var dialogheader = document.createElement('div');
    dialogheader.id = 'dialog-header';
    var dialogtitle = document.createElement('div');
    dialogtitle.id = 'dialog-title';
    var dialogclose = document.createElement('div');
    dialogclose.id = 'dialog-close';
    var dialogcontent = document.createElement('div');
	var dialogmessage = document.createElement('div');
	if (type=='warning-large' || type=='success-large')
	{
	    dialogcontent.id = 'dialog-largecontent';
	    dialogmessage.id = 'dialog-largemessage';
	}
	else
	{
	    dialogcontent.id = 'dialog-content';
	    dialogmessage.id = 'dialog-message';
	}

    // ADDED BY LEVC:::::::::::::::::::::11/05/2009
     if (optxt=='True')
	  {
       var dialogtextbox= document.createElement('div');
       dialogtextbox.id = 'dialog-textbox'; 

	   var dialogtext = document.createElement('textarea');
	   dialogtext.id = 'TextBox';
	   dialogtext.width = "500";
	   
	  }			
	//::::::::::::::::::::::::::::::::::::::::::::::::
    
	
	var dialogbutton = document.createElement('div');
	dialogbutton.id = 'dialog-button';
	var dialogmask = document.createElement('div');
    dialogmask.id = 'dialog-mask';
    
    
    var buttonyes = document.createElement('input');
	buttonyes.id = 'button-yes';
	buttonyes.type = "button";
	buttonyes.value = "Yes";
	buttonyes.className = "buttons";
	var buttonno = document.createElement('input');
	buttonno.id = 'button-no';
	buttonno.type = "button";
	buttonno.value = "No";
	buttonno.className = "buttons";
	if (window.navigator.appName.toLowerCase() == 'microsoft internet explorer')
    {
        document.getElementById('content').appendChild(dialogmask);
        document.getElementById('content').appendChild(dialog);
    }
    else 
    {
        document.body.appendChild(dialogmask);
        document.body.appendChild(dialog);
    }
    dialog.appendChild(dialogheader);
	dialog.appendChild(dialogcontent);
	
	dialogcontent.appendChild(dialogmessage);
	
	// ADEDD BY LEVC::::::::::::::::::::::::::::
	if (optxt=='True')
	   {
	    dialogcontent.appendChild(dialogtext);
	   }
    //:::::::::::::::::::::::::::::::::::::::::::
	
	dialogcontent.appendChild(dialogbutton);
	dialogheader.appendChild(dialogtitle);
	if (type != 'prompt')
    {
        dialogheader.appendChild(dialogclose);
    }
	
	if (type == 'prompt')
	{	
	dialogbutton.appendChild(buttonyes);
	dialogbutton.appendChild(buttonno);
	buttonno.className = "buttons";
    }
    else
    {
		buttonyes.value = "Ok";
		dialogbutton.appendChild(buttonyes);
	}
	dialogclose.setAttribute('onclick','hideDialog()');
    dialogclose.onclick = hideDialog;
    buttonyes.onclick = confirmProcess;
    //MODIFIED BY LEVC::::::::::::::::14-05-2009 
    buttonno.onclick = confirmProcessNo;
    //:::::::::::::::::::::::::::::::::::::::::
  }
  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);
  if (type == 'warning-large' || type=='success-large')
  {
    dialog.style.top = "10%";
    dialog.style.left = "35%";
  }
  else
  {
    dialog.style.top = topposition + "px";
    dialog.style.left = leftposition + "px";
  }
  
 //ADDED BY LEVC::::::::::::::::::::::::::::15-05-2009
  if (optxt=='True')
     {
      dialogbutton.style.top="10%";
      dialogmessage.style.height="30%";
      dialogtext.style.height="40px";    
      dialogtext.style.width="385px";
     }
 //:::::::::::::::::::::::::::::::::::::::::::::::::::
  
  dialogheader.className = type + "header";
  dialogtitle.innerHTML = title;
  dialogcontent.className = type;
  dialogmessage.innerHTML = message;
  
  buttonyes.focus();
  var content = document.getElementById(WRAPPER);
  dialogmask.style.height = content.offsetHeight + 'px';
  dialog.timer = setInterval("fadeDialog(1)", TIMER);
  if(autohide) 
  {
    dialogclose.style.visibility = "hidden";
    window.setTimeout("hideDialog()", (autohide * 1000));
	location.replace(PAGE);
  } 
  else 
  {
    dialogclose.style.visibility = "visible";
  }
}

function confirmProcess() 
{
 hideDialog();
 var npthdn = document.getElementById(GetClientId('inputhidden'));
 
 //ADDED BY LEVC::::::::::::::::::::::::::::::::::::::::::::::::::::::::::14-05-2009
 if (TYPEDIALOG == 'prompt')  
    { 
     if (OPTEXTBOX == 'True')
        {
            npthdn.value=document.getElementById('TextBox').value; 
         //document.getElementById('inputhidden').value = document.getElementById('TextBox').value 
        }
      else
        {
               npthdn.value="True";
              //document.getElementById('inputhidden').value = "True";
        }
      
      __doPostBack('inputhidden','');
      
      }
 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::      

}



//ADDED BY LEVC::::::::::::::::::::::::::::::::::::::::::::::::::::::::::15-05-2009
function confirmProcessNo() 
{
var npthdn = document.getElementById(GetClientId('inputhidden'));
 hideDialog();

     if (OPTEXTBOX == 'True')
        {
           npthdn.value="";
         //document.getElementById('inputhidden').value = ""; 
                        
         __doPostBack('inputhidden','');
        }
           
}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


// hide the dialog box //
function hideDialog() {
  var dialog = document.getElementById('dialog');
  clearInterval(dialog.timer);
  dialog.timer = setInterval("fadeDialog(0)", TIMER);
  if (PAGE) {
     	location.replace(PAGE); }
}

// 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);
    var parent = dialog.parentNode;
    parent.removeChild(dialog);
  }
}