/**
 * AXIÁL
 * Javascript függvények
 * (C) NetGo.hu Kft. Minden jog fenntartva.
 * Molnár Sándor
 */

$(document).ready(function(){    
    
    //IE6 meghatározása
    var is_IE6 = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32"); //JQuery IE6 bug esetén ha animatespeed van megadva akkor nem hajtódik végre
   
    if($(window).height()<=610){
        $('#right_side').css({
            'position':'absolute'
        });
    }
    
    $(".head_menu_div").hover( function () { 
        $(this).children(".head_menu_sub2").stop(true,true);
        $(this).children(".head_menu_a").css('backgroundColor','#E7E7E7');
        $(this).children(".head_menu_a").css('color','#008E46');
        if (is_IE6) {
            $(this).children(".head_menu_sub2").show();        
        }
        else{
            $(this).children(".head_menu_sub2").slideDown(400);        
        }
    
    },
    function () {
        $(this).children(".head_menu_sub2").stop(true,true);
        if (is_IE6) {
            $(this).children(".head_menu_sub2").hide();        
        }
        else{
            $(this).children(".head_menu_sub2").slideUp(400);  
        }
                    
        $(this).children(".head_menu_a").css('backgroundColor','');
        $(this).children(".head_menu_a").css('color','#FBFBFB');
    }
    )
    
    if (is_IE6) {
        
    }
        
    
    $(".head_menu_sub_li").hover( function () { 
        $(this).stop(true,true); 
        if (is_IE6) {
            $(this).children(".head_menu_sub").show();    
        }
        else {
        
            $(this).children(".head_menu_sub").show(300);    
        }
                
    },
    function () {
        $(this).stop(true,true);
        if (is_IE6) {  
            $(this).children(".head_menu_sub").hide();    
        }
        else {
        
            $(this).children(".head_menu_sub").hide(300);    
        }
        
        
        
    });
    
    $(".js_button").each(function(){
        $(this).data('e',((typeof($(this).attr('src'))=='undefined')?$(this).find('img:first'):$(this)));
        $(this).data('f',$(this).data('e').attr('src').split('.'));
        $(this).hover(function(){
            $(this).data('e').attr('src',($(this).data('f')[0]+'_hover.'+$(this).data('f')[1]))
        }
        ,function()
        {
            $(this).data('e').attr('src',($(this).data('f')[0]+'.'+$(this).data('f')[1]))
        });
    });
    
    $(".location_label").click(function(){        
        if(!$(this).data('open') || $(this).data('open')=='close'){                                    
            $(".location_label").each(function(){
                $(this).data('open','close'); 
                $(this).removeClass('location_label_hover');
                $(this).parent().children(".location_content").slideUp();               
            });
            $(this).data('open','open');            
            $(this).addClass('location_label_hover');
            $(this).parent().children(".location_content").slideDown();
        }
        else{            
            $(this).data('open','close');            
            $(this).removeClass('location_label_hover');                         
            $(this).parent().children(".location_content").slideUp();
        }                
    }) ; 
    
    //hírek lista választó
    $(".list_box_change_url").change(function(){
        window.location=$(this).val();          
    });  
    
    //contact managers rész
    $(".contact_list_container_bottom").click(function(){        
        if(!$(this).data("parent")){
            $(this).data("parent",$(this).parent());
        }
        if(!$(this).data('open') || $(this).data('open')=='close'){                                              
            $(this).data('open','open');                          
            var h=$(this).data("parent").children(".contact_list").height();          
            h=h+30;
            $(this).data("parent").animate({
                height: h
            });
            $(this).css('backgroundImage','url(images/images/website/manager_up_arrow.gif)');
        }
        else{            
            $(this).data('open','close');                                          
            $(this).data("parent").animate({
                height: 150
            });
            $(this).css('backgroundImage','url(images/images/website/manager_down_arrow.gif)');
        }
    });
    //regisztráció box
    $("#home_sign_a").click(function(e){          
        if(!$(this).data('open')){            
            $("#registration_box").load($(this).attr('href'),function(response, status, xhr) {                                
                $("#login_box").hide(10,function(){
                    $("#home_login_a").css('backgroundImage','none');                   
                });                                  
                $("#home_login_a").data('open','false');
                $("#home_sign_a").css('backgroundImage','url(images/images/website/reg_button_hover_88.png)');                               
                $("#registration_box").slideDown();
            }
            );
            $(this).data('open','true');            
        } 
        else {            
            if($(this).data('open')=='false'){
                $(this).data('open','true');
                $("#login_box").hide(10,function(){
                    $("#home_login_a").css('backgroundImage','none');
                    $("#home_login_a").data('open','false');
                    $("#home_sign_a").css('backgroundImage','url(images/images/website/reg_button_hover_88.png)');
                    $("#registration_box").slideDown(); 
                }); 
               
                
            }
            else {
                $(this).data('open','false');                
                $("#registration_box").slideUp(function(){
                    $("#home_sign_a").css('backgroundImage','none');
                });
                
            }                                  
        }       
        e.preventDefault();
    });
    //bejelentkezés box
    $("#home_login_a").click(function(e){                
        if(!$(this).data('open') || ($(this).data('open')=='false')){          
            $(this).data('open','true'); 
            $("#registration_box").hide(10,function(){
                $("#home_sign_a").css('backgroundImage','none');
                $("#home_sign_a").data('open','');
                $("#home_login_a").css('backgroundImage','url(images/images/website/reg_button_hover_88.png)');
                $("#login_box").slideDown();             
            });
            
        } 
        else {                      
            $(this).data('open','false');
            $("#login_box").slideUp(function(){
                $("#home_login_a").css('backgroundImage','none');
            });         
        }       
        e.preventDefault();
    });
    
    $("#save_gomb").click(function(e){
        e.preventDefault(); 
    });
    
    //bejelentkezés e-mail
    $("#login_email").click(function(){       
        if($(this).val()=='E-mail'){
            $(this).val(''); 
        }
        //enter esetén lépjen át a jelszó mezőbe
        $(this).focus().keypress(function(event) {
            if ( event.which == 13 ) {                
                event.preventDefault();
                $("#login_passwd").val('');
                $("#login_passwd").focus();
            }  
        });
         
    });
    //bejelentkezés e-mail
    $("#login_passwd").click(function(){       
        if($(this).val()=='********'){
            $(this).val(''); 
        } 
        $(this).focus();
        
    });
    //ENTER esetén fusson le a submit
    $("#login_passwd").keypress(function(event) {
        if ( event.which == 13 ) {            
            event.preventDefault();
            document.head_login_form.submit();
        }
  
    });

    
      
    //használtgép termék lista tr kattintás
    $('.sh_product_list_tr').click(function(e){
        var link=$(this).children('.sh_product_table_td_first').children("input").val();
        if(link){            
            window.location=link;
            e.preventDefault();
        }
             
    });
      
    $('.sh_equipment').hover(
        function(){
            $(this).children('.equipment_container').show();
        },
        function(){
            $(this).children('.equipment_container').hide();
        });
      
    //kódolt email visszakódolása
     
    $(".encryptemail").click(function(e){
        var email=$(this).attr('href');         
        if(email){
            uncryptmailto(email.substr(7));
        }
        e.preventDefault();
    })
      
      
      
    //használtgép fordítás
    $('#axial_translate').click(function(){          
        if(!$(this).data('open') || ($(this).data('open')=='false')){              
            $(this).data('open','true'); 
            var translated=$(this).parent().children('#translated').html();         
            if(translated==''){                 
                $.ajax({
                    cache: false,
                    type: "POST",
                    data: "product_id="+$("#translate_hidden_product_id").val(),
                    url: $("#translate_hidden_url").val(),
                    dataType: "html",
                    success: function(data){
                        $("#translated").html(data);
                    }
                })
          
            }
            $("#translate").hide();
            $("#translated").show();
        }
        else {
            $(this).data('open','false');  
            $("#translated").hide();
            $("#translate").show();
        }                     
    });
    
    //használtgép kereső
    $('#sh_search_input').click(function(){
        var sh_search_text=$(this).val();
        var sh_search_default=$('#sh_search_ok').val();        
        if(sh_search_text==sh_search_default){
            $(this).val('');
        }
    });
    
    //használtgép ajánlatkérő
    $('#sh_offer_button').click(function(e) {
        $('#sh_offer_container').toggle('fast');
        e.preventDefault();
    }); 
    //használtgép termékeknél kapcsolattartók kinyitása
    $('#sh_contacts_button').click(function(e) {
        $('#sh_contacts_container').toggle('fast');
        e.preventDefault();
    }); 
    //használtgép parkolóba és webshop kívánságlista pakolása
    $('.sh_park_button').live('click',function(e){               
        sh_ajax_alert_window($(this).attr('href'),$(this).children('span'));
        e.preventDefault();
    });   
    //használtgép és webshop termék összehasonlításba pakolása
    $('.sh_comp_button').live('click',function(e) {          
        sh_ajax_alert_window($(this).attr('href'),$(this).children('span'));
        e.preventDefault();
    });
    
    
    //használtgép message ablak
    function sh_ajax_alert_window(url,span,style,right,bottom,fadein,delay,speed)
    {       
        if (!right) right = 50;
        if (!bottom) bottom = $(window).height()+$(window).scrollTop()-50;
        if (!fadein) fadein = 1000;
        if (!delay) delay = 1000;
        if (!speed) speed = 2000;
        !style ? style = 'alert_window' : style;        
        $.ajax({
            cache: false,
            type: "GET",        
            url: url,
            dataType: "html",
            success: function(data) {                         
                content='';                
                if(data){                         
                    var content=data.substr(4);                                                         
                    switch(data.substr(0,3)) {
                        case 'sin':
                            span.html('-');                            
                            break;
                        case 'sde':
                            span.html('+');                            
                            break;                                                            
                    }                     
                }                 
                var $new_alert_window = $('<div class="'+style+'" style="right: '+right+'px;top: '+bottom+'px;">'+content+'</div>');
                $('body').append($new_alert_window);
                $($new_alert_window).fadeIn(fadein);  
                $($new_alert_window).delay(delay).animate({
                    "top": ($(window).scrollTop()-50)+"px"
                },speed, function() {
                    $(this).remove();
                });         
            }
        });
    }
    
    //csak ie esetén kell majd lefuttatni a overflow: auto hibás kezelése miatt, ne kerüljön oldalra scroll azért mert alulra kerül
    if ( $.browser.msie ) {
        $('.sh_comp_container').height($('.sh_comp').height()+20);        
        $('#ws_products_comp_container').height($('.ws_products_comp_table').height()+40);
    }  
    
    
    
    
    //WEBSHOP funkciók            
    $('#mini_basket_button').click(function(){
        if ($(this).data('open')==1)
        {                
                
            mini_basket_open();
            $(this).data('open',0);
        }
        else
        {      
            //ajaxal betolteni a tartalmat ha üres           
            if($('#mini_basket_content').html()){
                
            }
            else //csak akkor kell betölteni az oldalt ha a tartalom üres
            {
                var tags={
                    '#mini_basket_content' : '#mini_basket_content'
                };
                $.ajax({
                    cache: false,
                    type: "POST",
                    data: 'mini_slide_shopping_cart=true',
                    url: $(this).children('input').val(),
                    dataType: "html",
                    success: function(data) {                    
                        data = '<div>'+data+'</div>';
                        $.each(tags, function(to,from) {
                            var from_value = '';
                            $.each($(data).find(from),function()
                            {
                                from_value +=$(this).html();
                            });
                            $(to).html(from_value);
                        });                    
                    } 
                })
                            
            }
            mini_basket_open('open');
            $(this).data('open',1);
        }
    });  
    
    //webshop product tab            
    $(".tabs_header_content").each(function(){
        $(this).data('e',((typeof($(this).attr('src'))=='undefined')?$(this).find('img:first'):$(this)));
        var src=$(this).data('e').attr('src').split('.');        
        if(src[0].substr(-6)=='_hover'){
            $(this).data('active','1');
            $(this).data('hover',src[0]+'.'+src[1]);              
            $(this).data('button',src[0].substr(0,(src[0].length-6))+'.'+src[1]);
        }
        else {
            $(this).data('active','0');
            $(this).data('button',src[0]+'.'+src[1]);
            $(this).data('hover',src[0]+'_hover.'+src[1]);
        }                                
        
        $(this).click(function(e){     
            var index=$(this).children('input').val();
            $(this).parent().parent().parent().parent().children('.tabs_tab_content').removeClass('tabs_tab_active');        
            $('#ws_product_art_params_container_tab_content'+index).addClass('tabs_tab_active'); 
            
            $(".tabs_header_content").each(function(){
                
                $(this).data('e').attr('src',$(this).data('button')); 
                $(this).data('active','0');               
            });
            
            $(this).data('e').attr('src',$(this).data('hover')); 
            $(this).data('active','1');               
            
            e.preventDefault();
        });                              
    });
    
    $('.tabs_header_content').hover(function(){
        
        $(this).data('e').attr('src',$(this).data('hover'));
    }
    ,function()
    {
            
        if($(this).data('active')!='1'){
            $(this).data('e').attr('src',$(this).data('button'));
        }  
               
    });
            
});

function mini_basket_open(type){
    if(!type){
        $('#mini_basket').animate({
            width:29                    
        },201,function(){
            $('#mini_basket').css({
                'z-index' : '1000'
            });                
            $('.ws_wish_button').css({
                'z-index' : '1001'
            });
        });
    }
    else {
        $('#mini_basket').css({
            'z-index' : '1001'
        });
        $('.ws_wish_button').css({
            'z-index' : '999'
        });
        $('#mini_basket').animate({
            width:329
        },201);
    }
}

function mini_basket_tocart(){
    if ($('#mini_basket_button').data('open')==1)
    {                                       
    }
    else
    {  
        mini_basket_open('open');
        $('#mini_basket_button').data('open',1);
        setTimeout(
            function(){
                mini_basket_open();
                $('#mini_basket_button').data('open',0);
            },2500);
    } 
  
}


function ajax_form(url,id,form_id){    
    $("#"+form_id).find("#ok").val(1);
    var post = $("#"+form_id).serialize();       
    $.ajax({
        cache: false,
        type: "POST",
        data: post,
        url: url,
        dataType: "html",
        success: function(data) {
            $("#" + id).html(data);              
        }
    });
}

function flottakovetes(text){
    var ic=$('#ic').val();
    var user=$('#il').val();
    var passw=$('#ipw').val();        
    if(!ic || !user || !passw){
        alert(text);            
    }
    else{
        document.ilogin.submit();
    }
}

function is_short(text){
    if(text.length<3 || text.length>150){
        return true;
    }
    return false;
}
function change_src(x,y)
{
    document.getElementById(x).src=y;
}

