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("ASUTP_URL");
	if (userCookie == null)
		createCookie("ASUTP_URL", visits, 1000);
	else
		visits = userCookie;

//*******************************************************************
// Проверка правильности заполнения регистрационной формы
//*******************************************************************

function checkAll() {
	answer_str = "";
	if (!isValid(document.MainForm.login.value)) {
		answer_str += "'Login'. "
	}
	if (!isValid(document.MainForm.password.value)) {
		answer_str += "'Password'. "
	}
	if (!isValid(document.MainForm.company_rus.value)) {
		answer_str += "'Hазвание организации'. "
	}
	if (!isValid(document.MainForm.country.value)) {
		answer_str += "'Страна'. "
	}
	if (!isValid(document.MainForm.city.value)) {
		answer_str += "'Город'. "
	}
	if (!isValid(document.MainForm.address_rus.value)) {
		answer_str += "'Адрес офиса'. "
	}
	if (!isValid(document.MainForm.address_1_rus.value)) {
		answer_str += "'Адрес для писем'. "
	}
	if (!isValid(document.MainForm.telefon.value)) {
		answer_str += "'Телефон'. "
	}
	if (!isValid(document.MainForm.annotation_rus.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_contact() {
	answer_str = "";
	if (!isValid(document.MainForm.company_rus.value)) {
		answer_str += "'Hазвание организации'. "
	}
	if (!isValid(document.MainForm.company_rub.value)) {
		answer_str += "'Рубрика'. "
	}
	if (!isValid(document.MainForm.country.value)) {
		answer_str += "'Страна'. "
	}
	if (!isValid(document.MainForm.city.value)) {
		answer_str += "'Город'. "
	}
	if (!isValid(document.MainForm.address_rus.value)) {
		answer_str += "'Адрес'. "
	}
	if (!isValid(document.MainForm.telefon.value)) {
		answer_str += "'Телефон'. "
	}
	if (!isValid(document.MainForm.annotation_rus.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;
		}
}

//*******************************************************************
// Проверка заполнения поля
//*******************************************************************
function isValid(str) {
	//check for blank field
	if (str == "") {
		return false
	}
	return true
}
//*******************************************************************
// Проверка правильности ввода E-Mail
//*******************************************************************

function check_EMAIL() {
	answer_str = "Заполните следующие поля:\n";
	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 == "Заполните следующие поля:\n") {
		}
		else {
			alert(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
}

