var num = parseFloat('10.1')*5;
point = ',';
if(num>50) {
	point = '.';
}

// if point=='.'
// number(5.3) => 5.3
// number(5,3) => 5.3
function number(num)
{
	var myString = 0;
	if (num) {
		myString = new String(num); //String ÐÅÒÅÍÅÎÎÁÑ
		if (point=='.') {
			myString = myString.replace(",",".");
		} else {
			myString = myString.replace(".",",");
		}
	}
	num = parseFloat(myString);
	if(isNaN(num)) {
		num = 0;
	}
	return num;
}

function TabSW( aTab )
{
    var i=1;
    while(document.getElementById("tab"+i)){ 
        if ( aTab == i) {
            document.getElementById("tab"+i).style.display = 'block';
        }else{
            document.getElementById("tab"+i).style.display = 'none';
        }	
        i++;
    }
}
function Cart( sw )
{
    if (sw ==1){
        document.getElementById("incart").style.display = 'block';
        document.getElementById("cart_open").style.display = 'none';
    }	else{
        document.getElementById("incart").style.display = 'none';
        document.getElementById("cart_open").style.display = 'block';
    }
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function toggleUlMenu (el) {
    var ul = null;
    var childs = el.childNodes;
    for (var i = 0; i<childs.length; i++) {
        if (childs[i].tagName == 'UL') {
            ul = childs[i];
        }
    }
    if (ul) {
        if (ul.style.display == '')	{
            childs = ul.getElementsByTagName('UL');
            for (var i = 0; i<childs.length; i++) {
                childs[i].style.display = 'none';
            }
            ul.style.display = 'none';
        } else {
            ul.style.display = '';
        }
    }
    if (el.parentNode.id && el.parentNode.parentNode.tagName != 'UL' && el.parentNode.parentNode.tagName != 'LI') {
        childs = el.parentNode.childNodes;
        for (var i = 0; i<childs.length; i++) {
            if (childs[i].tagName == 'LI' && childs[i] != el) {
                var uls = childs[i].getElementsByTagName('UL');
                for (var j=0; j<uls.length; j++) {
                    uls[j].style.display = 'none';
                }
            }
        }
        
    }
}

function rollMenu(except, subcat, suba)
{
	var node = null;
	var i = 1;
	while(node=document.getElementById(subcat+i)) {
		if(except!=i) {
			node.style.display = 'none';
			if(node=document.getElementById(suba+i)) {
				node.className='';
			}
		}
		i++;
	}
}

function toggleMenu (el) 
{
	var ul = null;
	//var id = null;
	//id = document.getElementById(el);
	var childs = document.getElementById(el).childNodes;
	
	for (var i = 0; i<childs.length; i++) {
		if (childs[i].tagName == 'UL') {
			ul = childs[i];
		}
		
		if (childs[i].tagName == 'A') {
			childs[i].className = (childs[i].className=='active' ? '' : 'active');
		}
	}
	
	if (ul) {
		if (ul.style.display == '')	{
			childs = ul.getElementsByTagName('UL');
			for (var i = 0; i<childs.length; i++) {
				childs[i].style.display = 'none';
			}
			ul.style.display = 'none';
		} else {
			ul.style.display = '';
		}
	}
	return false
}


function toggleCart()
{
	if ($("#incart").css("display") == 'none') {
		$("#cart_open").hide();
		$("#cart_close").show();
	}
	
	$("#incart").slideToggle("normal", function() {
	
			if (this.style.display == 'none') {
				$("#cart_open").show();	
			}
			
			createCookie('cart_state', (this.style.display == 'none' ? 'close' : 'open'), 0);
			}
		);
    
}

function toggleFilters()
{
    if ($("#side_filters").css("display") == 'none') {
        $("#side_filters_open").hide();
    }
    $("#side_filters").slideToggle("normal", function() {
                                                if (this.style.display == 'none') {
                                                    $("#side_filters_close").hide();
                                                    $("#side_filters_open").show();
                                                } else {
                                                    $("#side_filters_open").hide();
                                                    $("#side_filters_close").show();
                                                }
                                                createCookie('filters_state', (this.style.display == 'none' ? 'close' : 'open'), 0);
                                             });
}

function move_analogs (dir)
{
    var start_ind = -1;
    var stop_ind = -1;
    var items = $("#analogs > .item");
    var count = items.length;
    if (count>3) {
        var ind = 0;
        var first = -1;
        var last = -1;
        items.each(function() {
            if (first<0 && $(this).css("display") != 'none') {
                first = ind;
            }
            if ($(this).css("display") != 'none') {
                last = ind;
            }
            ind++;
        });
        if (last - first == 2) {
            if (dir == 'left' && first > 0) {
                $(items.get(last)).hide();
                $(items.get(first-1)).show();
            }
            if (dir == 'right' && last < count-1) {
                $(items.get(first)).hide();
                $(items.get(last+1)).show();
            }
        }
    }
}

var analogs_animate = 0;
function move_analogs_anim (dir, item_size, item_count)
{
    if (!analogs_animate) {
        if (dir == 'left') {
            if (parseInt($("#analogs_inner").css("left"))<0) {
                analogs_animate = 1;
                $("#analogs_inner").animate({left: parseInt($("#analogs_inner").css("left")) + item_size + 'px'}, 500, function() {analogs_animate = 0});                
            }
        } else if (dir == 'right') {
            if (parseInt($("#analogs_inner").css("left")) > item_size * item_count - parseInt($("#analogs_inner").css("width"))) {
                analogs_animate = 1;
                $("#analogs_inner").animate({left: parseInt($("#analogs_inner").css("left")) - item_size + 'px'}, 500, function() {analogs_animate = 0});
            }
        }
    }
}


////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
function win_popup(url,width,heigh,win)
{
	var win_handle = window.open(url,win,'height='+heigh+',width='+width+',resizable=yes,scrollbars=yes,toolbar=no,status=no,location=no,menubar=no');
	win_handle.window.focus();
}

function win_popup_menu(url,width,heigh,win)
{
	var win_handle = window.open(url,win,'height='+heigh+',width='+width+',resizable=yes,scrollbars=yes,toolbar=no,status=no,location=no,menubar=yes');
	win_handle.window.focus();
}

function open_window(url,width,heigh) 
{
	win_popup(url,width,heigh,'compare');
}

function open_window_order(url,width,heigh) 
{
	win_popup(url,width,heigh,'order');
}

//Ôóíêöèÿ äëÿ âûáîðêè çàäàííîãî cookie íà JavaScript
//var cook_uname = GetCookie('uname');
function GetCookie (name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var endstr = 0;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			endstr = document.cookie.indexOf (";", j);
			if (endstr == -1){
				endstr = document.cookie.length;
			}
			return unescape(document.cookie.substring(j, endstr));
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) { break; }
	}
	return null;
}

function setTitle(my, title)
{
	if(my.value=='') {
		my.value=title;
	}
}

function clearField(my, title)
{
	if(my.value==title) {
		my.value='';
	}
}

function removeFocusOnAllLinks()
{  
	for(var i=0; i<document.links.length; i++) {
		document.links[i].onfocus=blurLink;
	}
}

function blurLink() 
{
	if (this.blur) {
		this.blur();
	}
}

//window.onload=removeFocusOnAllLinks; 

function showLoader()
{
	var txt = '<div id="jquery-overlay" style="background-color:rgb(0, 0, 0); opacity:0.6; width:1263px; height:2049px; left:0pt; line-height:0pt; position:absolute; text-align:center; top:0pt; width:100%; z-index:100;"></div>';
	$("body").append(txt);
	
	txt = "<div id='TB_load'><img src='/img/js/loadingAnimation.gif' onload=''/></div>";
	$("body").append(txt);
	$('#TB_load').show();
}
function removeLoader()
{
	$("#jquery-overlay").remove();
	$("#TB_load").remove();
}

function createIFrame(id, parent, l,t,w,h)
{	      
	var frame = document.getElementById('SelectIFrame');
	if (!frame) {
	    frame = document.createElement('IFRAME'); 
	    menu = document.getElementById(parent);
	    menu.appendChild(frame);  
	} 
    frame.setAttribute('id',id);   
    frame.style.position = 'absolute';  
    frame.style.left = l+"px";
    frame.style.top = t+"px";
    frame.style.background = "transparent";
    frame.style.width = w+"px";
    frame.style.height = h+"px";  
    frame.style.display = "none";
    frame.style.zIndex = 97;
    frame.frameBorder = 0;	   	 
}



function SW( aTab )
{
	var i=1;
	while(i<10){
		if(document.getElementById("sub"+i)){
			if ( aTab == i) {
				document.getElementById("sub"+i).style.display = 'block';
					var active = $("ul[id='sub"+aTab+"']");
					active.show();	
					
					if ( $.browser.msie ) {
						var pos = active.position();
						if (pos) {	
							createIFrame("SelectIFrame",'main_menu', pos.left,pos.top,active.outerWidth(),active.outerHeight());
							$("#SelectIFrame").show();	
						}
					}
			}else{
				document.getElementById("sub"+i).style.display = 'none';
			}	
		}
		i++;
	}
}

function Hide( )
{
	var i=1;
	while(i<10){
		if(document.getElementById("sub"+i)){
			document.getElementById("sub"+i).style.display = 'none';
		}
		i++;
	}
	if ( $.browser.msie ) $("#SelectIFrame").hide();
}


function Cart( sw )
{
	if (sw ==1){
		document.getElementById("incart").style.display = 'block';
		document.getElementById("cart_open").style.display = 'none';
		}	else{
		document.getElementById("incart").style.display = 'none';
		document.getElementById("cart_open").style.display = 'block';
		}
}
