    function addEvent(obj, evType, fn){
        if (obj.addEventListener){
            obj.addEventListener(evType, fn, true);
            return true;
        } else if (obj.attachEvent) {
            var r = obj.attachEvent('on'+evType, fn);
            return r;
        } else {
            return false;
        }
    }
    addEvent(window, 'load', function() {
        hide_on_load();
        show_on_load();
    });
    
    function hide_on_load() {
        var elements_hide = document.getElementsByClassName('hide_on_load');
        if (!elements_hide) { return; }
        for(var x=0; x<elements_hide.length; x++) {
            elements_hide[x].style.display = "none";
        }
    }
    
    function show_on_load() {
        var elements_show = document.getElementsByClassName('show_on_load');
        if (!elements_show) { return; }
        for(var x=0; x<elements_show.length; x++) {
            elements_show[x].style.display = "block";
        }
    }
    
    
        var active_options = new Object();
        function activate_product_option_selection(group_id, option_id) {
            if (!option_id) {
                deactivate_options(group_id);
            }
            var sel = document.getElementById('ProductOptionGroup' + group_id);
            if (!sel) {
                return false;
            }
            //sel.value = option_id;
            
            var optlink = document.getElementById('ProductOption' + group_id + '-' + option_id);
            if (optlink == null) {
                deactivate_options(group_id);
                return false;
            }
            //alert('optlink.className ' + optlink.className);
            //alert("optlink: " + optlink);
            if (optlink.className == 'option_active') {
                optlink.className = '';   
                deactivate_options(group_id);
            } else {
                deactivate_options(group_id);
                active_options[group_id] = option_id;
                optlink.className = 'option_active';   
                sel.value = option_id;
            }
            //alert("active: " + active_options);
            product_details_recalculate();
        }
        
        function deactivate_options(group_id) {
            document.getElementById('ProductOptionGroup' + group_id).value = '';
            for (var i in active_options) {
                //alert('i ' + i + ' \noption_id ' + active_options[i]);
                if (i == group_id) {
                    document.getElementById('ProductOption' + i + '-' + active_options[i]).className = '';
                }
            }
            
            delete active_options[group_id];
            e_subtotal = document.getElementById('product_subtotal').innerHTML = parseFloat(document.getElementById('product_base_price').innerHTML);
        }
        
        var available_option_groups = new Object();
        
        function product_details_recalculate() {
            if (available_option_groups.length == 0) { 
                return false;
            }
            if (!document.getElementById('product_base_price')) {
                return false;
            }
            var base_price = parseFloat(document.getElementById('product_base_price').innerHTML);
            var e_subtotal = document.getElementById('product_subtotal');
            var new_subtotal = base_price;
            //alert(e_subtotal.value);
            //for (var i in active_options) {
            for (var i in available_option_groups) {
                var sel = document.getElementById('ProductOptionGroup' + i);
                group_active_option = sel.value;
                if (group_active_option == "") {
                    group_active_option_price_type = 'adds';
                    group_active_option_price = 0.00;
                } else {
                    group_active_option_price_type = eval("product_option_group_" + i + "_prices[" + group_active_option + "]['type']");
                    group_active_option_price = eval("product_option_group_" + i + "_prices[" + group_active_option + "]['price']");
                }
                //alert('base_price: ' + base_price + '\ntype: ' + group_active_option_price_type + '\nprice: ' + group_active_option_price)
                if (group_active_option_price_type == 'adds') {
                    new_subtotal += group_active_option_price;
                } else if (group_active_option_type_type == 'subtracts') {
                    new_subtotal -= group_active_option_price;
                } else if (group_active_option_type_type == 'is') {
                    is_price_difference = group_active_option_price - base_price;
                    new_subtotal += is_price_difference;
                }
            }
            e_subtotal.innerHTML = formatCurrency(new_subtotal);
            if (document.getElementById('discounted_price_wrapper').style.display == "block") {
                product_discount_calculate();
            }
        }
        function formatCurrency(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);
        }
        
        function product_discount_calculate() {
            var subtotal = document.getElementById('product_subtotal').innerHTML;
            subtotal = subtotal.replace(',', '');
            //alert('subtotal:' + subtotal);
            var discount_percent = document.getElementById('discount_percent').innerHTML;
            //var discount_amount = document.getElementById('discount_amount').innerHTML;
            var discount_amount = subtotal * (discount_percent / 100);
            document.getElementById('discount_amount').innerHTML = discount_amount;
            //alert('discount_amount' + discount_amount);
            var discounted_price = subtotal - discount_amount;
            document.getElementById('discounted_price').innerHTML = formatCurrency(discounted_price);
            document.getElementById('discounted_price_wrapper').style.display = "block";
            if (document.getElementById('discounted_price_wrapper2')) {
                document.getElementById('discounted_price2').innerHTML = formatCurrency(discounted_price);
            	document.getElementById('discounted_price_wrapper2').style.display = "block";
            }
        }
        
        
        addEvent(window, 'load', function() {
            product_details_recalculate();
        });
        
        
        function get_browser_width() {
            if (window.innerWidth){
                return window.innerWidth;}  
            else if (document.documentElement && document.documentElement.clientWidth != 0){
                return document.documentElement.clientWidth;    }
            else if (document.body){return document.body.clientWidth;}      
                return 0;
        }
        function get_browser_height() {
            if (window.innerHeight){
                return window.innerHeight;}  
            else if (document.documentElement && document.documentElement.clientHeight != 0){
                return document.documentElement.clientHeight;    }
            else if (document.body){return document.body.clientHeight;}      
                return 0;
        }
        
    
        function ajax_error() {
            return '<br><br><div class=\'flash_message_error\'><center>'
            + 'Error, problem communicating with server.<br><br>Please try again momentarily.'
            + '<br><br><a href=\'javascript:expert_help_form_close();\'>Close<' + '/a><' + '/center><' + '/div>'
        }
        
        function getObject( obj ) {
            if ( document.getElementById ) {
                obj = document.getElementById( obj );
            } else if ( document.all ) {
                obj = document.all.item( obj );
            } else {
                obj = null;
            }
            return obj;
        }
        function moveObject( obj, offsetX, offsetY, e ) {
            var tempX = 0;
            var tempY = 0;
            var objHolder = obj;
            obj = getObject( obj );
            if (obj==null) return;
            tempX = Event.pointerX(e)
            tempY = Event.pointerY(e)
            //alert('tempX: ' + tempX + '\n\ntempY: ' + tempY);
            if (tempX < 0){tempX = 0}
            if (tempY < 0){tempY = 0}
            obj.style.top  = (parseInt(tempY) + parseInt(offsetX)) + 'px';
            obj.style.left = (parseInt(tempX) + parseInt(offsetY)) + 'px';
        }
        function expert_help_form_close() {
            new Effect.Shrink('expert_help_form', {duration: 0.5});
            document.getElementById('expert_help_form_shim').style.display="none";
        }
        
        function expert_help_form_set_shim() {
            var theform_container = document.getElementById('expert_help_form');
            var theshim = document.getElementById('expert_help_form_shim');
            theform_container.style.display = "block";
            theshim.style.top = theform_container.style.top;
            theshim.style.left = theform_container.style.left;
            theshim.style.width = theform_container.offsetWidth;
            theshim.style.height = theform_container.offsetHeight;
            //alert('container offsetHeight: ' + theform_container.style.height);
            theshim.style.zIndex = theform_container.style.zIndex + 1;
            theshim.style.display = "block";
        }
        
        function expert_help_form_open(e) {
            moveObject('expert_help_form', -300,  -400, e);
            
            //expert_help_form_set_shim();
            
            document.getElementById('expert_help_form').innerHTML = "<div style='height:385px; text-align:center;'>"
                + "<br><br>Loading Expert Help Form...<br><br><img src='/img/ajax-loader-xlg-circle-with-text-cccccc.gif'></div>";
                            
            //new Effect.Appear('expert_help_form', {duration: 0.5});
        }
        
        function expert_help_form_loading() {
            load_error = 0;
            expert_help_form_set_shim();
        }
        function expert_help_form_failure() {
            //alert('failure');
            load_error = 1;
            document.getElementById('expert_help_form').innerHTML = ajax_error();
        }
        function expert_help_form_exception() {
            load_error = 1;
            document.getElementById('expert_help_form').innerHTML = ajax_error();
        }
        function expert_help_form_complete() {
            if (load_error == 1) {
                document.getElementById('expert_help_form').innerHTML = ajax_error();
            }
        }
        function expert_help_form_hide() {
            document.getElementById('expert_help_form').style.display="none";
            document.getElementById('expert_help_form_shim').style.display="none";
        } 
        
        function expert_help_form_click(event, link_attributes) {
            new Ajax.Updater('expert_help_form',
                    '/customer_inquiries/ajax_inquiry/' + link_attributes, 
                    {asynchronous:true, 
                    evalScripts:true, 
                    onLoading:function(request) {expert_help_form_loading()}, 
                    onFailure:function(request) {expert_help_form_failure()},
                    onException:function(request) {expert_help_form_exception()},
                    onComplete:function(request) {expert_help_form_complete()}});
                    expert_help_form_open(event); return false;
        }
