var expireDate = new Date();
var year = expireDate.getYear();
year = (year < 1900) ? year + 1900 : year;
expireDate.setYear(year + 3);

function cookieChck() {
  var allcookies = document.cookie;
  var detectCookie = allcookies.indexOf("necro_check=");
	if (detectCookie != -1) {

		var start = detectCookie + 19;
		var end = allcookies.indexOf(";",start);

		if (end==-1) end = allcookies.length;

		var userAge = allcookies.substring(start,end);
		userAge = unescape(userAge);

		var age = new Date(userAge);

		if (over17(age)){
			var playURL = window.location.href;
			var queryString = playURL.split("?")[1];

			if(queryString){
				jumpTo = queryString.split("jumpTo=")[1];
				contest = queryString.split("contest=")[1];
				play = queryString.split("play=")[1];
			}else{
				jumpTo = "none";
				contest = "none";
				play = "none";
			}

			if(!contest){
				contest = "none";
			}
			if(!play){
				play = "none";
			}
			if(!jumpTo){
				jumpTo = "none";
			}

			if(jumpTo == "qwerty"){
				location.replace(jumpTo+"/");
			}else if(contest == "yes"){
				location.replace("/");
			}else if(play == "qwerty"){
				location.replace("/");
			}else{
				location.replace("html");
			}
		}
		else
		{
			location.replace("noway.html");
		}
	}
	else {checkDate();}
}

function my_setCookie(nam, val, expire, domain, path) {
	var cookie_str = "";
	cookie_str += nam + "=" + escape(val);
	cookie_str += "; expires=" + expire.toGMTString();
	document.cookie = cookie_str;
};

function setCookie() {

	var user_age = new Date();

	user_age.setMonth(document.ValidFormNV.birthmonth.options[document.ValidFormNV.birthmonth.selectedIndex].value-1);
	user_age.setDate(document.ValidFormNV.birthday.options[document.ValidFormNV.birthday.selectedIndex].value);
	user_age.setFullYear(document.ValidFormNV.birthyear.options[document.ValidFormNV.birthyear.selectedIndex].value);

	my_setCookie("necro_check", user_age.toUTCString() , expireDate, ".necrovision-game.com", "/");
	my_setCookie("necro_visit", "0" , expireDate, ".necrovision-game.com", "/");
}

function over17(age) {
	var ageDate = new Date();
	var ageYear = ageDate.getFullYear()-17;
	ageDate.setFullYear(ageYear);
	if (age <= ageDate) {return true;}
	else {return false;}
}

function checkDate() {
	var age = new Date();
	age.setMonth(document.ValidFormNV.birthmonth.options[document.ValidFormNV.birthmonth.selectedIndex].value-1);
	age.setDate(document.ValidFormNV.birthday.options[document.ValidFormNV.birthday.selectedIndex].value);
	age.setYear(document.ValidFormNV.birthyear.options[document.ValidFormNV.birthyear.selectedIndex].value);

	if ((document.ValidFormNV.birthday.options[document.ValidFormNV.birthday.selectedIndex].value != 0) && (document.ValidFormNV.birthmonth.options[document.ValidFormNV.birthmonth.selectedIndex].value !=0) && (document.ValidFormNV.birthyear.options[document.ValidFormNV.birthyear.selectedIndex].value != 0))
	{
		setCookie();

		var playURL = window.location.href;
		var queryString = playURL.split("?")[1];
		var contest;

		if(queryString){
			jumpTo = queryString.split("jumpTo=")[1];
			contest = queryString.split("contest=")[1];
			play = queryString.split("play=")[1];
		}else{
			jumpTo = "none";
			contest = "none";
			play = "none";
		}

		if(!contest){
			contest = "none";
		}
		if(!play){
			play = "none";
		}
		if(!jumpTo){
			jumpTo = "none";
		}

		if (over17(age))
			{
				location.replace("html");
			}
		else
		{
			location.replace("noway.html");
		}
	}
}

function checkDate1() {
	var age = new Date();
	age.setMonth(document.ValidFormNV.birthmonth.options[document.ValidFormNV.birthmonth.selectedIndex].value-1);
	age.setDate(document.ValidFormNV.birthday.options[document.ValidFormNV.birthday.selectedIndex].value);
	age.setYear(document.ValidFormNV.birthyear.options[document.ValidFormNV.birthyear.selectedIndex].value);

	if ((document.ValidFormNV.birthday.options[document.ValidFormNV.birthday.selectedIndex].value != 0) && (document.ValidFormNV.birthmonth.options[document.ValidFormNV.birthmonth.selectedIndex].value !=0) && (document.ValidFormNV.birthyear.options[document.ValidFormNV.birthyear.selectedIndex].value != 0))
	{
		setCookie();

		var playURL = window.location.href;
		var queryString = playURL.split("?")[1];
		var contest;

		if(queryString){
			jumpTo = queryString.split("jumpTo=")[1];
			contest = queryString.split("contest=")[1];
			play = queryString.split("play=")[1];
		}else{
			jumpTo = "none";
			contest = "none";
			play = "none";
		}

		if(!contest){
			contest = "none";
		}
		if(!play){
			play = "none";
		}
		if(!jumpTo){
			jumpTo = "none";
		}

		if (over17(age))
			{
				location.replace("Flash");
			}
		else
		{
			location.replace("noway.html");
		}
	}
}

function checkDateLC() {
	var ageLC = new Date();
	ageLC.setMonth(document.ValidFormLC.birthmonthLC.options[document.ValidFormLC.birthmonthLC.selectedIndex].value-1);
	ageLC.setDate(document.ValidFormLC.birthdayLC.options[document.ValidFormLC.birthdayLC.selectedIndex].value);
	ageLC.setYear(document.ValidFormLC.birthyearLC.options[document.ValidFormLC.birthyearLC.selectedIndex].value);

	if ((document.ValidFormLC.birthdayLC.options[document.ValidFormLC.birthdayLC.selectedIndex].value != 0) && (document.ValidFormLC.birthmonthLC.options[document.ValidFormLC.birthmonthLC.selectedIndex].value !=0) && (document.ValidFormLC.birthyearLC.options[document.ValidFormLC.birthyearLC.selectedIndex].value != 0))
	{
		setCookie();

		var playURL = window.location.href;
		var queryString = playURL.split("?")[1];
		var contest;

		if(queryString){
			jumpTo = queryString.split("jumpTo=")[1];
			contest = queryString.split("contest=")[1];
			play = queryString.split("play=")[1];
		}else{
			jumpTo = "none";
			contest = "none";
			play = "none";
		}

		if(!contest){
			contest = "none";
		}
		if(!play){
			play = "none";
		}
		if(!jumpTo){
			jumpTo = "none";
		}

		if (over17(ageLC))
			{
				location.replace("html/index.php?deflang=lcen");
			}
		else
		{
			location.replace("noway.html");
		}
	}
}

function over18(ageLC) {
	var ageDateLC = new Date();
	var ageYearLC = ageDateLC.getFullYear()-18;
	ageDateLC.setFullYear(ageYearLC);
	if (ageLC <= ageDateLC) {return true;}
	else {return false;}
}