﻿imagens = "01,02,03"; // nomes das imagens
img_dir = "img/parceiros/";  // diretorio das imagens
tipo = ".gif";         // extensão das imagens
largura = 132;
altura = 72;
var expDias = 7;      // validade do cookie (dias)

var exp = new Date();
exp.setTime(exp.getTime() + (expDias * 24 * 60 * 60 * 1000));
nome_cookie = "imagem_rand";

function SetCookie(name, value) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape(value) +
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  ((path == null) ? "" : ("; path=" + path)) +
  ((domain == null) ? "" : ("; domain=" + domain)) +
  ((secure == true) ? "; secure" : "");
}

function GetCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return getCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}

function DeleteCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = GetCookie(name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function getCookieVal(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

valor = GetCookie(nome_cookie);
if (valor == null) {
    valor = imagens;
    SetCookie(nome_cookie, valor);
} else {
    valor = valor.split(",");
    retornar = "";
    limite = (valor.length - 1);
    for (i = 0; i <= limite; i++) {
        if (i > 0) {
            sep = ",";
            if (i < limite) {
                valor[i] = valor[i + 1];
            } else {
                valor[i] = ultimo;
            }
        } else {
            sep = "";
            ultimo = valor[i];
            valor[i] = valor[i + 1];
        }
        retornar += sep + valor[i];
    }
    DeleteCookie(nome_cookie);
    SetCookie(nome_cookie, retornar);
    imagens = retornar;
}

imagem = imagens.split(",");

function abreLink(src) {
    switch (src) {
        case 01:
            window.location.href = 'http://www.ciss.com.br';
            break;
        case 02:
            window.location.href = 'http://www.consisanet.com';
            break;
        case 03:
            window.location.href = 'http://www.econtabil.com';
            break;
        default:
            break;
    }
}
