function open_pop_up(path, name, width, height)
{
    var centerWidth  = (window.screen.width - width) / 2;
    var centerHeight = 200;

    window.open(path, name, 'width=' + width + ', height=' + height + ', scrollbars=yes, left=' + centerWidth + ', top=' + centerHeight);

    return false;
}

//******* requiert jquery ********//

function resize_content(target)
{
	// left_section_content position and margin/padding
    var offset     = Number($(target).offset().top);
    var padTop     = $(target).css("padding-top") != undefined ? Number($(target).css("padding-top").replace("px", "")) : 0;
	var padBottom  = $(target).css("padding-bottom") != undefined ? Number($(target).css("padding-bottom").replace("px", "")) : 0;
	var margTop    = $(target).css("margin-top") != undefined ? Number($(target).css("margin-top").replace("px", "")) : 0;
	var margBottom = $(target).css("margin-bottom") != undefined ? Number($(target).css("margin-bottom").replace("px", "")) : 0;

	$(window).resize(function(){
		resizeWindow();
	});

	function resizeWindow()
	{
		// reset height property
		$(target).css("height", null);
		
		var section_height = $(window).height() - (offset + padTop + padBottom + margTop + margBottom);
		var current_height = $(target).height();

		if(current_height < section_height)
			$(target).css("height", section_height + "px");
		}

	resizeWindow();
}


/**
 *	Slideshow
 */
function slideSwitch(selector)
{
	var $active = $(selector+".active");

	if ( $active.length == 0 ) $active = $(selector+':last');

	// use this to pull the divs in the order they appear in the markup
	var $next =  $active.next().length ? $active.next() : $(selector+':first');

	// uncomment below to pull the divs randomly
	// var $sibs  = $active.siblings();
	// var rndNum = Math.floor(Math.random() * $sibs.length );
	// var $next  = $( $sibs[ rndNum ] );

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}


/**
 * Rezise background
 */
function resize_background(params)
{
	var minWidth  = params.minWidth;
	var minHeight = params.minHeight;

	$(params.image).css("width", "");
	$(params.image).css("height", "");

	var pageWidth  = $("body").width();
	var pageHeight = $("body").height();

	if(pageWidth < minWidth)
		pageWidth = minWidth;
	if(pageHeight < minHeight)
		pageHeight = minHeight;

	var w1 = 1300; //$(params.container).width();
	var h1 = 755; //$(params.container).height();
	
	var w2 = pageWidth;
	var h2 = w2 * h1 / w1;
	$(params.image).css("width", w2+"px");
	$(params.image).css("height", h2+"px");

	if (h2 < pageHeight)
	{
		h2 = pageHeight;
		$(params.image).css("height", h2+"px");
		w2 = w1 * h2 / h1;
		$(params.image).css("width", w2+"px");
	};
}

jQuery(document).ready(function()
{
	resizeParams = {container:"#background div.active",
					   image: "#background div img",
					   minWidth: 1000,
					   minHeight: 800};
	$(window).resize(function() {
		resize_background(resizeParams);
	});
	resize_content("#left_section_content");
	resize_background(resizeParams);

	//setTimeout("resize_background(resizeParams)", 100);
});

var dictionary                         = new Array();
dictionary["no_title"]                 = {en:"Please choose your title",  fr:"Veuillez choisir votre titre"};
dictionary["no_first_name"]            = {en:"Please enter your first name", fr:"Veuillez entrer votre pr&eacute;nom"};
dictionary["no_last_name"]             = {en:"Please enter your last name", fr:"Veuillez entrer votre nom"};
dictionary["no_email"]                 = {en:"Please enter your email",  fr:"Veuillez entrer votre courriel"};
dictionary["bad_email"]                = {en:"Please enter a valid email", fr:"Veuillez entrer un courriel valide"};
dictionary["no_shipping_address"]      = {en:"Please enter your shipping address", fr:"Veuillez entrer une adresse de livraison"};
dictionary["no_city"]                  = {en:"Please enter your city", fr:"Veuillez entrer votre ville"};
dictionary["no_province"]              = {en:"Please choose your province", fr:"Veuillez choisir votre province"};
dictionary["no_postal_code"]           = {en:"Please enter your postal code", fr:"Veuillez entrer votre code postal"};
dictionary["bad_postal_code"]          = {en:"Please enter a valid postal code (ex: A1A 1A1)", fr:"Veuillez entrer un code postal valide (ex: A1A 1A1)"};
dictionary["shipping_billing_address"] = {en:"Please choose if your shipping adress is the same as your billing address", fr:"Veuillez choisir si votre adresse de livraison est la m&ecirc;me que votre adresse de facturation"};
dictionary["no_billing_address"]       = {en:"Please enter your billing address", fr:"Veuillez entrer votre adresse de facturation"};
dictionary["no_billing_city"]          = {en:"Please enter your city", fr:"Veuillez entrer votre ville"};
dictionary["no_billing_province"]      = {en:"Please enter your province", fr:"Veuillez entrer votre province"};
dictionary["no_phone"]                 = {en:"Please enter your phone number", fr:"Veuillez entrer votre num&eacute;ro de t&eacute;l&eacute;phone"};
dictionary["bad_phone"]                = {en:"Please enter a valid phone number (###-###-####)", fr:"Veuillez entrer un num&eacute;ro de t&eacute;l&eacute;phone valide (###-###-####)"};
dictionary["no_quantity"]              = {en:"Please enter your desired quantity", fr:"Veuillez entrer votre quantit&eacute; d&eacute;sir&eacute;e"};
dictionary["no_product"]              = {en:"Please enter your desired product", fr:"Veuillez entrer votre produit d&eacute;sir&eacute;"};
dictionary["bad_quantity"]             = {en:"Please enter a valid quantity", fr:"Veuillez entrer une quantit&eacute; valide"};

function check_if_one_radio_button_is_selected(optionsList)
{
    for (var i = 0; i < optionsList.length; i++) 
    {
        if (optionsList[i].checked == true)
        {
            return true;
        }
    }

    return false;
}

function check_if_specific_field_is_valid(exp_reg, input_text)
{
    if (exp_reg.test(input_text) == true)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function check_if_value_is_not_empty(input_text)
{
    if (input_text == "")
    {
        return false;
    }
    else
    {
        return true;
    }
}

function display_or_hide(id, value)
{
    document.getElementById(id).style.display = value;
}

function getVar (nomVariable)
{
    var infos = location.href.substring(location.href.indexOf("?") + 1, location.href.length) + "&";

    if (infos.indexOf("#") != -1)
    {
        infos = infos.substring(0, infos.indexOf("#")) + "&";
    }

    nomVariable = nomVariable + "=";

    var variable = 0;    
    var taille   = nomVariable.length;

    if (infos.indexOf(nomVariable) != -1)
    {
        variable = infos.substring(infos.indexOf(nomVariable) + taille, infos.length).substring(0, infos.substring(infos.indexOf(nomVariable) + taille, infos.length).indexOf("&"));
    }

    return variable;
} 

function change_couleur (obj, couleur) 
{
    obj.style.borderColor = couleur;
    obj.style.borderWidth = "5px";
}

function validate_product_form(lang)
{
    var couleur_rouge = "#fe5c5c";
    var d               = document.form_contact;
    var exp_email       = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    var exp_postal_code = /^(([A-Za-z]\d[A-Za-z])\s{0,1}\d[A-Za-z]\d{1})$/;
    var exp_phone       = /^(\d{3}[-\s]?\d{3}[-\s]?\d{4})$/;
    
    if (check_if_one_radio_button_is_selected(new Array (d.rdo_miss, d.rdo_mister)) == false)
    {
        write_message(dictionary["no_title"][lang]);
        return false;
    }
    if (check_if_value_is_not_empty(d.txt_first_name.value) == false)
    {
        change_couleur(d.txt_first_name, couleur_rouge, "5px");
        write_message(dictionary["no_first_name"][lang]);
        //d.txt_first_name.focus();
        return false;
    }
    else 
        change_couleur(d.txt_first_name, "", "");
    if (check_if_value_is_not_empty(d.txt_last_name.value) == false)
    {
        change_couleur(d.txt_last_name, couleur_rouge, "5px");
        write_message(dictionary["no_last_name"][lang]);
        //d.txt_last_name.focus();
        return false;
    }
    else 
        change_couleur(d.txt_last_name, "", "");
    if (check_if_value_is_not_empty(d.txt_email.value) == false)
    {
        change_couleur(d.txt_email, couleur_rouge, "5px");
        write_message(dictionary["no_email"][lang]);
        //d.txt_email.focus();
        return false;
    }
    else 
        change_couleur(d.txt_email, "", "");
    if (check_if_specific_field_is_valid(exp_email, d.txt_email.value) == false)
    {
        change_couleur(d.txt_email, couleur_rouge, "5px");
        write_message(dictionary["bad_email"][lang]);
        //d.txt_email.focus();
        return false;
    }
    else 
        change_couleur(d.txt_email, "", "");
    if (check_if_value_is_not_empty(d.txt_phone.value) == false && check_if_value_is_not_empty(d.txt_phoneNight.value) == false)
    {
        change_couleur(d.txt_phone, couleur_rouge, "5px");
        change_couleur(d.txt_phoneNight, couleur_rouge, "5px");
        write_message(dictionary["no_phone"][lang]);
        //d.txt_phone.focus();
        return false;
    }
    else {
        change_couleur(d.txt_phone, "", "");
        change_couleur(d.txt_phoneNight, "", "");
    }
    if ((check_if_value_is_not_empty(d.txt_phone.value) == true && check_if_specific_field_is_valid(exp_phone, d.txt_phone.value) == false) || (check_if_value_is_not_empty(d.txt_phoneNight.value) == true && check_if_specific_field_is_valid(exp_phone, d.txt_phoneNight.value) == false))
    {
        change_couleur(d.txt_phone, couleur_rouge, "5px");
        change_couleur(d.txt_phoneNight, couleur_rouge, "5px");
        write_message(dictionary["bad_phone"][lang]);
        //d.txt_phone.focus();
        return false;
    }
    else {
        change_couleur(d.txt_phone, "", "");
        change_couleur(d.txt_phoneNight, "", "");
    }
    if (check_if_value_is_not_empty(d.txt_address.value) == false)
    {
        change_couleur(d.txt_address, couleur_rouge, "5px");
        write_message(dictionary["no_shipping_address"][lang]);
        //d.txt_address.focus();
        return false;
    }
    else 
        change_couleur(d.txt_address, "", "");
    if (check_if_value_is_not_empty(d.txt_city.value) == false)
    {
        change_couleur(d.txt_city, couleur_rouge, "5px");
        write_message(dictionary["no_city"][lang]);
        //d.txt_city.focus();
        return false;
    }
    else 
        change_couleur(d.txt_city, "", "");
    if (check_if_value_is_not_empty(d.quebec_province.options[d.quebec_province.selectedIndex].value) == false)
    {
        write_message(dictionary["no_province"][lang]);
        return false;
    }
    if (check_if_value_is_not_empty(d.txt_postal_code.value) == false)
    {
        change_couleur(d.txt_postal_code, couleur_rouge, "5px");
        write_message(dictionary["no_postal_code"][lang]);
        //d.txt_postal_code.focus();
        return false;
    }
    else 
        change_couleur(d.txt_postal_code, "", "");
    if (check_if_specific_field_is_valid(exp_postal_code, d.txt_postal_code.value) == false)
    {
        change_couleur(d.txt_postal_code, couleur_rouge, "5px");
        write_message(dictionary["bad_postal_code"][lang]);
        //d.txt_postal_code.focus();
        return false;
    }
    else 
        change_couleur(d.txt_postal_code, "", "");
    if (d.rdo_yes.checked == false && d.rdo_no.checked == false)
    {
        write_message(dictionary["shipping_billing_address"][lang]);
        return false;
    }
    if (d.rdo_no.checked == true)
    { 
        if (check_if_value_is_not_empty(d.txt_billing_address.value) == false)
        {
            write_message(dictionary["no_billing_address"][lang]);
            //d.txt_billing_address.focus();
            return false;
        }
        if (check_if_value_is_not_empty(d.txt_billing_city.value) == false)
        {
            write_message(dictionary["no_billing_city"][lang]);
            //d.txt_billing_city.focus();
            return false;
        }
        if (check_if_value_is_not_empty(d.quebec_province_billing.options[d.quebec_province_billing.selectedIndex].value) == false)
        {
            write_message(dictionary["no_billing_province"][lang]);
            return false;
        }
        if (check_if_value_is_not_empty(d.txt_billing_postal_code.value) == false)
        {
            write_message(dictionary["no_postal_code"][lang]);
            //d.txt_billing_postal_code.focus();
            return false;
        }
        if (check_if_specific_field_is_valid(exp_postal_code, d.txt_billing_postal_code.value) == false)
        {
            write_message(dictionary["bad_postal_code"][lang]);
            //d.txt_billing_postal_code.focus();
            return false;
        }
    }
    if (d.option_1.checked == false && d.option_2.checked == false && d.option_3.checked == false && d.option_4.checked == false)
    {
        write_message(dictionary["no_product"][lang]);
        //d.txt_quantity.focus();
        return false;
    }
    if (d.option_1.checked == true && check_if_value_is_not_empty(check_if_value_is_not_empty(d.txt_quantity_product_1.options[d.txt_quantity_product_1.selectedIndex].value)) == false)
    {
        write_message(dictionary["no_quantity"][lang]);
        return false;
    }
    if (d.option_2.checked == true && check_if_value_is_not_empty(check_if_value_is_not_empty(d.txt_quantity_product_2.options[d.txt_quantity_product_2.selectedIndex].value)) == false)
    {
        write_message(dictionary["no_quantity"][lang]);
        return false;
    }
    if (d.option_3.checked == true && check_if_value_is_not_empty(check_if_value_is_not_empty(d.txt_quantity_product_3.options[d.txt_quantity_product_3.selectedIndex].value)) == false)
    {
        write_message(dictionary["no_quantity"][lang]);
        return false;
    }
    if (d.option_4.checked == true && check_if_value_is_not_empty(check_if_value_is_not_empty(d.txt_quantity_product_4.options[d.txt_quantity_product_4.selectedIndex].value)) == false)
    {
        write_message(dictionary["no_quantity"][lang]);
        return false;
    }
    /*if (check_if_value_is_not_empty(check_if_value_is_not_empty(d.txt_quantity.options[d.txt_quantity.selectedIndex].value)) == false)
    {
        write_message(dictionary["no_quantity"][lang]);
        //d.txt_quantity.focus();
        return false;
    }*/

    return true;
}

function validate_book_form(lang)
{
    var couleur_rouge = "#fe5c5c";
    var d               = document.form_contact;
    var exp_email       = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    var exp_postal_code = /^(([A-Za-z]\d[A-Za-z])\s{0,1}\d[A-Za-z]\d{1})$/;
    var exp_phone       = /^(\d{3}[-\s]?\d{3}[-\s]?\d{4})$/;

    if (check_if_one_radio_button_is_selected(new Array (d.rdo_miss, d.rdo_mister)) == false)
    {
        write_message(dictionary["no_title"][lang]);
        return false;
    }
    if (check_if_value_is_not_empty(d.txt_first_name.value) == false)
    {
        change_couleur(d.txt_first_name, couleur_rouge, "5px");
        write_message(dictionary["no_first_name"][lang]);
        //d.txt_first_name.focus();
        return false;
    }
    else 
        change_couleur(d.txt_first_name, "", "");
    if (check_if_value_is_not_empty(d.txt_last_name.value) == false)
    {
        change_couleur(d.txt_last_name, couleur_rouge, "5px");
        write_message(dictionary["no_last_name"][lang]);
        //d.txt_last_name.focus();
        return false;
    }
    else 
        change_couleur(d.txt_last_name, "", "");
    if (check_if_value_is_not_empty(d.txt_email.value) == false)
    {
        change_couleur(d.txt_email, couleur_rouge, "5px");
        write_message(dictionary["no_email"][lang]);
        //d.txt_email.focus();
        return false;
    }
    else 
        change_couleur(d.txt_email, "", "");
    if (check_if_specific_field_is_valid(exp_email, d.txt_email.value) == false)
    {
        change_couleur(d.txt_email, couleur_rouge, "5px");
        write_message(dictionary["bad_email"][lang]);
        //d.txt_email.focus();
        return false;
    }
    else 
        change_couleur(d.txt_email, "", "");
    if (check_if_value_is_not_empty(d.txt_phone.value) == false && check_if_value_is_not_empty(d.txt_phoneNight.value) == false)
    {
        change_couleur(d.txt_phone, couleur_rouge, "5px");
        change_couleur(d.txt_phoneNight, couleur_rouge, "5px");
        write_message(dictionary["no_phone"][lang]);
        //d.txt_phone.focus();
        return false;
    }
    else {
        change_couleur(d.txt_phone, "", "");
        change_couleur(d.txt_phoneNight, "", "");
    }
    if ((check_if_value_is_not_empty(d.txt_phone.value) == true && check_if_specific_field_is_valid(exp_phone, d.txt_phone.value) == false) || (check_if_value_is_not_empty(d.txt_phoneNight.value) == true && check_if_specific_field_is_valid(exp_phone, d.txt_phoneNight.value) == false))
    {
        change_couleur(d.txt_phone, couleur_rouge, "5px");
        change_couleur(d.txt_phoneNight, couleur_rouge, "5px");
        write_message(dictionary["bad_phone"][lang]);
        //d.txt_phone.focus();
        return false;
    }
    else {
        change_couleur(d.txt_phone, "", "");
        change_couleur(d.txt_phoneNight, "", "");
    }
    if (check_if_value_is_not_empty(d.txt_address.value) == false)
    {
        change_couleur(d.txt_address, couleur_rouge, "5px");
        write_message(dictionary["no_shipping_address"][lang]);
        //d.txt_address.focus();
        return false;
    }
    else 
        change_couleur(d.txt_address, "", "");
    if (check_if_value_is_not_empty(d.txt_city.value) == false)
    {
        change_couleur(d.txt_city, couleur_rouge, "5px");
        write_message(dictionary["no_city"][lang]);
        //d.txt_city.focus();
        return false;
    }
    else 
        change_couleur(d.txt_city, "", "");
    if (check_if_value_is_not_empty(d.quebec_province.options[d.quebec_province.selectedIndex].value) == false)
    {
        write_message(dictionary["no_province"][lang]);
        return false;
    }
    if (check_if_value_is_not_empty(d.txt_postal_code.value) == false)
    {
        change_couleur(d.txt_postal_code, couleur_rouge, "5px");
        write_message(dictionary["no_postal_code"][lang]);
        //d.txt_postal_code.focus();
        return false;
    }
    else 
        change_couleur(d.txt_postal_code, "", "");
    if (check_if_specific_field_is_valid(exp_postal_code, d.txt_postal_code.value) == false)
    {
        change_couleur(d.txt_postal_code, couleur_rouge, "5px");
        write_message(dictionary["bad_postal_code"][lang]);
        //d.txt_postal_code.focus();
        return false;
    }
    else 
        change_couleur(d.txt_postal_code, "", "");
    if (d.rdo_yes.checked == false && d.rdo_no.checked == false)
    {
        write_message(dictionary["shipping_billing_address"][lang]);
        return false;
    }
    if (d.rdo_no.checked == true)
    { 
        if (check_if_value_is_not_empty(d.txt_billing_address.value) == false)
        {
            write_message(dictionary["no_billing_address"][lang]);
            //d.txt_billing_address.focus();
            return false;
        }
        if (check_if_value_is_not_empty(d.txt_billing_city.value) == false)
        {
            write_message(dictionary["no_billing_city"][lang]);
            //d.txt_billing_city.focus();
            return false;
        }
        if (check_if_value_is_not_empty(d.quebec_province_billing.options[d.quebec_province_billing.selectedIndex].value) == false)
        {
            write_message(dictionary["no_billing_province"][lang]);
            return false;
        }
        if (check_if_value_is_not_empty(d.txt_billing_postal_code.value) == false)
        {
            write_message(dictionary["no_postal_code"][lang]);
            //d.txt_billing_postal_code.focus();
            return false;
        }
        if (check_if_specific_field_is_valid(exp_postal_code, d.txt_billing_postal_code.value) == false)
        {
            write_message(dictionary["bad_postal_code"][lang]);
            //d.txt_billing_postal_code.focus();
            return false;
        }
    }
    if (check_if_value_is_not_empty(check_if_value_is_not_empty(d.txt_quantity.options[d.txt_quantity.selectedIndex].value)) == false)
    {
        write_message(dictionary["no_quantity"][lang]);
        //d.txt_quantity.focus();
        return false;
    }

    return true;
}

function get_param(value)
{
    if (typeof(params[value]) === "undefined")
    {
        return "";    
    }
    else
    {
        return params[value];
    }
}

function parse_query(query)
{
    var params = new Object ();
    var pairs  = query.split(/[;&]/);

    if (!query)
    {
        return params;
    }

    for (var i = 0; i < pairs.length; i++)
    {
        var key_val = pairs[i].split('=');

        if (!key_val || key_val.length != 2)
        {
            continue;
        }

        var key = unescape(key_val[0]);
        var val = unescape(key_val[1]);
        val = val.replace(/\+/g, ' ');
        params[key] = val;
    }
    return params;
}

function write_message(message)
{
    document.getElementById("display_message").innerHTML = message;
}

function check_if_quantity_is_visible(name)
{
    if ($("#" + name).hasClass("display_none") == true)
    {
        $("#" + name).removeClass("display_none");
        $("#" + name).addClass("display_block");
    }
    else if ($("#" + name).hasClass("display_block") == true)
    {
        $("#" + name).removeClass("display_block");
        $("#" + name).addClass("display_none");
    }
}

//******* requiert jquery ********//
