// window.onorientationchange = function () {
//     window.location.reload();
// }

//Remove inline-block node
$('.removeTextNodes').contents().filter(function() {
    return this.nodeType === 3;
}).remove();


// header fixed
$(function() {
    $(window).scroll(function() {
        var scroll = $(window).scrollTop();
        if (scroll >= 136) {
            $('.header-wrap').addClass('is-fixed');
        } else {
            $('.header-wrap').removeClass('is-fixed');
        }
    });
    if ($('.header-wrap').offset().top >= 136) {
        $('.header-wrap').addClass('is-fixed');
    }
});


// nav btn
$(function() {
    $(".n-currency h2").click(function() {
        $(".n-currency").find(".select").slideToggle();
        $(".n-lang .select").slideUp();
    });
});
$(function() {
    $(".n-lang h2").click(function() {
        $(".n-lang").find(".select").slideToggle();
        $(".n-currency .select").slideUp();
    });
});

//register btn
$(function() {
	$(".regist-submit").click(function(){
		var check = false;
		$(".regist-wrap .check_need").each(function(){
			if($(this).val() == "" || $(this).val() == null){
				check = $(this).closest(".regist-input").find("H3").eq(0).html();
				return false;
			}
		});
		if(check !== false){
			swal_(lang_txt.note,lang_txt.noinput+"\""+check+"\"",1);
			return ;
		}
		if($(this).closest("form").find("input[name=password]").val() != $(this).closest("form").find("input[name=password2]").val()){
			swal_(lang_txt.note,lang_txt.pwddifferent,1);
			return ;
		}
		if(!$("#c2").prop("checked")){
			swal_(lang_txt.note,lang_txt.nocheckyes,1);
			return ;
		}
		swal({
		  title: lang_txt.informationcorrect,
		  text: lang_txt.nextstep,
		  type: 'warning',
		  showCancelButton: true,
		  confirmButtonText: lang_txt.determine,
		  cancelButtonText: lang_txt.cancel
		},function(result){
		  if (result) {
		    $("#m_register").submit();
		  }
		});
	});
	
	$(".forgetpwd-submit").click(function(){
		var check = false;
		$(".forgetpwd-wrap .check_need").each(function(){
			if($(this).val() == "" || $(this).val() == null){
				check = $(this).closest(".regist-input").find("H3").eq(0).html();
				return false;
			}
		});
		if(check !== false){
			swal_(lang_txt.note,lang_txt.noinput+"\""+check+"\"",1);
			return ;
		}
		swal({
		  title: lang_txt.informationcorrect,
		  text: lang_txt.nextstep,
		  type: 'warning',
		  showCancelButton: true,
		  confirmButtonText: lang_txt.determine,
		  cancelButtonText: lang_txt.cancel
		},function(result){
		  if (result) {
		    $("#m_forgetpwd").submit();
		  }
		});
	});
});

// login btn
$(function() {
    $(".btn-login").click(function() {
        if ($("html").hasClass("is-login")) {
            location.href = "m_data.php";
        } else {
            $(".login-wrap").fadeIn();
        }
        $("html, body").addClass("no-scroll");
        $(".overlay").addClass("active");
    });
    $(".btn-regist").click(function() {
        $(".login-wrap").fadeOut();
        $(".forgetpwd-wrap").fadeOut();
        $(".regist-wrap").fadeIn();
    });
    $(".btn-forgetpwd").click(function() {
        $(".login-wrap").fadeOut();
        $(".regist-wrap").fadeOut();
        $(".forgetpwd-wrap").fadeIn();
    });
});


// btn close
$(function() {
    $(".btn-close").click(function() {
        $("html, body").removeClass("no-scroll");
        $(".overlay").removeClass("active");
        $(".login-wrap, .regist-wrap, .forgetpwd-wrap").fadeOut();
        $(".index-welcome-wrap").addClass("close");
        $(".items-aside, .m-data-aside").removeClass("active");
    });
});


// header btn
$(function() {
    $(".nav-btn").click(function() {
        $("html, body").addClass("no-scroll");
        $(".nav-wrap").addClass("active");
    });
    $(".nav-close").click(function() {
        $("html, body").removeClass("no-scroll");
        $(".nav-wrap").removeClass("active");
        $(".n-currency, .n-lang").find(".select").fadeOut("fast");
    });
});


// link search
$(function() {
    $(".btn-search").click(function() {
        $(".js-search-input").toggleClass("active");
        if($(".js-search-input").hasClass("active")){
        	$("#chat-widget-container").css("bottom" , "120px");
        }else{
        	$("#chat-widget-container").css("bottom" , "60px");
        }
    });
});


// nav cart
$(function() {
    var num = $(".nav-cart li").length;
    $(".link-cart").find("a").append("<strong class='car_num'>" + num + "</strong>");
});


// Form placeholder
$(function() {
    $("input[type='text'] , input[type='password'] , textarea").each(function() {
        $(this).focus(function() {
            $(this).addClass("placeholder");
        });
        $(this).blur(function() {
            $(this).removeClass("placeholder");
        });
    });
});


// Overlay
$(function() {
    $(".overlay").click(function() {
        $("html, body").removeClass("no-scroll");
        $(this).removeClass("active").css("z-index", "");
        $(".nav-wrap").removeClass("active");
        $(".login-wrap, .regist-wrap, .forgetpwd-wrap").fadeOut();
        $(".m-receive-form").removeClass("active");
    });
});


// Go top
$(function() {
    $(window).scroll(function() {
        if ($(this).scrollTop() > 240) {
            $(".btn-top").fadeIn();
        } else {
            $(".btn-top").fadeOut();
        }
    });
    $(".btn-top").click(function() {
        $('body, html').animate({
            scrollTop: 0
        }, 500);
    });
});