var clicable = true;

function activVid(which, switcher)
{
	switch(switcher)
	{
		case 'vids':
			str 	= "v";
			rep_str = 'act';
			counter = 4;
			i		= 0;
		break;
		
		case 'titles':
			str 	= "t";
			rep_str = 'sel';
			counter = 10;
			i		= 1;
		break;
		
		case 'faq':
			str 	= "fQuest_img_";
			rep_str = 'sel';
			counter = 4;
			i		= 1;
		break;
	}
	for(i=i; i<=counter; i++)
	{
		if( (document.getElementById(str+i).id == which.id && document.getElementById(str+i).className.search("selected") != -1 && switcher != 'vids') || document.getElementById(str+i).id != which.id)
		{
			
			if(document.getElementById(str+i).src.search("_"+rep_str) != -1)
			{
				document.getElementById(str+i).src = document.getElementById(str+i).src.replace("_"+rep_str, "_of");
			}
			document.getElementById(str+i).parentNode.style.fontWeight = 'normal';
			document.getElementById(str+i).className = document.getElementById(str+i).className.replace("selected", "");
		}
		else if(document.getElementById(str+i).id == which.id && document.getElementById(str+i).className.search("selected") == -1)
		{
			which.src = which.src.replace("_ov","_"+rep_str);
			which.parentNode.style.fontWeight = 'bold';
			which.className += " selected";
		}
		
		
		/*
		if(document.getElementById(str+i).id == which.id)
		{
			if(which.className.search("selected") != -1 && switcher != 'vids')
			{
				//alert("selected");
				which.src = which.src.replace("_"+rep_str,"_ov");
				which.className = which.className.replace(" selected", "");
			}
			else
			{
				which.src = which.src.replace("_ov","_"+rep_str);
				which.className += " selected";
				which.parentNode.style.fontWeight = 'bold';
			}
		}
		else
		{
			document.getElementById(str+i).src = document.getElementById(str+i).src.replace("_"+rep_str, "_of");
			document.getElementById(str+i).parentNode.style.fontWeight = 'normal';
			document.getElementById(str+i).className = document.getElementById(str+i).className.replace(" selected", "");
		}
		*/
	}
}

function is_in_array(my_str, my_array)
{
	//alert(my_str+'; '+my_array)
	var myJoin = "|" + my_array.join("|") + "|";
	return myJoin.indexOf("|"+my_str+"|");
}

function toggle_visible(show_this)
{
	
	//alert('toggle_visible - '+show_this);
	
	//var available_divs 	= new Array('no1', 'no2', 'no3', 'no4', 'no5', 'no6', 'no7', 'no8', 'no9', 'no10');

	if(clicable == true)
	{
		clicable = false;
		for(tvi=0; tvi<available_divs.length; tvi++)
		{
			my_element = document.getElementById(available_divs[tvi]);
			my_element_vis = my_element.style.display;
			var new_state = function(my_element)
			{
				my_element.style.display = 'block';
			}
			
			//alert(available_divs[tvi] + ', ' + show_this + ', ' + my_element_vis);
			
			if( available_divs[tvi] != show_this && my_element_vis != 'none') 
			{
				//alert(available_divs[i] + ' if');
				my_element.style.display = 'none';
			}
			else if(available_divs[tvi] == show_this && my_element_vis == 'none' ) 
			{
				myeffect = new Effect.toggle(available_divs[tvi],'appear');
				//setTimeout("my_element.style.display = 'block'", 500);
			}
		}
		setTimeout("clicable = true;", 500);
	}
}

function change_menu_state(my_element)
{
	//alert('change_menu_state - '+my_element);
	
	var this_parent = my_element.parentNode.parentNode;
	var child_count = this_parent.getElementsByTagName('li').length;
	var this_child;
	
	//alert(child_count);
	
	for(i=0; i<child_count; i++)
	{
		this_child = this_parent.getElementsByTagName('li')[i];
		if(this_child.className.indexOf('selected') != -1)
		{
			this_child.className = this_child.className.replace('selected', '');
		}
		
	}
	
	my_element.parentNode.className += ' selected';
	
}

/********** GALLERY FUNCTIONS **********/
function loadPicture(aIndex){
	var pictureHolder = document.getElementById('gallery1_container');
	pictureHolder.getElementsByTagName('img')[0].src = arrLargeImages[aIndex];
	currentPicture = aIndex;

/*	var imgMenu = document.getElementById('imgMenu'+aIndex);
    imgMenu.style["filter"] = "alpha(opacity=50)";
    imgMenu.style["-moz-opacity"] = 50/100;
    imgMenu.style["-khtml-opacity"] = 50/100;
    imgMenu.style["opacity"] = 50/100;
	*/
}
function nextPicture(){
	var nextPictureIndex = currentPicture + 1;
	if(nextPictureIndex > arrLargeImages.length - 1){
		nextPictureIndex = 1;
	}
	loadPicture(nextPictureIndex);
}
function prevPicture(){
	var prevPictureIndex = currentPicture - 1;
	if(prevPictureIndex === 0){
		prevPictureIndex = arrLargeImages.length - 1;
	}
	loadPicture(prevPictureIndex);
}

/********** MENU LOOP **********/
var currentMenuPosition = 1;
var intval = "";
function loopMenu(){
	toggle_visible('no'+currentMenuPosition);
	change_menu_state(document.getElementById('t'+currentMenuPosition));
	currentMenuPosition++;
	if(currentMenuPosition > available_divs.length){
		currentMenuPosition = 1;
	}
}

function loopStop(){
	if(intval != ""){
		window.clearInterval(intval);
	}
}

/********** INSCRIPTION **********/

function coutTotal (ligne)
{
    var coutForfait
    var coutForfait2
    var coutBanquet
    var coutTotal
    var nbBillet
    var billetF
    var billetB

    if (ligne == 'forfait')
    {
        var testspace = /^ $/
        if (isNaN(document.form_mpv.nombreForfait.value) || (testspace .test(document.form_mpv.nombreForfait.value)))
        {
            alert("Inscrire des chiffres seulement.");
            document.form_mpv.totalForfait.value = "0";
            document.form_mpv.nombreForfait.value = "0";
            document.form_mpv.grandTotal.value = "0";
        }
        else
        {
            if (document.form_mpv.nombreForfait.value != "")
            {
                if ((document.form_mpv.nombreForfait.value == "\b") ||  (document.form_mpv.nombreForfait.value == "\t") || (document.form_mpv.nombreForfait.value == "\r") || (document.form_mpv.nombreForfait.value == " "))
                {
                    document.form_mpv.totalForfait.value = "";
                    document.form_mpv.grandTotal.value = "";
                }
                else
                {
                    coutForfait = 2150 *parseInt( document.form_mpv.nombreForfait.value);
                    document.form_mpv.totalForfait.value = coutForfait + " $";
                    coutTotal = parseInt(document.form_mpv.totalBanquet.value) + coutForfait + parseInt(document.form_mpv.totalForfait2.value);
                    document.form_mpv.grandTotal.value = coutTotal + " $";
                    billetE = parseInt(document.form_mpv.nombreForfait2.value);
                    billetF = parseInt(document.form_mpv.nombreForfait.value);
                    billetB = parseInt(document.form_mpv.nombreBanquet.value);
                    nbBillets = billetF + billetB + billetE
                    document.form_mpv.totalBillets.value = nbBillets
                }
            }
            else
            {
                document.form_mpv.totalForfait.value = "0 $";
                document.form_mpv.grandTotal.value = "0 $";
            }
        }
    } // fin if forfait

    if (ligne == 'forfait2')
    {
        var testspace = /^ $/
        if (isNaN(document.form_mpv.nombreForfait2.value) || (testspace .test(document.form_mpv.nombreForfait2.value)))
        {
            alert("Inscrire des chiffres seulement.");
            document.form_mpv.totalForfait.value = "0";
            document.form_mpv.nombreForfait2.value = "0";
            document.form_mpv.grandTotal.value = "0";
        }
        else
        {
            if (document.form_mpv.nombreForfait2.value != "")
            {
                if ((document.form_mpv.nombreForfait2.value == "\b") ||  (document.form_mpv.nombreForfait2.value == "\t") || (document.form_mpv.nombreForfait2.value == "\r") || (document.form_mpv.nombreForfait2.value == " "))
                {
                    document.form_mpv.totalForfait2.value = "";
                    document.form_mpv.grandTotal.value = "";
                }
                else
                {
                    coutForfait2 = 1700 *parseInt( document.form_mpv.nombreForfait2.value);
                    document.form_mpv.totalForfait2.value = coutForfait2 + " $";
                    coutTotal = parseInt(document.form_mpv.totalBanquet.value) + coutForfait2 + parseInt(document.form_mpv.totalForfait.value);
                    document.form_mpv.grandTotal.value = coutTotal + " $";
                    billetE = parseInt(document.form_mpv.nombreForfait2.value);
                    billetF = parseInt(document.form_mpv.nombreForfait.value);
                    billetB = parseInt(document.form_mpv.nombreBanquet.value);
                    nbBillets = billetF + billetB + billetE
                    document.form_mpv.totalBillets.value = nbBillets
                }
            }
            else
            {
                document.form_mpv.totalForfait2.value = "0 $";
                document.form_mpv.grandTotal.value = "0 $";
            }
        }
    } // fin if forfait

    if(ligne == 'banquet')
    {
        var testspace = /^ $/
        if (isNaN(document.form_mpv.nombreBanquet.value) || (testspace .test(document.form_mpv.nombreBanquet.value)))
        {
            alert("Inscrire des chiffres seulement.");
            document.form_mpv.totalBanquet.value = "0";
            document.form_mpv.nombreBanquet.value = "0";
            document.form_mpv.grandTotal.value = "0";
        }
        else
        {
            if (document.form_mpv.nombreBanquet.value != "")
            {
                if ((document.form_mpv.nombreBanquet.value == "\b") ||  (document.form_mpv.nombreBanquet.value == "\t") || (document.form_mpv.nombreBanquet.value == "\r") || (document.form_mpv.nombreBanquet.value == " "))
                {
                    document.form_mpv.totalBanquet.value = "";
                    document.form_mpv.grandTotal.value = "";
                }
                else
                {
                    coutBanquet = 800 *parseInt( document.form_mpv.nombreBanquet.value);
                    document.form_mpv.totalBanquet.value = coutBanquet + " $";
                    coutTotal = parseInt(document.form_mpv.totalForfait.value) + coutBanquet + parseInt(document.form_mpv.totalForfait2.value);
                    document.form_mpv.grandTotal.value = coutTotal + " $";
                    billetE = parseInt(document.form_mpv.nombreForfait2.value);
                    billetF = parseInt(document.form_mpv.nombreForfait.value);
                    billetB = parseInt(document.form_mpv.nombreBanquet.value);
                    nbBillets = billetF + billetB + billetE
                    document.form_mpv.totalBillets.value = nbBillets
                }
            }
            else
            {
                document.form_mpv.totalBanquet.value = "0 $";
                document.form_mpv.grandTotal.value = "0 $";
            }
        }
    } // fin if banquet


}

function verifierSiVide(tx){
  for (var a=0; a < tx.length; a++){
	var caractere = tx.charAt(a);
	if((caractere != "") && (caractere != '\n') && (caractere != '\t')){
		return false;
	}
  }
  return true;
}

function pasVide(valeur)
{
    var v
    if (valeur == 'forfait')
    {
        v = verifierSiVide(document.form_mpv.nombreForfait.value)
        if (v == true)
        {
            document.form_mpv.nombreForfait.value = 0
            document.form_mpv.totalForfait.value = 0
            coutTotal ("forfait")
        }
    }
    if (valeur == 'forfait2')
    {
        v = verifierSiVide(document.form_mpv.nombreForfait2.value)
        if (v == true)
        {
            document.form_mpv.nombreForfait2.value = 0
            document.form_mpv.totalForfait2.value = 0
            coutTotal ("forfait2")
        }
    }
    if (valeur == 'banquet')
    {
        v = verifierSiVide(document.form_mpv.nombreBanquet.value)
        if (v == true)
        {
            document.form_mpv.nombreBanquet.value = 0
            document.form_mpv.totalBanquet.value = 0
            coutTotal ("banquet")
        }
    }
}

function isFormValid(){
    var nameField = document.form_mpv.name;
    var addressField = document.form_mpv.address;
    var cityField = document.form_mpv.city;
    var provinceField = document.form_mpv.province;
    var postalField = document.form_mpv.postal;
    var postalpat = /^(?!.*[DFIOQU])[A-Z][0-9][A-Z] [0-9][A-Z][0-9]$/;
    var phoneField = document.form_mpv.phone;
    var phonepat = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
    var emailField = document.form_mpv.email;
    var emailpat = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var reIsEn = new RegExp("lang=en", "g");
    var isEn = document.location.href.match(reIsEn);

    //--- NAME ---
    if (nameField.value === "" || nameField.value.length < 1) {
        if (!isEn) {
            nameField.value = "Veuillez indiquer votre nom complet";
        }
        else {
            nameField.value = "Please enter your full name";
        }
        nameField.style.color = "red";
        nameField.style.borderColor = "red";
        nameField.focus();

        return false;
    }
    if (nameField.style.color === "red") {
        nameField.style.color = "#000000";
        nameField.style.borderColor = "";
    }
    //--- ADDRESS ---
    if (addressField.value === "" || addressField.value.length < 5) {
        if (!isEn) {
            addressField.value = "Veuillez indiquer votre adresse";
        }
        else {
            addressField.value = "Please enter your address";
        }
        addressField.style.color = "red";
        addressField.style.borderColor = "red";
        addressField.focus();

        return false;
    }
    if (addressField.style.color === "red") {
        addressField.style.color = "#000000";
        addressField.style.borderColor = "";
    }
    //--- CITY ---
    if (cityField.value === "" || cityField.value.length < 2) {
        if (!isEn) {
            cityField.value = "Veuillez indiquer votre ville";
        }
        else {
            cityField.value = "Please enter your city";
        }
        cityField.style.color = "red";
        cityField.style.borderColor = "red";
        cityField.focus();

        return false;
    }
    if (cityField.style.color === "red") {
        cityField.style.color = "#000000";
        cityField.style.borderColor = "";
    }
    //--- PROVINCE ---
    if (provinceField.value === "" || provinceField.value.length < 2) {
        if (!isEn) {
            provinceField.value = "Veuillez indiquer votre province";
        }
        else {
            provinceField.value = "Please enter your province";
        }
        provinceField.style.color = "red";
        provinceField.style.borderColor = "red";
        provinceField.focus();

        return false;
    }
    if (provinceField.style.color === "red") {
        provinceField.style.color = "#000000";
        provinceField.style.borderColor = "";
    }
    //--- POSTAL CODE ---
    if (!postalpat.test(postalField.value)) {
        if (!isEn) {
            postalField.value = "Veuillez indiquer votre code postal";
        }
        else {
            postalField.value = "Please enter your postal code";
        }
        postalField.style.color = "red";
        postalField.style.borderColor = "red";
        postalField.focus();

        return false;
    }
    if (postalField.style.color === "red") {
        postalField.style.color = "#000000";
        postalField.style.borderColor = "";
    }

    //--- PHONE ---
    if (!phonepat.test(phoneField.value)) {
        if (!isEn) {
            phoneField.value = "Veuillez entrer un numéro valide";
        }
        else {
            phoneField.value = "Please enter a valid number";
        }
        phoneField.style.color = "red";
        phoneField.style.borderColor = "red";
        phoneField.focus();

        return false;
    }
    if (phoneField.style.color === "red") {
        phoneField.style.color = "#000000";
        phoneField.style.borderColor = "";
    }

    //--- EMAIL ---
	if (!emailpat.test(emailField.value)) {
		if (!isEn) {
			emailField.value = "L'adresse de courriel est erronée.";
		} else {
			emailField.value = "Incorrect email address";
		}
		emailField.style.color = "red";
		emailField.style.borderColor = "red";
		emailField.focus();

		return false;
	}
	if (emailField.style.color === "red") {
		emailField.style.color = "#000000";
		emailField.style.borderColor = "";
	}
    //return true;
    document.getElementById("form_mpv").submit();
    //document.commentform.submit();
}


/* Fixes for IE6, so the submenu will show/hide on mouseover/moseout when we're already in the "Programme" section. Worked without JS
   before we highlighted the current section in the menus :( */
function showsub(aObject){
	$list = aObject.getElementsByTagName('table')[0].getElementsByTagName('tr')[0].getElementsByTagName('td')[0].getElementsByTagName('ul')[0];
	$list.style.display = 'block';
}

function hidesub(aObject){
	$list = aObject.getElementsByTagName('table')[0].getElementsByTagName('tr')[0].getElementsByTagName('td')[0].getElementsByTagName('ul')[0];
	$list.style.display = 'none';
}