var $j = jQuery.noConflict();

$j(document).ready(function(){

	$j('.hintHolder').click(function(){
			showHint(this);
			return false;
	});	

	$j('div.question a.view').click(function(){
			$j(this).text() == 'Поcмотреть ответ' ? $j(this).text('Скрыть ответ') : $j(this).text('Поcмотреть ответ');
			$j(this).parent().next().toggle();
			return false;		
	});


	$j("#topsearch input[name='search_string']").focus(function(){
			this.value = '';
	});

	$j("#topsearch input[name='search_string']").blur(function(){
			if(!this.value.length){this.value = 'Поиск по сайту';}
	});

	/*Попдиска на рассылку*/
	$j("#subscribeForm input[name='sbs_mail']").focus(function(){
			this.value = '';
	});

	$j("#subscribeForm input[name='sbs_mail']").blur(function(){
			if(!this.value.length){this.value = 'Введите e-mail';}
	});


	$j("form.webforms input, form.webforms textarea").focus(function() {
		this.value = '';
	});

	$j("form.webforms").submit(function(){
		return checkForm(this.id);
	});



	/*Проверка заполнения формы*/

	checkForm = function(formId) {
		var cheked = true;
		var reg = new RegExp("[0-9a-z_]+@[0-9a-z_^.]+\\.[a-z]{2,3}", 'i'); 

		$j('#' + formId + ' .[required]').each(function(){
			//$j('#' + this.id).removeClass("error");
			if(/^\s*$/.test(this.value)) {
				alert(this.getAttribute('required'));
				this.focus();
				$j('#' + this.id).addClass("error");
				cheked = false;
				return false;
			}
		});
		$j('#' + formId + ' .[mail]').each(function(){
			if (!reg.test(this.value)) {
				alert(this.getAttribute('mail'));
				this.focus();
				cheked = false;
				return false;
			}
		});


		return cheked;
	}

	$j('table').tblColor();

});


jQuery.fn.tblColor = function(options){
    
	// настройки по умолчанию
	var options = jQuery.extend({
		evenClass: 'even', // бэкграунд для четных строк
        oddClass: 'odd'
	},options);
	
	return this.each(function() {
		//jQuery(this).find('tr:even').addClass(options.evenClass);
        jQuery(this).find('tr:odd').addClass(options.oddClass);
        
	});

};


showHint = function(el) {
    var realId = (el.id).replace('hint_','');
    var hintBody = document.getElementById('hintBody_'+ realId);
    $j(el).addClass('noneunderline');
    if(hintBody) {
        $j(hintBody).show();
    }else {
        var content = $j('#body_' + realId).html();
        var hintLink = $j(el).html();
        linkClose = document.createElement('A');
        $j(linkClose).attr('id','close_'+realId);
        $j(linkClose).attr('href','#');
        $j(linkClose).attr('class','hintClose');
        linkClose.innerHTML = 'Закрыть';
        $j(el).html('<div class="tip"><div class="hintTop"></div><div class="hintHead"><h2>Справка</h2></div><div class="hintBody">' + content + '</div><div class="hintBottom"></div></div>');
        $j(el).each(function() {this.firstChild.id = "hintBody_"+ realId});
        $j('#hintBody_'+ realId + ' .hintHead').each(function() {this.appendChild(linkClose)});
        $j(el).append(hintLink);
        $j('#close_'+ realId).click(function(){
            $j('#hintBody_' + realId).hide();
            $j(el).removeClass('noneunderline');
            return false;
        });
    }
}


//srAddEvent(window, 'load', doEqual);
