﻿
// Clear the default value in an input box
function clearText(thefield) {
    if (thefield.defaultValue==thefield.value)
        thefield.value = "";
} 

function handleEnter(e,triggerElementID) {
	//if the key pressed is "enter"
	if(e.keyCode==13) {	
		//if the user's browser is Mozilla's based, the first method is available since
		//their DOM implementation is more advanced than IE
		if (e.preventDefault)
		    {e.preventDefault();}
		else
    		{window.event.returnValue=false;}

		//Focus and click on the trigger
		document.getElementById(triggerElementID).focus(); 
		document.getElementById(triggerElementID).click();
	} else {
		return true;
	}
}

function rollOver(which) {
    which.src = which.src.replace('_of','_ov');
}

function rollOut(which) {
    which.src = which.src.replace('_ov','_of');
}


function CIVB_PopUPWindow(theURL) { 
  window.open(theURL,'civbPopUpWindow','scrollbars=yes,width=500,height=630');
}

function CIVBGlossaire_PopUPWindow(theURL) { 
  window.open(theURL,'civbPopUpWindow','scrollbars=yes,width=545,height=520');
}

function CIVBSendtoFriend_PopUPWindow(theURL) { 
  window.open(theURL,'civbPopUpWindow','scrollbars=yes,width=480,height=630');
}



if (!ToggleImages) {
    var ToggleImages = true;  // Uses images by default
}
if (!ToggleImageOpen) {
    var ToggleImageOpen = "url(../Images/btnToggleDown.gif)";  // Uses this image by default for the open button
}
if (!ToggleImageClose) {
    var ToggleImageClose = "url(../Images/btnToggleUp.gif)";  // Uses this image by default fot the close button
}
if (!ToggleCloseAll) {
    var ToggleCloseAll = true;  // By default, only one Toggle div can be opened
}

// Resize the images in the background

function expandMyBGmyBg(imgID) {
	
	var myWidth = document.body.clientWidth ;
	
	document.getElementById(imgID).style.width = myWidth + "px";
}


function toggleCloseAll(which, whichNotToClose) {
    // Close all Toggles
    // which = the div containing all the "ToggleContainer" classed Divs
    // l is the number of sibling "ToggleContainer"s
    l = which.childNodes.length;

    // We need to search all the siblings to close all the toggles
    for (i=0; i < l; i++) {
        // te = this element
        te = which.childNodes[i];

        if (te.className == "ToggleContainer" && te != whichNotToClose) {
            // We've found a sibbling, we need to search it for a "ToggleContent" to hide and
            // a "ToggleH2" to switch the +/- background
            // sl = number of elements in this toggleContainer
            sl = te.childNodes.length;
            for (j=0; j < sl; j++) {
            
                // tse = this sub-element
                tse = te.childNodes[j];
                if (te.childNodes[j].className) {
                    // hide this content
                    if (te.childNodes[j].className == "ToggleContent") {
                            te.childNodes[j].style.display = "none";
                    }
                    // Change this icon
                    if (te.childNodes[j].className == "ToggleH2" && ToggleImages) {
                         te.childNodes[j].style.backgroundImage = ToggleImageClose;
                    }
                }
            }               
        }
    }
}

function toggle(which) {
    // Close all Toggles before we open another
    if (ToggleCloseAll) {
        toggleCloseAll(which.parentNode.parentNode, which.parentNode); // Close all toggles EXCEPT this one
    }
    
    // Check all elements whithin this ToggleContainer    
    l = which.parentNode.childNodes.length;
    
    for (i = 0; i < l; i++) {
        cn = which.parentNode.childNodes[i];
        // Find the title h2 and the content div
        if (cn.className) { 
            if (cn.className == "ToggleH2") {
                title = which.parentNode.childNodes[i];
            }
            if (cn.className == "ToggleContent") {
                content = which.parentNode.childNodes[i];
            }
        }
    }

    // Toggle them on / off
    if (content.style.display != "inline") {
        content.style.display = "inline";
        if (ToggleImages) {
            title.style.backgroundImage = ToggleImageOpen;
            title.style.backgroundImage = ToggleImageOpen;
        }    
    } else {
        content.style.display = "none";
        if (ToggleImages) {
            title.style.backgroundImage = ToggleImageClose;
            title.style.backgroundImage = ToggleImageClose;
        }
    }
}

function openToggle(which) {
    // To Open a Toggle by it's ID
    // Assign an id to the ToggleH2 classed <h2> tag
    
    findElement = document.getElementById(which);
    toggle(findElement)
}


function insertImage() {
    ih = document.getElementById("DescriptionText").innerHTML.split(/<P>/gi);
    im = document.getElementById("image2").innerHTML;
    
    txt='';
    for(i=0; i < ih.length; i++) {
        if(i == ih.length - 2) {
            txt += im;
        }
        if (!document.all && i == 0) {
            txt +=  ih[i];
        } else {
            txt +=  "<P>" + ih[i];
        }
    }
    document.getElementById("DescriptionText").innerHTML = txt;
}

/************************************************
Script for the images in in the bottom left corner
**************************************************/

// Set up the image files to be used.
var theImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array.

theImages[0] = 'img0.gif'
theImages[1] = 'img1.gif'
theImages[2] = 'img2.gif'
theImages[3] = 'img3.gif'
theImages[4] = 'img4.gif'
theImages[5] = 'img5.gif'
theImages[6] = 'img6.gif'
theImages[7] = 'img7.gif'
theImages[8] = 'img8.gif'
theImages[9] = 'img9.gif'
theImages[10] = 'img10.gif'
theImages[11] = 'img11.gif'
theImages[12] = 'img12.gif'
theImages[13] = 'img13.gif'
theImages[14] = 'img14.gif'
theImages[15] = 'img15.gif'



// do not edit anything below this line

var j = 0
var p = theImages.length;
var whichImage = Math.round(Math.random()*(p-1));
function showImage(relativeRootLocation){
document.write('<img src="' + relativeRootLocation + '/Images/'+theImages[whichImage]+'">');
}

//  End -->
