﻿$(document).ready(function() {
  var url = location.href;
  var get_url = url.substring(url.lastIndexOf('/') + 1);


  $("div#menu-left").children("a").each(function() {
    if ($(this).attr("href") == get_url){
      $(this).next("div").css("display", "block");
    }if($(this).attr("href") != get_url){
      $(this).next("div").css("display", "none");
    }

  });

$("div#menu-left").children("div#submenu").children("a").each(function() {
 if ($(this).attr("href") == get_url){
   $(this).parent("div").css("display", "block");
 }
});



  if (window.navigator.userAgent.indexOf ("Opera") >= 0)
  {
   ua = 'Opera';
  }
else
if (window.navigator.userAgent.indexOf ("Gecko") >= 0) // (Mozilla, Netscape, FireFox)
  {
   ua = 'Mozilla';
}
else
if (window.navigator.userAgent.indexOf ("MSIE") >= 0)
  {
   ua = 'Explorer';
}
else
   ua = window.navigator.appName;

switch(ua){
 case 'Explorer':
 $("div#faq").css("marginBottom", "100px");
 $("div#faq").find("div#faq-content").css("display", "none");
 $("div#faq ul").find("li").click(function() {
  if($(this).attr("class") == 'hide'){
    $(this).find("div#faq-content:first").slideDown("slow");
    $(this).attr("class", "show");
    return false;
  }
  if($(this).attr("class") == 'show'){
    $(this).find("div#faq-content :first").slideUp();
    $(this).attr("class", "hide");
    return false;
  }
 });
 break
 default:
 $("div#faq ul li").each(function() {
   $(this).next("div#faq-content").css("display", "none");
   $(this).click(function() {
     if ($(this).attr("class") == 'hide'){
       $(this).next("div#faq-content").slideDown("slow");
       $(this).attr("class", "show");
       return false;
     }
     if ($(this).attr("class") == 'show'){
       $(this).next("div#faq-content").slideUp("slow");
       $(this).attr("class", "hide");
       return false;
     }
   });
 });
 break
}


 $("span.linked").each(function() {
  $(this).click(function() {
    $("div#sendMailDialog").dialog({
    modal: true,
    title: "Отправка сообщения на адрес: " + $(this).text(),
    bgiframe: true,
    width: 500,
    buttons: {
      "Отправить": function() {
        $("form#sendMailDialog").submit();
        $(this).dialog("close");
        alert("Ваша заявка в свободной форме успешно отправлена!");
      },
      "Очистить": function() {
        $("form :input").val('');
      }
    },
    open: function() {
      $("form#sendMailDialog").append('<input type="hidden" name="tomails" id="tomails" value="'+$(this).text()+'">');
    },
    close: function() {
      $("form :input").val('');
    }
  });
  })
 });

 $("span.anketa").each(function() {
   $(this).click(function() {
     $("div#anketa").dialog({
       modal: true,
       title: "Отправка анкеты на адрес: " + 'info#com-center.ru',
       bgiframe: true,
       width: 450,
       buttons: {
         "Отправить анкету": function() {
           $("form#anketa").submit();
           $(this).dialog("close");
           alert("Вы успешно отправил свою анкету!");
         },
         "Очистить поля": function() {
           $("form :input").val('');
         }
       },
      open: function() {
      $("form#anketa").append('<input type="hidden" name="tomails" id="tomails" value="info#com-center.ru"');
    },
    close: function() {
      $("form :input").val('');
    }
     });
   });
 });
 
 
  $("div#anounce").children("span").each(function() {
   $(this).click(function() {
	  alert($(this).next("div#anounce-content").text());
	  });
  });
  
  $(".send_respond").click(function() {
   if ($("div#send-respond").attr("class") == 'hide'){
	   $("div#send-respond").slideDown("slow");
	   $("div#send-respond").attr("class", "show");
	   return false;
	   }
	if ($("div#send-respond").attr("class") == 'show'){
	   $("div#send-respond").slideUp("slow");
	   $("div#send-respond").attr("class", "hide");
	   return false;
	   }
	  });

 $("span.form_seminar").click(function() {
   $("#formaseminar").dialog({
       modal: true,
       title: "Форма заказа семинара",
       bgiframe: true,
       width: 450,
       buttons: {
         "Заказать": function(){
           $("form##forma-seminar").submit();
         },
         "Очистить поля": function() {
           $("form##forma-seminar :text").val('');
         }
       },
       close: function() {
         $("form##forma-seminar :text").val('');
       }
   });
 });

$("form#send_mail :hidden#request").val(window.location);

$("form#send_mail").submit(function() {
  var name = $(":text#firstname");
  var email = $(":text#email");
  var theme = $(":text#theme");
  var text = $(":text#maintext");

  p = /^[a-z0-9_\.\-]+@([a-z0-9\-]+\.)+[a-z]{2,4}$/i;

  var arr = $.makeArray(name, email, theme, text);
  for (var i=0; i<arr.lenght; i++){
    if(arr[i].val() == ''){
      alert("Обязательные поля должны быть заполнены");
      return false;
    }else {
      $("#ajax-loader").css("display", "block");
      return true;

    }
  }
  if(!p.test(email.val())){
    alert("Не верно заполнено поле Контактный E-mail");
    return false;
  }else{
  $("#ajax-loader").css("display", "block");
  return true;

  }
  $(this).reset();

});

$("form#respond #start").val(window.location);
});
