﻿// JScript File

//General javascript functions

function OnError(message, context) {
    alert('An unhandled exception has occurred:\n' + message);
}

function RemoveCurrencyPound(value) {
    return value.replace(/£/, '');
}

function FormatCurrencyPound(value) {
    return "£" + Math.round(value);
}

function RTrim(argvalue) {
    while (1) {
        if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
            break;
        argvalue = argvalue.substring(0, argvalue.length - 1);
    }

    return argvalue;
}

function LTrim(argvalue) {
    while (1) {
        if (argvalue.substring(0, 1) != " ")
            break;
        argvalue = argvalue.substring(1, argvalue.length);
    }

    return argvalue;
}

function PopMeUp2(theUrl, width, height) {
    PopUpWindow(theUrl, width, height, 'no', 'no', 'no', 'yes', 'no');
}

function PopMeUp(theUrl) {
    PopUpWindow(theUrl, 545, 400, 'no', 'no', 'no', 'yes', 'no');
}

function PopUpWindow(url, width, height, toolbar, location, menubar, scrollbars, resizeable) {
    window.open(url, 'info', 'toolbar=' + toolbar + ',location=' + location + ',directories=no,status=no,menubar=' + menubar + ',scrollbars=' + scrollbars + ',resizable=' + resizeable + ',width=' + width + ',height=' + height + ',top=100,left=100');
}

function PopUpWindowTab(url, target) {
    var newWindow = window.open(url, target);
    newWindow.focus();
}

function IsInt(s) {
    s = s.replace(",", "");
    var i = parseInt(s);
    if (isNaN(i)) {
        return false;
    }
    i = i.toString();
    return i == s;
}

// Shows the Feedback modal popup, given its client ID
function ShowFeedback(dlgID) {
    var dlg = $find(dlgID);
    dlg.show();
    return false;
}

/* Adds a feedback button to the page, given the ID of the modal dialog which we wish it to show
and the ID of the control to which the button should be added */
function AddFeedbackButton(FeedbackDialogID, LocationControlID) {
    // Create an input type dynamically
    var element = document.createElement("input");
    // Assign different attributes to the element
    element.setAttribute("type", "button");
    element.setAttribute("className", "FeedbackButton");
    element.setAttribute("class", "FeedbackButton");
    element.onclick = function() {
        ShowFeedback(FeedbackDialogID);
        return true;
    };

    var ctl = document.getElementById(LocationControlID);
    // Append the element in page
    if (ctl != null) {
        ctl.appendChild(element);
    }
} 
