jQuery.fn.dataTableExt.oSort['currency-asc'] = function(a,b) {
	/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
	var x = a == "-" ? 0 : a.replace( /,/g, "" );
	var y = b == "-" ? 0 : b.replace( /,/g, "" );
	
	/* Remove the currency sign */
	x = x.substring( 1 );
	y = y.substring( 1 );
	
	/* Parse and return */
	x = parseFloat( x );
	y = parseFloat( y );
	return x - y;
};

jQuery.fn.dataTableExt.oSort['currency-desc'] = function(a,b) {
	/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
	var x = a == "-" ? 0 : a.replace( /,/g, "" );
	var y = b == "-" ? 0 : b.replace( /,/g, "" );
	
	/* Remove the currency sign */
	x = x.substring( 1 );
	y = y.substring( 1 );
	
	/* Parse and return */
	x = parseFloat( x );
	y = parseFloat( y );
	return y - x;
};

        //LOG OUT WARNING
        //function warnuser(){
        //            if (confirm("There has been no activity for some time. Click OK if you wish to continue your session, click CANCEL to log out. For your security, if you are unable to respond to this message within 2 minutes you will be logged out automatically."))
        //            {
        //                //post the page to itself
        //                document.location.href = "Utilities.aspx" 
        //            }
        //            else
        //            {
        //                document.location.href = "Default.aspx"
        //            }
        //        };
        
        $("#bigMenu").hide;
        jQuery.fn.exists = function() { return jQuery(this).length > 0; };

           
        //Get Enter Key
//        function GetEnter() {
//            //if (window.event.keyCode == 13) {
//                alert('key pressed');
//                $('ctl00_head3content_login_txtUserName').preventDefault();
//                $('#ctl00_head3content_login_txtPassword').focus(); 
//            //}
//        };
        //
 
        //parse string to array function - by http://www.greywyvern.com/
        String.prototype.splitCSV = function(sep) {
            for (var foo = this.split(sep = sep || ","), x = foo.length - 1, tl; x >= 0; x--) {
                if (foo[x].replace(/"\s+$/, '"').charAt(foo[x].length - 1) == '"') {
                    if ((tl = foo[x].replace(/^\s+"/, '"')).length > 1 && tl.charAt(0) == '"') {
                        foo[x] = foo[x].replace(/^\s*"|"\s*$/g, '').replace(/""/g, '"');
                    } else if (x) {
                        foo.splice(x - 1, 2, [foo[x - 1], foo[x]].join(sep));
                    } else foo = foo.shift().split(sep).concat(foo);
                } else foo[x].replace(/""/g, '"');
            } return foo;
        };

        //pause function - http://dev-notes.com/code.php?q=60
        function pause(milliseconds) {
            var dt = new Date();
            while ( ( new Date() ) - dt <= milliseconds) { /* Do nothing */ }
        };

        //improved 'contains' function for exact match
        $.expr[":"].econtains = function(obj, index, meta, stack) {
            return (obj.textContent || obj.innerText || $(obj).text() || "").toLowerCase() == meta[3].toLowerCase();
        };

        //format currency
        function formatCurrency2(num) {
            num = num.toString().replace(/\$|\,/g, '');
            if (isNaN(num))
                num = "0";
            sign = (num == (num = Math.abs(num)));
            num = Math.floor(num * 100 + 0.50000000001);
            cents = num % 100;
            num = Math.floor(num / 100).toString();
            if (cents < 10)
                cents = "0" + cents;
            for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
                num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
            return (((sign) ? '' : '-') + '$' + num + '.' + cents);
        };

        $(document).ready(function() {

            $('#ctl00_head3content_login_txtUserName').keypress(function(e) {
                if (e.which == 13) {
                    //e.PreventDefault();
                    $('#ctl00_head3content_login_txtPassword').focus();  //Use whatever selector necessary to focus the 'next' input
                    return false;
                }
            });

            $('#ctl00_head3content_login_txtPassword').keypress(function(e) {
                if (e.which == 13) {
                    $('#aspnetForm').submit();
                    return false;
                }
            });

            $('#ctl00_plcMain_OrderReview1_txtPO').keypress(function(e) {
                if (e.which == 13) {
                    $('#ctl00_plcMain_OrderReview1_txtReqDate').focus();  
                    return false;
                }
            });

            $('#ctl00_plcMain_OrderReview1_txtReqDate').keypress(function(e) {
                if (e.which == 13) {
                    $('#ctl00_plcMain_OrderReview1_txtOrdComment').focus();
                    return false;
                }
            });

            $('#ctl00_plcMain_OrderReview1_txtOrdComment').keypress(function(e) {
                if (e.which == 13) {
                    $('#ctl00_plcMain_OrderReview1_btnSubmit').focus();
                    return false;
                }
            });

            $('#ctl00_textSearch').keypress(function(e) {
                if (e.which == 13) {
                    var sValue = $('#ctl00_textSearch').val();
                    var hrefLoc = '/CUST_Portal/results.aspx?pKey=' + sValue + '&pType=S';
                    window.location = hrefLoc;
                    return false;
                }
            });

            /*$('#menuCol a').replaceText('And', 'and');
            $('#menuCol a').replaceText('Dvd', 'DVD');
            $('#menuCol a').replaceText('vhs', 'VHS');
            $('#menuCol a').replaceText('Am/fm', 'AM/FM');
            $('#menuCol a').replaceText('Hd ', 'HD ');
            $('#menuCol a').replaceText('A-bus', 'A-BUS');
            $('#menuCol a').replaceText('Ir', 'IR');
            $('#menuCol a').replaceText('On-q', 'On-Q');
            $('#menuCol a').replaceText('Din', 'DIN');
            $('#menuCol a').replaceText('12v', '12V');
            $('#menuCol a').replaceText('A/c', 'A/C');
            $('#menuCol a').replaceText('A/v', 'A/V');
            $('#menuCol a').replaceText('D/w', 'D/W');
            $('#menuCol a').replaceText('Dlp', 'DLP');
            $('#menuCol a').replaceText('Lcd', 'LCD');
            $('#menuCol a').replaceText('dvd', 'DVD');
            $('#menuCol a').replaceText('Vcr', 'VCR');
            $('#menuCol a').replaceText('Led', 'LED');
            $('#menuCol a').replaceText('Rti', 'RTI');
            $('#menuCol a').replaceText('Lcr', 'LCR');
            $('#menuCol a').replaceText('hdmi', 'HDMI');
            $('#menuCol a').replaceText('Pc', 'PC');
            $('#menuCol a').replaceText('Cd', 'CD');
            $('#menuCol a').replaceText('Htib', 'HTiB');
            $('#menuCol a').replaceText('DINing', 'Dining');
            $('#menuCol a').replaceText('Hd', 'HD');
            $('#menuCol a').replaceText('/hd', 'HD');
            $('#menuCol a').replaceText('oem', 'OEM');
            $('#menuCol a').replaceText('Tv', 'TV');
            $('#menuCol a').replaceText('Xm/sir', 'XM/SIR');
            $('#menuCol a').replaceText('Crt', 'CRT');
            $('#menuCol a').replaceText('crt', 'CRT');
            $('#menuCol a').replaceText('Xm', 'XM');
            $('#menuCol a').replaceText('Mp3', 'MP3');
            $('#menuCol a').replaceText('SIRHD', 'SIR HD'); */

            $('#priceButton').click(function() {
                parent.location = '/CUST_Portal/PriceLookup.aspx';
                return false;
            });

            $('#btnForgot').click(function() {
                parent.location = '/RetrievePwd.aspx';
                return false;
            });

            // Dialog			
            //            $('#dialog').dialog({
            //                autoOpen: false,
            //                width: 600,
            //                buttons: {
            //                    "Ok": function() {
            //                        $(this).dialog("close");
            //                    },
            //                    "Cancel": function() {
            //                        $(this).dialog("close");
            //                    }
            //                }
            //            });

            // Dialog Link
            //            $('#dialog_link').click(function() {
            //                $('#dialog').dialog('open');
            //                return false;
            //            });

            //            // Datepicker
            //            $('#datepicker').datepicker({
            //                inline: true
            //            });

            //            // Progressbar
            //            $("#progressbar").progressbar({
            //                value: 20
            //            });

            //hover states on the static widgets
            $('#dialog_link, ul#icons li').hover(
                function() {
                    $(this).addClass('ui-state-hover');
                }, function() {
                    $(this).removeClass('ui-state-hover');
                });

            // Sort Li Collection
            //$("#brandList>li").tinysort();

            //  BUTTON JQUERY UI BUTTON INITIATE
            //$("input[type=submit]#ctl00_head3content_login_btnForgot").button({ icons: { primary: 'ui-icon-print'} });
            //$("input[type=button]").button();
            //$("#ctl00_head3content_login_btnLogOff").button();
            //$("#ctl00_head3content_login_btnSubmit").button();
            //$("#ctl00_plcMain_addButton").button();
                           
            //$("input[type=submit]").button();
            $("#ctl00_head3content_lastButton").button({ icons: { primary: 'ui-icon-circle-zoomin'} });
            //$("#backButton").button({
                //icons: {
                    //primary: 'ui-icon-circle-triangle-w'
                //}
            //});
            //$("#printButton").button({
                //icons: {
                    //primary: 'ui-icon-print'
                //}
            //});
            $("#printButton2").button({
                icons: {
                    primary: 'ui-icon-print'
                }
            });
            $(".sideLink").button();
            $("#powerButton").button({
                icons: {
                    primary: 'ui-icon-power'
                }
            });
            $("#emailButton").button({
                icons: {
                    primary: 'ui-icon-mail-closed'
                }
            });
            $("#emailButton2").button({
                icons: {
                    primary: 'ui-icon-mail-closed'
                }
            });
            $("#priceButton").button({
                icons: {
                    primary: 'ui-icon-tag'
                }
            });
            //$("#btnForgot").button({
                //icons: {
                    //primary: 'ui-icon-help'
                //}
            //});

            var kids = $('#ctl00_mCatalog_tvwCatalog').children();
            $('#vertMenu0').append(kids);
            $('#ctl00_mCatalog_tvwCatalog').remove();

            $('a:contains("BRAND")').parent().remove();
            $('a:contains("SPECIALS")').parent().remove();
            $('div#ctl00_mainBody', 'div#ctl00_plcMain_Catalog1_upOrders').css({
                'background-color': 'none'
            });
            $('span.AspNet-TreeView-Expand').remove();
            $('div#ctl00_mCatalog_tvwCatalog').removeClass('AspNet-TreeView');
            $('div#ctl00_mCatalog_tvwCatalog ul, li').removeClass('AspNet-TreeView-Parent AspNet-TreeView-Hide AspNet-TreeView-Root AspNet-TreeView-Leaf');

            //SEARCH BOX
            /**
            * the element
            */
            var $ui = $('#ui_element');

            /**
            * on focus and on click display the dropdown, 
            * and change the arrow image
            */
            //            $ui.find('.sb_input').bind('focus click', function() {
            //                $ui.find('.sb_down').addClass('sb_up').removeClass('sb_down').andSelf().find('.sb_dropdown').show();
            //            });
            //            /**
            //            * on mouse leave hide the dropdown, 
            //            * and change the arrow image
            //            */
            //            $ui.bind('mouseleave', function() {
            //                $ui.find('.sb_up').addClass('sb_down').removeClass('sb_up').andSelf().find('.sb_dropdown').hide();
            //            });
            //            /**
            //            * selecting all checkboxes
            //            */
            //            $ui.find('.sb_dropdown').find('label[for="all"]').prev().bind('click', function() {
            //                $(this).parent().siblings().find(':checkbox').attr('checked', this.checked).attr('disabled', this.checked);
            //            });
            $('.sb_input').dynoBox();

            function textSearch_onclick() {
                var sValue = $('#ctl00_textSearch').val();
                var hrefLoc = '/CUST_Portal/results.aspx?pKey=' + sValue + '&pType=S';
                window.location = hrefLoc;
            };

            //MENUS

            ddsmoothmenu.init({
                mainmenuid: "navMenu",
                //Menu DIV id
                orientation: 'h',
                //Horizontal or vertical menu: Set to "h" or "v"
                classname: 'ddsmoothmenu',
                //class added to menu's outer DIV
                //customtheme: ["#804000", "#482400"],
                contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
            });

            //QTIP INITIATION
            $('#emailButton').qtip({
                content: 'Click here to email general questions to info@edinw.com',
                style: 'dark',
                show: {
                    delay: 200
                },
                position: {
                    target: 'mouse',
                    adjust: {
                        mouse: true
                    }
                }
            });

            $('#emailButton2').qtip({
                content: 'Click here to email login questions to login@edinw.com',
                style: 'dark',
                show: {
                    delay: 200
                },
                position: {
                    target: 'mouse',
                    adjust: {
                        mouse: true
                    }
                }
            });

            $('#powerButton').qtip({
                content: 'Click here for for information on EDI&#146;s buying group',
                style: 'dark',
                show: {
                    delay: 200
                },
                position: {
                    target: 'mouse',
                    adjust: {
                        mouse: true
                    }
                }
            });

            $('#linkedIn').qtip({
                content: 'Click here for EDI @ LinkedIn',
                style: 'dark',
                show: {
                    delay: 200
                },
                position: {
                    target: 'mouse',
                    adjust: {
                        mouse: true
                    }
                }
            });

            $('#faceBook').qtip({
                content: 'Click here for EDI @ Facebook',
                style: 'dark',
                show: {
                    delay: 200
                },
                position: {
                    target: 'mouse',
                    adjust: {
                        mouse: true
                    }
                }
            });
            
            

//            $('#twitter').qtip({
//                content: 'Click here for EDI @ Twitter',
//                style: 'dark',
//                show: {
//                    delay: 200
//                },
//                position: {
//                    target: 'mouse',
//                    adjust: {
//                        mouse: true
//                    }
//                }
//            });
//            
            
            $('.fg-button').hover(
                function() {
                    $(this).removeClass('ui-state-default').addClass('ui-state-focus');
                }, function() {
                    $(this).removeClass('ui-state-focus').addClass('ui-state-default');
                });

            //MENUS
            $('#hierarchybreadcrumb').menu({
                content: $('#hierarchybreadcrumb').next().html(),
                width: 180,
                maxHeight: 520,
                detectV: false,
                directionV: 'down',
                showSpeed: 100,
                crossSpeed: 100,
                backLink: true
            });
            
  
            
            
            

            //            //REMEMBER UL MENU LEVEL - uses cookies and jquery transversing - by Mark Nixon - EDI
            //            var menuPath = 'div.positionHelper ul li a';  //location of 'a' menu elements in UL
            //            $('#test1').text($.cookie('mLevel22'));

            //            //temporarily kill click handler	
            //            $(menuPath).die('mousedown');

            //            //if menu levels are stored in cookie then loop through each
            //            if ($.cookie("mLevel22") !== null) {
            //                var levelArray = $.cookie('mLevel22').splitCSV() //parse the cookie string to array
            //                for (var i = levelArray.length - 1; i > 0; i--) {
            //                    
            //                    var nextLevel = $(menuPath + ':econtains("' + levelArray[i] + '")');
            //                    var nextLevelText = $(nextLevel).text(); //debug variable only
            //                    $(nextLevel).click();
            //                    //pause(500);
            //                     //debugger;
            //                    //console.log(nextLevel);
            //                    //$(nextLevel).toggleClass('beta');
            //                };
            //            };

            //            //add click handler, store level hierarchy to cookie on click of any sublevel
            //            $(menuPath).live('mousedown', function() {
            //                if ($(this).text() == 'TOP LEVEL') { $.cookie('mLevel22', null); $('#test1').text('TOP') }
            //                else {
            //                    var x = 0;
            //                    var upLevel = $(this);
            //                    var levels = new Array();
            //                    levels[x] = $(this).text();

            //                    while ($(upLevel).text() !== "") {
            //                        x = x + 1;
            //                        upLevel = upLevel.parent().parent().parent().children('a');
            //                        if ($(upLevel).text() !== "") { levels[x] = $(upLevel).text() };
            //                    };

            //                    $.cookie("mLevel22", levels.join(), { expires: 7, path: '/' });
            //                    $('#test1').text($.cookie('mLevel22'));
            //                    //var sURL = unescape(window.location.pathname);
            //                    //window.location.href = sURL;
            //                };
            //            });
        });     //end -Document Ready


