﻿function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+ "; path=/" +"; domain=oktoberfesta.it";
}

function getCookie(Name) {
   var search = Name + "="
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search) 
      if (offset != -1) { // if cookie exists 
         offset += search.length 
         end = document.cookie.indexOf(";", offset) 
         if (end == -1) 
            end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      } 
   }
}
        var agenzia = 0;
        var str = document.referrer;
        var valore = str.indexOf(".capodanno.roma.it");
        if( valore > 0) {
            agenzia = 1;
        }
        var valore = str.indexOf(".viaggio-in-germania.de");
        if( valore > 0) {
            agenzia = 2;
        }
        var valore = str.indexOf(".tuttobaviera.it");
        if( valore > 0) {
            agenzia = 3;
        }
        var valore = str.indexOf(".monacobaviera.com");
        if( valore > 0) {
            agenzia = 4;
        }
        var valore = str.indexOf(".berlino.com");
        if( valore > 0) {
            agenzia = 5;
        }
        var valore = str.indexOf(".guidagermania.com");
        if( valore > 0) {
            agenzia = 6;
        }
        
        
    if (getCookie("busagenzia") == null) {
        if (getCookie("busagenzia") == 0) {
            setCookie("busagenzia", agenzia, 365);}
        else {
        setCookie("busagenzia", agenzia, 30);
        }
    }



