function formPhone(){
   $('#phoneinfo').toggle();
}
$(document).ready(function() {// -- scrolling rates
   // Popup contacts
   var country = getCookie('country');
   if(country == undefined || country == '' || country == null) {
       if(typeof window['geoip_country_code'] == 'function' && geoip_country_code() == 'UA') {
           setCookie('country', 'UA', 365);
           showContactsPopup('UA');
       }
       if(typeof window['geoip_country_code'] == 'function' && geoip_country_code() == 'RU') {
           setCookie('country', 'RU', 365);
           showContactsPopup('RU');
       }
       if(typeof window['geoip_country_code'] == 'function' && geoip_country_code() != 'RU' && geoip_country_code() != 'UA') {
           setCookie('country', '', 365);
       }
       if(typeof window['geoip_country_code'] != 'function') {
          $.ajax(
          {
             url: 'geoip.php?action=get_country_code',
             success: function(data, textStatus, jqXHR){
                if(data.success){
                   setCookie('country', data.code, 365);
                   country = data.code;
                   showContactsPopup(country);
                }else{
                   setCookie('country', '', 365);
                }
             }
          }
          );
       }
   } else {
      showContactsPopup(country);
   }

   // Promo code ajax validation
   var regFormObj = $('#freg');
   if(regFormObj) {
      regFormObj.ajaxValidation({
         validationUrl: 'regist_1.html',
         filter: '.validatePromoCode',
         badClass: 'promo-code-bad',
         goodClass: 'promo-code-good',
         waiterClass: 'promo-code-waiter'
      });
   }
   var promoCodeFormObj = $('#promo_code_form');
   if(promoCodeFormObj) {
      promoCodeFormObj.ajaxValidation({
         validationUrl: '/cabinet.html',
         filter: '.validatePromoCode',
         badClass: 'promo-code-bad',
         goodClass: 'promo-code-good',
         waiterClass: 'promo-code-waiter',
         mode: 'keyup',
         beforeValidate: function(query, form) {
            // Check only correctly promo code
            var promo_code_value = form.find('.validatePromoCode').val();
            if(promo_code_value.match(/^\d{4}\-\d{4}\-\d{4}\-\d{4}$/)) {
               return query;
            } else {
               // Clear message
               var validationSummary = form.find('.validationSummary');
               validationSummary.html('');
               validationSummary.removeClass('promo-code-bad').removeClass('promo-code-good').removeClass('promo-code-waiter');

               return false;
            }
         }
      });
   }
   tableStyle('deposit');
   tableStyle('cashout');
   function tableStyle(table){
      $('table.' + table + ' tbody tr:odd').addClass('blaw');
      $('table.' + table + ' tbody tr:even').removeClass();
      $('table.' + table).find('input:radio').removeAttr('width');
      $('.cashout tr td input:radio').removeAttr('width');
      $('table.' + table).siblings('br:first').remove();
   }
   $('table.operation_history tr').click(function(){
      $(this).addClass('checked').siblings('tr').removeClass('checked');
   })
   // Quotes Carousel
    try{
       $('#undermenu').jCarouselLite({
          auto: 3000,
          speed: 1000,
          visible: 1,
          vertical: true
       });
   }catch(e){

    }
   // Bottom scroll and background fix
   //document.body.style.overflowX = "scroll";
   var onresize = function() {
      if(document.body.clientWidth <= 1280) {
         document.body.style.backgroundPosition = "-318px 0px";
      }
      else {
         document.body.style.backgroundPosition = "50% 0px";
      }
   }
   $(window).resize(onresize);
   onresize();
});
function showContactsPopup(country) {
   if(country == undefined || country == '' || country == null) {
      return;
   }

   if(country != 'UA' && country != 'RU') {
      return;
   }

   country = country.toLowerCase();

   hidePopupContacts = getCookie(country + '_hide_contacts');

   if(hidePopupContacts != 1) {
      $('#contatcs_popup_' + country).show();
      $('#contatcs_popup_' + country + ' .kreuz').click(function(){
         $('#contatcs_popup_' + country).hide();
      });
      $('#contatcs_popup_' + country + ' > #clickable_popup').click(function(){
         window.location.href = '/contact.html';
      });
      setCookie(country + '_hide_contacts', 1, 365);
   }
}
function setCookie(name,value,days) {
   if (days) {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = "; expires="+date.toGMTString();
   }
   else var expires = "";
   document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
   var nameEQ = name + "=";
   var ca = document.cookie.split(';');
   for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
   }
   return null;
}

function deleteCookie(name) {
   setCookie(name,"",-1);
}

function openVideo(){
   window.open(
      "video.html",
      "2909037",
      "left="+Math.round(screen.width/2-300)+", top="+Math.round(screen.height/2-200)+", width=375, height=285, directories=no, location=no, menubar=no, resizable=no, scrollbars=yes, status=no, toolbar=no"
      );
   return true;
}
function commitFlashObject(_obj, _container){
   var _output=""
   var _paramoutput=""
   var _src=""
   var _ver=""
   for(_cO in _obj){
      _output+=_cO+"=\""+_obj[_cO]+"\" "
      _paramoutput+="<param name="+_cO+" value=\""+_obj[_cO]+"\">";
      if(_cO=="movie")_src="src=\""+_obj[_cO]+"\"";
      if(_cO=="version")_ver=_obj[_cO];
   }
   if(_ver=="")_ver="8,0,0,0"
   var ihtm="<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+_ver+" "+_output+">\n"
   ihtm+=_paramoutput+"\n"
   ihtm+="<embed "+_src+" pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash "+_output+">\n";
   ihtm+="</embed>\n";
   ihtm+="</object>\n";
   if(ihtm)
      $(_container).html(ihtm);
}
function flashOpenAccount(){
   if(DetectFlashVer(8, 0, 0)){
      AC_FL_RunContent(
         'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
         'width','270',
         'height', '142',
         'src', '2',
         'quality', 'high',
         'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
         'align', 'middle',
         'play', 'true',
         'loop', 'true',
         'scale', 'showall',
         'wmode', 'window',
         'devicefont', 'false',
         'id', 'flashMt4',
         'bgcolor', '',
         'name', 'mt4',
         'menu', 'true',
         'allowFullScreen', 'false',
         'allowScriptAccess','sameDomain',
         'movie', '2',
         'salign', '',
         'target', 'flash3'
         )
   }
}
function flashMt4Download(){
   if(DetectFlashVer(8, 0, 0)){
      AC_FL_RunContent(
         'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
         'width','270',
         'height', '142',
         'src', '1',
         'quality', 'high',
         'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
         'align', 'middle',
         'play', 'true',
         'loop', 'true',
         'scale', 'showall',
         'wmode', 'window',
         'devicefont', 'false',
         'id', 'flashMt4',
         'bgcolor', '',
         'name', 'mt4',
         'menu', 'true',
         'allowFullScreen', 'false',
         'allowScriptAccess','sameDomain',
         'movie', '1',
         'salign', '',
         'target', 'flash2'
         )
   }
}
function getPlayerCode () {
   var code = '<iframe src="http://ru.forex-mmcis.com/get-player.html" width="390" height="295" scrolling="no" frameborder="0"></iframe>';
   var codeField = document.getElementById ("playerCode");
   codeField.style.display = 'inline';
   codeField.value = code;
}
function TabLeft(prefix)
{
   var prefix = prefix || '';
   if(DetectFlashVer(8, 0, 0)){
      //document.getElementById('right-tabs').style.display = 'none';
      $("#right-tabs").css("display",'none');
      document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="180" height="425" id="right_menu" align="middle">\n');
      var right_menu;
      var size = {};
      if(document.body.clientWidth < 1366){
         right_menu = 'right_menu'+prefix+'.swf';
         size.width = 180;
         size.height = 430;
      }else{
         right_menu = 'right_menu'+prefix+'.swf';
         size.width = 180;
         size.height = 425;
      }

      document.write('<param name="movie" value="/themes/2011-06-01/flash/' + right_menu + '" />\n');
      document.write('<param name="quality" value="high" />\n');
      document.write('<param name="bgcolor" value="#ffffff" />\n');
      document.write('<param name="play" value="true" />\n');
      document.write('<param name="loop" value="true" />\n');
      document.write('<param name="wmode" value="transparent" />\n');
      document.write('<param name="scale" value="showall" />\n');
      document.write('<param name="menu" value="true" />\n');
      document.write('<param name="devicefont" value="false" />\n');
      document.write('<param name="salign" value="" />\n');
      document.write('<param name="name" value="'+prefix+'" />\n');
      document.write('<param name="allowScriptAccess" value="sameDomain" />\n');

      document.write('<!--[if !IE]>-->\n');
      document.write('<object type="application/x-shockwave-flash" data="/themes/2011-06-01/flash/' + right_menu + '" width="' + size.width + '" height="' + size.height + '">\n');
      document.write('<param name="movie" value="/themes/2011-06-01/flash/' + right_menu + '" />\n');
      document.write('<param name="quality" value="high" />\n');
      document.write('<param name="bgcolor" value="#ffffff" />\n');
      document.write('<param name="play" value="true" />\n');
      document.write('<param name="loop" value="true" />\n');
      document.write('<param name="wmode" value="transparent" />\n');
      document.write('<param name="scale" value="showall" />\n');
      document.write('<param name="menu" value="true" />\n');
      document.write('<param name="devicefont" value="false" />\n');
      document.write('<param name="salign" value="" />\n');
      document.write('<param name="name" value="'+prefix+'" />\n');
      document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
      document.write('<!--<![endif]-->\n');
      document.write('<a href="http://www.adobe.com/go/getflash">\n');
      document.write('<img src="' + location.protocol + '//www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Загрузить Adobe Flash Player" />\n');
      document.write('</a>\n');
      document.write('<!--[if !IE]>-->\n');
      document.write('</object>\n');
      document.write('<!--<![endif]-->\n');
      document.write('</object>\n');
   }
}

var timer;
function whatIsNextNews(){
   var xm, xh, xs,
   m, h, s;
   $.ajax({
      type: 'POST',
      dataType: 'json',
      url: 'module/getNextNews.php',
      success: function(data){
         if(data.news){
            $('#news_box').empty().append(data.news);
            // News Carousel
            $('#news_box').jCarouselLite({
               auto: 4000,
               speed: 1000,
               visible: 1,
               vertical: true
            });
            s = data.seconds;
            m = data.minutes;
            h = data.hours;
            xm = -(m * 58);
            xs = -(s * 44);
            xh = -(h * 58);
            $('#mins').css({
               'background-position': xm + 'px top'
            });
            $('#seconds').css({
               'background-position': xs + 'px bottom'
            });
            $('#hours').css({
               'background-position': xh + 'px top'
            });
            startTime(s,m,h);
            return true;
         }else{
            $('#news_box').empty().append(data.nonews);
            return false;
         }
      }
   });
}

function startTime(s, m, h){
   var xm, xh, xs, total;
   //   s=12; m = 0; h = 0;
   total = h*3600 + m*60 + s;
   if(timer) clearInterval(timer);
   timer = setInterval(function(){
      if((total-1) == 0){
         $('#seconds').css({
            'background-position': 'left bottom'
         });
         $('#mins').css({
            'background-position': 'left top'
         });
         $('#hours').css({
            'background-position': 'left top'
         });
         setTimeout(function(){
            whatIsNextNews();
         },5000);
      }else{
         total = total - 1;
         s = total%60;
         var tmp = Math.floor(total/60);
         m = tmp % 60;
         h = Math.floor(tmp/60);
         xh = -58*h;
         xm = -58*m;
         xs = -44*s;
         $('#seconds').css({
            'background-position': xs + 'px bottom'
         });
         $('#mins').css({
            'background-position': xm + 'px top'
         });
         $('#hours').css({
            'background-position': xh + 'px top'
         });
      }
   }, 1000);
}

function whatIsForex(){
   if(DetectFlashVer(8, 0, 0)) {
      AC_FL_RunContent(
         'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
         'width','600',
         'height', '380',
         'src', 'forex',
         'quality', 'high',
         'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
         'align', 'middle',
         'play', 'true',
         'loop', 'true',
         'scale', 'showall',
         'wmode', 'transparent',
         'devicefont', 'false',
         'id', 'whatIsForexMovie',
         'bgcolor', '',
         'name', 'flashSnow',
         'menu', 'true',
         'allowFullScreen', 'false',
         'allowScriptAccess','sameDomain',
         'movie', 'forex',
         'salign', '',
         'target', 'forex',
         'flashvars', 'clickTAG=http://ru.forex-mmcis.com/regist_1.html'
         ); //end AC code
   }
}
