var date_URL = new Date();
date_URL.setDate(date_URL.getDate() + 0);
var visits = date_URL.toLocaleString() + "\t" + document.referrer;
var Anketa; 


function ReadCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
			if (begin != 0) 
				return (null);  
	} 
	else
		begin += 2;
		var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}

function createCookie(name, visits, expiredays) {
var todayDate = new Date();
var count = 0;
var str1 = "";

while (count <= visits.length)
{
	//count = str.indexOf("%",count);
	if (visits.substring(count,count+1) == "%") {
		count = count + 2;
		if (visits.substring(count-2,count) == "%A")
			str1 = str1 + "%u039" + visits.substring(count,count+1);
		if (visits.substring(count-2,count) == "%B")
			str1 = str1 + "%u040" + visits.substring(count,count+1);
		if (visits.substring(count-2,count) == "%C")
			str1 = str1 + "%u041" + visits.substring(count,count+1);
		if (visits.substring(count-2,count) == "%D")
			str1 = str1 + "%u042" + visits.substring(count,count+1);
		if (visits.substring(count-2,count) == "%E")
			str1 = str1 + "%u043" + visits.substring(count,count+1);
		if (visits.substring(count-2,count) == "%F")
			str1 = str1 + "%u044" + visits.substring(count,count+1);
	}
	else
		str1 = str1 + visits.substring(count,count+1);

	 
count++;
}


todayDate.setDate(todayDate.getDate() + expiredays);
document.cookie = name + "=" + unescape(str1) +"; expires=" + todayDate.toGMTString() + "; path=/;"
}

//function showHits() {


userCookie = ReadCookie("MKA_URL");
	if (userCookie == null)
		createCookie("MKA_URL", visits, 1000);
	else
		visits = userCookie;

//*******************************************************************
// Проверка правильности заполнения заявки на подписку или архивные номера
//*******************************************************************

function check_subscribe() {
	answer_str = "";
	if (!isValid(document.MainForm.Family.value)) {
		answer_str += "'Фамилия'. "
	}
	if (!isValid(document.MainForm.Name.value)) {
		answer_str += "'Имя'. "
	}
	if (!isValid(document.MainForm.Otr1.value)) {
		answer_str += "'Отрасль'. "
	}
	if (!isValid(document.MainForm.Company.value)) {
		answer_str += "'Компания'. "
	}
	if (!isValid(document.MainForm.Zip.value)) {
		answer_str += "'Индекс'. "
	}
	if (!isValid(document.MainForm.Country.value)) {
		answer_str += "'Страна'. "
	}
	if (!isValid(document.MainForm.City.value)) {
		answer_str += "'Город'. "
	}
	if (!isValid(document.MainForm.Address.value)) {
		answer_str += "'Улица, дом'. "
	}
	if (!isValid_Email(document.MainForm.Email.value)) {
		answer_str += "Укажите правильный E-mail.\n"
	}
	if (answer_str == "") {
		}
		else {
			alert("Заполните поля:\n"+answer_str);
			return false;
		}
}

//*******************************************************************
// Проверка правильности заполнения заявки на доступ к статьям
//*******************************************************************

function check_access() {
	answer_str = "";
	if (!isValid(document.MainForm.Family.value)) {
		answer_str += "'Фамилия'. "
	}
	if (!isValid(document.MainForm.Name.value)) {
		answer_str += "'Имя'. "
	}
	if (!isValid(document.MainForm.Otr1.value)) {
		answer_str += "'Отрасль'. "
	}
	if (!isValid(document.MainForm.Company.value)) {
		answer_str += "'Компания'. "
	}
	if (!isValid(document.MainForm.Post.value)) {
		answer_str += "'Должность'. "
	}
	if (!isValid_Email(document.MainForm.email.value)) {
		answer_str += "Укажите правильный E-mail.\n"
	}
	if (answer_str == "") {
		}
		else {
			alert("Заполните поля:\n"+answer_str);
			return false;
		}
}
//*******************************************************************
// Проверка правильности заполнения заявки на подписку или архивные номера
//*******************************************************************

function check_subscribe() {
	answer_str = "";
	if (!isValid(document.MainForm.Family.value)) {
		answer_str += "'Фамилия'. "
	}
	if (!isValid(document.MainForm.Name.value)) {
		answer_str += "'Имя'. "
	}
	if (!isValid(document.MainForm.Otr1.value)) {
		answer_str += "'Отрасль'. "
	}
	if (!isValid(document.MainForm.Company.value)) {
		answer_str += "'Компания'. "
	}
	if (!isValid(document.MainForm.Zip.value)) {
		answer_str += "'Индекс'. "
	}
	if (!isValid(document.MainForm.Country.value)) {
		answer_str += "'Страна'. "
	}
	if (!isValid(document.MainForm.City.value)) {
		answer_str += "'Город'. "
	}
	if (!isValid(document.MainForm.Address.value)) {
		answer_str += "'Улица, дом'. "
	}
	if (!isValid_Email(document.MainForm.Email.value)) {
		answer_str += "Укажите правильный E-mail.\n"
	}
	if (answer_str == "") {
		}
		else {
			alert("Заполните поля:\n"+answer_str);
			return false;
		}
}

//*******************************************************************
// Проверка правильности регистрации на мероприятие
//*******************************************************************

function check_action() {
	answer_str = "";

	if (!isValid(document.MainForm.Family.value)) {
		answer_str += "'Фамилия'. "
	}
	if (!isValid(document.MainForm.Name.value)) {
		answer_str += "'Имя'. "
	}
	if (!isValid(document.MainForm.City.value)) {
		answer_str += "'Город'. "
	}
	if (!isValid(document.MainForm.Otr1.value)) {
		answer_str += "'Отрасль'. "
	}
	if (!isValid(document.MainForm.Company.value)) {
		answer_str += "'Организация'. "
	}
	if (!isValid_Email(document.MainForm.Email.value)) {
		answer_str += "\nУкажите правильный E-mail."
	}
	if (answer_str == "") {
		}
		else {
			alert("Заполните поля:\n"+answer_str);
			return false;
		}
}

//*******************************************************************
// Проверка правильности регистрации URL
//*******************************************************************

function check_URLS() {
	answer_str = "";

	if (!isValid(document.MainForm.name.value)) {
		answer_str += "'Название ресурса'. "
	}
	if (!isValid(document.MainForm.url.value)) {
		answer_str += "'URL'. "
	}
	if (!isValid(document.MainForm.description.value)) {
		answer_str += "'Описание ресурса'. "
	}
	if (!isValid(document.MainForm.type.value)) {
		answer_str += "'Тип ресурса'. "
	}
	if (answer_str == "") {
		}
		else {
			alert("Заполните поля:\n"+answer_str);
			return false;
		}
}

//*******************************************************************
// Проверка заполнения поля
//*******************************************************************
function isValid(str) {
	//check for blank field
	if (str == "") {
		return false
	}
	return true
}
//*******************************************************************
// Проверка правильности ввода E-Mail
//*******************************************************************

function check_Email() {
	answer_str = "";
	if (!isValid_Email(document.Email_Form.email.value)) {
		answer_str = "E-Mail."
	}
	if (!isValid(document.Email_Form.fio.value)) {
		answer_str += "ФИО."
	}
	if (!isValid(document.Email_Form.company.value)) {
		answer_str += "Организация."
	}
	if (!isValid(document.Email_Form.Post.value)) {
		answer_str += "Должность."
	}
	if (answer_str == "") {
		}
		else {
			alert("Заполните поля:\n"+answer_str);
			return false;
		}
}
//*******************************************************************
// Проверка правильности ввода E-Mail
//*******************************************************************
function isValid_Email(str) {
	//check for blank field
	if (str == "") {
		return false
	}
	//check for '@' sign
	for (var i=0; i<str.length; i++) {
		var ch=str.charAt(i);
		if (ch == "@") {
			return true
			}
		}
		return false
}


