var  age_form_url='http://www.arma2.com/agegate/agegate.html';
var  age_form_fail_url='http://www.bistudio.com/';
var  age_cookie_name='bc';
var  age_cookie_return='url';
var  age_cookie_minage='ma';

function ageCheck() {

  if (location.href != age_form_url) {
    birthdate_ms = ageCookie(age_cookie_name);
    if (birthdate_ms == null) {
      ageSetCookie(age_cookie_return,escape(location.href),0);
      location.replace(age_form_url);
    } else {
      birthdate_ms = parseInt(birthdate_ms,10);
      mage=parseInt(ageCookie(age_cookie_minage),10);
      if (mage != null) {  
        if (!ageIsOver(mage, birthdate_ms)) {
          location.replace(age_form_fail_url);
        }
      }
    }
  }
}

function ageIsOver(min_age, birthdate_ms) {
  var deadline = new Date(birthdate_ms);
  deadline.setFullYear(deadline.getFullYear()+min_age);
  return new Date().getTime() > deadline.getTime();
}

function ageCookie(cookie_name) {
  var cookies = " "+document.cookie+";";
  var startpos = cookies.indexOf(" "+cookie_name+"=");
  if (startpos != -1) {
    startpos = startpos + (cookie_name.length) + 2;
    var endpos = cookies.indexOf(";",startpos);
    return cookies.substring(startpos,endpos);
  } else {
    return null;
  }
}

function ageSetCookie(cookie_name, cookie_value, persistent_minutes) {
  if (persistent_minutes != 0) {
    var expire_date = new Date( new Date().getTime()+(60000*persistent_minutes) ).toGMTString();
    document.cookie = cookie_name+"="+cookie_value+"; path=/; expires="+expire_date;
  } else {
    document.cookie = cookie_name+"="+cookie_value+";path=/";
  }
}
