var CANOPYv100ModalDialogWindow;
    
function CANOPYv100ModalDialogShow(DialogSource, ModuleCompositeKey, ModuleArgs, CallbackEventHandler, Width, Height, Top, Left, Title, Args1)
{
    var args = new Array();
    args[0] = window;
    if (Args1)
    {
        args[1] = Args1;
    }

	var opts = 'center:1;resizable:1;scroll:0;status:0';

	if (Width != null)
	{
		opts += ';dialogWidth:' + Width + 'px'
	}

	if (Height != null)
	{
		opts += ';dialogHeight:' + Height + 'px'
	}

	CANOPYv100ModalDialogWindow=window.showModalDialog("dialog.aspx?dialogsource=" + DialogSource + "&compositekey=" + ModuleCompositeKey + "&" + ModuleArgs + "&Title=" + Title,args,opts);
	return CANOPYv100ModalDialogWindow;
}

function CANOPYv100ModalDialogShow2(PortalBaseUrl, DialogSource, ModuleCompositeKey, ModuleArgs, CallbackEventHandler, Width, Height, Top, Left, Title)
{
	var opts = 'center:1;resizable:1;scroll:0;status:0';

	if (Width != null)
	{
		opts += ';dialogWidth:' + Width + 'px'
	}

	if (Height != null)
	{
		opts += ';dialogHeight:' + Height + 'px'
	}

	CANOPYv100ModalDialogWindow=window.showModalDialog(PortalBaseUrl + "dialog.aspx?dialogsource=" + DialogSource + "&compositekey=" + ModuleCompositeKey + "&" + ModuleArgs + "&Title=" + Title,"",opts);
	return CANOPYv100ModalDialogWindow;
}

function CANOPYv100ModalEditorShow(EditorSource, ModuleCompositeKey, ModuleArgs, CallbackEventHandler, Width, Height, Top, Left)
{
	var opts = 'center:1;resizable:1;scroll:1;status:0';

	if (Width != null)
	{
		opts += ';dialogWidth:' + Width + 'px'
	}

	if (Height != null)
	{
		opts += ';dialogHeight:' + Height + 'px'
	}

	CANOPYv100ModalEditorWindow=window.showModalDialog("dialog.aspx?editorsource=" + EditorSource + "&compositekey=" + ModuleCompositeKey + "&" + ModuleArgs,"",opts); 
	return CANOPYv100ModalEditorWindow;
}

function CANOPYv100ItemDetailShow(DialogSource, ModuleCompositeKey, ModuleArgs, CallbackEventHandler, Width, Height, Top, Left, Title)
{
	var opts = 'location=no,status=yes,resizable=yes,scrollbars=yes,menubar=no';

	if (Width != null)
	{
		opts += ',Width=' + Width
	}

	if (Height != null)
	{
		opts += ',Height=' + Height
	}

	window.open("itemdetail.aspx?dialogsource=" + DialogSource + "&compositekey=" + ModuleCompositeKey + "&" + ModuleArgs + "&Title=" + Title,"",opts);
}

function CANOPYv100WindowOpen(WindowURL, Width, Height, Top, Left, Title)
{
	var opts = 'location=no,status=yes,resizable=yes,scrollbars=yes,menubar=no';

	if (Width != null)
	{
		opts += ',Width=' + Width
	}

	if (Height != null)
	{
		opts += ',Height=' + Height
	}

	window.open(WindowURL,"",opts);
}

function CANOPYv100PMDialogShow(DialogSource, ModuleCompositeKey, ModuleArgs, CallbackEventHandler, Width, Height, Top, Left, Title)
{
	var opts = 'location=no,status=yes,resizable=yes,scrollbars=no,menubar=no';

	if (Width != null)
	{
		opts += ',Width=' + Width
	}

	if (Height != null)
	{
		opts += ',Height=' + Height
	}

	window.open(DialogSource,"",opts);
}

function CANOPYv100HelpShow(HelpUrl, ModuleCompositeKey, ModuleArgs, CallbackEventHandler, Width, Height, Top, Left, Title)
{
	var opts = 'location=no,status=yes,resizable=yes,scrollbars=yes,menubar=no';

	if (Width != null)
	{
		opts += ',Width=' + Width
	}

	if (Height != null)
	{
		opts += ',Height=' + Height
	}

	window.open(HelpUrl + "&compositekey=" + ModuleCompositeKey + "&" + ModuleArgs + "&Title=" + Title,"",opts);
}

function CANOPYv100AutoSizeTextarea(TextareaClientID, MinRows)
{
    var oTextarea = document.getElementById(TextareaClientID);
	if (oTextarea != null)
	{
        oTextarea.rows = Math.max((oTextarea.scrollHeight *  oTextarea.rows / oTextarea.clientHeight) + 1, MinRows);
    }
}

function CANOPYv100AddLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function CANOPYv100AddScrollEvent(func) {
  var oldonscroll = window.onscroll;
  if (typeof window.onscroll != 'function') {
    window.onscroll = func;
  } else {
    window.onscroll = function() {
      if (oldonscroll) {
        oldonscroll();
      }
      func();
    }
  }
}

function CANOPYv100AddBeforeUnloadEvent(func) {
  var oldonbeforeunload = window.onbeforeunload;
  if (typeof window.onbeforeunload != 'function') {
    window.onbeforeunload = func;
  } else {
    window.onbeforeunload = function() {
      if (oldonbeforeunload) {
        oldonbeforeunload();
      }
      return func();
    }
  }
}

function CANOPYv100AddClickEvent(func) {
  var oldonclick = window.onclick;
  if (typeof window.onclick != 'function') {
    window.onclick = func;
  } else {
    window.onclick = function() {
      if (oldonclick) {
        oldonclick();
      }
      func();
    }
  }
}

function CANOPYv100AddKeyPressEvent(func) {
  var oldonkeypress = window.onkeypress;
  if (typeof window.onkeypress != 'function') {
    window.onkeypress = func;
  } else {
    window.onkeypress = function() {
      if (oldonkeypress) {
        oldonkeypress();
      }
      func();
    }
  }
}

function CANOPYv100CheckKeyAndPostback(aEvent, aKeyCode, aObjectID) 
{
	if (aEvent.keyCode == aKeyCode) {
		__doPostBack(aObjectID, '');
	}
}

function CANOPYv100CheckKeyAndFocus(aEvent, aKeyCode, aObjectID) 
{
	if (aEvent.keyCode == aKeyCode) {
		document.getElementById(aObjectID).focus();
		return false;
	}
	return true;
}

function CANOPYv100EndFarpointGridEditing(sGrid) {

    var grid = document.getElementById(sGrid);
    if(grid != null) {
        grid.EndEdit();
        grid.UpdatePostbackData();
        grid.Update();
    }
}