﻿//you can query three properties of the BrowserDetect object:

//Use  BrowserDetect.init(); then

//Browser name: BrowserDetect.browser 
//Browser version: BrowserDetect.version 
//OS name: BrowserDetect.OS 
var BrowserDetect = {
    init: function () {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function (data) {
        for (var i = 0; i < data.length; i++) {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function (dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
    },
    dataBrowser: [
		{
		    string: navigator.userAgent,
		    subString: "Chrome",
		    identity: "Chrome"
		},
		{
		    string: navigator.userAgent,
		    subString: "OmniWeb",
		    versionSearch: "OmniWeb/",
		    identity: "OmniWeb"
		},
		{
		    string: navigator.vendor,
		    subString: "Apple",
		    identity: "Safari",
		    versionSearch: "Version"
		},
		{
		    prop: window.opera,
		    identity: "Opera"
		},
		{
		    string: navigator.vendor,
		    subString: "iCab",
		    identity: "iCab"
		},
		{
		    string: navigator.vendor,
		    subString: "KDE",
		    identity: "Konqueror"
		},
		{
		    string: navigator.userAgent,
		    subString: "Firefox",
		    identity: "Firefox"
		},
		{
		    string: navigator.vendor,
		    subString: "Camino",
		    identity: "Camino"
		},
		{		// for newer Netscapes (6+)
		    string: navigator.userAgent,
		    subString: "Netscape",
		    identity: "Netscape"
		},
		{
		    string: navigator.userAgent,
		    subString: "MSIE",
		    identity: "Explorer",
		    versionSearch: "MSIE"
		},
		{
		    string: navigator.userAgent,
		    subString: "Gecko",
		    identity: "Mozilla",
		    versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
		    string: navigator.userAgent,
		    subString: "Mozilla",
		    identity: "Netscape",
		    versionSearch: "Mozilla"
		}
    ],
    dataOS: [
		{
		    string: navigator.platform,
		    subString: "Win",
		    identity: "Windows"
		},
		{
		    string: navigator.platform,
		    subString: "Mac",
		    identity: "Mac"
		},
		{
		    string: navigator.userAgent,
		    subString: "iPhone",
		    identity: "iPhone/iPod"
		},
		{
		    string: navigator.platform,
		    subString: "Linux",
		    identity: "Linux"
		}
    ]

};



function getText(control) {
    if (BrowserDetect.browser == "Explorer") {
        return control.innerText;
    }
    else {
        if (control == null) {
            return "";
        }
        else {
            return control.textContent;
        }
    }
}

function setText(control, value) {

    if (BrowserDetect.browser == "Explorer") {
        control.innerText = value;
    }
    else {
        if (control == null) {

        }
        else {
            control.textContent = value;
        }
    }
}



function showMessageBox(id) {
    debugger;
    BrowserDetect.init();
    var strMessage = getText(document.getElementById(id));
    var msgWidth = 1;

    if (typeof strMessage != "undefined" && (strMessage.toLowerCase().indexOf("back dated transactions created partially") != -1 || strMessage.toLowerCase().indexOf("members splitted successfully") != -1))
        msgWidth = 600;
    setText(document.getElementById(id), "");
    if (strMessage != "") {
        debugger;
        var divMsg = document.createElement("div");
        var innerDivWidth = msgWidth;
        //var offsetLeft = document.getElementById('MainMenu').offsetLeft;
        divMsg.id = "divMsg";
        divMsg.style.position = 'fixed';
        divMsg.style.zIndex = '10';
        divMsg.style.top = '50%';
        divMsg.style.float = 'left';
        divMsg.style.width = '100%';
        divMsg.innerHTML = "<div style='margin:auto; max-width:700px; padding:10px 15px;border:solid 2px #ec0000; border-radius:5px; box-shadow:0px 0px 10px #999; display:table;text-align:center;font-family:Verdana, Geneva, sans-serif; font-size:12px;color:#555; background:#fff; line-height:18px;'>" + strMessage + "</div>";
        $('.MessagePopupBackGround').show();
        document.body.insertBefore(divMsg, document.body.firstChild);
        setTimeout("$('#divMsg').fadeOut(3000)", 3000);
        setTimeout("$('.MessagePopupBackGround').fadeOut(3000)", 3000);
    }
}

function isIE6() {
    BrowserDetect.init();
    if (BrowserDetect.browser == "Explorer" && BrowserDetect.version == 6)
        return true;
    else
        return false;
}


var myDialog;
var isDialogOpen = 0;

function JQDialog(title, contentUrl, width, height) {
    //debugger;
    //var screenHeight = window.pageYOffset; //screen.height;
    var screenHeight = $(window).scrollTop();
    var screenWidth = screen.width;
    var windowHeight = height;
    var windowWidth = width;


    //var posTop = parseInt((screenHeight));
    var posTop = -$(window).screenHeight; //-1115;
    if (contentUrl.indexOf("DPCustomerDetails.aspx") != -1)
        posTop = parseInt((screenHeight) / 2);

    var posLeft = parseInt((screenWidth - windowWidth) / 2);


    if (contentUrl.indexOf("SearchForm.aspx") != -1) {
        width = '660';
        height = '285';
    }

    if (contentUrl.indexOf("DpCRMGroups.aspx") != -1) {
        posTop = 200;
        posLeft = 222;
    }

    if (isDialogOpen == 0) {
        if (width == undefined) {
            width = 'auto';
        }
        if (height == undefined) {
            height = 'auto';
        }
        if (title == "Add New Customer") {
            var dialog1 = $("<div id='popdiv' style='border: none;'>").dialog(
                {
                    autoOpen: false,
                    modal: true,
                    title: title == 'Progress' ? '' : title,
                    height: height,
                    width: parseInt(width),
                    resizable: false,
                    close: function (e, ui) {
                        $(this).remove();
                    }
                });
        }
        else {
            var dialog1 = $("<div id='popdiv'>").dialog(
                {
                    autoOpen: false,
                    modal: true,
                    title: title == 'Progress' ? '' : title,
                    height: height,
                    width: parseInt(width) + 3,
                    resizable: false,
                    close: function (e, ui) {
                        $(this).remove();
                    }
                });
        }
        //        dialog1.id = "dialog1";
        //        dialog1.html("<iframe id='iframeDialog' src='" + contentUrl + "' style='width:" + width + "px;height:" + height + "px;text-align:center;font: bold 13px Arial, Helvetica, sans-serif'></iframe>");
        myDialog = dialog1;
        dialog1.load(contentUrl).dialog('open');
        if (title != 'Progress') {
            //debugger;
            $('div.ui-dialog-content').css({ 'width': width, 'height': height });
            if (contentUrl.indexOf("FileUploadGDrive.aspx") != -1)
                $('div.ui-dialog').css({ 'left': posLeft });
            else
                $('div.ui-dialog').css({ 'top': posTop, 'left': posLeft });
            $('div.ui-dialog-titlebar').css({ 'height': '25px', 'text-align': 'center', 'border-radius': '0px', 'border-bottom': 'solid 1px #333', 'background': '#1d7cbe' });

            $('button.ui-button').remove();
            //$('div.ui-dialog-titlebar').append('<table width="100%" border="0px"><tr><td align="center" style="width:95%"><span class="headerCaption">' + title + '</span></td><td align="right" valign="top" style="width:5%"><image src="/images/button_lighBoxClose.jpg" onclick="CloseDialog()" style="cursor:pointer; margin: -3px -3px 0px 0px" width="25px"  height="25px" /></td></tr></table>');
            $('div.ui-dialog-titlebar').append('<div style="width:100%;position:absolute;top:0px;height:25px"><div style="width:auto;float:left"><span class="headerCaption" id="spntitle" style="padding-left:10px; padding-top:5px;">' + title + '</span></div><div style="width:25px;float:right"><image id="btnClose" src="/images/button_lighBoxClose.jpg" onclick="CloseDialog()" style="cursor:pointer; margin: 0px -3px 0px 0px" width="25px"  height="25px" /></div></div>');
            $('span.ui-dialog-title').remove();
        }
        else {
            //debugger;
            $('div.ui-widget-content').css({ 'border': 'none' });
            $('div.ui-dialog-content').css({ 'border': 'none' });
            $('div.ui-dialog-content').css({ 'width': width, 'height': height });
            if (contentUrl.indexOf("DPCustomerDetails.aspx") != -1) {
                $('div.ui-dialog').css({ 'margin-top': '-69%' });
            }
            $('div.ui-dialog').css({ 'top': '0px' });
            //$('div.ui-dialog-titlebar').css({ 'height': '0px', 'text-align': 'center', 'border-radius': '0px', 'border-bottom': 'solid 1px #333', 'background': '#1d7cbe' });
            $('div.ui-dialog-titlebar').css({ 'height': '0px', 'text-align': 'center', 'border-radius': '0px', 'border': 'none' });

            $('button.ui-button').remove();
            $('div.ui-dialog-titlebar').append('<div style="width:100%;position:absolute;top:0px;height:25px"><div style="width:auto;float:left"><span class="headerCaption" style="padding-left:10px; padding-top:5px;>' + title + '</span></div></div>');
            $('span.ui-dialog-title').remove();
        }
        isDialogOpen = 1;

        //if ($("#popdiv").is(':empty')) {
        //    $("#popdiv").innerHTML("<div class='se-pre-con'></div>");
        //    $(".se-pre-con").fadeOut("slow");
        //}
    }
}

function CloseDialog() {
    myDialog.dialog('close');
    myDialog = null;
    isDialogOpen = 0;
    return false;
}

function ProgressBar() {

    if (myDialog == null) {
        JQDialog("Progress", '/ProgressBar.aspx?url=' + window.location.href, '300', '200');
    }
}

function ProgressBar(url) {

    if (url == undefined) {
        if (myDialog == null) {
            JQDialog("Progress", '/ProgressBar.aspx?url=' + window.location.href, '306', '200');
        }
    }
    else {
        if (myDialog == null) {
            JQDialog("Progress", url + '?url=' + window.location.href, '306', '200');
        }
    }
}
function toTitleCase(str) {
    var strnew = "";
    var i = 0;
    for (i = 0; i < str.length; i++) {
        if (i == 0) {
            strnew = strnew + str[i].toUpperCase();
        }
        else if (i != 0 && str[i - 1] == " ") {
            strnew = strnew + str[i].toUpperCase();
        }
        else {
            strnew = strnew + str[i];
        }
    }
    //alert(strnew);
}

function SetBackURL() {
    history.back();
}

