﻿function OnRequestStart(sender, args)
{
    document.body.style.cursor = "wait";
//    var Split1 = $get('Split1');
//    Split1.disabled = true;
}

function OnResponseEnd(sender, args)
{
    document.body.style.cursor = "default";
//    var Split1 = $get('Split1');
//    Split1.disabled = false;
}

function GetRadWindow()   
{   
    var oWindow = null;
    
    if (window.RadWindow)
    {
        oWindow = window.RadWindow;
    }
    else if (window.frameElement.radWindow)
    {
        oWindow = window.frameElement.radWindow;
    }
    
    return oWindow; 
}

function WindowClose()
{
    GetRadWindow().Close();
}

/**
* This function inserts a text at the current cursor position
*
* @param string text to insert at current position
* @param DOMElement field in which the value should be inserted
*/
function insertAtCurrentPosition( aControlName, value )
{
    var dest = $get(aControlName);

    /* for Internet Explorer */
    if (document.selection) {
        dest.focus();
        var sel = document.selection.createRange();
        sel.text = value;
    }
    /* for Mozilla */
    else if (dest.selectionStart || dest.selectionStart == '0')
    {
        var startPos = dest.selectionStart;
        var endPos = dest.selectionEnd;
        dest.value = dest.value.substring(0, startPos) + value + dest.value.substring(endPos, dest.value.length);
    }
    else
    {
        dest.value += value;
    }
}

var newwindow;   
function poptasticOpen(url, height, width)
{
    newwindow = window.open(url,'name','height=' + height + ',width=' + width + ',left=255,top=200,scrollbars=0,toolbar=0,menubar=0,location=0,resizable=1,status=1');   
    if (window.focus)
    {
        newwindow.focus()
    }
}   

var newwindowToolBar;
function poptasticOpenToolbar(url)
{
    newwindowToolBar = window.open(url);   
    if (window.focus)
    {
        newwindowToolBar.focus()
    }
}   

function poptasticClose()
{
    close();
}

function ShowSearchWindow(url)
{
    var oWnd = $find( SearchSplitter );
    if ( oWnd != null )
    {
        oWnd.expand();
        oWnd.set_contentUrl(url);
    }
    else
    {
        alert('Ops');
    }
}

var FileUpload;
var RecordTime;
var TimerTime;
var PdfInvoiceDownload;
var PdfQuotationDownload;

function OnClientButtonClicking(sender, args)
{
    if(args.get_item().get_value() == "PdfInvoice")
    {
        poptasticOpen(PdfInvoiceDownload, 200, 340);
        args.set_cancel(true);
    }

    if(args.get_item().get_value() == "PdfQuotation")
    {
        poptasticOpen(PdfQuotationDownload, 200, 340);
        args.set_cancel(true);
    }

    if(args.get_item().get_value() == "RecordTime")
    {
        ShowWindow(RecordTime, 560, 420);
        args.set_cancel(true);
    }

    if(args.get_item().get_value() == "TimerTime")
    {
        poptasticOpen(TimerTime, 450, 355);
        args.set_cancel(true);
    }

    if(args.get_item().get_value() == "DeleteFolder")
    {
        if(confirm('Confirm delete folder and documents ?'))
            return false;
        args.set_cancel(true);
    }

    if(args.get_item().get_value() == "DeleteDocument")
    {
        if(confirm('Confirm delete document(s) ?'))
            return false;
        args.set_cancel(true);
    }
}

function ShowWindow(url, height, width )
{
    var wnd = window.radopen( url );
    wnd.set_visibleStatusbar(false);
    wnd.set_behaviors( Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close );
    wnd.set_modal(true);
    wnd.set_width(width);
    wnd.set_height(height);
    wnd.add_close(OnClientClose);
    wnd.Show();
}

var PostBack;
function OnClientClose(oWnd)
{
    if ( PostBack != null ) 
    {
        eval(PostBack);
    }
}

function goFullSize( targetURL )
{
window.open(targetURL, '', 'fullscreen=yes, scrollbars=auto');
daddy = window.self;
daddy.opener = window.self;
daddy.close();
}

function WindowSize(myWidth, myHeight)
{
  myWidth = 0;
  myHeight = 0;
  
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
}

function OpenWindow( Url )
{
    var oNewWindow = window.open(Url,"Main","left=0px, top=0px,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no")
    var myWidth = 2000, myHeight = 2000;

    try
    {
        oNewWindow.resizeTo(myWidth, myHeight);
    }
    catch(err)
    {}
}

var RecurringAjax;

function textAdd( aControl, replaceText )
{
    var SelectedControlId = $get( 'SelectedControlId' );
    SelectedControlId.value = aControl;

    var SelectedControlText = $get( 'SelectedControlText' );
    SelectedControlText.value = replaceText;
        
    eval(RecurringAjax);
}

function body_onkeydown(e)
{
    if (!e) e=window.event;
    var code;
    if ((e.charCode) && (e.keyCode==0))
        code = e.charCode
    else
        code = e.keyCode;
    
    if( code==27 )
    {
        WindowClose();
    }
}

function ShowDropDownFunction( aComboBox )
{
    var combo = $find( aComboBox );
    if ( combo != null )
    {
        combo.showDropDown();
    }
}

function OnClientEditorLoad(editor, args)
{
    var editorObject = editor;
    //set the focus in the editor
    setTimeout(function()
    {
        editorObject.setFocus();
    }, 10);
}

function showRadComboBoxDropDown(comboBoxId)
{
    $find(comboBoxId).showDropDown();
}

function OnClientCommand(sender, eventArgs)
{
    try
    {
        var command = eventArgs.Command;
        var dockZoneID = sender.get_dockZoneID();
        var dockZone = $find(dockZoneID);
        if (command.get_state() == 1)
        {
            //alert("Dock expanded");
            sender.set_width(700);
            sender.set_left(-480);
            dockZone.set_fitDocks(false);
        }
        else if (command.get_state() == 2)
        {
            //alert("Dock collapsed");
            sender.set_width("100%");
            sender.set_left(1);
            dockZone.set_fitDocks(true);
        }
    }
    catch (err)
    {
        alert('Ops');
    }
}

var range = null;
function AddTextToRadEditor( aControlName, value)
{
    editor = $find(aControlName);
    editor.pasteHtml(value);
}

var CustomText;

function SetupEditor()
{
    Telerik.Web.UI.Editor.CommandList["Custom1"] = function(commandName, editor, args)
    {
      editor.pasteHtml(CustomText[0]);
    };
    Telerik.Web.UI.Editor.CommandList["Custom2"] = function(commandName, editor, args)
    {
      editor.pasteHtml(CustomText[1]);
    };
    Telerik.Web.UI.Editor.CommandList["Custom3"] = function(commandName, editor, args)
    {
      editor.pasteHtml(CustomText[2]);
    };
    Telerik.Web.UI.Editor.CommandList["Custom4"] = function(commandName, editor, args)
    {
      editor.pasteHtml(CustomText[3]);
    };
    Telerik.Web.UI.Editor.CommandList["Custom5"] = function(commandName, editor, args)
    {
      editor.pasteHtml(CustomText[4]);
    };
    Telerik.Web.UI.Editor.CommandList["Custom6"] = function(commandName, editor, args)
    {
      editor.pasteHtml(CustomText[5]);
    };
    Telerik.Web.UI.Editor.CommandList["Custom7"] = function(commandName, editor, args)
    {
      editor.pasteHtml(CustomText[6]);
    };
}