﻿/***********************************************
Function to treat specific menu Header function
************************************************/

/* WEB SITE selection */
function headerGoWebSite(listID) {
    var ctrl = document.getElementById(listID);
    if (ctrl != null) {
        if (ctrl.options[ctrl.selectedIndex].value != '') {
            window.location.href = ctrl.options[ctrl.selectedIndex].value;
            return true;
        }
    }
    return false;
}

/* SEARCH function */
function headerClearDefault(ctrl) {
    if (ctrl.defaultValue == "Critères de recherche") ctrl.value = "";
    ctrl.className = "AOG_hdrSearchOutput";
}

function headerSearchKey(ctrl, pageURL, e) {
    var kC = (document.layers) ? e.which : document.all ? event.keyCode : document.getElementById ? e.keyCode : null;
    if (kC == 13) {
        return headerSearchGo(ctrl.id, pageURL);
    } else {
        return true
    
}}

function headerSearchGo(criteriaID, pageURL) {

    var criteria = "";
    var utftext = "";
    
    // Extract criteria
    criteria = document.getElementById(criteriaID).value;
    
    // UTF-8 encoding
    criteria = criteria.replace(/\r\n/g, "\n");
    for (var n = 0; n < criteria.length; n++) {

        var c = criteria.charCodeAt(n);

		if (c < 128) {
		    utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) {
		    utftext += String.fromCharCode((c >> 6) | 192);
		    utftext += String.fromCharCode((c & 63) | 128);
		} else {
		    utftext += String.fromCharCode((c >> 12) | 224);
		    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
		    utftext += String.fromCharCode((c & 63) | 128);
		}

	}

    // Submit request
	window.location.href = pageURL + '&criteria=' + escape(utftext);

    return false;
}
