﻿// JScript File

function confirm_delete()
    {
    if (confirm("Are you sure you want to delete?")==true)
        return true;
    else
        return false;
    }
    
function confirm_remove_page()
    {
    if (confirm("Are you sure you want to remove this page from this site?\n\nNote: This will also remove any navigation links that are currently linking to this page.")==true)
        return true;
    else
        return false;
    }
    
function confirm_remove_form()
    {
    if (confirm("Are you sure you want to remove this form from this page?")==true)
        return true;
    else
        return false;
    }
    
function confirm_cancellation()
    {
    if (confirm("Are you sure you want to cancel your subscription?")==true)
        return true;
    else
        return false;
    }
    
function confirm_billing()
    {
    if (confirm("Are you sure this billing information is correct?")==true)
        return true;
    else
        return false;
    }
    
function OpenAjaxWindow(window, url, width, height, fill)
    {
        
        loadjscssfile("windows.css", "css"); 
        
        var oWnd = $find(window);
        var oWidth = GetWidth();
        var oHeight = GetHeight();
        
        if (fill == true)
            {
                if (oWidth < width || oHeight < height) 
                    {
                        oWnd.set_width(oWidth);
                        oWnd.set_height(oHeight);                    
                    }
                else
                    {
                        oWnd.set_width(GetWidth() - 15);
                        oWnd.set_height(GetHeight() - 15);
                    }
            }
        else
            {
                if (oWidth < width) 
                    {
                        oWnd.set_width(oWidth);                  
                    }
                else
                    {
                        oWnd.set_width(width);
                    }

                if (oHeight < height)
                    {
                        oWnd.set_height(oHeight); 
                    }
                else
                    {
                        oWnd.set_height(height);
                    }
            }
        
        oWnd.setUrl(url);
        oWnd.set_visibleTitlebar(false);
        oWnd.set_visibleStatusbar(false);
        oWnd.maximize;
        oWnd.show();
        
        return false;

    }

function CloseAjaxWindow(window)
    {
        var oWnd = $find(window); 
        oWnd.close();
        
        removejscssfile("windows.css", "css"); 
      
        var ajaxManager = $find('ajax_manager');
        //ajaxManager.ajaxRequest();
        ajaxManager.ajaxRequestWithTarget('btn_update', '');

    }
    
function OpenNewWebsite(window, recid)
    {
        GetAjaxWindowParent().BrowserWindow.CloseAjaxWindow(window);
        GetAjaxWindowParent().BrowserWindow.window.location="AdminSitesDetails.aspx?id=" + recid;
    }
  
function GetAjaxWindowParent()
    {
          var oWindow = null;
          if (window.radWindow) oWindow = window.radWindow;
          else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
          return oWindow;
    }
    
function OpenAjaxWindowParent(window, url, width, height, fill)
    {
        GetAjaxWindowParent().BrowserWindow.OpenAjaxWindow(window, url, width, height, fill);
    }
    
function CloseAjaxWindowParent(window)
    {
       GetAjaxWindowParent().BrowserWindow.CloseAjaxWindow(window);  
    }
    
function GetWidth()
    {
        var x = 0;
        if (self.innerWidth)
            {
                    x = self.innerWidth;
            }
        else if (document.documentElement && document.documentElement.clientHeight)
            {
                    x = document.documentElement.clientWidth;
            }
        else if (document.body)
            {
                    x = document.body.clientWidth;
            }
        return x;
    }
 
function GetHeight()
    {
        var y = 0;
        if (self.innerHeight)
            {
                    y = self.innerHeight;
            }
        else if (document.documentElement && document.documentElement.clientHeight)
            {
                    y = document.documentElement.clientHeight;
            }
        else if (document.body)
            {
                    y = document.body.clientHeight;
            }
        return y;
    }
    
function GUrlParam( name )
    {
      name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
      var regexS = "[\\?&]"+name+"=([^&#]*)";
      var regex = new RegExp( regexS );
      var results = regex.exec( window.location.href );
      if( results == null )
        return "";
      else
        return results[1];
    }
    
function getRadWindow()
        {
            var oWindow = null;
            if (window.radWindow) oWindow = window.radWindow;
            else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
            return oWindow;
        }
    
//Scripts for the file explorer
function OnFileSelected(wnd, fileSelected, txtbox)
		{
			var textbox = $get(txtbox);
			textbox.value = fileSelected;
		}

function OnClientGridDblClick(sender, args)
        {
            var item = args.get_item();

            //If file (and not a folder) is selected - call the OnFileSelected method on the parent page
            if (item.get_type() == Telerik.Web.UI.FileExplorerItemType.File)
            {
                args.set_cancel(true);
                //Get a reference to the opener parent page  using rad window
                var wnd = getRadWindow();
                var openerPage = wnd.BrowserWindow;
                
                var txtbox = GUrlParam('txtbox');
                //if you need the URL for the item, use get_url() instead of get_path()
                openerPage.OnFileSelected(wnd, item.get_url(), txtbox);
                //Close window
                wnd.close();
            }
        }
        
//Scripts for the color picker
function OnColorSelected(wnd, colorSelected, txtbox)
		{
			var textbox = $get(txtbox);
			textbox.value = colorSelected;
			
			var swatch = $get(txtbox + "_Swatch");
			swatch.style.backgroundColor=colorSelected;
		}

function ColorSelected(colorSelected)
        {
            
            //Get a reference to the opener parent page  using rad window
            var wnd = getRadWindow();
            var openerPage = wnd.BrowserWindow;
            
            var txtbox = GUrlParam('txtbox');
            
            //Execute the function on the opener page to set the color textbox
            openerPage.OnColorSelected(wnd, colorSelected, txtbox);
            
            //Close window
            wnd.close();
        }
        
//Scripts for the color picker
function OpenColorPicker(txtbox)
		{
			
			var textbox = $get(txtbox);
			var currentColor = textbox.value;
			currentColor = currentColor.replace("#", '');
			var url = 'AdminColorPicker.aspx?txtbox=' + txtbox + '&color=' + currentColor

			OpenAjaxWindow('window_color_picker', url, 550, 485, false);
			
			return false;
			
		}
		
		
// Scripts to manage the RadWindow componets to keep it centered even if the main page is scrolled

function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

function removejscssfile(filename, filetype){
 var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist from
 var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
 var allsuspects=document.getElementsByTagName(targetelement)
 for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
  if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1)
   allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
 }
}
