$(document).ready(function() {
    $("#tabs").tabs();     
	
	$('p').removeClass('MsoNormal');
	$('p').removeClass('MsoBodyText');
	$('#tab2 p').removeAttr("style");
	$('#tab2 p').removeAttr("class");
	
    /*kereso*/
    $('#searchbox').keyup(function(event) {
        var barmi = Url.encode($('#searchbox').val());


        var text = Url.decode(barmi);
        $hossz = $('#searchbox').val().length;
        if($hossz >= 3){
            var toUrl = 'index.php?mod=search&cla=search&fun=access&ajax=liveSearch&text='+text;
            $.ajax({url: toUrl, success: function(data){
                if(data.length != ""){
                   $('#searchResult').css("display","block");
                   setHeight();
                }
                $('#searchResult').html(data);
                setHeight();
              }});
        } else {
            $('#searchResult').css("display","none");
            setHeight();
        }       
    });
    /*kereso*/

	/*Banner*/
	$('#banner').bxSlider({
    	pager: true,
		controls: false,
		auto: true,
		autoHover: true,
		speed: 1500,
		mode: 'fade',
		pause: 5000
  });


    /*markabolt megjelenito*/
    var filterUrl = 'index.php?mod=webshop_product&cla=webshop_product&fun=showManufacturerFilteredCategorys&ajax=filter&manid='+$("#filterMenuSelect").val();
    $.ajax({url: filterUrl, success: function(data){
            $("#filteredMenu").html(data);
            setHeight();
        }});
    $('#filterMenuSelect').change(function(){
        filterUrl = 'index.php?mod=webshop_product&cla=webshop_product&fun=showManufacturerFilteredCategorys&ajax=filter&manid='+$("#filterMenuSelect").val();
        $.ajax({url: filterUrl, success: function(data){
            $("#filteredMenu").html(data);
            $(".wmenulevel_1").css("display","none");
            window.location = $("#filteredMenu ul li:first-child a").attr('href');
            setHeight();
        }});        
    });
    if(getUrlVars()["gyartokod"]){
        $(".wmenulevel_1").css("display","none");
    }

    $(".webshop_fejlec").click(function(){
        $(".wmenulevel_1").css("display","block");
    });
    /*markabolt megjelenito*/

    /*szallitasi koltseg folyamat jelzo*/
    var osszeg = $("#actValueInCart").html();
    var maxValue = 10000;
    var osszegTemp = {};
    osszegTemp = osszeg.split(" ");
    var actValue = osszegTemp[0];

    if(actValue < maxValue){
        var szazalek = ((actValue / maxValue)*100);
        var innerDivWidth = Math.round(125*(szazalek/100));
        $(".innerDiv").css("width",innerDivWidth);
    } else {
        $(".innerDiv").css("width","125px");
    }

    if(actValue < 5000){
        $(".freedeliveryText").html("szállítási díj: 600 Ft");
    }
    if(actValue > 5000 && actValue < 10000){
        $(".freedeliveryText").html("szállítási díj: 300 Ft");
    }
    if(actValue > 10000){
        $(".freedeliveryText").html("ingyenes kiszállítás");
    }

    /*szallitasi koltseg folyamat jelzo*/

    /*login inputok alapertelmezett szovegmegjelenitese*/
    $("#loginName").val("e-mail cím");
    $("#loginName").click(function(){
        if($("#loginName").val() == "e-mail cím"){
            $("#loginName").val("");
        }
    });
    $("#loginName").blur(function(){
        if($("#loginName").val() == ""){
            $("#loginName").val("e-mail cím");
        }
    });
    $("#loginPass").val("jelszo");
    $("#loginPass").click(function(){
        if($("#loginPass").val() == "jelszo"){
            $("#loginPass").val("");
        }
    });
    $("#loginPass").blur(function(){
        if($("#loginPass").val() == ""){
            $("#loginPass").val("jelszo");
        }
    });

    setHeight();

    /*login inputok alapertelmezett szovegmegjelenitese*/

    /*termekkepek kozepre igazitasa*/
    /*
    if($('div.product_list_content div.left').length){
        if($('div.product_list_content div.left img').length){
            var kepmeret = $('div.product_list_content div.left img').width();
          
            var divmeret = $(this).width();

            var marginleft = Math.round((divmeret-kepmeret)/2);

            $(this).children('img').css('margin-left', marginleft);

        }

    }
    */
    /*termekkepek kozepre igazitasa*/
    
    

});

function setHeight(){

    /*hatterkep lenti*/
    var maindivheight = document.getElementById("maindiv").offsetHeight;
    $(".bottom_bg").css("height", maindivheight);
    /*hatterkep lenti*/

}

function size(plusminus){
    var maxFontSize = 15;
    var minFontSize = 10;
    var actFontSize;

    if($(".fulltext p").length){
        actFontSize = $(".fulltext p").css("font-size").substr(0, 2);
    }

    if($(".introtext p").length){
        actFontSize = $(".introtext p").css("font-size").substr(0, 2);
    }
    if($(".text p").length){
        actFontSize = $(".text p").css("font-size").substr(0, 2);
    }

    if(plusminus == 'minus'){
        if(actFontSize > minFontSize){
                actFontSize--;
        }
    }

    if(plusminus == 'plus'){
        if(actFontSize < maxFontSize){
                actFontSize++;
            }
    }

    if(plusminus == 'original'){
        actFontSize = 11;
    }

    if($(".fulltext p").length)
        $(".fulltext p").css("font-size",actFontSize+"px");

    if($(".introtext p").length)
        $(".introtext p").css("font-size",actFontSize+"px");

    if($(".text p").length)
      $(".text p").css("font-size",actFontSize+"px");

}

function addTextToInput(esemeny,elem) {

    if(esemeny=='focus') {

        if(elem.value=='Írja be a keresett szót!') {
            elem.value='';
        }
        elem.style.border='1px solid #6f6f6f';

    }
    else if(esemeny=='blur') {

        if(elem.value=='') {
            elem.value='Írja be a keresett szót!';
        }
        elem.style.border='1px solid #424242';

    }

}

function getUrlVars() {
	var vars = {};
	var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
		vars[key] = value;
	});
	return vars;
}

function addFav() {
  if(document.all) {
    window.external.AddFavorite(location.href,document.title)
  } else {
    if(window.sidebar) {
      window.sidebar.addPanel(document.title,location.href,'');
    }
  }
}


var Url = {

	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},

	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}

function setAlert(user_id,sku){

	var selectName = 'period_'+user_id+'_'+sku; 
	
	var Url = 'index.php?mod=webshop_order_manager&cla=webshop_order_manager&fun=setAlert&user_id='+user_id+'&sku='+sku+'&period='+$('#'+selectName).val()+'&ajax=enabled';
    $.ajax({url: Url, success: function(data){
            location.reload();            
    }});	


}
