
function main_custom () {
    this.global = new Array();
    this.change_select = function(){
        $(".change_select").each(function(){
            var id = $(this).attr("id");
            var name = $(this).attr("name");

            var f_child = $(this).find("option:eq(0)");

            var l = $(this).find("option").length;
            if (l > 4) l = 4;
            var h = l * 32;

            var final_l  ="<div id='name_" + id + "' class='s_name"+($(this).parent().hasClass("select_1")?" small":"")+"' onclick='custom.show_drop(\"" + id + "\");'>" + f_child.text() + "</div>";
            final_l += "<input type='hidden' name='" + name + "'  price='"+f_child.attr("price")+"' value='" + f_child.val() + "' title='" + f_child.text() + "' id='val_" + id + "' />";
            final_l += "<div class='drop' id='drop_" + id + "'>";
            final_l += "<div class='drop_up' onclick='custom.hide_drop();'>" + f_child.text() + "</div>";
            final_l += "<div class='drop_center'><div class='scroll' style='height:"+h+"px'>";
            $(this).find("option").each(function(){
                var v = $(this).val();
                var t = $(this).text();
                

                final_l += "<div class='op' value='" + v + "' price='"+$(this).attr("price")+"' onclick='custom.change_val(\"" + id + "\" , $(this), "+$(this).attr("price")+")'>" + t + "</div>";
            })

            final_l += "</div></div>";
            final_l += "<div class='drop_bottom'></div>";
            final_l += "</div>";
            var p = $(this).parent("div");
            p.html(final_l);
        })
    }

    this.hide_drop = function(){
        $(".drop").hide();
    }

    this.show_drop = function(id){

        this.hide_drop();


        $("#drop_" + id) . show();
        $("#drop_" + id).find(".drop_center .scroll").jScrollPane({
            scrollbarWidth : 15,
	dragMinHeight :18
        });
    }

    this.change_val = function(id , obj){
        var v = obj.attr("value");

        if (v==2) {selected_europe();}
        if (v==1) {selected_usa();}
        if (v==0) {noselected();}

        var t = obj.text();
        $("#val_" + id).val(v).attr({
            "title" : t
        });

        this.hide_drop();

        $("#drop_" + id).find(".drop_up").text(t);
        $("#name_" + id).text(t);
        $("#server_id").val(v);
        if ($("#levelupform").length)
		{
			calc_level();
			return;
		}
        itemprice = obj.attr("price");

        $("#val_" + id).attr("price",itemprice);
        calc2(document.getElementById("item_count"));
    }

    this.change_valuta = function(v , obj){
        $("#valuta_t").html(v);
        $("#valuta").val(obj.attr("currency_id"));//v
        changeCurrency(obj.attr("currency_id"));

        $(".radio").removeClass("active")
        obj.addClass("active")
    }

    this.login = function(){
        $(".overlay").css({
            "opacity" : 0 ,
            "display" : "block"
        }).animate({
            "opacity" : 1
        } , 500);

        $(".popups").css({
            "opacity" : 0 ,
            "display" : "block"
        }).animate({
            "opacity" : 1
        } , 500);
        $(".popups").removeClass('error').removeClass('success');

        $(".pops").hide();
        $(".popup_login").show();
    }
//
//
    this.register = function(){
        $(".overlay").css({
            "opacity" : 0 ,
            "display" : "block"
        }).animate({
            "opacity" : 1
        } , 500);

        $(".popups").css({
            "opacity" : 0 ,
            "display" : "block"
        }).animate({
            "opacity" : 1
        } , 500);
        $(".popups").removeClass('error').removeClass('success');

        $(".pops").hide();
        $(".popup_register").show();
    }
//
    this.forgot_pass = function(){
        this.close_pop();

        setTimeout(function(){

            $(".overlay").css({
                "opacity" : 0 ,
                "display" : "block"
            }).animate({
                "opacity" : 1
            } , 500);

            $(".popups").css({
                "opacity" : 0 ,
                "display" : "block"
            }).animate({
                "opacity" : 1
            } , 500);
            $(".popups").removeClass('error').removeClass('success');

            $(".pops").hide();
            $(".popup_forg_pass").show();
        } , 600 , custom)
    }

    this.wait_register = function(){
        this.close_pop();

        setTimeout(function(){

            custom.register();
        } , 600 , custom)
    }

    this.close_pop = function(){
        $(".overlay").animate({
            "opacity" : 0
        } , 500 , function(){
            $(this).css({
                "display" : "none"
            });
        });

        $(".popups").animate({
            "opacity" : 0
        } , 500 , function(){
            $(this).css({
                "display" : "none"
            });
        });
    }
}

var custom = new main_custom();

$(document).ready(function(){



    custom.change_select();
})
$(document).bind('click', function(e) {
    var $clicked = $(e.target);
    if ($clicked.parents().attr("id") != "mini_select")
        $("#mini_select_inner").hide();
});


$(document).ready(function(){

    $(".europa_mask").hover(function(){

       var lang = $(this).attr("lang");
       
       if (lang!='selecteds') {
       $(".bik_img_2").stop().animate({"opacity":1},300);
       $(".bik_img_1").stop().animate({"opacity":0},400);
       $(".usa_img_1").stop().animate({"opacity":0.6},400);
       $(".server_name_eu").stop().animate({"opacity":1},400);
       $(".server_name_usa").stop().animate({"opacity":0.6},400);

       }

       var val = $("#val_select_0").val();

      if (val!=2 && lang=='selecteds') {

       $(".bik_img_2").stop().animate({"opacity":1},300);
       $(".bik_img_1").stop().animate({"opacity":0},400);
       $(".server_name_eu").stop().animate({"opacity":1},400);

       }

       }).mouseout(function(){


       var lang = $(this).attr("lang");
       if (lang!='selecteds') {
       $(".bik_img_2").stop().animate({"opacity":0},300);
       $(".bik_img_1").stop().animate({"opacity":1},300);
       $(".server_name_eu").stop().animate({"opacity":1},400);
       $(".usa_img_1").stop().animate({"opacity":1},400);
       $(".server_name_usa").stop().animate({"opacity":1},400);
       }


       var val = $("#val_select_0").val();

       if (val!=2 && lang=='selecteds') {

       $(".bik_img_2").stop().animate({"opacity":0},300);
       $(".bik_img_1").stop().animate({"opacity":0.3},400);
       $(".server_name_eu").stop().animate({"opacity":0.3},400);

       }



       });


    $(".usa_mask").hover(function(){

  var lang = $(this).attr("lang");

if (lang!='selecteds') {
       $(".usa_img_2").stop().animate({"opacity":1},300);
       $(".usa_img_1").stop().animate({"opacity":0},400);
       $(".bik_img_1").stop().animate({"opacity":0.6},400);
       $(".server_name_usa").stop().animate({"opacity":1},400);
       $(".server_name_eu").stop().animate({"opacity":0.6},400);
}


var val = $("#val_select_0").val();

       if (val!=1 && lang=='selecteds') {
	       $(".usa_img_2").stop().animate({"opacity":1},300);
	       $(".usa_img_1").stop().animate({"opacity":0},400);
       	$(".server_name_usa").stop().animate({"opacity":1},400);
       }
    }).mouseout(function(){

    var lang = $(this).attr("lang");
    if (lang!='selecteds') {
       $(".usa_img_2").stop().animate({"opacity":0},300);
       $(".usa_img_1").stop().animate({"opacity":1},300);
       $(".bik_img_1").stop().animate({"opacity":1},400);
       $(".server_name_usa").stop().animate({"opacity":1},400);
       $(".server_name_eu").stop().animate({"opacity":1},400);
    }

    var val = $("#val_select_0").val();

       if (val!=1 && lang=='selecteds') {
	       $(".usa_img_2").stop().animate({"opacity":0},300);
       		$(".usa_img_1").stop().animate({"opacity":0.3},400);
	       $(".server_name_usa").stop().animate({"opacity":0.3},400);
       }
    });

    $(".europa_mask").click(function(){selected_europe();

    $("#chose_game .check").removeClass("active");
    $("#chose_game .check").eq(1).addClass("active");
    $("#val_select_0").val(2);


    });

$(".usa_mask").click(function(){
    selected_usa();
    $("#val_select_0").val(1);
    $("#chose_game .check").removeClass("active");
    $("#chose_game .check").eq(0).addClass("active");
   // var obj = $(".scroll .op").eq(1);
   // custom.change_val("select_1" ,obj);
});

$("#chose_game .check").click(function(){

 $("#chose_game .check").removeClass("active");

    if ($(this).attr("value")==2) {

        selected_europe();
        $(this).addClass("active");
        $("#val_select_0").val(2);
        

    }
    if ($(this).attr("value")==1) {

        selected_usa();
        $(this).addClass("active");
        $("#val_select_0").val(1);
    }

    $(".games_item").hide();
    $(".game_"+$(this).attr("value")).show();
    
    $("#server_id").val($("#val_select_"+$(this).attr("value")).val());
    $("#chose_fraction").val($(".chose_fraction.game_"+$(this).attr("value")+" .active").attr("value")); 

    if ($("#levelupform").length)
		{
			calc_level();
			return;
		}

        itemprice = $("#val_select_"+$(this).attr("value")).attr("price");
        calc2(document.getElementById("item_count"));
    
});



$(".chose_fraction .check").click(function(){
 $(".check", $(this).parent()).removeClass("active");
 	$(this).addClass("active");
        $("#chose_fraction").val($(this).attr("value")); 
    /*if ($(this).attr("value")==2) {
        $(this).addClass("active");
        $("#chose_fraction").val(1); 
    }
    if ($(this).attr("value")==1) {
        $(this).addClass("active");
        $("#chose_fraction").val(2); 
    }*/

});





});




function selected_europe() {
        $(".bik_img_2").stop().animate({"opacity":1},300);
        $(".bik_img_1").stop().animate({"opacity":0},400);
        $(".usa_img_1").stop().animate({"opacity":0.3},400);
        $(".server_name_usa").stop().animate({"opacity":0.3},400);
        $(".server_name_eu").stop().animate({"opacity":1},400);
        $(".usa_img_2").stop().animate({"opacity":0},400);
        $(".europa_mask").attr("lang","selecteds");
        $(".usa_mask").attr("lang","selecteds");
}


function selected_usa() { //alert("x");
        $(".usa_img_1").stop().animate({"opacity":0},300);
        $(".usa_img_2").stop().animate({"opacity":1},400);
        $(".bik_img_1").stop().animate({"opacity":0.3},400);
        $(".bik_img_2").stop().animate({"opacity":0},400);
        
        $(".usa_mask").attr("lang","selecteds");
        $(".server_name_usa").stop().animate({"opacity":1},400);
        $(".server_name_eu").stop().animate({"opacity":0.3},400);
}

function noselected() {
        $(".usa_img_1").stop().animate({"opacity":1},300);
        $(".usa_img_2").stop().animate({"opacity":0},400);
        $(".bik_img_1").stop().animate({"opacity":1},400);
        $(".bik_img_2").stop().animate({"opacity":0},400);
        $(".europa_mask").attr("lang","nan");
        $(".usa_mask").attr("lang","nan");
        $(".server_name_usa").stop().animate({"opacity":1},400);
        $(".server_name_eu").stop().animate({"opacity":1},400);
}


function calc() {
	//alert();

	if ($("#levelupform").length)
		{
			calc_level();
			return;
		}
	//	var o = document.getElementById("select_1");
	//alert(o);
	//var ser = $("#server_id").val();
	//itemprice = $("#server_li_"+ser).attr("price");
	if (itemprice>0) {
		calc2(document.getElementById("item_count"));
	} else {
		$("#item_sum").val("---");
	}
}


	function changeCurrency(i) {
		selectedCurrency = i;
	        if ($("#levelupform").length)
		{
			calc_level();
			return;
		}
		
		calc2(document.getElementById("item_count"));

	
	}


function calc2(o) {
	var c = itemprice;

	if ((c<=0)&&(defaultPrice)&&(defaultPrice>0)) 
		c = defaultPrice;
		o.value = o.value*1;
		

	if(Math.floor(o.value)!=o.value)
		o.value = Math.floor(o.value);

	if (o.value=="NaN")
		o.value = 0;

	
	if ((c<=0)||(o.value<0)) {
		jQuery("#item_sum").val(0);
		o.value = 0;
				 if (document.getElementById("discountSpan")) {
				document.getElementById("discountSpan").innerHTML = 0;
				}
		return;
	}

	if (o.value=="-") {
		jQuery("#item_sum").val(0);
				 if (document.getElementById("discountSpan")) {
				document.getElementById("discountSpan").innerHTML = 0;
				}
		return;
	}

	var d = userdiscount;



	var t = c*(Math.round(o.value*1));
	for(var i=0;i<discounts.length;i++) if (discounts[i]) {
		if (discounts[i][1]*1<=t) {
			if (discounts[i][0]>d)
				d = discounts[i][0];//+" - "+discounts[i][1];
		} else {
			break;
		}
	}
	if (userdiscount>d) {
			d = userdiscount;
		}
	if (d)  {
		t = t-d*t/100;
		
	}
	if (document.getElementById("discountSpan"))   {
			document.getElementById("discountSpan").innerHTML = d;
			}
	if (selectedCurrency)
		if(allCurrencies[selectedCurrency]>0)
			t = t * allCurrencies[selectedCurrency];

	jQuery("#item_sum").val(t.toFixed(2)*1);
	
	//t.toFixed(2)

}


function calc3(o) {
	var c = itemprice;
	if ((c<=0)&&(defaultPrice)&&(defaultPrice>0)) 
		c = defaultPrice;
		o.value = o.value*1;
	if (o.value=="NaN")
		o.value = 0;

	if ((c<=0)||(o.value<0)) {
		jQuery("#item_count").val(0);
		o.value = 0;
				 if (document.getElementById("discountSpan")) {
				document.getElementById("discountSpan").innerHTML = 0;
				}
	} else {
		var s = o.value.replace(",",".");
		var t = 1.0*(s)/c;

		if (selectedCurrency)
			if(allCurrencies[selectedCurrency]>0)
				t = t / allCurrencies[selectedCurrency];


		var d = userdiscount;
		
		for(var i=0;i<discounts.length;i++) if (discounts[i] ) {
			
			if ((discounts[i][1]<=s)) {
				if (discounts[i][0]>d*1)
				
					d = discounts[i][0];//+" - "+discounts[i][1];
			} /*else if ((((o.value*100/(100-discounts[i][0]))/c>=discounts[i][1]))&&(d<discounts[i][0])) {
				d = discounts[i][0];
				break;
			}*/
		}
		

		if (userdiscount>d) {
			d = userdiscount;
		}

		if (d){
		 	t = t*100/(100-d);
		 	

		 }
		 if (document.getElementById("discountSpan")) {
				document.getElementById("discountSpan").innerHTML = d;
				}

		jQuery("#item_count").val(Math.round(t));
//		alert(c + " "+ d+" "+s);
		//Math.floor(t)
		 //+" "+ d+" "+c+" "+o.value/

	}
	

}

/* USA */

var itemprice = 0;
function calc() {
	//alert();

	if ($("#levelupform").length)
		{
			calc_level();
			return;
		}
	var ser = $("#server_id").val();
	itemprice = $("#server_li_"+ser).attr("price");
	if (itemprice>0) {
		calc2(document.getElementById("item_count"));
	} else {
		$("#item_sum").val("---");
	}
}

function calc_level() {
	var sq = "", pr_id = -1;
	if ($("#item_id_hidden").val()==-1) {
		sq = "_profs";
		pr_id = $("#val_level_profession_id").val();
	}
	var ser = $("#server_id").val(), lev_1 = 1*$("#val_item_level1"+sq).val(), lev_2 = 1*$("#val_item_level2"+sq).val();
	//alert(lev_1+" "+lev_2);

	if (lev_1*1>=lev_2*1) {
		//$("#item_level2").val(lev_1+1);
		$("#days_need").html("---");
		$("#hours_need").html("---");
		$("#item_sum_html").html("---");
		return;
	}
	var s = 0,tim = 0, str="";
	
	
	for (var i=lev_1+1; i<=lev_2;i++) {
		if (sq=="") {
		if ((typeof(levelupprices[ser])!="undefined")&&(typeof(levelupprices[ser][i])!="undefined") )
			s += 1*levelupprices[ser][i];
		else if ((typeof(levelupprices[0][i])!="undefined")&&(levelupprices[0][i].p>0))  {
			
			s += 1*levelupprices[0][i].p;
			//s = Math.round(s*100)/100;
		} else {
			$("#item_sum").val("---");
			return;
		}
		if ((typeof(levelupprices[0][i])!="undefined")&&(levelupprices[0][i].t>0))  {
			
			tim += levelupprices[0][i].t;
		}
		} else {
			if (profs[pr_id].l[i] && profs[pr_id].l[i].p) {
				s += 1*profs[pr_id].l[i].p*1;
				tim += 1*profs[pr_id].l[i].t*1;
			} else {
				$("#item_sum").val("---");
				return;
			}
		}
		
	}

	var t = s;
	
	var d = userdiscount;
	
	for(var i=0;i<discounts.length;i++) if (discounts[i]) {
		if (discounts[i][1]*1<=t) {
			if (discounts[i][0]>d)
				d = discounts[i][0];//+" - "+discounts[i][1];
		} else {
			break;
		}
	}
	if (userdiscount>d) {
			d = userdiscount;
		}
	if (d)  {
		t = t-d*t/100;
		
	}
	var rat = 1;
	
	if (document.getElementById("discountSpan"))   {
			document.getElementById("discountSpan").innerHTML = d;
			}
			if (selectedCurrency)
	if(allCurrencies[selectedCurrency]>0) {
			rat = allCurrencies[selectedCurrency];
			t = t * rat;
        }

	//$("#item_sum").val(t);
	$("#days_need").html(Math.floor(tim/24));
	$("#hours_need").html(tim%24);
	var te = $("#item_price_hidden").val()*rat;

	if ((te>0)&&(te>t)) {
		t = te;
		$("#need_more_help").show();
	} else {
		$("#need_more_help").hide();
	}

	$("#item_sum_html").html(Math.round(t*100)/100);


}
var discounts = [], userdiscount = 0;


jQuery(function(){
	if(jQuery('.bay_isk form input[type="radio"]:checked').attr('value') == 4)
			jQuery('.bay_isk form li:eq(1) input').addClass('euro');
	jQuery('.bay_isk form input[type="radio"]').change(function(){
		if(jQuery(this).attr('value') == 4)
			jQuery('.bay_isk form li:eq(1) input').addClass('euro');
		else
			jQuery('.bay_isk form li:eq(1) input').removeClass('euro');
	});
	jQuery(".my_table li").click(function () {
		if ($("a",$(this)).attr("href")) {
			window.location = $("a",$(this)).attr("href");
			
		}
	}
	);
});

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
