﻿/**
* Fonction de récupération des paramètres GET de la page
* @return Array Tableau associatif contenant les paramètres GET
*/
function extractUrlParams() {
    var t = location.search.substring(1).split('&');
    var f = [];
    for (var i = 0; i < t.length; i++) {
        var x = t[i].split('=');
        f[x[0]] = x[1];
    }
    return f;
}

function updateStyle(styleToshow){

    var elt = document.documentElement;
    addStyle(elt,"morning","hide","show");
    addStyle(elt,"afternoon","hide","show");
    addStyle(elt,"night","hide","show");
    
    addStyle(elt,styleToshow,"show","hide");
}

function OnClientItemsRequesting(sender, e) {
    if (sender.get_appendItems())
        e.get_context().CustomText = "";
    else
        e.get_context().CustomText = sender.get_text();
}

function PressKey(sender, e) {
    var keyCode = e.get_domEvent().keyCode;
    if (keyCode == 13) {
        var btn = document.getElementById('btnCallForeCast');
        if (btn != null) {
            if (btn.getAttribute('onclick') == null) {
                if (btn.getAttribute('href')) document.location = btn.getAttribute('href');
            }
            else btn.onclick();

        }
    }
}

function addStyle(elt, curStyle ,newStyle,styleToDelete ){
    for( var i =0; i <  elt.childNodes.length ; i++){
        var curElt = elt.childNodes[i];
        if( hasClass(curElt, curStyle)  ){
             addClass(curElt, newStyle);
             if(styleToDelete) rmvClass(curElt, styleToDelete);
        }else{
             addStyle(curElt, curStyle ,newStyle, styleToDelete)
        }
    }
}

function rmvStyle(elt, curStyle ,newStyle){
    for( var i =0; i <  elt.childNodes.length ; i++){
        var curElt = elt.childNodes[i];
        if( hasClass(curElt, curStyle)  ){
             addClass(el, newStyle)
        }else{
             addStyle(curElt, curStyle ,newStyle)
        }
    }
}


// remove class name from attribut Class
function rmvClass(el, className) {
	if (!(el && el.className)) {
		return;
	}
	if(!hasClass(el, className)) return;
	var cls = el.className.split(" ");
	var pcls = className.split(" ");
	var ar = new Array();
	for (var i = 0; i < cls.length; i++) {
		var found = false;
			for(var j = 0; j < pcls.length && !found; j++ ){
				if (cls[i].search(pcls[j]) != -1) found = true;
			}
		if(!found)	ar[ar.length] = cls[i];
	}
	el.className = ar.join(" ");
};

// remove class name to attribut Class
function addClass(el, className) {
    if(!el) return;
    if(hasClass(el, className)) return;
	rmvClass(el, className);
	el.className += " " + className;
};

function hasClass(el, className){
	if (!(el && el.className)) {
		return false;
	}
	var cls = el.className.split(" ");
	for (var i = cls.length; i > 0;) {
		if (cls[--i] == className) {
			return true;
		}
	}
	return false;
}

