
function t()
{
	alert('gggg');
    return false;

}

function verify (f)
{
	var msg;
	var empty = "";
    var errors = "";
	for(var i = 0; i < f.length; i++) 
	{
		var e = f.elements[i];
		
		if (((e.type == "text") || (e.type == "textarea") || (e.type == "password") || (e.type == "file")) && (e.required || e.allow || e.compare  || e.less))
		{
			if ((e.value == null) || (e.value == "") && (e.required || e.compare))
			{
				empty += "- Must complete " + e.id + ".\n";
            	continue;
			}
			if(e.required == 'c' || e.allow == 'c')
			{
				var valid = /[A-Za-z]/;
				var text = e.value
				var result = text.match(valid);
				if (result == null && text != "") 
				{
				errors += "- The field " + e.id + " must be a valid character.";
				errors += ".\n";
				} 
			}
			if(e.required == 'i' || e.allow == 'i')
			{
				var valid = /(^-?\d\d*$)/;
				var text = e.value
				var result = text.match(valid);
				if (result == null && text != "") 
				{
				errors += "- The field " + e.id + " only accepts numbers e.g: 5554446789";
				errors += ".\n";
				} 
			}
			if(e.required == 'n' || e.allow == 'n')
			{
				var valid = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
				var text = e.value
				var result = text.match(valid);
				if (result == null && text != "") 
				{
				errors += "- The field " + e.id + " must be numeric.";
				errors += ".\n";
				} 
			}
			if(e.required == 'm' || e.allow == 'm')
			{
				var valid = /^[_a-zA-Z0-9-](\.{0,1}[_a-zA-Z0-9-])*@([a-zA-Z0-9-]{2,}\.){0,}[a-zA-Z0-9-]{3,}(\.[a-zA-Z]{2,4}){1,2}$/;
				var text = e.value
				var result = text.match(valid);
				if (result == null && text != "") 
				{
				errors += "- The field " + e.id + " must be a valid e-mail.";
				errors += ".\n";
				} 
			}
			if(e.required == 'p' || e.allow == 'p')
			{
				var valid = /[0-9\(\)\-]/;
				var text = e.value;
				var result = text.match(valid);
				if (result == null && text != "") 
				{
				errors += "- The field " + e.id + " must be a correct phone number.";
				errors += ".\n";
				} 
			}
			if(e.required == 'd' || e.allow == 'd')
			{
				var valid = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
				var text = e.value;
				var result = text.match(valid);
				if (result == null && text != "") 
				{
				errors += "- The field " + e.id + " must be a valid date (mm/dd/yyyy).";
				errors += ".\n";
				} 
			}
			if(e.required == 'pr' || e.allow == 'pr')
			{
				var valid = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
				var text = e.value;
				var result = text.match(valid);
				if (result == null && text != "") 
				{
					errors += "- The field " + e.id + " must be a number.";
					errors += ".\n";
				} 
//				if (e.value < 0.1 || e.value > 100)
                if (e.value < 0)
				{
					errors += "- The field " + e.id + " must be greater than 0";
					errors += ".\n";
				} 
			}
			if(e.compare)
			{
				if(e.value != e.compare)
				{
					errors += "- Please verify your password";
					errors += ".\n";
				}
			}
			if(e.less)
			{
				if(parseInt(e.value,10) > parseInt(e.less,10))
				{
					errors += "- Range MIN must be less or equal than Range MAX";
					errors += ".\n";
				}
			}
			if(e.allow == 'f')
			{
				if (LimitAttach(e.value) != null) 
				{
				errors += LimitAttach(e.value);
				errors += ".\n";
				} 
			}
		}
	}
	if (errors || empty)
	{
		msg = empty + "\r\n" + errors;
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
	
}

function verify_ad_select_form()
{
	var msg;
	var empty = "";
    var errors = "";

	//numeric validator
	var valid = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

    var year_from = document.getElementById("year_from").value;
	var year_till = document.getElementById("year_till").value;
	
    if ( (year_from != "" && year_from.match(valid) == null) || (year_till != "" && year_till.match(valid) == null) )
	{
				empty += "- Поля для ввода года должны быть числовыми.\n";
	}
	
    if (year_from != "" && year_till != "" && year_from.match(valid) != null && year_till.match(valid) != null && parseInt(year_from,10) >= parseInt(year_till,10))	
    {
				empty += "- Год выпуска: значение поля ОТ должно быть меньше значения поля ДО.\n";
	}

    var price_from = document.getElementById("price_from").value;
	var price_till = document.getElementById("price_till").value;
	
    if ( (price_from != "" && price_from.match(valid) == null) || (price_till != "" && price_till.match(valid) == null) )
	{
				empty += "- Поля для ввода цены должны быть числовыми.\n";
	}
	
    if (price_from != "" && price_till != "" && price_from.match(valid) != null && price_till.match(valid) != null && parseInt(price_from,10) >= parseInt(price_till,10))	
    {
				empty += "- Цена: значение поля ОТ должно быть меньше значения поля ДО.\n";
	}

    var km_from = document.getElementById("km_from").value;
	var km_till = document.getElementById("km_till").value;
	
    if ( (km_from != "" && km_from.match(valid) == null) || (km_till != "" && km_till.match(valid) == null) )
	{
				empty += "- Поля для ввода пробега должны быть числовыми.\n";
	}
	
    if (km_from != "" && km_till != "" && km_from.match(valid) != null && km_till.match(valid) != null && parseInt(km_from,10) >= parseInt(km_till,10))	
    {
				empty += "- Пробег: значение поля ОТ должно быть меньше значения поля ДО.\n";
	}


	
	if (errors || empty)
	{
		msg = empty + "\r\n" + errors;
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
	
}

function verify_ad_form()
{
	var msg;
	var empty = "";
    var errors = "";

    if (document.getElementById("car_brand").value == "другая" && (document.getElementById("other_brand").value == "" || document.getElementById("other_brand").value == null))
	{
				empty += "- Введите марку автомобиля.\n";
	}
    if (document.getElementById("personal1").checked && 
	    ( (document.getElementById("contact_phone").value == "" || document.getElementById("contact_phone").value == null) &&
		  (document.getElementById("contact_email").value == "" || document.getElementById("contact_email").value == null)
	    )
	   )	
	{
				empty += "- Введите телефон и/или e-mail.\n";
	}


	if (errors || empty)
	{
		msg = empty + "\r\n" + errors;
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
	
}

function verify_ad_personal_form()
{
	var msg;
	var empty = "";
    var errors = "";

	var valid = /^[_a-zA-Z0-9-](\.{0,1}[_a-zA-Z0-9-])*@([a-zA-Z0-9-]{2,}\.){0,}[a-zA-Z0-9-]{1,}(\.[a-zA-Z]{2,4}){1,2}$/;
	var email = document.getElementById("contact_email").value;
	var result = email.match(valid);

    if (document.getElementById("car_brand").value == "другая" && (document.getElementById("other_brand").value == "" || document.getElementById("other_brand").value == null))
	{
				empty += "- Введите марку автомобиля.\n";
	}
    if ( (document.getElementById("contact_phone").value == "" || document.getElementById("contact_phone").value == null) &&
		 (document.getElementById("contact_email").value == "" || document.getElementById("contact_email").value == null)
	    )	
	{
				empty += "- Введите телефон и/или e-mail.\n";
	}

	if (result == null && email != "") 
	{
	errors += "- Введен некорректный адрес электронной почты.";
	errors += ".\n";
	} 

	if (errors || empty)
	{
		msg = empty + "\r\n" + errors;
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
	
}

function verify_pb_form()
{
	var msg;
	var empty = "";
    var errors = "";

    if (document.getElementById("volume").value == "" || document.getElementById("volume").value == null)
	{
				empty += "- Необходимо выбрать номер журнала.\n";
	}
    if (document.getElementById("rubric").value == "" || document.getElementById("rubric").value == null)
	{
				empty += "- Необходимо выбрать рубрику.\n";
	}
	if (document.getElementById("name").value == "" || document.getElementById("name").value == null)
	{
				empty += "- Введите заголовок статьи.\n";
	}
	if (document.getElementById("shorttext").value == "" || document.getElementById("shorttext").value == null)
	{
				empty += "- Введите аннотацию к статье.\n";
	}
	if (document.getElementById("date").value == "" || document.getElementById("date").value == null)
	{
				empty += "- Введите дату в формате 'гггг-мм-дд чч:мм:сс'.\n";
	}
	if (document.getElementById("author").value == "" || document.getElementById("author").value == null)
	{
				empty += "- Введите имя автора.\n";
	}
	if (CountMultipleSelected('themecats') == 0)
	{
				empty += "- Выберите тематическую категорию (не больше 3 категорий).\n";
	}
	if (CountMultipleSelected('themecats') > 3)
	{
				empty += "- Вы не можете выбирать более 3 категорий.\n";
	}
	
	if (errors || empty)
	{
		msg = empty + "\r\n" + errors;
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
	
}

function CountMultipleSelected(select_id)
{
   selects = document.getElementById(select_id);	  
   selected = 0;
   for(var i = 0; i < selects.length; i++) 
	{
		var e = selects.options[i];
		if (e.selected) selected++;
	}
   return selected;
}

function verify_fb_form()
{
	var msg;
	var empty = "";
    var errors = "";
	
	var valid = /^[_a-zA-Z0-9-](\.{0,1}[_a-zA-Z0-9-])*@([a-zA-Z0-9-]{2,}\.){0,}[a-zA-Z0-9-]{1,}(\.[a-zA-Z]{2,4}){1,2}$/;
	var email = document.getElementById("fb_email").value;
	var result = email.match(valid);

	if (document.getElementById("fb_name").value == "" || document.getElementById("fb_name").value == null)
	{
				empty += "- Введите имя.\n";
	}
	if (document.getElementById("fb_email").value == "" || document.getElementById("fb_email").value == null)
	{
				empty += "- Введите Ваш адрес электронной почты.\n";
	}
	if (document.getElementById("fb_text").value == "" || document.getElementById("fb_text").value == null)
	{
				empty += "- Введите текст Вашего сообщения.\n";
	}
	if (result == null && email != "") 
	{
	errors += "- Введен некорректный адрес электронной почты.";
	errors += ".\n";
	} 


	if (errors || empty)
	{
		msg = empty + "\r\n" + errors;
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
	
}

function verify_fb_subscribe_form()
{
	var msg;
	var empty = "";
    var errors = "";
	
	var valid = /^[_a-zA-Z0-9-](\.{0,1}[_a-zA-Z0-9-])*@([a-zA-Z0-9-]{2,}\.){0,}[a-zA-Z0-9-]{1,}(\.[a-zA-Z]{2,4}){1,2}$/;
	var email = document.getElementById("fb_email").value;
	var result = email.match(valid);

	if (document.getElementById("fb_surname").value == "" || document.getElementById("fb_surname").value == null)
	{
				empty += "- Введите Вашу фамилию.\n";
	}
	if (document.getElementById("fb_name").value == "" || document.getElementById("fb_name").value == null)
	{
				empty += "- Введите Ваше имя.\n";
	}

	if (document.getElementById("adr_index").value == "" || document.getElementById("adr_index").value == null)
	{
				empty += "- Заполните поле 'Индекс'.\n";
	}
	if (document.getElementById("adr_city").value == "" || document.getElementById("adr_city").value == null)
	{
				empty += "- Заполните поле 'Город'.\n";
	}
	if (document.getElementById("adr_street").value == "" || document.getElementById("adr_street").value == null)
	{
				empty += "- Заполните поле 'Улица'.\n";
	}
	if (document.getElementById("adr_build").value == "" || document.getElementById("adr_build").value == null)
	{
				empty += "- Заполните поле 'Дом'.\n";
	}
	if (document.getElementById("adr_apt").value == "" || document.getElementById("adr_apt").value == null)
	{
				empty += "- Заполните поле 'Квартира'.\n";
	}
	
	if (document.getElementById("fb_email").value == "" || document.getElementById("fb_email").value == null)
	{
				empty += "- Введите Ваш адрес электронной почты.\n";
	}
	if (result == null && email != "") 
	{
	errors += "- Введен некорректный адрес электронной почты.";
	errors += ".\n";
	} 


	if (errors || empty)
	{
		msg = empty + "\r\n" + errors;
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
	
}

function verify_banner_form()
{
	var msg;
	var empty = "";
    var errors = "";
	
	var valid = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	
	if (document.getElementById("banner_name").value == "" || document.getElementById("banner_name").value == null)
	{
				empty += "- Введите название баннера.\n";
	}
	if ( document.getElementById("banner_maxshows").value == "" || document.getElementById("banner_maxshows").value == null )
	{
				empty += "- Заполните поле максимального количества показов.\n";
	}
    if ( document.getElementById("banner_maxshows").value != "" && document.getElementById("banner_maxshows").value.match(valid) == null )
	{
				empty += "- Поле максимального количества показов должно быть числовым.\n";
	}
	
	if (document.getElementById("banner_date_start").value == "" || document.getElementById("banner_date_start").value == null)
	{
				empty += "- Введите дату начала показов в формате 'гггг-мм-дд чч:мм:сс'.\n";
	}
	if (document.getElementById("banner_date_end").value == "" || document.getElementById("banner_date_end").value == null)
	{
				empty += "- Введите дату конца показов в формате 'гггг-мм-дд чч:мм:сс'.\n";
	}

	if (document.getElementById("banner_type1").checked == false)
	{
				if (document.getElementById("banner_htmlcode").value == "" || document.getElementById("banner_htmlcode").value == null)
	            {
				   empty += "- Введите HTML-код.\n";
	            }
	} else {
	
				if (document.getElementById("banner_img").value == "" || document.getElementById("banner_img").value == null)
	            {
				   empty += "- Укажите путь к изображению баннера.\n";
	            }
				if (document.getElementById("banner_alt").value == "" || document.getElementById("banner_alt").value == null)
	            {
				   empty += "- Введите ALT-текст.\n";
	            }
				if (document.getElementById("banner_href").value == "" || document.getElementById("banner_href").value == null)
	            {
				   empty += "- Введите ссылку.\n";
	            }
	}

	if (errors || empty)
	{
		msg = empty + "\r\n" + errors;
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
	
}


function verify_banner_view_form()
{
	var msg;
	var empty = "";
    var errors = "";
	
	var valid = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	
	if (document.getElementById("banner_name").value == "" || document.getElementById("banner_name").value == null)
	{
				empty += "- Введите название баннера.\n";
	}
	if ( document.getElementById("banner_maxshows").value == "" || document.getElementById("banner_maxshows").value == null )
	{
				empty += "- Заполните поле максимального количества показов.\n";
	}
    if ( document.getElementById("banner_maxshows").value != "" && document.getElementById("banner_maxshows").value.match(valid) == null )
	{
				empty += "- Поле максимального количества показов должно быть числовым.\n";
	}
	
	if (document.getElementById("banner_date_start").value == "" || document.getElementById("banner_date_start").value == null)
	{
				empty += "- Введите дату начала показов в формате 'гггг-мм-дд чч:мм:сс'.\n";
	}
	if (document.getElementById("banner_date_end").value == "" || document.getElementById("banner_date_end").value == null)
	{
				empty += "- Введите дату конца показов в формате 'гггг-мм-дд чч:мм:сс'.\n";
	}

	if (document.getElementById("banner_type1").checked == false)
	{
				if (document.getElementById("banner_htmlcode").value == "" || document.getElementById("banner_htmlcode").value == null)
	            {
				   empty += "- Введите HTML-код.\n";
	            }
	} else {
	
				if (document.getElementById("banner_alt").value == "" || document.getElementById("banner_alt").value == null)
	            {
				   empty += "- Введите ALT-текст.\n";
	            }
				if (document.getElementById("banner_href").value == "" || document.getElementById("banner_href").value == null)
	            {
				   empty += "- Введите ссылку.\n";
	            }
	}

	if (errors || empty)
	{
		msg = empty + "\r\n" + errors;
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
	
}

function verify_aln_form()
{
	var msg;
	var empty = "";
    var errors = "";
	
	var valid = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	
	if (document.getElementById("link_name").value == "" || document.getElementById("link_name").value == null)
	{
				empty += "- Введите название.\n";
	}

	if (errors || empty)
	{
		msg = empty + "\r\n" + errors;
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
	
}

function verify_areaitem_form()
{
	var msg;
	var empty = "";
    var errors = "";
	
	var valid = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	
	
	var clicks = document.getElementById("ai_clicks").value;
	var shows = document.getElementById("ai_shows").value;
	
    if ( shows != "" && shows.match(valid) == null )
	{
				errors += "- Значение поля количества показов должно быть числовым.\n";
	}
    if ( clicks != "" && clicks.match(valid) == null )
	{
				errors += "- Значение поля количества кликов должно быть числовым.\n";
	}
	
	if ( clicks != "" && shows != "" && clicks.match(valid) != null && shows.match(valid) != null && parseInt(clicks,10) > parseInt(shows,10))	
    {
				errors += "- Количество кликов не должно быть больше количества показов баннера.\n";
	}
	
	if (document.getElementById("ai_shows").value == "" || document.getElementById("ai_shows").value == null)
	{
				empty += "- Введите количество показов.\n";
	}
	if (document.getElementById("ai_clicks").value == "" || document.getElementById("ai_clicks").value == null)
	{
				empty += "- Введите количество кликов.\n";
	}


	if (errors || empty)
	{
		msg = empty + "\r\n" + errors;
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
	
}


function verify_poll_form()
{
	var msg;
	var empty = "";
    var errors = "";
	var found = false;
	
	var question = document.getElementById('poll_question').value;
	if ( question == "" )
	{
		errors += "- Необходимо ввести вопрос.\n";
	}
	
	for(var i=1; i<=10; i++) {
	    //alert('answer'+i);
		var answer = document.getElementById('answer'+i).value;
	    if ( answer != "")
		{
				found = true;
				break;
		}
	}	
		
    if (!found)
	{
		errors += "- Необходимо ввести хотя бы один вариант ответа.\n";
	}

	if (errors || empty)
	{
		msg = empty + "\r\n" + errors;
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
	
}

function verify_polledit_form()
{
	var msg;
	var empty = "";
    var errors = "";
	
	var question = document.getElementById('poll_question').value;
	if ( question == "" )
	{
		errors += "- Необходимо ввести вопрос.\n";
	}
	
	for(var i=1; i<=10; i++) {
		var answer = document.getElementById('answer'+i);
	    if (answer != null && answer.value == "")
		{
				errors += "- Пустое значение не допустимо.\n";
				break;
		}

	}	
		
	if (errors || empty)
	{
		msg = empty + "\r\n" + errors;
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
	
}

