function op_maat_options() {
    if ($('#intraEntreprise').attr('checked')=='checked') {
        $('#trainingRegProv').attr('disabled', 'disabled');
        $('#trainingRegProv').hide();
        $('#trainingRegProv_op').removeAttr('disabled');
        $('#trainingRegProv_op').show();
    }
    else {
        $('#trainingRegProv_op').attr('disabled', 'disabled');
        $('#trainingRegProv_op').hide();
        $('#trainingRegProv').removeAttr('disabled');
        $('#trainingRegProv').show();
    }
}

function changeLang(fileName, valueVar, query){
    if(valueVar != "none"){
        window.location = fileName + "?txtlang=" + valueVar + "&" + query;
    }
}

function changePage(fileName, valueVar, query){
    if(valueVar != "none"){
        window.location = fileName + query + "&start=" + valueVar;
    }
}

function displayHidden(idToDisplay)
{
    if (document.getElementById(idToDisplay).style.display == "none"
        || document.getElementById(idToDisplay).style.display == "") {
        document.getElementById(idToDisplay).style.display = "block";
    } else {
        document.getElementById(idToDisplay).style.display = "none";
    }
}

function displayHidden2(idToDisplay)
{
    if (document.getElementById(idToDisplay).style.display == "none") {
        document.getElementById(idToDisplay).style.display = "";
    } else {
        document.getElementById(idToDisplay).style.display = "none";
    }
}

function changeState(idToCheck)
{
    if (document.getElementById(idToCheck).checked == true)
        document.getElementById(idToCheck).checked = false;
    else
        document.getElementById(idToCheck).checked = true;
}

function uncheck(idToUncheck)
{
    document.getElementById(idToUncheck).checked = false;
}

function applyDefaultValue(field, defaultValue)
{
    var toSetDefault = document.getElementById(field);

    if (toSetDefault.selectedIndex == 0) {
        toSetDefault.selectedIndex = defaultValue;
    }
}

function calculatePrice(field, div, price, delivery)
{
    document.getElementById(div).innerHTML = Math.round((price*(document.getElementById(field).value))*100)/100;

    if (document.getElementById(delivery).value == 1){
        document.getElementById(div).innerHTML = parseFloat(document.getElementById(div).innerHTML)+6;
    }

}

function addDeliveryPrice(field, div)
{
    if (document.getElementById(field).value == 0){
        document.getElementById(div).innerHTML = parseFloat(document.getElementById(div).innerHTML)-6;
    } else {
        document.getElementById(div).innerHTML = parseFloat(document.getElementById(div).innerHTML)+6;
    }
}

function confirmDelete(id, target, orderBy, order){
    if (confirm("Do you really want to delete this conversation ?")) {
        window.location = target + ".php?id=" + id + "&delete=1&confirm=1&c=" + orderBy + "&o=" + order;
    }
}

function confirmDeleteImg(id, target, orderBy, order, idLogo){
    if (confirm("Do you really want to delete this picture ?")) {
        window.location = target + ".php?id=" + id + "&idlogo=" + idLogo + "&deletepic=1&c=" + orderBy + "&o=" + order;
    }
}

function confirmDeleteLogo(id, target, ref){
    if (confirm("Do you really want to delete this logo ?")) {
        window.location = target + ".php?id=" + id + "&ref=" + ref + "&deletepic=1";
    }
}

function deleteAnswer(id, idanswer, target, orderBy, order){
    if (confirm("Do you really want to delete this answer ?")) {
        window.location = target + ".php?id=" + id + "&idansw=" + idanswer + "&delete=1&confirm=1&c="+orderBy+"&o=" + order;
    }
}

function confirmPubl(id, idtopublish, publish, target, orderBy, order){
    if (publish == 1 && confirm("Do you really want to publish this message / profile ?")) {
        window.location = target + ".php?id=" + id + "&idpubl=" + idtopublish + "&publish=1&confirm=1&c="+orderBy+"&o=" + order;
    } else if (publish == 0 && confirm("Do you really want to unpublish this message / profile ?")) {
        window.location = target + ".php?id=" + id + "&idpubl=" + idtopublish + "&unpublish=1&confirm=1&c="+orderBy+"&o=" + order;
    } else if (publish == 2 && confirm("Do you really want to republish this message / profile ?")) {
        window.location = target + ".php?id=" + id + "&idpubl=" + idtopublish + "&republish=1&confirm=1&c="+orderBy+"&o=" + order;
    } else if (publish == 3 && confirm("Do you really want to publish this profile and send codes ?")) {
        window.location = target + ".php?id=" + id + "&idpubl=" + idtopublish + "&publish=2&confirm=1&c="+orderBy+"&o=" + order;
    } else if (publish == 4 && confirm("Do you really want to resend codes to this user?")) {
        window.location = target + ".php?id=" + id + "&idpubl=" + idtopublish + "&resend=1&confirm=1&c="+orderBy+"&o=" + order;
    } else if (publish == 5 && confirm("Do you really want to make inactive this logo ?")) {
        window.location = target + ".php?id=" + id + "&unpub=1";
    } else if (publish == 6 && confirm("Do you really want to make active this logo ?")) {
        window.location = target + ".php?id=" + id + "&pub=1";
    }
}

// FOR MULTIPLE FIELDS
function disableOrAbleFields(checkbox, fieldToAble, fieldToDisable)
{
    if (document.getElementById(checkbox).checked == true){
        document.getElementById(fieldToAble).disabled = false;
        document.getElementById(fieldToDisable).disabled = true;
    } else{
        document.getElementById(fieldToAble).disabled = true;
        document.getElementById(fieldToDisable).disabled = true;
    }
}

// For one field
function disableField(checkbox, field)
{
    if(document.getElementById(checkbox).checked == true) {
	document.getElementById(field).disabled = false;
    } 
    else {
	document.getElementById(field).disabled = true;
    }
}

// Disable province
function disableProvince(checkbox)
{
    if (document.getElementById(checkbox).checked == true){
        document.getElementById('selectProv').disabled = true;
        document.getElementById('trainingProv').disabled = true;
    } else{
        document.getElementById('selectProv').disabled = false;
        if (document.getElementById('selectProv').checked == true){
            document.getElementById('trainingProv').disabled = false;
        }
    }
}
