﻿$(function() {
	defaultSearchValue();
	formsSubmitHover();
	expandable();
	$('.selectbox').selectbox({
		//className: 'jquery-selectbox',
		animationSpeed: 50,
		//listboxMaxSize: 10,
		//replaceInvisible: false,
		itemHeight: 17
	});
})

function defaultSearchValue() {
	var lang = $('html').attr('lang');
	var word = {
		'ru-RU': 'Поиск по сайту',
		'ro-RO': 'Căutare pe site',
		'en-US': 'Site search'
	};
	$('#search-form-keyword').val(word[lang]).bind('focus', function() {
		checkValue($(this), word[lang], '');
	}).bind('blur', function() {
		checkValue($(this), '', word[lang]);
	});
}

function checkValue(obj, compare, set) {
	if (obj.val() == compare) {
		obj.val(set);
	};
}

function formsSubmitHover() {
	$('input.submit-form').bind('mouseover', function() {
		$(this).attr('class', $(this).attr('id') + '-hover');
	}).bind('mouseout', function() {
		$(this).attr('class', $(this).attr('id'));
});
$('button.submit-form').bind('mouseover', function() {
    $(this).attr('class', $(this).attr('id') + '-hover');
}).bind('mouseout', function() {
    $(this).attr('class', $(this).attr('id'));
});
}

function expandable() {
	$('.expandable a').bind('click', function() {
		var obj = $($(this).attr('href'));
		if (obj.is(':visible')) {
			obj.slideUp('fast');
			$(this).removeClass('expanded');
		}
		else {
			obj.slideDown('fast');
			$(this).addClass('expanded');
		};
		return false;
	});
}

function isEmailValid(fieldEmail)
{
    return /^.+@[\w\d-]+\.[\w\d-\.]+$/.test(document.getElementById(fieldEmail).value);
}

function isPhoneValid(fieldPhone, digits) 
{
    var re = new RegExp('^\\d{' + digits + '}$');
    var phone = document.getElementById(fieldPhone).value;
    return phone.match(re);
}

function imposeMaxLength(fieldName, MaxLen) 
{
    var data = document.getElementById(fieldName).value;
    return (data.length <= MaxLen);
}
