﻿//<![CDATA[
var rotatorindex;
function theRotator() {
    //Set the opacity of all images to 0
    $('div#rotator ul li').css({ opacity: 0.0 });

    //Get the first image and display it (gets set to full opacity)
    $('div#rotator ul li:first').css({ opacity: 1.0 });

    //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
   rotatorindex = setInterval('rotate()', 4000);

}

function rotate() {
    clearInterval(rotatorindex);
    //Get the first image
    var current = ($('div#rotator ul li.show') ? $('div#rotator ul li.show') : $('div#rotator ul li:first'));

    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') : current.next()) : $('div#rotator ul li:first'));

    //Set the fade in effect for the next image, the show class has higher z-index
    next.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 1000);

    //Hide the current image
    current.animate({ opacity: 0.0 }, 1000)
	.removeClass('show');
    rotatorindex = setInterval('rotate()', 4000);

}

function rotatePrevious() {
    clearInterval(rotatorindex);
    //Get the first image
    var current = ($('div#rotator ul li.show') ? $('div#rotator ul li.show') : $('div#rotator ul li:first'));

    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.prev().length) ? ((current.prev().hasClass('show')) ? $('div#rotator ul li:first') : current.prev()) : $('div#rotator ul li:first'));

    //Set the fade in effect for the next image, the show class has higher z-index
    next.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 1000);

    //Hide the current image
    current.animate({ opacity: 0.0 }, 1000)
	.removeClass('show');
    rotatorindex = setInterval('rotate()', 4000);
}

$(function () {
    $('.rollover').hover(function () {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hover'));
        $(this).attr('hover', currentImg);
    }, function () {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hover'));
        $(this).attr('hover', currentImg);
    });
});

 //fonction pour parser email
$("a[rel='3m4il']").each(function () {
    var spaceShip = $(this).text();
    var spaceStation = $(this).attr('href');
    $(this).replaceWith('<a href="mailto:' + spaceShip
        + '@' + spaceStation + '">' + spaceShip + '@' + spaceStation
        + '</a>');
});



    
var active_color = '#000'; // Colour of user provided text
var inactive_color = '#7E7E7E'; // Colour of default text

/**
* No need to modify anything below this line
*/

$(document).ready(
    function () {

        $("a[rel='demandeCatalogue']").each(function () {
            var spaceShip = 'info@bmcltee.ca';
            var spaceImg = $(this).text();
            var subject = $(this).attr('href');

            $(this).attr('href', "mailto:info@bmcltee.ca?subject=" + subject);
        });

        $(".myimage").error(function () { $(this).hide(); });



        $("input.default-value").css("color", inactive_color);

        // $("input.default-value").css("font-style", "italic");

        var default_values = new Array();

        $("input.default-value").focus(
            function () {
                if (!default_values[this.id]) {
                    default_values[this.id] = this.value;

                }
                if (this.value == default_values[this.id]) {
                    this.value = '';
                    this.style.color = active_color;
                    $("input.default-value").css("font-style", "normal");
                }
                $(this).blur(
                    function () {
                        if (this.value == '') {
                            this.style.color = inactive_color;
                            this.value = default_values[this.id];
                            $("input.default-value").css("font-style", "italic");
                        }
                    }
                );
            });


    });

var min = 8;
var max = 18;
function increaseFontSize() {
  var  p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}
function decreaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }
}

(function ($) {

    $.fn.autotab = function (options) {
        var defaults = {
            format: 'all', 		// text, numeric, alphanumeric, all
            maxlength: 2147483647, // Defaults to maxlength value
            uppercase: false, 	// Converts a string to UPPERCASE
            lowercase: false, 	// Converts a string to lowecase
            nospace: false, 	// Remove spaces in the user input
            target: null, 		// Where to auto tab to
            previous: null			// Backwards auto tab when all data is backspaced
        };

        $.extend(defaults, options);

        var check_element = function (name) {
            var val = null;
            var check_id = $('#' + name)[0];
            var check_name = $('input[name=' + name + ']')[0];

            if (check_id != undefined)
                val = $(check_id);
            else if (check_name != undefined)
                val = $(check_name);

            return val;
        };

        var key = function (e) {
            if (!e)
                e = window.event;

            return e.keyCode;
        };

        // Sets targets to element based on the name or ID passed
        if (typeof defaults.target == 'string')
            defaults.target = check_element(defaults.target);

        if (typeof defaults.previous == 'string')
            defaults.previous = check_element(defaults.previous);

        var maxlength = $(this).attr('maxlength');

        // Each text field has a maximum character limit of 2147483647

        // defaults.maxlength has not changed and maxlength was specified
        if (defaults.maxlength == 2147483647 && maxlength != 2147483647)
            defaults.maxlength = maxlength;
        // defaults.maxlength overrides maxlength
        else if (defaults.maxlength > 0)
            $(this).attr('maxlength', defaults.maxlength)
        // defaults.maxlength and maxlength have not been specified
        // A target cannot be used since there is no defined maxlength
        else
            defaults.target = null;

        // IE does not recognize the backspace key
        // with keypress in a blank input box
        if ($.browser.msie) {
            this.keydown(function (e) {
                if (key(e) == 8) {
                    var val = this.value;

                    if (val.length == 0 && defaults.previous)
                        defaults.previous.focus();
                }
            });
        }

        return this.keypress(function (e) {
            if (key(e) == 8) {
                var val = this.value;

                if (val.length == 0 && defaults.previous)
                    defaults.previous.focus();
            }
        }).keyup(function (e) {
            var val = this.value;

            switch (defaults.format) {
                case 'text':
                    var pattern = new RegExp('[0-9]+', 'g');
                    var val = val.replace(pattern, '');
                    break;

                case 'alpha':
                    var pattern = new RegExp('[^a-zA-Z]+', 'g');
                    var val = val.replace(pattern, '');
                    break;

                case 'number':
                case 'numeric':
                    var pattern = new RegExp('[^0-9]+', 'g');
                    var val = val.replace(pattern, '');
                    break;

                case 'alphanumeric':
                    var pattern = new RegExp('[^0-9a-zA-Z]+', 'g');
                    var val = val.replace(pattern, '');
                    break;

                case 'all':
                default:
                    break;
            }

            if (defaults.nospace) {
                pattern = new RegExp('[ ]+', 'g');
                val = val.replace(pattern, '');
            }

            if (defaults.uppercase)
                val = val.toUpperCase();

            if (defaults.lowercase)
                val = val.toLowerCase();

            this.value = val;

            /**
            * Do not auto tab when the following keys are pressed
            * 8:	Backspace
            * 9:	Tab
            * 16:	Shift
            * 17:	Ctrl
            * 18:	Alt
            * 19:	Pause Break
            * 20:	Caps Lock
            * 27:	Esc
            * 33:	Page Up
            * 34:	Page Down
            * 35:	End
            * 36:	Home
            * 37:	Left Arrow
            * 38:	Up Arrow
            * 39:	Right Arrow
            * 40:	Down Arroww
            * 45:	Insert
            * 46:	Delete
            * 144:	Num Lock
            * 145:	Scroll Lock
            */
            var keys = [8, 9, 16, 17, 18, 19, 20, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 144, 145];
            var string = keys.toString();

            if (string.indexOf(key(e)) == -1 && val.length == defaults.maxlength && defaults.target)
                defaults.target.focus();
        });
    };

})(jQuery);
 //]]>






    
