﻿
function DownLoadSelected(projects, projcount)
{
    if (projects.length > 0)
	{
		if (projcount < 250)
		{
			window.open('GenerateFile.aspx?projids=' + projects +'end','DownLoad','width=550,height=620');
		}
		else
		{
			alert('Please select less than 250 Projects');
		}
	}
	else
	{
		alert('Please select some Projects to download');
	}
}

function PopUpWind(NPage,w,h,r1,r2,s)
{
  var leftPos = screen.availWidth/2-(w/2);
  var topPos = screen.availHeight/2-(h/2);
  var newWindow = window.open(NPage,"","width="+w+",height="+h+",left="+leftPos+", top="+topPos+", resizable="+r1+", resize="+r2+",status=0,scrollbars="+s)

  if (newWindow.opener==null)
  {
    newWindow.opener=self
  }
  newWindow.focus()
}

function popuphelp2()
{
    var newhelpWindow = window.open("../help_centre/help_advsearch.asp","","width=760, height=500, resize=1, status=0, scrollbars=0")
    if (newhelpWindow.opener==null)
    {
	    newhelpWindow.opener=self
    }
	newhelpWindow.focus()
}	

function confirm_continue()
{
    if (confirm("Are you sure you want to clear all projects you have selected (over all pages)") == true)
        return true;
    else
        return false;
}
var Done = false;
function onClientSelect()
{
//    if (!Done)
//    {
//        assignEventsToCheckboxes();
//        Done = true;
//    }
}

function bookmarksite(title, url)
{
    if(document.all)
    window.external.AddFavorite(url,title);
    else if(window.sidebar)
    window.sidebar.addPanel(title, url, '')
}

function addNote(tabContainerId)
{
    var winHeight = document.body.clientHeight; 
    window.scrollTo(0, winHeight);
    $('#' + tabContainerId).tabs('select', 2);
    return false;
}

$(document).ready(function() {
    $('#printSelectedDialog').show();
    $('#printSelectedDialogNoProjects').show();
    $('#printSelectedDialog').dialog({ modal: true, autoOpen: false, height: 380, width: 640, buttons: { "Don't Print": function() { $(this).dialog("close"); } } });
    $('#printSelectedDialogNoProjects').dialog({ modal: true, autoOpen: false, height: 130, width: 280, buttons: { "Ok": function() { $(this).dialog("close"); } } });
});

function clearItemSelections(elem) {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/SelectionService.asmx/ClearItemSelections",
        data: "{selectionType:2}",
        dataType: "json",
        complete: onClear,
        context: elem
    });
}
function onClear() {
    $(this).html('<b>cleared</b>');
    $(this).fadeTo(1500, 1, function () { $(this).html('Clear selected') });
    var items = Glenigan.Bmi.ServerControls.SelectionCheckBoxBehavior.ItemTypes[2];
    for (item in items)
    {
        Array.forEach(items[item], function (box) {
            box.get_element().checked = false;
        });
    }
    Glenigan.Bmi.ServerControls.SelectionCheckBoxBehavior.SyncGroupSelectionBoxes();
}
function printSelectedProjects() {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/SelectionService.asmx/GetItemSelections",
        data: "{selectionType:2}",
        dataType: "json",
        success: onGetItems
    });
}

function onGetItems(data) {
    var selectedProjects = data['d'];
    $('#selectedProjectCount').text(selectedProjects.length);
    if (selectedProjects.length == 0) {
        $('#printSelectedDialogNoProjects').dialog('open');
    }
    else {
        $('#printSelectedDialog').dialog('open');
    }
}

function printProject() {
    $('#pluralOrSingular').text('project');
    $('#printSelectedDialog').dialog('open');
}


