var searchText = 'Поиск';
var is_ie = (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent));
function GID(id) { return (is_ie) ? document.all[id] : document.getElementById(id); }

$(document).ready(function() {
   $(document).pngFix();
   if (typeof window['checkFlash'] == 'function') checkFlash();
   if ($("#gallery a[rel=fancy]").length) $("#gallery a[rel=fancy]").fancybox({ 'hideOnContentClick': true, 'overlayShow': true, 'overlayOpacity': 0.5, 'speedIn': 1000, 'speedOut': 600, 'titlePosition': 'inside', 'transitionIn': 'elastic', 'transitionOut': 'elastic' });
   if ($("#gallery a.imgA").length) $("#gallery a.imgA").fancybox({ 'hideOnContentClick': true, 'overlayShow': true, 'overlayOpacity': 0.5, 'speedIn': 1000, 'speedOut': 600, 'titlePosition': 'inside', 'transitionIn': 'elastic', 'transitionOut': 'elastic' });
   $.fn.alignCenter = function() {
      var marginLeft = - $(this).width()/2 + 'px';
      var marginTop = - $(this).height()/2 + 'px';
      return $(this).css({'margin-left': marginLeft, 'margin-top': marginTop});
   };
   $.fn.togglePopup = function(){
      if ($('#popup').hasClass('hidden')) {
         if ($.browser.msie) {
            $('#opaco').height($(document).height()).toggleClass('hidden').click(function() { $(this).togglePopup(); } );
            $('#popup').css({'position': 'absolute', 'left': ($(document).width() / 2), 'top': ($(document).height() / 2)});
         }
         else {
            $('#opaco').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.7).click(function() { $(this).togglePopup(); } );
            $('#popup').css({'position': 'fixed', 'left': '50%', 'top': '50%'});
         }
         $('#popup').alignCenter().toggleClass('hidden');
      }
      else {
         $('#opaco').toggleClass('hidden').removeAttr('style').unbind('click');
         $('#popup').toggleClass('hidden');
      }
   };
});

function initVideo(page) {
   var fv = { backcolor: 'black', frontcolor: 'white', lightcolor: 'white', screencolor: 'black', repeat: 'single', autostart: true };
   if (page == 'plazmolifting') fv['file'] = '/data/file/Mosolova.flv';
   else if (page == 'injection') fv['file'] = '/data/file/ZuxraAmin.flv';
   else if (page == 'spa-procedure') fv['file'] = '/data/file/SPA.flv';
   htmlOptions = { src: "image/flvplayer.swf", width: '600', height: '480', flashvars: fv, replace: '<table class="noFlash"><tr><td align="center">Не установлен Adobe® Flash® Player<br /><a href="http://www.adobe.com/ru/products/flashplayer/" target="_blank">Установить</a></td></tr></table>' };
   $('#videoFlash').flash(htmlOptions, pluginOptions);
}

function fnCheckSearchForm(f) {
   if (!f.search.value.match(/^.+$/)) {
      alert("Укажите поисковый запрос!");
      f.search.focus();
      return false;
   }
   return true;
}

function fnCheckRegistrationForm(f) {
   if (!f.fio.value.match(/(.+)/)) {
      alert("Укажите ФИО!");
      f.fio.focus();
      return false;
   }
   if (!f.email.value.match(/^[0-9A-Za-z._-]+@([0-9a-z_-]+\.)+[a-z]{2,4}$/)) {
      alert("Укажите правильный E-mail!");
      f.email.focus();
      return false;
   }
   if (!f.password.value.match(/(.+)/)) {
      alert("Укажите пароль!");
      f.password.focus();
      return false;
   }
   if (f.password.value != f.re_password.value) {
      alert("Подтверждение пароля не совпадает с основным паролем!");
      f.re_password.focus();
      return false;
   }
   return true;
}

function fnCheckOrders(obj) {
   var is_ok = false;
   for (i = 0; i < obj.length; i++) {
      if (obj[i].type == "text") {
         if (!obj[i].value.match(/^([1-9][0-9]*)?$/)) {
            alert("Введено некорректное значение!");
            obj[i].focus();
            return false;
         }
         if (is_ok == false) {
            if (obj[i].value) {
               is_ok = true;
            }
         }
      }
   }
   if (is_ok == false) {
      alert("Укажите количество заказываемых позиций!");
      return false;
   }
   return true;
}

function fnCheckOrderForm(f) {
   if (!f.fio.value.match(/(.+)/)) {
      alert('Укажите ФИО!');
      f.fio.focus();
      return false;
   }
   if (!f.phones.value.match(/(.+)/)) {
      alert('Укажите контактные телефоны!');
      f.phones.focus();
      return false;
   }
   if (!f.email.value.match(/^[a-zA-Z0-9._-]+\@[^\s:,]+\.[^\s:,]+$/i)) {
      alert('Укажите правильный e-mail!');
      f.email.focus();
      return false;
   }
   if (!f.address.value.match(/(.+)/)) {
      alert('Укажите адрес!');
      f.address.focus();
      return false;
   }
   return true;
}
