﻿
//////////////////////////////////
// Functions for Modal Dialog
//////////////////////////////////

//LIVE VERSION
var rootpath = '/Cissec WebApplication/';
var cphExtra_Prefix = 'ctl00_cphExtra_';
//var LoadingPage = rootpath+'DefaultLoading.aspx';
var LoginPage = rootpath+'Login.aspx';
var ErrorPage = rootpath+'DefaultError.aspx';
var LoadingPage = 'DefaultLoading.aspx';

//OFFLINE VERSION
//var rootpath = '/amoms/';
//var cphExtra_Prefix = 'ctl00_cphExtra_';
//var LoadingPage = '/amoms/DefaultLoading.aspx';
//var LoginPage = '/amoms/Login.aspx';
//var ErrorPage = '/amoms/DefaultError.aspx';
var ModalTitle = 'ModalTitle';


function setContentPrefix (str){
   //FUNCTION SETS THE PREFIX SINCE IT IS IN A CONTENT PANEL
   cphExtra_Prefix = str;
}//+-----------------------------

function setTitle (Title){
   //FUNCTION SETS THE title for the window
    var otitle = document.getElementById(ModalTitle);
        if (otitle != null) {
           otitle.innerHTML = Title;
        }
}//+-----------------------------
function setParentTitle (Title){
   //FUNCTION SETS THE title for the window
   window.parent.setTitle(Title);
}//+-----------------------------


function CloseModalOK()
{
    window.parent.DoOKClick();
}
function CloseModalCancel()
{
    window.parent.DoCancelClick();
}






//////////////////////////////////
// Functions for Page calling Modal Dialog //////////////////////////////////
function SetParentModalDestinationAndShow(DestinationURL,Height,Width,Title)
{
    window.parent.SetModalDestinationAndShow(DestinationURL,Height,Width,0,Title);
}

function SetModalDestinationAndShow(DestinationURL,Height,Width,Title)
{
//debugger;
    // Changed July 31, 2007 by Kori. This method is compatible with all browsers.
    SetModalDestination(DestinationURL,Height,Width,0,Title);
    var obj = $find('pnlModalBehavior');
    if (obj != null) {
        obj.show();
  

    }
}


function SetModalDestinationAndShow(DestinationURL,Height,Width,FromRoot,Title)
{
//debugger;
    // Changed July 31, 2007 by Kori. This method is compatible with all browsers.
    if (FromRoot==1){DestinationURL = rootpath + DestinationURL;}
    SetModalDestination(DestinationURL,Height,Width,FromRoot,Title);
    var obj = $find('pnlModalBehavior');
    if (obj != null) {
      
       obj.show();
    }

}

function SetModalDestination(DestinationURL,Height,Width,FromRoot,Title)
{
    // Changing based on suggestion on ASP forum here:
    // http://forums.asp.net/thread/1332720.aspx   
      if (FromRoot==1){DestinationURL = rootpath + DestinationURL;}
    $get(cphExtra_Prefix+'ifrmModal').src = DestinationURL;
    var result = (Sys.Browser.agent === Sys.Browser.InternetExplorer);
    if (result) {
        $get(cphExtra_Prefix+'pnlModal').style.height = Height;
        $get(cphExtra_Prefix+'pnlModal').style.width = Width;
    } else {
        $get(cphExtra_Prefix+'pnlModal').style.height = Height + "px";
        $get(cphExtra_Prefix+'pnlModal').style.width = Width + "px";
    }
   //SET WINDOW TITLE 
       setTitle(Title);
    
}

function SetModalDestinationAndReturn(DestinationURL, Height, Width,Title) {
    $get(cphExtra_Prefix+'ifrmModal').src = DestinationURL;
    var result = (Sys.Browser.agent === Sys.Browser.InternetExplorer);
    if (result) {
        $get(cphExtra_Prefix+'pnlModal').style.height = Height;
        $get(cphExtra_Prefix+'pnlModal').style.width = Width;
    } else {
        $get(cphExtra_Prefix+'pnlModal').style.height = Height + "px";
        $get(cphExtra_Prefix+'pnlModal').style.width = Width + "px";
    }
   //SET WINDOW TITLE 
       setTitle(Title);
}

function SetModalSize(Height,Width)
{    
    var result = (Sys.Browser.agent === Sys.Browser.InternetExplorer);
    if (result) {
        $get(cphExtra_Prefix+'pnlModal').style.height = Height;
        $get(cphExtra_Prefix+'pnlModal').style.width = Width;
    } else {
        $get(cphExtra_Prefix+'pnlModal').style.height = Height + "px";
        $get(cphExtra_Prefix+'pnlModal').style.width = Width + "px";
    }
    $find('pnlModalBehavior')._layout();
}

function SetParentModalSize(Height, Width)
{
    window.parent.SetModalSize(Height, Width);   
}

// Because DOMElements in Mozilla do not have a click method,
// simulate the click event using dispatchEvent and manually creating
// the event object
function simulateClick(element) {
    var evt = document.createEvent("MouseEvents");
    if (document.createEvent){
    evt = document.createEvent("MouseEvents");
    evt.initMouseEvent("click", true, true, window,
    0, 0, 0, 0, 0, false, false, false, false, 0, null);
    }
    (evt)? element.dispatchEvent(evt):(element.click && element.click()); 
}


function DoClick(element)
{
  var obj = $find('pnlModalBehavior');
    if (obj != null) {
        obj.hide();
    }
    
    var evt;
    if (document.createEvent){
    evt = document.createEvent("MouseEvents");
    evt.initMouseEvent("click", true, true, window,
    0, 0, 0, 0, 0, false, false, false, false, 0, null);
    }
    (evt)? element.dispatchEvent(evt):(element.click && element.click()); }



function GetModalHeight()
{
    return $get(cphExtra_Prefix+'pnlModal').style.height;
}

function GetModalWidth()
{
    return $get(cphExtra_Prefix+'pnlModal').style.width;
}

function onModalClientOk()
{
    SetModalDestination(LoadingPage,'0px','0px',1,'');
}

function DoOKClick()
{
    SetModalDestination(LoadingPage,'0px','0px',1,'');
    // don't specifically hide the modal, will cause crash in Firefox.
    // ModalOK click must cause a postback.
    var ModalOK = $get(cphExtra_Prefix + 'ModalOK');   
    DoClick(ModalOK);
    
}
function DoError()
{
    SetModalDestination(LoadingPage,'0px','0px',1,'');
    // don't specifically hide the modal, will cause crash in Firefox.
    // ModalOK click must cause a postback.
    //var ModalOK = $get(cphExtra_Prefix + 'ModalOK');   
    //DoClick(ModalOK);
    window.location.href = ErrorPage+'?Logout=1';
    
    
}
function CheckParentPageInModal()
{
    if (window.location != window.parent.location)
    {
        SetParentPageDestionation(LoginPage);        
    }         
}
function DoCancelClick()
{
    //debugger;
    SetModalDestination(LoadingPage,'0px','0px',1,'');
    var modalPopupBehavior = $find('pnlModalBehavior');
    modalPopupBehavior.hide();
}

function SetParentPageDestionation(DestinationURL)
{
    window.parent.location.href=DestinationURL;
}

function DelayMe(millis) {
// JAVASCRIPT PAUSE USED MAIN FOR 
// ASYNC CALL BACKS

        var date = new Date();
        var curDate = null;
        do { curDate = new Date(); } 
        while(curDate-date < millis)
} //--------------------------------Pause