(function($){
 $.fn.extend({

 	customStyle : function(options) {
	  if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
	  return this.each(function() {

			var currentSelected = $(this).find(':selected');
			$(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+currentSelected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
			var selectBoxSpan = $(this).next();
			var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));
			var selectBoxSpanInner = selectBoxSpan.find(':first-child');
			selectBoxSpan.css({display:'inline-block'});
			selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
			var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
			$(this).height(selectBoxHeight).change(function(){
				selectBoxSpanInner.text($('option:selected',this).text()).parent().addClass('changed');
			});

	  });
	  }
	}
 });
})(jQuery);

$(document).ready(function(){
	$('.mySelectBoxClass').customStyle();
});

	function on_check(rek,check){
                 if (!check){
	         var req = document.getElementById(rek);
                 req.style.display = 'none';
                }
                 else
                {
                 var req = document.getElementById(rek); 
                 req.style.display = 'block';
                }
  
               	}	

	function on_click_mail(rek,text){
		var req = document.getElementById(rek);
                if (req.style.display == 'none') 
                 {
                 req.style.display = 'block';
                 }
                 else  
                 {
                 req.style.display = 'none';
                 }
	}




function on(rek,text){
		var req = document.getElementById(rek);
		req.style.background = '#ebfadd'; 
                req.style.border = '1px solid #ff9900';
               if (req.value == text) {req.value = '';}
	}
	function off(rek,text){
		var req = document.getElementById(rek);
		req.style.background = '#f6f6f6'; 
                req.style.border = '1px solid #999999';
               if (req.value == '') {req.value = text;}
	}

function on1(rek,text){
		var req = document.getElementById(rek);
		req.style.background = '#ebfadd'; 
                req.style.border = '1px solid #ff9900';
                req.style.color = '#336600';
                if (req.value == text) {req.value = '';}
	}
	function off1(rek,text){
		var req = document.getElementById(rek);
		req.style.background = '#f6f6f6'; 
                req.style.border = '1px solid #999999';
                req.style.color = '#333333';
                if (req.value == '') {req.value = text;}
	}

	
	

$(document).ready(function()
{tables =$("div.copen:not(:has(h4[class=contentnews]))");
tables1 = $("div.copen:has(h4[class=contentnews])");
tables1.each(function(q) {this.id = "mytable_" + q;});
tables.each(function(q){
this.id = "mytable" + q;
var zag = $("#mytable_" + q).text();

$("#mytable"+q).wrap("<div class='toggler-c' title='"+zag+"'></div>");
});

$(".contentnews").each(function(i){
this.id = "myhead" + i;
$("#myhead"+i).append("<div class='toggler'></div>");
$("#myhead"+i).remove();
});
$('div.toggler-c').toggleElements( { fxAnimation:'easeOutBounce', fxSpeed:'slow', className:'toggler' } );
});




function _go() {
    location.href=document.getElementById('cat').options[document.getElementById('cat').selectedIndex].value;
}
function _go1() {
    location.href=document.getElementById('region').options[document.getElementById('region').selectedIndex].value;
}
function _go_site() {
    location.href=document.getElementById('go_site').options[document.getElementById('go_site').selectedIndex].value;
}

function searchCheck()
	{
				if ( document.formpoisk.search.value.length <= 2 || document.formpoisk.search.value == 'Название фирмы, товара или услуги')
		{
			alert('Заполнителе поле для поиска');
			return false;
		}

	
		return true;
	}


	
function addsiteCheck()
	{
	var err = "<span style='color:red'> Ошибка!</span>"
	
		if (document.add_site.login.value.length <= 2)
		{
			//alert('Вы не ввели логин');
			document.getElementById("login_err1").innerHTML=err;
			
			return false;
		}
		else
		{
			document.getElementById("login_err1").innerHTML="";
		}
		
		if ( document.add_site.password.value.length <= 3 )
		{
		document.getElementById("password_err1").innerHTML=err;
		//	alert('Вы не написали пароль');
			return false;
		}
		else
		{
			document.getElementById("password_err1").innerHTML="";
		}
		
		if ( document.add_site.add_name.value.length <= 3 )
		{
		document.getElementById("add_name_err1").innerHTML=err;
		//	alert('Вы не написали пароль');
			return false;
		}
		else
		{
			document.getElementById("add_name_err1").innerHTML="";
		}
		
		if ( document.add_site.tel.value.length <= 5 )
		{
		document.getElementById("tel_err1").innerHTML=err;
		//	alert('Вы не написали пароль');
			return false;
		}
		else
		{
			document.getElementById("tel_err1").innerHTML="";
		}
		
		
		if ( emailCheck(document.add_site.email.value) == false )
		{
		document.getElementById("email_err1").innerHTML=err;
		//	alert('Вы не ввели E-mail');
			return false;
		}
		else
		{
			document.getElementById("email_err1").innerHTML="";
		}

		if (document.add_site.reg_cat.value == 2)
		{
		
		if ( document.add_site.title_add.value.length <= 2 )
		{
		document.getElementById("title_add_err1").innerHTML=err;
		//	alert('Вы не написали пароль');
			return false;
		}
		else
		{
			document.getElementById("title_add_err1").innerHTML="";
		}
		
		if ( document.add_site.adress_add.value.length <= 2 )
		{
		document.getElementById("adress_add_err1").innerHTML=err;
		//	alert('Вы не написали пароль');
			return false;
		}
		else
		{
			document.getElementById("adress_add_err1").innerHTML="";
		}
		
		if ( document.add_site.tel_add.value.length <= 2 )
		{
		document.getElementById("tel_add_err1").innerHTML=err;
		//	alert('Вы не написали пароль');
			return false;
		}
		else
		{
			document.getElementById("tel_add_err1").innerHTML="";
		}
		
			if ( document.add_site.meta_k.value.length <= 5 )
		{
		document.getElementById("meta_k_err1").innerHTML=err;
		//	alert('Вы не написали пароль');
			return false;
		}
		else
		{
			document.getElementById("meta_k_err1").innerHTML="";
		}
		
				if ( document.add_site.description.value.length <= 10 )
		{
		document.getElementById("description_err1").innerHTML=err;
		//	alert('Вы не написали пароль');
			return false;
		}
		else
		{
			document.getElementById("description_err1").innerHTML="";
		}
		
			if ( document.add_site.text.value.length <= 20 )
		{
		document.getElementById("text_err1").innerHTML=err;
		//	alert('Вы не написали пароль');
			return false;
		}
		else
		{
			document.getElementById("text_err1").innerHTML="";
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		}
		else if (document.add_site.reg_cat.value == 1)
		{
		
		if ( document.add_site.title1.value.length <= 2 )
		{
		document.getElementById("title1_err1").innerHTML=err;
		//	alert('Вы не написали пароль');
			return false;
		}
		else
		{
			document.getElementById("title1_err1").innerHTML="";
		}
		}
		
		
		
		
		if ( document.add_site.domen.value.length <= 2 )
		{
		document.getElementById("domen_err1").innerHTML=err;
		//	alert('Вы не написали пароль');
			return false;
		}
		else
		{
			document.getElementById("domen_err1").innerHTML="";
		}
	
	
	
	
	
		return true;
	}	
	
	
	
	
	
	

	function commentsCheck()
	{
	if ( document.form_com.rat.value = 0 )
		{
			alert('Выберите положительный или отрицательный комментарий');
			return false;
		}
		

	if ( document.form_com.author.value.length <= 2 )
		{
			alert('Вы не ввели имя');
			return false;
		}
		if ( document.form_com.text.value.length <= 3 )
		{
			alert('Вы не написали комментарий');
			return false;
		}
		if ( document.form_com.code.value.length <= 4 )
		{
			alert('Вы не переписали код с картинки');
			return false;
		}


		
		return true;
	}

			function mailCheck()
	{
		if (document.form_mail.name.value.length <= 2 || document.form_mail.name.value == 'Ваше имя')
		{
			alert('Вы не ввели имя');
			return false;
		}
		if ( emailCheck(document.form_mail.email.value) == false )
		{
			alert('Вы не ввели E-mail');
			return false;
		}
		if ( document.form_mail.subj.value.length <= 3 || document.form_mail.subj.value == 'Тема сообщения')
		{
			alert('Вы не написали тему сообщения');
			return false;
		}
		if ( document.form_mail.code.value.length <= 4 || document.form_mail.code.value == 'Введите код!')
		{
			alert('Вы не переписали код с картинки');
			return false;
		}


		if ( document.form_mail.text.value.length <= 5 || document.form_mail.text.value == 'Ваше сообщение...')
		{
			alert('Напишите собщение');
			return false;
		}
		
		return true;
	}


	
		function addphotoCheck()
	{
		if ( document.add_photo.name.value.length <= 2 )
		{
			alert('Вы не ввели имя');
			return false;
		}
			
		
		return true;
	}
	
	
	function addnewsCheck()
	{
		if ( document.add_news.name.value.length <= 2 )
		{
			alert('Вы не ввели имя');
			return false;
		}
		if ( document.add_news.rang.value.length <= 2 )
		{
			alert('Введите должность');
			return false;
		}
		if ( document.add_news.tel.value.length <= 2 )
		{
			alert('Вы не ввели контактный телефон');
			return false;
		}
		if ( emailCheck(document.add_news.email.value) == false )
		{
			alert('Вы не ввели E-mail');
			return false;
		}
		if ( document.add_news.title.value.length <= 3 )
		{
			alert('Напишите заголовок новости');
			return false;
		}
		if ( document.add_news.text.value.length <= 50 )
		{
			alert('Вы не написали текст новости, или объем текста менее 50 символов');
			return false;
		}
		if ( document.add_news.code.value.length <= 4 || document.add_news.code.value == 'Введите код' )
		{
			alert('Вы не переписали код с картинки');
			return false;
		}


		
		
		return true;
	}
	
	
	function editfirmCheck()
	{
		if ( document.edit_firm.name.value.length <= 2 )
		{
			alert('Вы не ввели имя');
			return false;
		}
		if ( document.edit_firm.rang.value.length <= 2 )
		{
			alert('Введите должность');
			return false;
		}
		if ( document.edit_firm.tel1.value.length <= 2 )
		{
			alert('Вы не ввели контактный телефон');
			return false;
		}
		if ( emailCheck(document.edit_firm.email1.value) == false )
		{
			alert('Вы не ввели E-mail');
			return false;
		}
		
		if ( document.edit_firm.title.value.length <= 2 )
		{
			alert('Наименование организации?');
			return false;
		}
		
		if ( document.edit_firm.meta_k.value.length <= 2 )
		{
			alert('Ключевые слова?');
			return false;
		}
		
		if ( document.edit_firm.adress.value.length <= 2 )
		{
			alert('Адрес?');
			return false;
		}
		
		if ( document.edit_firm.tel.value.length <= 2 )
		{
			alert('Телефон?');
			return false;
		}
		if ( document.edit_firm.description.value.length <= 10 )
		{
			alert('Краткое описание? Минимум 10 символов.');
			return false;
		}
		if ( document.edit_firm.text.value.length <= 50 )
		{
			alert('Подробное описание? Минимум 50 символов');
			return false;
		}
		
		if ( document.add_news.code.value.length <= 4 || document.add_news.code.value == 'Введите код' )
		{
			alert('Вы не переписали код с картинки');
			return false;
		}


		
		
		return true;
	}
	


	function addfirmCheck()
	{
		if ( document.add_firm.title.value.length <= 2 )
		{
			alert('Вы не ввели наименование организации');
			return false;
		}
		if ( document.add_firm.code.value.length <= 4 )
		{
			alert('Вы не переписали код с картинки');
			return false;
		}


		if ( document.add_firm.tel.value.length <= 5 )
		{
			alert('Напишите телефон организации');
			return false;
		}
		if ( document.add_firm.description.value.length <= 30 )
		{
			alert('Краткое описание должно быть не менее 30 символов');
			return false;
		}
		if ( document.add_firm.text.value.length <= 50 )
		{
			alert('Полное описание должно быть не менее 50 символов');
			return false;
		}
		
		return true;
	}

	function questionCheck()
	{
		if ( document.question_form.question_name.value.length <= 2 )
		{
			alert('Вы не ввели имя');
			return false;
		}
		if ( emailCheck(document.question_form.question_email.value) == false )
		{
			alert('Вы не ввели E-mail');
			return false;
		}
		if ( document.question_form.code.value.length <= 4 )
		{
			alert('Вы не переписали код с картинки');
			return false;
		}


		if ( document.question_form.question_text.value.length <= 5 )
		{
			alert('Напишите отзыв');
			return false;
		}
		
		return true;
	}

	
			function emailCheck (emailStr)
			{
				/* The following pattern is used to check if the entered e-mail address
				fits the user@domain format. It also is used to separate the username
				from the domain. */

				//var emailPat=/^(.+)@(.+)$/
				var emailPat=/^([a-zA-Z0-9._-]+)@(.+)$/
				/* The following string represents the pattern for matching all special
				characters. We don't want to allow special characters in the address. 
				These characters include ( ) < > @ , ; : \ " . [ ] */
				var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
				/* The following string represents the range of characters allowed in a 
				username or domainname. It really states which chars aren't allowed. */
				var validChars="\[^\\s" + specialChars + "\]"
				/* The following pattern applies if the "user" is a quoted string (in
				which case, there are no rules about which characters are allowed
				and which aren't; anything goes). E.g. "jiminy cricket"@disney.com
				is a legal e-mail address. */
				var quotedUser="(\"[^\"]*\")"
				/* The following pattern applies for domains that are IP addresses,
				rather than symbolic names. E.g. joe@[123.124.233.4] is a legal
				e-mail address. NOTE: The square brackets are required. */
				var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
				/* The following string represents an atom (basically a series of
				non-special characters.) */
				var atom=validChars + '+'
				/* The following string represents one word in the typical username.
				For example, in john.doe@somewhere.com, john and doe are words.
				Basically, a word is either an atom or quoted string. */
				var word="(" + atom + "|" + quotedUser + ")"
				// The following pattern describes the structure of the user
				var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
				/* The following pattern describes the structure of a normal symbolic
				domain, as opposed to ipDomainPat, shown above. */
				var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
				
				

				/* Finally, let's start trying to figure out if the supplied address is
				valid. */
				
				/* Begin with the coarse pattern to simply break up user@domain into
				different pieces that are easy to analyze. */
				var matchArray=emailStr.match(emailPat)
				if (matchArray==null)
				{
					/* Too many/few @'s or something; basically, this address doesn't
					even fit the general mould of a valid e-mail address. */
					alert("Email адрес введен некорректно \n(убедитесь что используются английские буквы, проверьте наличие @ и .)")
					return false
				}
				var user=matchArray[1]
				var domain=matchArray[2]
				
				// See if "user" is valid 
				if (user.match(userPat)==null)
				{

					// user is not valid
					alert("Имя пользователя введено неверно или отсутствует.")
					return false
				}

				/* if the e-mail address is at an IP address (as opposed to a symbolic
				host name) make sure the IP address is valid. */
				var IPArray=domain.match(ipDomainPat)
				if (IPArray!=null)
				{
					// this is an IP address
					for (var i=1;i<=4;i++)
					{
						if (IPArray[i]>255)
						{
							alert("IP адрес назначени неверный или отсутствует!")
							return false
						}
					}
					return true
				}

				// Domain is symbolic name
				var domainArray=domain.match(domainPat)
				if (domainArray==null)
				{
					alert("Неверно введено или отсутствует имя домена.")
					return false
				}
				
				/* domain name seems valid, but now make sure that it ends in a
				three-letter word (like com, edu, gov) or a two-letter word,
				representing country (uk, nl), and that there's a hostname preceding 
				the domain or country. */
				
				/* Now we need to break up the domain to get a count of how many atoms
				it consists of. */
				var atomPat=new RegExp(atom,"g")
				var domArr=domain.match(atomPat)
				var len=domArr.length
				if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
				{
					// the address must end in a two letter or three letter word.
					alert("Адрес должен заканчиваться 3 буквами после точки для домена, или 2 буквами для страны.")
					return false
				}
				
				// Make sure there's a host name preceding the domain.
				if (len<2)
				{
					var errStr="У адреса пропущено или отсутствует имя хостинга!"
					alert(errStr)
					return false
				}

				// If we've gotten this far, everything's valid!
				return true;
			}


