/**
 * Created by JetBrains PhpStorm.
 * User: Dmitrievsm
 * Date: 05.07.11
 * Time: 16:23
 * To change this template use File | Settings | File Templates.
 */
$(function() {
		$( "#tabs" ).tabs();
	});


function setTimeChooser (obj) {
    parentName = $(obj).attr('id');
    if ($(obj).attr('checked')) {
		$(obj).parent().parent().parent().parent().addClass('selected');

        $("#"+parentName.replace('wend','start')).attr('disabled','disabled');
        $("#"+parentName.replace('wend','end')).attr('disabled','disabled');
    } else {
		$(obj).parent().parent().parent().parent().removeClass('selected');

        $("#"+parentName.replace('wend','start')).removeAttr('disabled');
        $("#"+parentName.replace('wend','end')).removeAttr('disabled');
    }
}
/**
 * Функция для валидации e-mail адресов
 * @param email
 */
function isEmailCorrect(email) {
	var re = /^([a-z0-9_-]+\.)*[a-z0-9_-]+@[a-z0-9_-]+(\.[a-z0-9_-]+)*\.[a-z]{2,4}$/i;
	return re.test(email);
}

$(document).ready(function(){
	$("a.login").colorbox({iframe:true, width: "520" , height: "400"});
});

/**
 * Блокировка кнопки "Отправить" для форм
 * @author Roman Kudlay (roman.kudlay@softline.ru)
 * @param el Элемент кнопки
 */
function disableOnSubmit(el) {
	$(el).attr('disabled', 'disabled');
	$(el).parent('form').submit();
	return true;
}



/**
 * Голосование за отзыв о салоне
 * @author Roman Kudlay (roman.kudlay@softline.ru)
 * @param el Элемент действия
 * @param review ID отзыва
 * @param vote голос
 */
function doReviewVote(el, review, type, vote) {
	var cookie_type = (type == 'useful')?'u':'a';
	var cookie_name = 'WellnessCard_rv_' + cookie_type + review;
	if ($.cookie(cookie_name)) {
		return false;
	}
	$('.value', el).text(parseInt($('.value', el).text()) + Math.abs(vote));
	var parent = $(el).parents('.review_vote');

	disableReviewVote(parent);
	$.cookie(cookie_name, 1, {path: '/', expires: 730});
	$.getJSON(url_for['catalog_review_vote_ajax'], {
		'review':	review,
		'vote':		vote,
		'type':		type
	});
}



/**
 * Вкючает голосавание за отзыв
 * @author Roman Kudlay (roman.kudlay@softline.ru)
 * @param el элемент голосовалки
 * @param review ID отзыва
 */
function enableReviewVote(el, review, type) {
	var cookie_type = (type == 'useful')?'u':'a';
	var cookie_name = 'WellnessCard_rv_' + cookie_type + review;
	if ($.cookie(cookie_name)) {
		return false;
	}

	$('a.plus', el).addClass('cursor-pointer').click(function(){
			doReviewVote($('a.plus', el), review, type, 1)
	});
	$('a.minus', el).addClass('cursor-pointer').click(function(){
			doReviewVote($('a.minus', el), review, type, -1)
	});
}

/**
 * Блокирует голосовалку за отзыв
 * @author Roman Kudlay (roman.kudlay@softline.ru)
 * @param el элемент голосовалки
 */
function disableReviewVote(el) {
	$('a.plus', el).removeClass('cursor-pointer').unbind('click');
	$('a.minus', el).removeClass('cursor-pointer').unbind('click');
}
/**
 * Функция для отображения пароля
 * @param field
 * @param link
 */
function doShowPasswordToggle(field, link) {
	field = $(field);
	var show = field.attr('type')=='password';
	field.clone().attr('type', show?'text':'password').insertAfter(field);
	field.remove();
	$(link).text(show?'Скрыть пароль':'Показать пароль');
}



/**
 * Функция открывает tab по ID
 * @param sIDTabElement
 */
function openTab ( sIDTabElement ) {
	$("a[href='#" + sIDTabElement + "']").click();
}
