// scripts by SophieWeb http://sophieweb.com unless stated otherwise

function addBehaviour() {
}

function displayLayer(whichLayer,window) {
	if (window) {
		overlay = window.top.document.getElementById('overlay');
		layer = window.top.document.getElementById(whichLayer);
	}
	else {
		overlay = document.getElementById('overlay');
		layer = document.getElementById(whichLayer);
	}
	if (layer.style.display == "block") {
		overlay.style.display = "none";
		layer.style.display = "none";
	}
	else {
		overlay.style.display = "block";
		layer.style.display = "block";
	}
	
	/* faire une routine pour masquer tous les elements de formulaire sous le layer pour IE 6 */
}

function hideProducts() {
	if (document.getElementById('productNav').style.display == "block") {
		document.getElementById('productNav').style.display = "none";
		document.getElementById('mainNav').style.display = "block";
	}
	else {
		document.getElementById('productNav').style.display = "block";
		document.getElementById('mainNav').style.display = "none";
	}
}

function displayInfo(evnt,infoId) {
	getClickPosition(evnt);
	posClickTop = posClickTop-20;
   	document.getElementById(infoId).style.left = posClickLeft + "px";
	document.getElementById(infoId).style.top = posClickTop + "px";
	document.getElementById(infoId).style.display = "block";
}

function displayInfoDetail(evnt,infoId) {
	getClickPosition(evnt);
	posClickTop = posClickTop-20;
   	document.getElementById(infoId).style.left = "320px";
	document.getElementById(infoId).style.top = posClickTop + "px";
	document.getElementById(infoId).style.display = "block";
}

function displayInfoDetailTable(evnt,infoId) {
	getClickPosition(evnt);
	posClickTop = posClickTop-20;
   	document.getElementById(infoId).style.left = "215px";
	document.getElementById(infoId).style.top = posClickTop + "px";
	document.getElementById(infoId).style.display = "block";
}

function displayInfoFullWidth(evnt,infoId) {
	getClickPosition(evnt);
	posClickTop = posClickTop-20;
   	document.getElementById(infoId).style.left = (posClickLeft-150) + "px";
	document.getElementById(infoId).style.top = posClickTop + "px";
	document.getElementById(infoId).style.display = "block";
}

function displayFormulaLayer(evnt,layerId) {
	getClickPosition(evnt);
	posClickTop = posClickTop+15;
	document.getElementById(layerId).style.top = posClickTop + "px";
	document.getElementById(layerId).style.display = "block";
}

function displayFormulaLayerBottom(evnt,layerId) {
	getClickPosition(evnt);
	posClickTop = posClickTop-180;
	document.getElementById(layerId).style.top = posClickTop + "px";
	document.getElementById(layerId).style.display = "block";
}

function getClickPosition(evnt) {
	posClickLeft = evnt.pageX || (evnt.clientX +
      (document.documentElement.scrollLeft || document.body.scrollLeft));
	posClickTop = evnt.pageY || (evnt.clientY +
      (document.documentElement.scrollTop || document.body.scrollTop));
    return posClickLeft, posClickTop;
}

function selectPicto(whichPicto) {
	document.getElementById('bubble01').focus();
	var listName = "list0" + whichPicto;
	if(document.getElementById(listName).className==''){
		for (i=1;i<7;i++) {
			listNameTemp = "list0" + i;
			document.getElementById(listNameTemp).className='';
		}
		document.getElementById(listName).className='selected';
		var bubblePosition = (17+60*eval((whichPicto-1))) + 'px';
		document.getElementById('bubble01').style.left=bubblePosition;
		targetDiv = document.getElementById('otherVehicles').getElementsByTagName('div');
		for (i=0;i<targetDiv.length;i++) {
			if (targetDiv[i].className=='pictoSlide') {
				if (whichPicto==5) {
					targetDiv[i].style.display='block';
				}
				else {
					targetDiv[i].style.display='none';
				}
			}
		}
	}
}

function selectPicto1(whichPicto) {
	var listName = "list1" + whichPicto;
	if(document.getElementById(listName).className==''){
		for (i=1;i<7;i++) {
			listNameTemp = "list1" + i;
			document.getElementById(listNameTemp).className='';
		}
		document.getElementById(listName).className='selected';
		var bubblePosition = (17+60*eval((whichPicto-1))) + 'px';
		document.getElementById('bubble11').style.left=bubblePosition;
		document.getElementById('bubble11').focus();
	}
}

function selectSlide(whichList,whichSlide) {
	bubbleName = "bubble" + whichList + "1";
	document.getElementById(bubbleName).focus();
	var listName = "list" + whichList + whichSlide;
	if(document.getElementById(listName).className==''){
		for (i=1;i<4;i++) {
			listNameTemp = "list" + whichList + i;
			document.getElementById(listNameTemp).className='';
		}
		document.getElementById(listName).className='selected';
		var bubblePosition = (28+83*eval((whichSlide-1))) + 'px';
		document.getElementById(bubbleName).style.left=bubblePosition;
	}
}

function selectSlideGradient(whichList,whichSlide) {
	bubbleName = "bubble" + whichList + "1";
	document.getElementById(bubbleName).focus();
	var listName = "list" + whichList + whichSlide;
	if(document.getElementById(listName).className==''){
		for (i=1;i<4;i++) {
			listNameTemp = "list" + whichList + i;
			document.getElementById(listNameTemp).className='';
		}
		document.getElementById(listName).className='selected';
		var bubblePosition = (58+140*eval((whichSlide-1))) + 'px';
		document.getElementById(bubbleName).style.left=bubblePosition;
	}
}

function selectSlideWide(whichList,whichSlide) {
	bubbleName = "bubble" + whichList + "1";
	document.getElementById(bubbleName).focus();
	var listName = "list" + whichList + whichSlide;
	if(document.getElementById(listName).className==''){
		for (i=1;i<5;i++) {
			listNameTemp = "list" + whichList + i;
			document.getElementById(listNameTemp).className='';
		}
		document.getElementById(listName).className='selected';
		var bubblePosition = (40+105*eval((whichSlide-1))) + 'px';
		document.getElementById(bubbleName).style.left=bubblePosition;
	}
}

function selectSlideHome(whichSlide) {
	document.getElementById('bubble21').focus();
	var listName = "list0" + whichSlide;
	if(document.getElementById(listName).className==''){
		for (i=1;i<5;i++) {
			listNameTemp = "list0" + i;
			document.getElementById(listNameTemp).className='';
		}
		document.getElementById(listName).className='selected';
		var bubblePosition = (40+105*eval((whichSlide-1))) + 'px';
		document.getElementById('bubble21').style.left=bubblePosition;
	}
}

var nabAdults = 2;
var nabChildren = 2;

function people(whichDiv,how) {
	if(whichDiv=="adult") {
		nabPeople = nabAdults;
	}
	else {
		nabPeople = nabChildren;
	}
	divName = whichDiv + "People";
	spanName = whichDiv + "Number";
	if ((nabPeople==1)&&(how=="minus")&&(whichDiv=="adult")) {
		alert("Impossible de supprimer le dernier adulte");
		return false;
	}
	if ((nabPeople==0)&&(how=="minus")&&(whichDiv=="children")) {
		alert("Impossible de supprimer");
		return false;
	}
	if ((nabPeople>9)&&(how=="plus")) {
		alert("Impossible d'ajouter");
		return false;
	}
	else {
		if ((how=='plus')&&(nabPeople<10)) {
			nabPeople++;
		}
		if (((how=='minus')&&(nabPeople>1)&&(whichDiv=="adult"))||((how=='minus')&&(nabPeople>0)&&(whichDiv=="children"))) {
			nabPeople--;
		}
		divWidth = (nabPeople*18) + "px";
		document.getElementById(divName).style.width = divWidth ;
		document.getElementById(divName).title = nabPeople ;
		document.getElementById(spanName).innerHTML = nabPeople ;
		if(whichDiv=="adult") {
			nabAdults = nabPeople;
		}
		else {
			nabChildren = nabPeople;
		}
	}
}

//addEvent(window, 'load', addBehaviour); 

/*
	CRIR - Checkbox & Radio Input Replacement
	Author: Chris Erwin (me[at]chriserwin.com)
	www.chriserwin.com/scripts/crir/

	Updated July 27, 2006.
	Jesse Gavin added the AddEvent function to initialize
	the script. He also converted the script to JSON format.
	
	Updated July 30, 2006.
	Added the ability to tab to elements and use the spacebar
	to check the input element. This bit of functionality was
	based on a tip from Adam Burmister.
*/

crir = {
    init: function() {
        arrLabels = document.getElementsByTagName('label');

        searchLabels:
        for (var i = 0; i < arrLabels.length; i++) {
            // get the input element based on the for attribute of the label tag
            if (arrLabels[i].getAttributeNode('for') && arrLabels[i].getAttributeNode('for').value != '') {
                labelElementFor = arrLabels[i].getAttributeNode('for').value;
                inputElement = document.getElementById(labelElementFor);
                if (inputElement == null) continue searchLabels;
            }
            else {
                continue searchLabels;
            }

            inputElementClass = inputElement.className;

            // if the input is specified to be hidden intiate it
            if (inputElementClass == 'crirHiddenJS') {
                inputElement.className = 'crirHidden';

                inputElementType = inputElement.getAttributeNode('type').value;

                // add the appropriate event listener to the input element
                if (inputElementType == "checkbox") {
                    if (inputElement.onclick != null)
                        inputElement.onclick.value = "crir.toggleCheckboxLabel(); " + inputElement.onclick.value;
                    else
                        inputElement.onclick = crir.toggleCheckboxLabel;
                }
                else {
                    if (inputElement.onclick != null)
                        inputElement.onclick.value = "crir.toggleRadioLabel(); " + inputElement.onclick.value;
                    else
                        inputElement.onclick = crir.toggleRadioLabel;
                }

                // set the initial label state
                if (inputElement.checked) {
                    if (inputElementType == 'checkbox') { arrLabels[i].className = 'checkbox_checked' }
                    else { arrLabels[i].className = 'radio_checked' }
                }
                else {
                    if (inputElementType == 'checkbox') { arrLabels[i].className = 'checkbox_unchecked' }
                    else { arrLabels[i].className = 'radio_unchecked' }
                }
            }
            else if (inputElement.nodeName != 'SELECT' && inputElement.getAttributeNode('type') && inputElement.getAttributeNode('type').value == 'radio') { // this so even if a radio is not hidden but belongs to a group of hidden radios it will still work.
                if (arrLabels[i].onclick != null)
                    arrLabels[i].onclick.value = "crir.toggleRadioLabel(); " + arrLabels[i].onclick.value;
                else
                    arrLabels[i].onclick = crir.toggleRadioLabel;

                if (inputElement.onclick != null)
                    inputElement.onclick.value = "crir.toggleRadioLabel(); " + inputElement.onclick.value;
                else
                    inputElement.onclick = crir.toggleRadioLabel;
            }
        }
    },

    findLabel: function(inputElementID) {
        arrLabels = document.getElementsByTagName('label');

        searchLoop:
        for (var i = 0; i < arrLabels.length; i++) {
            if (arrLabels[i].getAttributeNode('for') && arrLabels[i].getAttributeNode('for').value == inputElementID) {
                return arrLabels[i];
                break searchLoop;
            }
        }
    },

    toggleCheckboxLabel: function() {
       if (this.getAttributeNode('id') == null) return;
       labelElement = crir.findLabel(this.getAttributeNode('id').value);

        if (labelElement.className == 'checkbox_checked') {
            labelElement.className = "checkbox_unchecked";
        }
        else {
            labelElement.className = "checkbox_checked";
        }
    },

    toggleRadioLabel: function() {
        if (this.getAttributeNode('id') == null) return;
        clickedLabelElement = crir.findLabel(this.getAttributeNode('id').value);

        clickedInputElement = this;
        if (clickedInputElement.getAttributeNode('name') == null) return;
        
        clickedInputElementName = clickedInputElement.getAttributeNode('name').value;

        arrInputs = document.getElementsByTagName('input');

        // uncheck (label class) all radios in the same group
        for (var i = 0; i < arrInputs.length; i++) {
            inputElementType = arrInputs[i].getAttributeNode('type').value;
            if (inputElementType == 'radio') {
                inputElementName = arrInputs[i].getAttributeNode('name').value;
                inputElementClass = arrInputs[i].className;
                // find radio buttons with the same 'name' as the one we've changed and have a class of chkHidden
                // and then set them to unchecked
                if (inputElementName == clickedInputElementName && inputElementClass == 'crirHidden') {
                    inputElementID = arrInputs[i].getAttributeNode('id').value;
                    labelElement = crir.findLabel(inputElementID);
                    labelElement.className = 'radio_unchecked';
                }
            }
        }

        // if the radio clicked is hidden set the label to checked
        if (clickedInputElement.className == 'crirHidden') {
            clickedLabelElement.className = 'radio_checked';
        }
    },

    addEvent: function(element, eventType, doFunction, useCapture) {
        if (element.addEventListener) {
            element.addEventListener(eventType, doFunction, useCapture);
            return true;
        } else if (element.attachEvent) {
            var r = element.attachEvent('on' + eventType, doFunction);
            return r;
        } else {
            element['on' + eventType] = doFunction;
        }
    }
}

//crir.addEvent(window, 'load', crir.init, false);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
