// JavaScript Document
function tr_on(line) {
	line.bgColor = '#cbe0fb';
	}

function tr_off(line) {
	line.bgColor = '';
	}

function tr_off_pink(line) {
	line.bgColor = '#fff0f0';
	}


function relightButton(relight) {
    buttons = relight.parentNode.getElementsByTagName("a");
    for ( var i = 0; i < buttons.length; i++ ) {
        button = buttons[i];
        className = (relight == button) ? "relight" : "";
        button.className = className;
    }
}

function relightTab(relight) {
    buttons = relight.parentNode.getElementsByTagName("a");
    for ( var i = 0; i < buttons.length; i++ ) {
        button = buttons[i];

        button_id = button.id;
        if ( !button_id ) continue;

        if ( relight == button ) {
            className = "relight";
            style = "block";
        } else {
            className = "";
            style = "none";
        }

        button.className = className;
        document.getElementById("tab_" + button_id).style.display = style;
    }
}

function showTab(tab) {
    active_button = tab.parentNode.parentNode;
    buttons = active_button.parentNode.getElementsByTagName("div");
    for ( var i = 0; i < buttons.length; i++ ) {
        button = buttons[i];

        button_id = button.id;
        if ( !button_id ) continue;

        if ( active_button == button ) {
            className = "button_on";
            childClassName = "button_on_right";
            style = "block";
        } else {
            className = "button_off";
            childClassName = "";
            style = "none";
        }

        button.className = className;
        button.childNodes[0].className = childClassName;
        document.getElementById("tab_" + button_id).style.display = style;
    }
}

function showImage(tab) {
    active_button = tab.parentNode;
    buttons = active_button.parentNode.getElementsByTagName("div");
    for ( var i = 0; i < buttons.length; i++ ) {
        button = buttons[i];

        if ( button_id = button.id )
            document.getElementById("chart_" + button_id).style.display = (active_button == button) ? "block" : "none";
    }
}

function checkAmount(value) {
    if ( !value.match('^[0-9]+(,[0-9]{1,2}){0,1}$')) {
        alert("Un montant positif est attendu");
        return false;
    }
    return true;
}

function checkQuantity(value) {
    if ( !value.match('^[0-9]+$') ) {
        alert("Une quantité positive est attendue");
        return false;
    }
    return true;
}

function checkDate(string) {
    if ( !string.match('^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/(20[0-9]{2})$') ) {
        alert("La date est invalide , veuillez entrer une date au format valide(jj/mm/AAAA)");
        return false;
    }
    return true;
}

function checkTime(string) {

      var reg1=new RegExp("^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$", "g");
      if (string.match(reg1)) {
            //alert("L\'heure valide");
            return true;
      }
      else {
            alert("L\'heure est invalide, veuillez entrer une heure au format (hh:mm:ss)");
            return false;
      }
}

function showHide(element) {
    element.style.display = element.style.display == "none" ? "" : "none";
}

function popupWindow(url, width, height, top, left) {
    popup = window.open(
        url,
        'popup',
        'toolbar=no,location=no,directories=no,status=no,menubar=no,'
            + 'top=' + (top ? top : 100) + ','
            + 'left=' + (left ? left : 200) + ','
            + 'width=' + (width ? width : 900) +','
            + 'height=' + (height ? height : 700)
    );
    popup.focus();
}

function printWindow() {
	imprimer = window.open(
        document.location.href + '&MODE=PRINT',
        'imprimer',
        'top=0,left=0,resizable=yes,toolbar=no,scrollbars=yes,menubar=yes,location=no,statusbar=no,width=600,height=700'
    )
    imprimer.focus();
}

