function MM_swapImgRestore() { //v3.0
    var i,x,a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_findObj(n, d) { //v4.01
    var p,i,x;
    if (!d) d = document;
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n];
    for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n);
    return x;
}

function MM_swapImage() { //v3.0
    var i,j = 0,x,a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) {
            document.MM_sr[j++] = x;
            if (!x.oSrc) x.oSrc = x.src;
            x.src = a[i + 2];
        }
}

function goDropDown(strForm, strElement) {
    var objElement = eval('document.' + strForm + '.' + strElement);
    var objElementValue = objElement[objElement.selectedIndex].value;
    if (objElementValue != "") {
        window.location = objElementValue;
    }
}

function returnParent(strURL) {
    if (window.opener) {
        window.opener.location = strURL;
    }
    else if (window.parent) {
        window.parent.location = strURL;
    }
    window.close();
}

//GLOBAL POPUP
var objChildWindow;
function doChildWindow(strURL, objWin, strOptions) {
    //check for open windows and close them
    if (objChildWindow && objChildWindow.closed == false) {
        objChildWindow.close();

        objChildWindow = window.open(strURL, objWin, strOptions);
        objChildWindow.focus();
    }
    else {
        objChildWindow = window.open(strURL, objWin, strOptions);
        objChildWindow.focus();
    }
}

function openPrintPage(strURL) {
    var strOptions;
    strOptions = "toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no,left=100,top=100,width=620,height=500";

    doChildWindow(strURL, 'child_window', strOptions);
    objChildWindow.focus();
}

//GLOBAL NEW WINDOW
function openNewWin(strURL, intWidth, intHeight) {
    var strOptions;
	//check for parameters and set defaults
    if ((intWidth == '') || (intHeight == '')) {
        strOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=100,top=100,width=615,height=345";
    }
    else {
        intWidth += 45;
        intHeight += 45;
        strOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=100,top=100,width=" + intWidth + ",height=" + intHeight;
    }
    doChildWindow(strURL, 'child_window', strOptions);
    objChildWindow.focus();
}

//VIEW LARGE IMAGE
function openNewImgWin(strImg, strTitle, intWidth, intHeight, strClose) {
    var strOptions;
    var imgObj;

    if (strClose == '')
    {
        strClose = "Close window";
    }
	//check for parameters and set defaults
    if ((intWidth == '') || (intHeight == '')) {
        strOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=100,top=100,width=400,height=400";
    }
    else {

        imgObj = new Image();
        imgObj.src = strImg;
        if (imgObj.width != 0) {
            intWidth = imgObj.width;
            intWidth += 45;
        }
        if (imgObj.height != 0) {
            intHeight = imgObj.height;
            intHeight += 45;
        }
        strOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=100,top=100,width=" + intWidth + ",height=" + intHeight;
    }
	//check for browser and execute
    if (!(objBrowser.bMacNN4)) {
        doChildWindow('', 'child_window' + intWidth, strOptions);
        var heightFix = 0;
        if (navigator.userAgent.indexOf("Firefox")!=-1) {
            heightFix = 20;
        }
        var strHTML;
        strHTML = '<html><head><title>' + strTitle + '</title></head><body marginwidth="10" marginheight="10" leftmargin="10" topmargin="10" alink="#999999" vlink="#666666" bgcolor="#ffffff"><font face="verdana" size="1">';
        strHTML += '<div align="center"><img src="' + strImg + '" onload="javascript:window.resizeTo(this.width + 50, this.height + 100 + heightFix);"/></div>';
        strHTML += '<div align="right"><a href="javascript:window.close();"><font color="#000000">' + strClose + '</font></a></div></font></body></html>';
        objChildWindow.document.open();
        objChildWindow.document.write(strHTML);
        objChildWindow.document.close();
    }
    else {
        doChildWindow(strImg, 'child_window', strOptions);
    }
	//focus the new window
    objChildWindow.focus();
}

//EMAIL NEWS LETTER EMAIL VALIDATE
function checkInputEmail(theForm) {
    return checkInputEmailWithMessage(theForm, "Please enter a valid email address");
}
function checkInputEmailWithMessage(theForm, errorMessage) {
    if ((theForm.enews.value == "") || (theForm.enews.value.indexOf("@") == -1) || (theForm.enews.value.indexOf(".") == -1)) {
        alert(errorMessage);
        return false;
    }
    return true;
}

function getURLForSwitchLanguage(lang)
{
    var url = location.href; // donn?es de la barre d'adresse
    if (url.indexOf('?') > -1)
        url += '&language_switch=' + lang;
    else
        url += '?language_switch=' + lang;
    location.href = url;
}


//hides the passed element if its value equals the indicator
function showHide(strForm, strSourceElement, strSourceIndicator, strDestinationElement) {
    var objForm = eval('document.' + strForm);
    if (objForm != null) {
        var objSourceElement = eval('document.' + strForm + '.' + strSourceElement);
        var objDestinationElement = eval('document.' + strForm + '.' + strDestinationElement);
        if (objSourceElement != null) {
            var objSourceElementValue = objSourceElement.value;
            if (objDestinationElement == null) {
                objDestinationElement = eval('document.getElementById("' + strDestinationElement + '")');
            }
            if (objSourceElementValue == strSourceIndicator) {
                objDestinationElement.style.display = '';
            } else {
                objDestinationElement.style.display = 'none';
            }
        }
    }
}

//displays the destinationElement if the sourceElement is empty, otherwise the form is submit
function doSubmit(strForm, strSourceElement, strDestinationElement) {
    var objSourceElement = eval('document.' + strForm + '.' + strSourceElement);
    var objSourceElementValue = objSourceElement.value;
    if ('' == objSourceElementValue) {
        var objDestinationElement = eval('document.' + strForm + '.' + strDestinationElement);
        if (objDestinationElement == null) {
            objDestinationElement = eval('document.getElementById("' + strDestinationElement + '")');
        }
        objDestinationElement.style.display = '';
    } else {
        var objForm = eval('document.getElementById("' + strForm + '")');
        objForm.submit();
    }
}

//sets the element to the given value
//also determines if form should be submit
function setElementValue(strForm, strSourceElement, strSourceValue, bnDoSubmit) {
    var objSourceElement = eval('document.' + strForm + '.' + strSourceElement);
    if (objSourceElement != null) {
        objSourceElement.value = strSourceValue;
    }
    if (bnDoSubmit) {
        var objForm = eval('document.getElementById("' + strForm + '")');
        objForm.submit();
    }
}

// Cookies utility functions.
var cookieValue = "test cookie";
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
                      ((expires) ? "; expires=" + expires.toGMTString() : "") +
                      ((path) ? "; path=" + path : "") +
                      ((domain) ? "; domain=" + domain : "") +
                      ((secure) ? "; secure" : "");
}
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else
        begin += 2;
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
        end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
                          ((path) ? "; path=" + path : "") +
                          ((domain) ? "; domain=" + domain : "") +
                          "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

