﻿// JScript File

//Rad Window



function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}


     function closeAllWindows(){
             var allWindows = GetRadWindowManager().GetWindowObjects();
              for (var i=0; i<allWindows.length; i++)
               {
                var win = allWindows[i];
                //alert("Is minimized: " + win.IsMinimized() + "; Is maximized: " + win.IsMaximized());
                win.Close();
               }        
        }
        
        
        
        function closeAndRefresh(){
            closeAllWindows();
            document.location.reload();
            
        }
        
        function closeAndRedirect(path,status){
            closeAllWindows();
            if (status=="created"){
                document.location.replace(path+"?status=new");
            }else if (status=="updated"){
                closeAndSelectInstance();
            }
        }
        
        function closeAndSelectInstance(){
            closeAllWindows();
            refreshPage();
        }
        
        function refreshPage(){
          // __doPostBack('ctl00$ContentPlaceHolder1$GridView1$ctl05$lnkSelect','');
          var ctr   =   document.getElementById("PostBackClientLink_hdn");
          if (ctr.value!=""){
            //alert(ctr.value);
            eval(ctr.value);
          }
        }      
        
        



        function UseWindowManager()
        {
           openWindow("/Branches/BranchSetup.aspx","Branch");
        }    
        
        function openWindow(url,title){
            //Getting rad window manager
            var oManager = GetRadWindowManager();
            //Success. Getting existing window DialogWindow using GetWindowByName
            var oWnd = oManager.GetWindowByName("DialogWindow");
            //Success. Setting a size and a Url to the window using its client API before showing
            oWnd.SetSize(700,600);
            oWnd.SetTitle(title);
            oWnd.SetModal(true);
            oWnd.SetUrl(url);
            oWnd.Center(true);
            oWnd.SetStatus(false);
            //Success. Opening window
            oWnd.Show();
            //Success. Calling window RadWindowManager.GetActiveWindow (should return reference to current window
            //var oActive = oManager.GetActiveWindow();
            //Success. Is current visible window the active one? " + (oActive != null && oActive == oWnd)
            //Success. Open a new window using RadWindowManager.Open using default settings
            //var oNew = oManager.Open("../TestPage/Default.html", "NewWindow");
        }
        
        function openWindowWH(url,title,width,height){
            //Getting rad window manager
            var oManager = GetRadWindowManager();
            //Success. Getting existing window DialogWindow using GetWindowByName
            var oWnd = oManager.GetWindowByName("DialogWindow");
            //Success. Setting a size and a Url to the window using its client API before showing
            oWnd.SetSize(width,height);
            oWnd.SetTitle(title);
            oWnd.SetModal(true);
            oWnd.SetUrl(url);
            oWnd.Center(true);
            oWnd.SetStatus(false);
            //Success. Opening window
            oWnd.Show();
            oWnd.OnClientClose  =   OnCloseWindow;
            //Success. Calling window RadWindowManager.GetActiveWindow (should return reference to current window
            //var oActive = oManager.GetActiveWindow();
            //Success. Is current visible window the active one? " + (oActive != null && oActive == oWnd)
            //Success. Open a new window using RadWindowManager.Open using default settings
            //var oNew = oManager.Open("../TestPage/Default.html", "NewWindow");
        }        
        
        function openWindowWHCloseEvent(url,title,width,height,closeFunction){
            var oManager = GetRadWindowManager();
            var oWnd = oManager.GetWindowByName("DialogWindow");
            oWnd.SetSize(width,height);
            oWnd.SetTitle(title);
            oWnd.SetModal(true);
            oWnd.SetUrl(url);
            oWnd.Center(true);
            oWnd.SetStatus(false);
            oWnd.Show();
            oWnd.OnClientClose  =   closeFunction;
        }
        
        
        
        function openWindowSmall(url,title){
            //Getting rad window manager
            var oManager = GetRadWindowManager();
            //Success. Getting existing window DialogWindow using GetWindowByName
            var oWnd = oManager.GetWindowByName("DialogWindow");
            //Success. Setting a size and a Url to the window using its client API before showing
            oWnd.SetSize(700,500);
            oWnd.SetTitle(title);
            oWnd.SetModal(true);
            oWnd.SetUrl(url);
            oWnd.Center(true);
            oWnd.SetStatus(false);
            //Success. Opening window
            oWnd.Show();
            //Success. Calling window RadWindowManager.GetActiveWindow (should return reference to current window
            //var oActive = oManager.GetActiveWindow();
            //Success. Is current visible window the active one? " + (oActive != null && oActive == oWnd)
            //Success. Open a new window using RadWindowManager.Open using default settings
            //var oNew = oManager.Open("../TestPage/Default.html", "NewWindow");
        }
        
   
    
        function deletefunction(ctr){
            //alert(ctr.id);
                ctr.parentElement.parentElement.style.backgroundColor   =   "#000000";            
            if (confirm("Are you sure to delete selected Branch?")){
                return(true);
            }else{
                ctr.parentElement.parentElement.style.backgroundColor   =   "#FFF7E7";                        
                return(false);
            }
        }

//Branches
function Branch(bid){
    if (bid==0){
        openWindow('/Branch/setupBranch.aspx','Branch');
    }else{
        openWindow('/Branch/setupBranch.aspx?type=edit&bid='+bid,'Branch');
    }
}

function Branches_DropDownList_Action(ctr){
    if (!isCheckBoxesSelected()){
        alert("Please select first.");
        ctr.selectedIndex   =   0;
        return(false);
    }
    if (ctr.value=="remove"){
        if (confirm("Are you sure to delete selected Branch(s)")){
            return(true);
        }
    }
    
    return(false);
}



//Users
function User(uid){
    if (uid==0){
        openWindowSmall('/onlinePartyBooking/Logon/usersetup.aspx','User');
    }else{
        openWindowSmall('/onlinePartyBooking/Logon/usersetup.aspx?type=edit&userid='+uid,'User');
    }
}


function Users_DropDownList_Action(ctr){
   if (!isCheckBoxesSelected()){
        alert("Please select first.");
        ctr.selectedIndex   =   0;
        return(false);
    }
    if (ctr.value=="remove"){
        if (confirm("Are you sure to delete selected user(s)")){
            return(true);
        }
    }
    
    return(false);
}




//Products
function Product(pid){
    if (pid==0){
        openWindowWH('/onlinePartyBooking/Products/productsetup.aspx','Product',700,800);
    }else{
        openWindowWH('/onlinePartyBooking/Products/productsetup.aspx?type=edit&pid='+pid,'Product',700,800);
    }
}

function Products_DropDownList_Action(ctr){
    //if (!isCheckBoxesSelected()){
    if (ctr.value==""){
        alert("Please select first.");
        ctr.selectedIndex   =   0;
        return(false);
    }
    if (ctr.value=="remove"){
        if (confirm("Are you sure to delete selected product(s)")){
            return(true);
        }
    }else if (ctr.value=="displayselectedproduct"){
        if (confirm("Are you sure to display selected product(s)")){
            return(true);
        }
    }else if (ctr.value=="hideselectedproduct"){
        if (confirm("Are you sure to hide selected product(s)")){
            return(true);
        }
    }else if (ctr.value=="assigntoselectedservice"){
            return(true);
    }
    
    //
    
    return(false);
}


function productImage(pid){
   
   openWindowWH('/onlinePartyBooking/Tools/Image.aspx?id='+pid+'&type=productimage','Product Image',700,700);
   return false;
}


function ActiveProduct(pid,rid,flag){
    var doaction    =   false;
    if (flag){
        if(confirm("Would You like to display on web")){
            doaction    =   true;
        }
    }else{
        if(confirm("Would You like to hide on web")){
            doaction    =   true;
        }
    }
    if (doaction){
        document.location.replace("activeProduct.aspx?pid="+pid+"&rid="+rid+"&flag="+flag);
    }
    return false;
}






function confirmed(){
  radconfirm('Are you sure?', confirmCallBackFn, 330, 100); 
  
}

function confirmCallBackFn(arg)
{
    alert("Confirm returned the following result: " + arg);
}






function GetRadWindow()
{
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
    return oWindow;
}

function SizeToFit()
{
window.setTimeout(
    function()
    {
        var oWnd = GetRadWindow();
        oWnd.SetWidth(document.body.scrollWidth + 4);
        oWnd.SetHeight(document.body.scrollHeight + 110);
        oWnd.Center(); 
    }, 400);
}
