﻿
function ShowModalWindow(winURL, args, winFeatures) {
    window.modalCallbackValue = '';
    $("divPageMask").show();
    window.showModalDialog(winURL, args, winFeatures);
    $("divPageMask").hide();
    
}

function SetWindowSize() {
    if (vIE() == 6) {
        var dlgHeight = parseFloat(window.dialogHeight);
        var difference = dlgHeight - document.documentElement.offsetHeight;
        window.dialogHeight = dlgHeight + difference + "px";
    }
}

//Returns the version umber of IE
function vIE() {
    return (navigator.appName == 'Microsoft Internet Explorer') ? parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]) : -1;
}

function ActionWizard(wizardId, wizardName, wizardType, source, processId) {

    $("divPageMask").show();
    
    $("hdnWizardID").value = wizardId;
    $("btnUpdateClickCount").click();
    
    switch (wizardType) {
        case 'gSO':
            setTimeout("Launch_gSO_Wizard(" + wizardId + ", '" + wizardName + "', '" + source + "', '" + processId + "')", 500);
            break;

        case 'URL':
            setTimeout("Launch_Web_Wizard('" + source + "')", 500);
            break;

        case 'File':
            setTimeout("Download_File_Wizard('" + source + "')", 500);
            break;
    }

    setTimeout("$('divPageMask').hide();", 1000);
}

function Launch_gSO_Wizard(wizardId, wizardName, dsn, processId) {
    var width = 1000;
    var height = 800;
    var left = parseInt(0.5 * (screen.availWidth - width));
    var top = parseInt(0.5 * (screen.availHeight - height));
    var winFeatures = 'menubar=no,location=no,toolbar=no,resizable=yes,scrollbars=no,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height;

    var winURL = 'ActionWizard.aspx?WizardID=' + wizardId + '&WizardName=' + wizardName + '&DSN=' + dsn + '&processId=' + processId;

    var win = window.open(winURL, 'WizardWiki', winFeatures);

    if (win) {
        win.focus();
        window.modalCallbackValue = 'CHECK';
        setTimeout("CheckCallbackValue();", 5000);
    }
    
    if (window.modalCallbackValue == 'Reload') {
        $("btnRefresh").click();
    }
}

function Launch_Web_Wizard(winURL) {
    var win = window.open(winURL, 'WizardWiki');

    if (win)
        win.focus();
}

function Download_File_Wizard(winURL) {
    var win = window.open(winURL, 'WizardWiki');

    if (win)
        win.focus();
}

//Used after ActionWizard has been called to check for login.
function CheckCallbackValue() {
    if (window.modalCallbackValue == 'CHECK') {
        setTimeout("CheckCallbackValue();", 5000);
    }
    if (window.modalCallbackValue == 'Reload') {
        $("btnRefresh").click();
    }
}

function SubmitWizard(iWizardId) {
    var width = 500;
    var height = 600;
    var left = screen.width / 2 - width / 2;
    var top = screen.height / 2 - height / 2;
    var winFeatures = 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;dialogTop:' + top + 'px;dialogLeft:' + left + 'px;scroll:no';
    var winURL = 'SubmitWizard.aspx?WizardId=' + iWizardId;
    var args = self;

    ShowModalWindow(winURL, args, winFeatures);

    if (window.modalCallbackValue == 'Reload') {
        $("btnRefresh").click();
    } else {
        return false;
    }
}

function CommissionWizard() {
    var width = 560;
    var height = 840;
    var left = screen.width / 2 - width / 2;
    var top = screen.height / 2 - height / 2;
    var winFeatures = 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;dialogTop:' + top + 'px;dialogLeft:' + left + 'px;scroll:no';
    var winURL = 'CommissionWizard.aspx';
    var args = '';

    ShowModalWindow(winURL, args, winFeatures);

    return false;
}

function ShowDescription(wizardId) {
    var i = 0;
    for (i = 0; i < $("lstWizardDecriptions").options.length; i++) {
        if ($("lstWizardDecriptions").options[i].value == wizardId) {

            var width = 500;
            var height = 300;
            var x = parseInt(0.5 * (screen.availWidth - width));
            var y = parseInt(0.4 * (screen.availHeight - height));

            $("lblDescription").innerHTML = $("lstWizardDecriptions").options[i].text;

            $("divDescription").style.width = width + 'px';
            $("divDescription").style.height = height + 'px';
            $("divDescription").style.top = y + 'px';
            $("divDescription").style.left = x + 'px';

            $("divPageMask").show();
            $("divDescription").show();
        }
    }
}

function CloseDescription() {
    $("divPageMask").hide();
    $("divDescription").hide();
}

function DisplayInfo(sInfoPage) {
    var width = 800;
    var height = 800;
    var left = parseInt(0.5 * (screen.availWidth - width));
    var top = parseInt(0.5 * (screen.availHeight - height));
    var winFeatures = 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;dialogTop:' + top + 'px;dialogLeft:' + left + 'px;scroll:no;resizable:no;unadorned:yes;';
    var args = '';
    
    var winURL = 'info_pages/' + sInfoPage;

    ShowModalWindow(winURL, args, winFeatures);
    
    return false;
}

function ContactUs() {
    var width = 500;
    var height = 440;
    var left = parseInt(0.5 * (screen.availWidth - width));
    var top = parseInt(0.5 * (screen.availHeight - height));
    var winFeatures = 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;dialogTop:' + top + 'px;dialogLeft:' + left + 'px;scroll:no;resizable:no;unadorned:yes;';
    var args = '';

    var winURL = 'contact.aspx';

    ShowModalWindow(winURL, args, winFeatures);

    return false;
}

function ManageAccount(sOption) {
    var width;
    var height;
    var winURL;

    switch (sOption) {
        case 'Register':
            width = 480;
            height = 340;
            winURL = 'AccountRegister.aspx';
            break;

        case 'Login':
            width = 420;
            height = 200;
            winURL = 'AccountLogin.aspx';
            break;

        case 'Manage':
            width = 500;
            height = 340;
            winURL = 'AccountManagement.aspx';
            break;
    }
    
    var left = parseInt(0.5 * (screen.availWidth - width));
    var top = parseInt(0.5 * (screen.availHeight - height));
    var winFeatures = 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;dialogTop:' + top + 'px;dialogLeft:' + left + 'px;scroll:no;resizable:no;unadorned:yes;';
    var args = self;

    ShowModalWindow(winURL, args, winFeatures);

    if (window.modalCallbackValue == 'Reload') {
        $("btnRefresh").click();
    } else {
        return false;
    }
}
function ShowUserWizards() {
    var width = 760;
    var height = 500;
    var left = screen.width / 2 - width / 2;
    var top = screen.height / 2 - height / 2;
    var winFeatures = 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;dialogTop:' + top + 'px;dialogLeft:' + left + 'px;scroll:no';
    var winURL = 'UserWizards.aspx';
    var args = '';

    ShowModalWindow(winURL, args, winFeatures);

    return false;
}

function UpdateUserWizardsDeletedList(chkResource) {
    var strValue = chkResource.id + "##";

    if ($("hdnDeleted")) {
        var myRE = strValue;
        var aMatch;

        if (chkResource.checked) {
            aMatch = $F("hdnDeleted").match(myRE);

            if (aMatch == null) {
                $("hdnDeleted").value = $F("hdnDeleted") + strValue;
            }
        } else {
            aMatch = $F("hdnDeleted").match(myRE);

            if (aMatch != null) {
                $("hdnDeleted").value = $F("hdnDeleted").gsub(strValue, "");
            }
        }
    }

    ToggleDeleteImage(!$F("hdnDeleted").empty());
}

function ToggleDeleteImage(blnEnabled) {
    if ($("imgDelete")) {
        if (blnEnabled) {
            $("imgDelete").src = "Images\\Delete_enabled.gif";
            $("imgDelete").disabled = false;
        } else {
            $("imgDelete").src = "Images\\Delete_disabled.gif";
            $("imgDelete").disabled = true;
        }
    }
}

function Reopen_gSO_Wizard(Username, WizardName, DSN, CaseID) {
    var width = 1000;
    var height = 800;
    var left = parseInt(0.5 * (screen.availWidth - width));
    var top = parseInt(0.5 * (screen.availHeight - height));
    var winFeatures = 'menubar=no,location=no,toolbar=no,resizable=yes,scrollbars=no,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height;

    var winURL = 'http://www.gstepone.net/gStepOneWS/WizardWiki.asp?Username=' + Username + '&WizardName=' + WizardName + '&DSN=' + DSN + '&CaseID=' + CaseID;

    var win = window.open(winURL, 'WizardWiki', winFeatures);

    if (win)
        win.focus();
}