﻿var cookieExpiresDays = 1;

/*
function AddToSelection(vehicleId, selectionCookieName){
    var cookie = Utilities_getCookie(selectionCookieName);
    var isContain = false;
    if (cookie != null && typeof(cookie) != "undefined" && cookie != "") {
        var s = cookie.split(",");
        for (var i=0; i < s.length; i++) {
            if (s[i] == vehicleId){
                isContain=true;
                break;
            }
        }
        if (isContain == false){
            cookie = cookie + ',' + vehicleId;
        }
    }
    else {
        cookie = vehicleId;
    }
    Utilities_Set_Cookie( selectionCookieName, cookie, cookieExpiresDays, '/', '');
}
function RemoveFromSelection(vehicleId, selectionCookieName) {
    var cookie = Utilities_getCookie(selectionCookieName);
    if (cookie != null && typeof (cookie) != "undefined" && cookie != "") {
        var s = cookie.split(",");
        var newValue = "";

        for (var i = 0; i < s.length; i++) {
            if (s[i] != vehicleId) {
                if (newValue != "") {
                    newValue = newValue + "," + s[i];
                }
                else {
                    newValue = s[i];
                }
            }
        }
    }
    Utilities_Set_Cookie(selectionCookieName, newValue, cookieExpiresDays, '/', '')
}
*/

function AddToComparator(vehicleId, comparatorCookieName, errorMsg)
{
    var cookie = Utilities_getCookie(comparatorCookieName);
    var isContain = false;
    if (cookie != null && typeof(cookie) != "undefined"&& cookie != "") {
        var s = cookie.split(",");
        if (s.length == 4){
            alert(errorMsg);
            return;
        }
        else{
            for (var i=0; i < s.length; i++) {
                if (s[i] == vehicleId){
                    isContain=true;
                    break;
                }
            }
        }
        if (isContain == false){
            cookie = cookie + ',' + vehicleId;
        }
    }
    else {
        cookie = vehicleId;
    }
    Utilities_Set_Cookie( comparatorCookieName, cookie, cookieExpiresDays, '/', '') 
}
function RemoveFromComparator(vehicleId, comparatorCookieName)
{
    var cookie = Utilities_getCookie(comparatorCookieName);
    if (cookie != null && typeof(cookie) != "undefined") {
        var s = cookie.split(",");
        var newValue = "";

        for (var i = 0; i < s.length; i++) {
            if (s[i] != vehicleId){
                if (newValue != ""){
                    newValue = newValue + "," + s[i];
                }
                else {
                    newValue = s[i];
                }
            }
        }
    }
    Utilities_Set_Cookie( comparatorCookieName, newValue, cookieExpiresDays, '/', '') 
}

function UpdateNumberOfComparator(comparatorCookieName){
    var cookie = Utilities_getCookie(comparatorCookieName);
    var count =0;
    if (cookie != null && typeof(cookie) != "undefined") {
        var s = cookie.split(",");
        count =  s.length;
    }
    var span = document.getElementById('spanMyComparator');
    if (span != "undefined" && span != null){
        span.innerHTML = "Comparateur Véhicules(" + count + ")";
    }
}

function UpdateRowHiddenInComparator(rowValue ,cookieName)
{
    var cookie = Utilities_getCookie(cookieName);
    var isContain = false;
    if (cookie != null && typeof(cookie) != "undefined"&& cookie != "") {
        var s = cookie.split(",");
         for (var i=0; i < s.length; i++) {
            if (s[i] == rowValue){
                isContain=true;
                break;
            }
        }
        if (isContain == false){
            cookie = cookie + ',' + rowValue;
        }
    }
    else {
        cookie = rowValue;
    }
    Utilities_Set_Cookie( cookieName, cookie, cookieExpiresDays, '/', '') 
}
