//Switch de langue

function switchLang(oldLang,newLang,campaignID) {
	var newUrl;
	var oldUrl;

	if (oldLang == "fr") {
		oldLang = "motovasion";
		newLang = "openroadprogram";
	} else {
		oldLang = "openroadprogram";
		newLang = "motovasion";
	}
	oldUrl=document.location.href;
	newUrl=oldUrl.replace(oldLang,newLang);
	if (oldUrl.indexOf("campaignid") != -1) {
		window.location.href=newUrl;
	} else {
		window.location.href=newUrl + "?campaignid=" + campaignID;
	}

}



function type_insurance_redirection() {
	window.location.href=window.document.type_insurance_form.type_insurance.options[window.document.type_insurance_form.type_insurance.selectedIndex].value ;
} 

function openpopup(url, windowtarget) {
    window.open(
        url, 
        windowtarget,
        'scrollbars=yes,width=430,height=500');
}
function openpopupprint(url, windowtarget) {
    window.open(
        url, 
        windowtarget,
        'scrollbars=yes,width=700,height=400');
}


/* BEGIN: [Number Randomizer v.1 :: Author: Addam Driver :: Date: 5/5/2008 ]
	** Disclaimer:  Use at your own risk, copyright Addam Driver 2008  
	** Example on calling this function:
	** randomizeMe(this, {maxNumber: 10, exempt: [5, 6,7,8]});
	** The Randomizer randomly generate a number from 0 to the "maximumNumber" you pass it.  
	** If it comes across any exempt numbers, it will start the script over until it finds one that doesn't match the exempt.
*/
function randomizeMe(me, options){
    var options = options || {}; // setup the options
    var imExempt = options.exempt || null; // capture the exempt numbers
    var maxNum = options.maxNumber || 0; // capture the maximum number to randomize	
    var rand_no = Math.floor(Math.random()*maxNum); // run the random numbers
    
    if(imExempt != null){ // check to see if there are any exempt numbers
        imExempt = imExempt.toString(); // turn the exemptions into a string
        for(i=0; i <= maxNum; i++){ // loop throught the set number
            if(imExempt.search(rand_no) != -1){ // check for exempt numbers			
                return randomizeMe(me, {exempt: imExempt, maxNumber: maxNum}); // start over 
            }
        }
    }    
    return rand_no;// return the new random number
} 


//A la fin du chargement du DOM
$(document).ready(function(){ 

	// Vertical-align middle pour le content de dropdown
 	topValue = ($("#dropdown").height() - $("#dropdown_content").height()) / 2;
 	if ($.browser.msie) {
 		topValue = topValue -2;
 	}
 	$("#dropdown_content").css({top: topValue + "px"})
 	$("#dropdown_content").css({display: "block"})
	
	// Enleve la barre du dernier item du footer_menu 
	$("#footer_menu li:last-child").css({background:"none"})
	
 	//Ajuste la hauteur de #content selon la hauteur de #right-column, si #right-column est plus haut que #content
	if ($("#right-column").height() > $("#content").height()) {
		hauteurVoulu = $("#content").height() + ($("#right-column").height()-$("#content").height()) + 10;
		$("#content").height(hauteurVoulu);
	}
	
	var dToday = new Date;
	if ($("body").attr("id") == "home") {
		//if (dToday.getMonth() > 1 && dToday.getFullYear() < 2012) {
			$("#box_newsletter").show();
			$("#next_events").hide()
		//}
	}
	
} );

//Anim photo header
$(document).ready(function() {
	$.fn.cycle.defaults = { 
		timeout:       9000,  // milliseconds between slide transitions (0 to disable auto advance) 
		speed:         1000,  // speed of the transition (any valid fx speed value) 
		next:          null,  // id of element to use as click trigger for next slide 
		prev:          null,  // id of element to use as click trigger for previous slide 
		before:        null,  // transition callback (scope set to element to be shown) 
		after:         null,  // transition callback (scope set to element that was shown) 
		height:       'auto', // container height 
		sync:          1,     // true if in/out transitions should occur simultaneously 
		fit:           0,     // force slides to fit container 
		pause:         0,     // true to enable "pause on hover" 
		delay:         0,     // additional delay (in ms) for first transition (hint: can be negative) 
		slideExpr:     null   // expression for selecting slides (if something other than all children is required) 
	}; 
    $('#header_photo').cycle();
    $('.header_texte').show();
});

//select active tab
$(document).ready(function() {
	var filePath = window.location.pathname; 
	var fileName = filePath.substr(filePath.lastIndexOf("/") + 1); 
	
	if (fileName.length > 0) {
		$('#newmenu li a').each(function(index) {
			var currentPage = $(this).attr("href");
			if (currentPage == fileName) {
				$(this).addClass('active');	
			}
			else {
				$(this).removeClass('active');	
			}
		});
	}
	
	$('#AB').hide();
	$('#ON').hide();
	$('#QC').hide();
	$('#OT').hide();
	
	$("#provinceSelected").change(function () {
		var province = $(this).val();
		
		if(province.length > 0) {
			
			$('#details > div').each(function(){ 							
				if ($(this).attr('id') == province) 
					$(this).fadeIn('slow').show();					
				else 
					$(this).hide();							
			});
			
		}		
	});	
	

});

