﻿function CurrToNumber(sCurrency) 
{
    var Temp = new String();
	Temp=sCurrency;
    return Temp.replace(/[/.]/ig,'');
}

function NumToCurrency(sNumber,nDec) {  
  if (sNumber!=null && sNumber!='')
  {

  var Temp = new String();
  var Top, Bottom, Num; 
	Temp = sNumber;
	Temp = Temp.replace(/[.]/ig,'');
	Temp = Temp.replace(/[,]/ig,'.');
	Num = parseFloat(Temp.replace(/[^\d\.]/ig,''));	
	if (isNaN(Num)) return '';
	else {
	    if (nDec == -1)
	        return Num;
	        
  	  Top = Math.floor(Num);
	  Bottom = Math.round((Num - Math.floor(Num)) * Math.pow(10,nDec));	  
	  Bottom = Bottom.toString();
	  if (Bottom==100) {Bottom='00'; Top=Top+1}
	  Top = Top.toString();
	  Temp='';
	  while (Bottom.length<nDec) {
 	    Bottom = '0' + Bottom;
	  }
	  while (Top.length>3) {
	    Temp = '.' + Top.slice(Top.length-3) + Temp;
	    Top = Top.substr(0,Top.length-3);
	  }	
	  if (nDec>0) 
		{Temp= Top + Temp + "," + Bottom;
		}
	  else
	    {Temp= Top + Temp}
	  if (sNumber.substring(0,1) == '-')
	  {
	  Temp='-'+Temp
	  }
	  return Temp;
	}
	
	}
	else
	{
	return ''
	}
}

function LinkTo(name, company, domain) {
      locationstring = 'mai' + 'lto:' + name + '@' + company + '.' + domain;
      window.location.replace(locationstring);
   }

function Popup(url, w, h)
{
    wleft = (screen.width - w) / 2;
    wtop = (screen.height - h) / 2;
    window.open(url, "popPrint", "dependent,modal,center=yes;resizable=yes,toolbar=no,scrollbars=yes,menubar=no,status=yes,directories=no,width=" + w + ",height=" + h + ",top=" + wtop + ",left=" + wleft);
}

var tags = new Array( 'span', 'div','td','tr','p','b','table','strong','emphasis','a','h1','h2','h3','pre','sub','sup','i','th','cp','ul','ol','li','dt','dd');
var pixelArray =  new Array('9','11','13','15','24','30','40');
var emArray =  new Array('0.6','0.9','1.0','1.5','2.0','2.5','3');
var initSize = 1;
var incSize = 1;

function FontSizer(inc, unit) {
	
	if (!document.getElementById) 
		return;
			
    incSize += inc;    
    if (incSize <0)
        incSize=0;    
    
    inc = incSize;    
	var sizeTitle = 20;
	var size = initSize;
		size = inc;
		
		if (inc > 1)
			sizeTitle +=inc;
		
	if (size < 0 ) {
		size = 0;
        }
	        if (size > 6 ) {
		        size = 6;
        }
        initSize = size;
        getBody = document.getElementById('content');				
	for (i = 0 ; i < tags.length ; i++ ) {
		getallTags = getBody.getElementsByTagName(tags[i]);
	for (k = 0 ; k < getallTags.length ; k++) 		
		{
		//if (getallTags[k].style.fontSize != undefined) alert(getallTags[k].style.fontSize)		
		
		if (getallTags[k].className == "tabTitle")		
			{
			getallTags[k].style.fontSize = sizeTitle+'px';						
			}
		else if (getallTags[k].tagName == "H1")		
			{
			getallTags[k].style.fontSize = sizeTitle+'px';						
			}			
		else
			getallTags[k].style.fontSize = (unit=='px') ? pixelArray[size]+unit: emArray[size]+unit;			
		}
	}
}

var lineH=1;
function LineHeightInc()
{
    lineH +=0.5;
    $('div#content').css("lineHeight", lineH);
}

function FaqToogle(element) {
    $(".answer", $(element).parent().parent()).each(function() { $(this).hide('slow') });
    $(element).next().toggle('slow');
}

function SetTabs() {
    var selGroup  = 0, selItem = 0;
    var loc = window.location.toString();
    if (loc.indexOf('#tab') > 0)
    {
        loc = loc.substring(loc.indexOf('#tab')+4);
        selGroup = loc.split('_')[0];
        selItem = loc.split('_')[1];        
    }

    $("#content .tabWrapper").each(function (groupIndex) {
        var wrapper = $(this);
        var html = "<ul class='tabManager clear'>";
        wrapper.children().each(function (index) {            
            html += "<li class='t'>" + $(this).attr("title") + "</li>";
        });

        wrapper.children().wrapAll("<div class='tabContent' />");
        wrapper.children(":eq(0)").before(html + "</ul>");

        if (groupIndex == selGroup)
        {
            wrapper.find(".hidden:eq("+selItem+")").show();
            $("li.t:eq("+selItem+")", wrapper).addClass("active");
        }
        else
        {
            wrapper.find(".hidden:eq(0)").show();
            $("li.t:first", wrapper).addClass("active");
        }

        $("li.t", wrapper).each(function (index) {
            $(this).bind("click", function () {
                $(this).parent().next().children().hide();
                $(this).parent().next().children(":eq(" + $(this).index() + ")").show();
                $("li.t", $(this).parent()).removeClass('active');
                $(this).addClass('active');
                window.location = "#tab" + groupIndex + "_" + index;                
            })
        });
    });        
}

function SetTabsOld() {  
    var selGroup  = 0, selItem = 0;
    var loc = window.location.toString();
    if (loc.indexOf('#tab') > 0)
    {
        loc = loc.substring(loc.indexOf('#tab')+4);
        selGroup = loc.split('_')[0];
        selItem = loc.split('_')[1];        
    }
        
    $("#content .tabWrapper").each(function(groupIndex) {
        var wrapper = $(this);        
        var html = "<ul class='tabManager clear'>";            
        wrapper.children().each(function(index) {                                         
            html += "<li class='t'>" + $(this).attr("title") + "</li>";
        });
        
        if (groupIndex == selGroup)
        {
            wrapper.append(html + "</ul><div class='tabContent'>" + wrapper.children(":eq("+selItem+")").html() + "</div>");
            $("li.t:eq("+selItem+")", wrapper).addClass("active");                
        }
        else
        {
            wrapper.append(html + "</ul><div class='tabContent'>" + wrapper.children(":first").html() + "</div>");
            $("li.t:first", wrapper).addClass("active");                
        }
        
        $("li.t", wrapper).each(function(index) {            
            $(this).bind("click", function() {                
                $(this).parent().next().html($(this).parent().parent().children(":eq(" + $(this).index() + ")").html());
                window.location = "#tab" + groupIndex + "_" + index;
                $("li.t", $(this).parent()).removeClass('active');
                $(this).addClass('active');
            })
        });        
    });  
}

function MenuTopAppLink(elem, over)
{       
    $(elem).removeClass("over")    
    if (over)
        $(elem).addClass("over")
}

function MenuTopLink(elem, over)
{
    $(elem).removeClass("linkOver")    
    if (over)
        $(elem).addClass("linkOver")
}

function SlidingBannerMove(direction) {
    var el = $("#bannerMainContentLst .show");
el.removeClass("show");

    if (direction == 'next') {
        if (el.next().length)
            el = el.next();
        else
            el = $("#bannerMainContentLst li:first");
    }
    else {
        if (el.prev().length)
            el = el.prev();
        else
            el = $("#bannerMainContentLst li:last");
    }
    el.addClass("show");
    
    $(".bannerMain .boxOuter .boxInner a").attr("href", el.children(":last").find("a").attr("href"));    
    $(".bannerMain .boxOuter .boxInner .title h1").fadeOut(1000, function() { $(this).html(el.children(":first").html()).fadeIn(500); });
    $(".bannerMain .boxOuter .boxInner .text span").fadeOut(1000, function() { $(this).html(el.children(":eq(1)").html()).fadeIn(500); });
    $("#bannerMainContent").fadeOut(1000, function() { $(this).html(el.children(":eq(2)").html()).fadeIn(1000) });
}

function AddBookmark() {
    if (window.sidebar)
        window.sidebar.addPanel(document.title, location.href, "");
    else if (window.external)
        window.external.AddFavorite(location.href, document.title);
    else if (window.opera && window.print)
        return true;
}

$.fn.ModalDialogHide = function($params) {
    var element = $(this);
    $(document).unbind('keyup');
    element.hide();
    $("#ModalPopupOuter").hide();
    $("#btnCloseWrapper", element).remove();
}

$.fn.ModalDialogShow = function($params) {
    var element = $(this);
    var $defaults = {        
        closeButton: true,
        onFade: function(element){}        
    };
    var $p = $.extend($defaults, $params);
    
    ShowPopup();
    
    function ShowPopup() {
        if ($("#ModalPopupOuter").length == 0)        
            $("#top").before("<div id='ModalPopupOuter'></div>");                                                            
                
        $(document).keyup(function(e) {if (e.keyCode == 27) {element.ModalDialogHide()}}); 
        if ($p.closeButton)
        {
            element.append("<div id='btnCloseWrapper' class='clear padBottom10'><div class='btnCloseDialog'><input type='button' id='btnCloseMP' class='btnRed' value='Zapri'/></div></div>");
            $("#btnCloseMP", element).click(function(){element.ModalDialogHide()});
        }
        
        var maskHeight = $(window).height();
        var maskWidth = $(window).width();
        
        if ($.browser.msie)
            maskWidth = $("#outer").width();
                
        $("#ModalPopupOuter").css({'width': maskWidth, 'height': maskHeight });
        $("#ModalPopupOuter").fadeTo("fast", 0.7);
        $("#ModalPopupOuter").fadeIn(500);

        var winH = $(window).height();
        var winW = $(window).width();      
        
        element.css('top', winH / 2 - element.height() / 2 + $(window).scrollTop());
        element.css('left', winW / 2 - element.width() / 2);
        element.fadeIn(500, function(){$p.onFade($(this))});
    }
};

$.fn.hint = function (blurClass) {
    if (!blurClass) blurClass = 'blur';    
    return this.each(function () {
        var $input = $(this),
            title = $input.attr('title'),
            $form = $(this.form),
            $win = $(window);

        function remove() {
            if (this.value === title && $input.hasClass(blurClass)) {
                $input.val('').removeClass(blurClass);
            }
        }
        
        if (title) {             
            $input.blur(function () {
                if (this.value == '') {
                    $input.val(title).addClass(blurClass);
                }
            }).focus(remove).blur();
                        
            $form.submit(remove);
            $win.unload(remove); 
        }
    });
};

var mnuVisible = false;
var ddAppsVisible = false;
var mnuActive;

function DdAppsToggle(show) {
    var dd = $("#ddPanel");
        
    ddAppsVisible = show;    

    if (show)    
        dd.stop(false, true).slideDown(500);      
    else
        window.setTimeout(function() {if (!ddAppsVisible) {dd.hide(100);}}, 200);    
}    

function MenuLinkClick(url) 
{
    window.location = url;    
}

function MenuTopToggle(show, sender) {
    var mnuBg = $("#mnuTopMask");
    var mnuContent = $("#contentBox .mnuTopContent");

    mnuVisible = show;

    if (show)
        mnuBg.fadeTo(300, 0.6, function() { mnuContent.fadeIn(1); });
    else {
        window.setTimeout(function() {
            if (!mnuVisible) {
                mnuBg.hide(1, function() { mnuContent.hide(1) })
                 $("#mnuTopBox .itm").removeClass("itmSel");
                if (mnuActive)
                    $(mnuActive).addClass("itmSel");                    
            }
        }, 200);
    }
}

function MenuTopSwitchContent(sender) 
{
    sender = $(sender);
    
    $("#mnuTopBox .itm").each(function() {
    $("#topMenuContent" + GetMenuID($(this))).hide();
        $(this).removeClass("itmSel");
    });
    
    var id = GetMenuID(sender);
        
    sender.addClass("itmSel")        
    $("#topMenuContent" + id).show();    
    $("#contentBox .mnuTopContent").css("background","url('"+eval("topMenuContent"+id)+"') no-repeat scroll right 0 #fff");    
}

function GetMenuID(elem) {
    return elem.attr("id").replace("mt", "");
}

