﻿var KursLastTabOpen = "kursTab1"
var AcademyLastTabOpen = "academyMain"
var FirstCheck = true;

$(document).ready(function() {

    

    


    $('li.hover').hover(
    function() {
    $(this).children("ul.hide").addClass("sub");
    },
    function() {
    $(this).children("ul.hide").removeClass("sub");
    });
    
    
    //menu hover 
    $('div.nav ul li').hover(
        function() {
        $(this).addClass('menuHover');
        },
        function() {
        $(this).removeClass('menuHover');
        });
        
    //video page
    
        //video first item
        var firstvideo = $('div.vidBox:first a').attr('rel');
        $('div.vidLargeHref').html('<object width="456" height="369"><param name="movie" value="' + firstvideo + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+ firstvideo + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="456" height="369"></embed></object>');
        
        $('div.vidBox:first').addClass('vidActive');
    
        var thisFirstVidName = $('div.vidBox:first a').next('p').children('span.vidName').text();    
        var thisFirstVidLength = $('div.vidBox:first a').next('p').children('span.vidLength').text();   
        
        $('div.vidLarge p span.vidNameShow').text(thisFirstVidName);
        $('div.vidLarge p span.vidLengthShow').text(thisFirstVidLength);               
        
    
        //video onclick function
        $('div.vidBox a').click(function() {
            var vidlink = $(this).attr('rel');    
            
            $('div.vidBox').removeClass('vidActive');
            $(this).parent('div.vidBox').addClass('vidActive');
            
            $('div.vidLargeHref').html('<object width="456" height="369"><param name="movie" value="' + vidlink + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+ vidlink + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="456" height="369"></embed></object>');
            $('body , html').animate({scrollTop:0}, 'slow');

            var thisVidName = $(this).next('p').children('span.vidName').text(); 
            var thisVidLength = $(this).next('p').children('span.vidLength').text(); 
            
            $('div.vidLarge p span.vidNameShow').text(thisVidName);
            $('div.vidLarge p span.vidLengthShow').text(thisVidLength);
    }); 
    
    
    
    
    //video box hover
    $('div.vidBox').hover(
    function() {
    $(this).addClass('vidHover');
    },
    function() {
    $(this).removeClass('vidHover');
    });
    
    
    $('div.galleryBox a').lightBox();
    
    $('div.nav ul li:last-child a').addClass('navLast');
    
    $('div.daysList ul li:first-child').css('background-image','none');
    
    $('div.sideMenu ul li:first-child').css('border-top','1px solid #CDCDCD');
    
    $('div.academyTabs table tr td:first').addClass('firstTd');
    $('div.academyTabs table tr td:second').addClass('secondTd');
    
    $('div.newsBox:last-child').css('border-left','0');
    
    
    $('div.sideMenu ul li').hover(
        function() {
        $(this).css('background-color','#F6F6F7');
        },
        function() {
        $(this).css('background-color','white');
        });

   $('#footer').css('opacity','0.6');
   $('#footer').hover(
        function() {
        $(this).css('opacity','1');
        },
        function() {
        $(this).css('opacity','0.6');
        });   
        
     // kursim tabs
    $('div.KursDiv').hide();
    $('div.KursDiv:first').show();
    $('ul.kursimLinks li:first').addClass('KursActive');
    
    $('ul.kursimLinks li').click(function() {
        $('ul.kursimLinks li').removeClass('KursActive');      
     if (KursLastTabOpen  != this.className) {
     
        $('#' + KursLastTabOpen ).hide();
        $('#' + this.className).show();
        var curentHeader = $(this).attr("title");
        $('h2.subHeader').html(curentHeader);
         KursLastTabOpen = this.className;
        }
        $('ul.kursimLinks li.' + this.className).addClass('KursActive'); 
    }); 
    


    // academy tabs
    $('div.academyTabs').hide();
    $('div.academyTabs:first').show();
    
    $('div.academyHeaderM ul li').click(function () {return false;});  
    
    $('div.academyHeaderM ul li').click(function() {
    $('div.academyMain').hide();
     if (AcademyLastTabOpen  != this.className) {
     
        $('#' + AcademyLastTabOpen ).hide();
        $('#' + this.className).show();
        var curentHeader = $(this).attr("title");
        $('h2.subHeader').html(curentHeader);
         AcademyLastTabOpen = this.className;
        }
    }); 
    
    
    // open day form
    $(".openDayBut").click(function() {  
        return checkFormOP();      
    });  
    function checkFormOP()
    {
         FirstCheckOP = false;
        check = true; 
   
          $("input#ctl00_ContentPlaceHolder1_OPtbPhone").prev('span').removeClass();    
         var phone22 = $("input#ctl00_ContentPlaceHolder1_OPtbPhone").val();  
           if (phone22.length < 7 || !(IsNumeric(phone22))) {            
         $("input#ctl00_ContentPlaceHolder1_OPtbPhone").prev('span').addClass('fieldhover');             
         $("input#ctl00_ContentPlaceHolder1_OPtbPhone").focus();  
         check = false;
       }   
             
         $("input#ctl00_ContentPlaceHolder1_OPtbEmail").prev('span').removeClass();      
         var email22 = $("input#ctl00_ContentPlaceHolder1_OPtbEmail").val();   
           if (email22 == "" || !(emailChek(email22)) ) {  
         $("input#ctl00_ContentPlaceHolder1_OPtbEmail").prev('span').addClass('fieldhover');                 
         $("input#ctl00_ContentPlaceHolder1_OPtbEmail").focus();  
         check = false;
       }   
                           
        $("input#ctl00_ContentPlaceHolder1_OPtbName").prev('span').removeClass();    
           if ($("input#ctl00_ContentPlaceHolder1_OPtbName").val() == "") {  
         $("input#ctl00_ContentPlaceHolder1_OPtbName").prev('span').addClass('fieldhover');    
         $("input#ctl00_ContentPlaceHolder1_OPtbName").focus();  
         check = false;
       }                                
       return check;                 
    }
    
    
    
    
       
    // contact form
    $(".but, .but-reg").click(function () {  
        return checkForm();      
             
    });  
    function checkForm()
    {
         FirstCheck = false;
        check = true; 
     
         $("input#ctl00_ContentPlaceHolder1_tbEmail , input#tbEmail").prev('span').removeClass();      
         var email2 = $("input#ctl00_ContentPlaceHolder1_tbEmail , input#tbEmail").val();   
           if (email2 == "" || !(emailChek(email2)) ) {  
         $("input#ctl00_ContentPlaceHolder1_tbEmail , input#tbEmail").prev('span').addClass('fieldhover');                 
         $("input#ctl00_ContentPlaceHolder1_tbEmail , input#tbEmail").focus();  
         check = false;
       }      
          $("input#ctl00_ContentPlaceHolder1_tbPhone , input#tbPhone").prev('span').removeClass();    
         var phone2 = $("input#ctl00_ContentPlaceHolder1_tbPhone , input#tbPhone").val();  
           if (phone2.length < 8 || !(IsNumeric(phone2))) {            
         $("input#ctl00_ContentPlaceHolder1_tbPhone , input#tbPhone").prev('span').addClass('fieldhover');             
         $("input#ctl00_ContentPlaceHolder1_tbPhone , input#tbPhone").focus();  
         check = false;
       }         
        $("input#ctl00_ContentPlaceHolder1_tbAddress , input#tbAddress").prev('span').removeClass();    
           if ($("input#ctl00_ContentPlaceHolder1_tbAddress , input#tbAddress").val() == "") {  
         $("input#ctl00_ContentPlaceHolder1_tbAddress , input#tbAddress").prev('span').addClass('fieldhover');    
         $("input#ctl00_ContentPlaceHolder1_tbAddress , input#tbAddress").focus();  
         check = false;
       }                       
        $("input#ctl00_ContentPlaceHolder1_tbName , input#tbName").prev('span').removeClass();    
           if ($("input#ctl00_ContentPlaceHolder1_tbName , input#tbName").val() == "") {  
         $("input#ctl00_ContentPlaceHolder1_tbName , input#tbName").prev('span').addClass('fieldhover');    
         $("input#ctl00_ContentPlaceHolder1_tbName , input#tbName").focus();  
         check = false;
       }                                
       return check;                 
    }
    
    
    
    
    
        function emailChek(str)
    {

		    var at="@"
		    var dot="."
		    var lat=str.indexOf(at)
		    var lstr=str.length
		    var ldot=str.indexOf(dot)
		    if (str.indexOf(at)==-1){
    		  
		       return false
		    }

		    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
    		   
		       return false
		    }

		    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    		    
		        return false
		    }

		     if (str.indexOf(at,(lat+1))!=-1){

		        return false
		     }

		     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

		        return false
		     }

		     if (str.indexOf(dot,(lat+2))==-1){

		        return false
		     }
    		
		     if (str.indexOf(" ")!=-1){
    		    
		        return false
		     }

 		     return true					
    }
    
    function IsNumeric(inputVal) 
    {
         if (isNaN(parseFloat(inputVal))) 
         { 
              return false;
         }
         else
         {
            return true;
         }
    }    
    
    
    
    
    
    
    
    
});
