﻿function MenuCallouts_OnBeforeShow()
    {
        var AssetCallout = ISGetObject("AssetCallout");
        AssetCallout.Hide();
        var TimeCallout = ISGetObject("TimeCallout");
        TimeCallout.Hide();
        var InventoryCallOut = ISGetObject("InventoryCallOut");
        InventoryCallOut.Hide();
        var InspectionCallOut = ISGetObject("InspectionCallOut");
        InspectionCallOut.Hide();
        var SecurityCallOut = ISGetObject("SecurityCallOut");
        SecurityCallOut.Hide();
        var DeliveryCallOut = ISGetObject("DeliveryCallOut");
        DeliveryCallOut.Hide();
        var DispatchCallOut = ISGetObject("DispatchCallOut");
        DispatchCallOut.Hide();
        var ContactCallout = ISGetObject("ContactCallout");
        ContactCallout.Hide();
        var PaymentCallout = ISGetObject("PaymentCallout");
        PaymentCallout.Hide();
        return true;
    }

function LeftExplorerPane_OnBeforeExpand() 
    {
        var LeftExplorerPane = ISGetObject("LeftExplorerPane");
        LeftExplorerPane.Panes[0].DoCollapse();
        LeftExplorerPane.Panes[1].DoCollapse();
        LeftExplorerPane.Panes[2].DoCollapse();
        LeftExplorerPane.Panes[3].DoCollapse();
        LeftExplorerPane.Panes[4].DoCollapse();
        LeftExplorerPane.Panes[5].DoCollapse();
        return true;
    }

function setItemBack(strObjName) 
    {
        document.getElementById(strObjName).style.backgroundColor = "#CCCCCC";
    }

function loginCustomer() 
    {
        var WDBLogin = ISGetObject("WDBLogin");
        WDBLogin.ShowDialog();
    }

function cancelLogin() 
    {
        var WDBLogin = ISGetObject("WDBLogin");
        WDBLogin.CloseDialog();
        return false;
    }


function relative_time(time_value)
    {
        var baddate = time_value.split(" ");
        var newdate = baddate[0] + " " + baddate[1] + " " + baddate[2] + " " + baddate[5] + " " + baddate[3] + " " + baddate[4];

        var parsed_date = Date.parse(newdate);
        var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
        var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);

        if (delta < 60) {
            return 'less than a minute ago';
        } else if (delta < 120) {
            return 'about a minute ago';
        } else if (delta < (45 * 60)) {
            return (parseInt(delta / 60)).toString() + ' minutes ago';
        } else if (delta < (90 * 60)) {
            return 'about an hour ago';
        } else if (delta < (24 * 60 * 60)) {
            return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
        } else if (delta < (48 * 60 * 60)) {
            return '1 day ago';
        } else {
            return (parseInt(delta / 86400)).toString() + ' days ago';
        }
    }

function linkify(inputText)
    {
        var replaceText, replacePattern1, replacePattern2, replacePattern3;

        //URLs starting with http://, https://, or ftp://
        replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
        replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>');

        //URLs starting with www. (without // before it, or it'd re-link the ones done above)
        replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
        replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">$2</a>');

        //Change email addresses to mailto:: links
        replacePattern3 = /(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim;
        replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');

        return replacedText;
    }


function twitterCallback(data)
    {
        var stringTwitter = ''

        for (x = 0; x < 3; x++) {
            stringTwitter = stringTwitter + '<div><a href="http://twitter.com/sierradata/statuses/' + data[x].id_str + '"><img src="http://www.datarrive.com/blog/widgets/twitter/twitter.ico" border="0"></a> ';
            stringTwitter = stringTwitter + linkify(data[x].text);
            stringTwitter = stringTwitter + ' - ' + relative_time(data[x].created_at) + '</div><br />';
        }
        var divTwitter = document.getElementById('divTwitter');
        divTwitter.innerHTML = stringTwitter;
    }

