$(document).ready(function(){
  var elem = $(window);
 //----
    $("A").mousedown( function(){  
         $(this).blur();
    }).focus( function(){
         $(this).blur();
    }).click( function(){
         $(this).blur();
    });

	// truncate comment data
	$(".tiny").focus( function() {
		if( $(this).val() == "Введите здесь свой комментарий") $(this).val('');
	});
	
	scanOpenSessions();

	$.fn.tagName = function() { 
		return this.get(0).tagName; 
	} 
	$.fn.maxZIndex = function(opt) {
		var def = { inc: 10, group: "*" };
		$.extend(def, opt);    
		var zmax = 0;
		$(def.group).each(function() {
			var cur = parseInt($(this).css('z-index'));
			zmax = cur > zmax ? cur : zmax;
		});
		if (!this.jquery)
			return zmax;

		return this.each(function() {
			zmax += def.inc;
			$(this).css("z-index", zmax);
		});
	}
	$.extend($.expr[':'], {  
		noid: function(a) {  
			return $(a).attr("id") == '';  
		}  
	}); 

	$(".bm-bg-last").css( {'backgroundImage':'url(/project/img/bm-non.png)', 'background-position' : '100% 0'} );

	$.each( $(".bm-bg"), function(i,val) {
		//var id = $(this).attr('id').replace( 'bm-container','' );
		//$( "#" + id + " .bm-bg-i:last").css( {'backgroundImage':'url(/project/img/bm-non.png)'} );
	});

	$(".bm-bg-i").css( {'backgroundImage':'url(/project/img/bm-non.gif)', 'background-position' : '100% 0' } );
	$("#bm-bg1").css( {'backgroundImage':'url(/project/img/bm-act.gif)'} );
	$("#bm-bg1 A").css( {'color':'#2e4d60'} );

	var lid = $(".bm-bg-i:last").attr("id");

 //---
  //$(".shadow").dropShadow({left: 0, top: 0, opacity: 1.0, blur: 2});
 //---
    $("a.anons").mouseover(function(e){
       $("body").append('<div id="float-text"><div id="shadow"><div>'+$(this).attr("anons")+'</div></div></div>');
       $("#shadow").dropShadow({left: 0, top: 0, opacity: 1.0, blur: 2});
       var floatX = ( elem.width() < e.pageX + 490 ) ? e.pageX - 320 : e.pageX+20;
       $("#float-text").css( {'position':'absolute','top':e.pageY,'left':floatX,'z-index':'200' } );
    }).mouseout(function(){
       $("div#float-text").remove();
    }).mousemove(function(e){
       var floatX = ( elem.width() < e.pageX + 490 ) ? e.pageX - 320 : e.pageX+20;
       $("#float-text").css( {'position':'absolute','top':e.pageY,'left':floatX,'z-index':'200' } );
    })
 //---
    $("a.float-link").mouseover(function(e){
	var float_id = $(this).attr("id");
	$(this).css( { 'color':'#990000'} );
       var floatX = ( elem.width() < e.pageX + 520 ) ? e.pageX - 320 : e.pageX+20;
       $( "#float-" + float_id ).css( { 'top' : e.pageY-40, 'left' : floatX } );
	$( "#" + float_id + "> img").css( { 'border' : '1px solid #f00'} );
	//$( "#" + float_id + "> img").dropShadow({left: 0, top: 0, opacity: 0.5, blur: 1});
    }).mouseout(function(){
	var float_id = $(this).attr("id");
	$(this).css( { 'color':'#808080'} );
       $( "#float-" + float_id ).css( { 'left' : '-500px' } );
	$( "#" + float_id + "> img").css( { 'border' : '1px solid #fff'} );
    }).mousemove(function(e){
	var float_id = $(this).attr("id");
       var floatX = ( elem.width() < e.pageX + 520 ) ? e.pageX - 320 : e.pageX+20;
       $( "#float-" + float_id ).css( {'position':'absolute','top':e.pageY,'left':floatX,'z-index':'200' } );
    })
 //---
	$(".bm-link").click(function() {
		$(this).attr( "class", "bm-active" ); 

		var group = $(this).attr('group');
		$("#bm-container"+group+" .bm-area").css( 'display','none' );
		$("#bm-container"+group+" .bm-bg-i").css( 'backgroundImage','url(/project/img/bm-non.gif)' );
		$("#bm-container"+group+" .bm-bg-last").css('backgroundImage','url(/project/img/bm-non.png)');
		$("#bm-container"+group+" .bm-active").attr( 'class','bm-link' );
		$("#bm-container"+group+" .bm-bg-i A").css('color','#fff');
		$("#bm-container"+group+" .bm-bg-last A").css('color','#fff');

		var bmactive = $(this).attr("bm"); 
		$("#bm-container"+group+" #bm" + bmactive).css( {'display':'block'} );
		var acss = $("#bm-container"+group+" #bm-bg" + bmactive).attr('class');
		if( acss == "bm-bg-last" ) {
			$("#bm-container"+group+" #bm-bg" + bmactive).css( {'backgroundImage':'url(/project/img/bm-act.png)'} );
		} else {
			$("#bm-container"+group+" #bm-bg" + bmactive).css( {'backgroundImage':'url(/project/img/bm-act.gif)'} );
		}
		$("#bm-container"+group+" #bm-bg" + bmactive + " A").css( {'color':'#2e4d60'} );
	});
 //---
  var toUseSearch = 0;
  $("#searchfld").focus(function () {
       toUseSearch = "searchfld";
	if( $("#searchfld").val() == "Введите слово или фразу для поиска.." ) {
		$("#searchfld").val("");
	}	
  });
  $("#searchfld").blur(function () {
       toUseSearch = 0;
	if( $("#searchfld").val() == "" ) $("#searchfld").val("Введите слово или фразу для поиска..");	
  });
  $("#searchfld1").focus(function () {
       toUseSearch = "searchfld1";
  });
  $("#searchfld1").blur(function () {
       toUseSearch = 0;
  });
  $("#sbutton1").click(function () {
       search("searchfld1");
  });
  $("#sbutton").click(function () {
       search("searchfld");
  });

  $(document).keyup(function(event){
      if (event.keyCode == 13 && toUseSearch != 0 ) {
          search( toUseSearch );
      }
  });

});



$(window).scroll(function() {
	if( dropshadow[1] ) {
		dropshadow[1].remove(); 
		var xy = getScrollXY();
		$clone.css('top', 30 + xy[1] );
		dropshadow[1] = $clone.dropShadow({left: 10, top: 10, opacity: 0.2, blur: 0, color: "black" });
	}

	var xy = getScrollXY();
	var win = $(window);
	var floatX = 300;
	var floatY = xy[1];
	var floatendX = win.width() - 252;

	// delete shadow from container
    	var sid = $("#float-alert").shadowId();
    	$("#"+sid).remove();

	$("#float-alert").css( {'top': floatY });
	$("#float-alert").dropShadow({left: -4, top: 2, opacity: 0.1, blur: 1});
});

function search( toUseSearch ) {
	var addurl = "";
       var s = document.getElementById(toUseSearch ).value;
	s = s.replace("(", "");
	s = s.replace(")", "");
	s = s.replace("/", "");

	s = URLDecode(s);
	s = s.replace(/%20/g, "+");
	if( s != '') {
		var url = "/searchtext/search," + s + "/" + addurl;
		window.location.href = url;
	}
    return false;
}

function SetOrder( id , param, price){
	closeAlert();
	var count = parseInt( document.getElementById('count' + id).value );
	if( !count ) count = 0;
	if( document.getElementById( 'sum' )) {
		var sum = parseInt( document.getElementById('sum').innerHTML );
	}

	if( count == 0) {
		alert("Число элементов равно нулю");
		return false;
	}
	//var ajax = new sack();
	//ajax.setVar("id_cat", id);
	//ajax.setVar("action", "order");

	if( obj = document.getElementById("imagebasket" + id)) {
		obj.src = "/_page/img/fullbasket.gif";
	}

	if( param == 0) {
		if( confirm( "Вы действительно хотите удалить позицию из корзины?" )) {
			document.getElementById( "orderid" + id ).style.display = "none";
			document.getElementById( 'sum' ).innerHTML = sum - count * price;
			$.get("/project/phpfiles/_ajax.php", { id_cat: id, action: 'order', param: param, count: count, price: price }, function( data ) {
				return;
			});
		} else {
			alert( "Удаление отменено" );
			return false;
		}
	} else {
		if( param == 2) {
			//alert( "Позиция сохранена в количестве " + count + " элементов");
			document.getElementById( 'sum' ).innerHTML = sumBetter( sum + count * price - parseInt( document.getElementById('sum' + id).innerHTML ));
			document.getElementById('sum' + id).innerHTML = count * price;
		} else {
			//alert( "В корзину добавлено " + count + " элементов");
			var xy = getScrollXY();
			var win = $(window);
			var floatX = 300;
			var floatY = xy[1];
			var floatendX = win.width() - 252;
       		$.get("/project/phpfiles/_ajax.php", { id_cat: id, action: 'order', param: param, count: count, price: price }, function( data ) {
				$("#body").append("<div class=\"float-alert\" id=\"float-alert\"><div class=\"inner\">"+data+"</div></div>");
				$("#float-alert").css( { 'top': floatY, 'left': floatX, 'visibility' : 'visible', 'opacity': 0, 'background':'#fff' } );
				$("#float-alert").animate( {left: floatendX, opacity:1 }, 500, function() { 
					$("#float-alert").dropShadow({left: -4, top: 2, opacity: 0.2, blur: 1});
 				});
				
       		});
		}
	}
}

function closeAlert() {
	var i = $("#float-alert").attr("id");
	if( i != undefined ) {
		var sid = $("#float-alert").shadowId();
		$("#"+sid).remove();
		$("#float-alert").remove();
	}
	return;
}

function getScrollXY() {
       var scrOfX = 0, scrOfY = 0;
       if( typeof( window.pageYOffset ) == 'number' ) {
               //Netscape compliant
               scrOfY = window.pageYOffset;
               scrOfX = window.pageXOffset;
       } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
               //DOM compliant
               scrOfY = document.body.scrollTop;
               scrOfX = document.body.scrollLeft;
       } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
               //IE6 Strict
               scrOfY = document.documentElement.scrollTop;
               scrOfX = document.documentElement.scrollLeft;
       }
       return [ scrOfX, scrOfY ];
}
/**
*  CONSULT
**/
function scanOpenSessions() {
	$.get("/project/phpfiles/_consult.php", { action: 'showactive', r: Math.random()}, function(data) {
		if( data && !opensess[1] ){	
			//if( confirm("Мы можем помочь Вам с выбором интересующего Вас продукта!\nРазрешите открыть сеанс связи с оператором?") ) {
				openConsult( 1, "" ); // cookie & ip
			//}
		}
	});
	scanopen = window.setTimeout( "scanOpenSessions()", 2000 );
}


var global = 0;
var opensess = [];
sess = new Array();
var clones = [];
var textarea = [];
var messages = [];
var shadow = [];
var dropshadow = [];
var operator = [];
var icall = [];
var heads = [];

function openConsult( id, page) {
	if( opensess[id] ) return;
	opensess[id] = 1;
	$clone = $("#form-container").clone().removeAttr("id");
	clones[id] = $clone;
	$clone.attr("id", "form-container" + id);
 	$("#consult-container").append($clone);
	var xy = getScrollXY();
   	$clone.css({'position':'absolute','visibility':'visible','left' : (global*300 + 30) + "px",'top' : (global*30 + 30 + xy[1]) + "px"});
	$clone.maxZIndex({ inc: 5 });
	dropshadow[id] = $clone.dropShadow({left: 10, top: 10, opacity: 0.2, blur: 0, color: "black" });
	$.each( $(".form-header:noid:first"), function(i,val) {
		heads[id] = $(this);
		$(this).css({backgroundPosition: "50% 50%"});
	});
	$clone.draggable({ cursor: "move", handle: heads[id],
		start: function(event, ui) { dropshadow[id].remove(); },
		stop: function(event, ui) { dropshadow[id] = $(this).dropShadow({left: 10, top: 10, opacity: 0.3, blur: 0}); }
	});

	$clone.resizable({
		minHeight: 480,
		minWidth: 400,
   		start: function(event, ui) { dropshadow[id].remove(); },
		resize: function(event, ui) { 
			messages[id].css({ 'width' : ($clone.width() - 135)+'px' , 'height' : ($(this).height()-335)+'px'});
			textarea[id].css({ 'width' : '100%' });
		},
		stop: function(event, ui) { 
			dropshadow[id] = $(this).dropShadow({left: 10, top: 10, opacity: 0.3, blur: 0});
			messages[id].css({ 'width' : ($clone.width() - 135)+'px' , 'height' : ($(this).height()-335)+'px'});
			textarea[id].css({'width':'100%'});
		}
	});
	var isCtrl = false;
	$clone.keyup(function (e) {
		if(e.keyCode == 17) isCtrl=false;
	}).keydown(function (e) {
		if(e.keyCode == 17) isCtrl=true;
		if(e.keyCode == 13 && isCtrl == true) {
			var idc = $(this).attr("id").replace('form-container','');
			var txt = textarea[idc].val();
			textarea[idc].val("");
			$.get("/project/phpfiles/_consult.php", {message: txt}, function(data) {
				messages[idc].html(data);
			});
			return false;
		}
	});
	$.each( $(".btn-close:noid:first"), function(i,val) {
		$(this).attr("id", "close"+id);			
		$(this).click( function() {
			var idc = $(this).attr("id").replace('close','');
			clones[idc].remove();
			dropshadow[idc].remove();
			opensess[idc] = 0;
			// terminate call
			$.get("/project/phpfiles/_consult.php", { action: 'terminate', r: Math.random() });
			clearTimeout(scanopen);
		});
	});
	$.each( $(".ip:noid:first"), function(i,val) {
		$(this).attr("id", "ip"+id);
		$(this).html("<span>Онлайн Консультант</span>");
		document.getElementById("ip"+id).onselectstart = function() { return false; };
		$(this).unselectable = "on";
		$(this).css('-moz-user-select', 'none');   
		$(this).dblclick(function(e) { 
			var idc = $(this).attr("id").replace('ip','');
 			dropshadow[idc].remove();
			if( clones[idc].data('roll') == null ) {
				clones[idc].css({'overflow':'hidden', 'height':'470px'});
				clones[idc].stop().animate({'height' : '35px'},500, function() {
					dropshadow[idc] = clones[idc].dropShadow({left: 10, top: 10, opacity: 0.2, blur: 0});
				});

				clones[idc].data('roll',1);
			} else {
				clones[idc].stop().animate({'height' : '470px'},500, function() {
					dropshadow[idc] = clones[idc].dropShadow({left: 10, top: 10, opacity: 0.2, blur: 0});
					messages[idc].css({ 'width' : '100%', 'height' : ($(this).height()-335)+'px'});
				});
				clones[idc].data('roll',null);
			}
		});
	});
	$.each( $(".symple:noid:first"), function(i,val) {
		$(this).attr("id", "textarea"+id);
		textarea[id] = $(this);
	});
	$.each( $(".input-call:noid:first"), function(i,val) {
		$(this).attr("id", "icall"+id);
		icall[id] = $(this);
	});
	$.each( $(".btn-call:noid:first"), function(i,val) {
		$(this).attr("id", "bcall"+id);
		$(this).click( function() {
			var idc = $(this).attr("id").replace('bcall','');
			var abonent = icall[idc].val();
			$(this).val("Соединяем...");
			$.get("/project/phpfiles/_consult.php", {abonent: abonent, action: 'call', page: page, r: Math.random()}, function(data) {
				var res = data.split("|");
				icall[idc].val(res[0]);
				if( res[1] == 1 ) {
					$(this).attr("disabled","disabled");
					$(this).val("Установлено соединение!");
				}
			});
		});
	});
	$.each( $(".messages:noid:first"), function(i,val) {
		messages[id] = $(this);
		refreshMess( id );
	});

	$.each( $(".btn-send:noid:first"), function(i,val) {
		$(this).attr("id", "send"+id);
		$(this).click( function() {
			var idc = $(this).attr("id").replace('send','');
			var txt = textarea[idc].val();
			textarea[idc].val("");
			$.get("/project/phpfiles/_consult.php", {message: txt}, function(data) {
				messages[idc].html(data);
			});
		});
	});

	// activate call
	$.get("/project/phpfiles/_consult.php", { action: 'activate', r: Math.random() }, function(data) {
		//
	});
}


function refreshMess( idc ) {
	//heads[idc].css({'background':'url(/project/img/c-header-animate.png)'});
	//heads[idc].animate({backgroundPosition:"(1000px 0)"}, {duration:1500});
	$.get("/project/phpfiles/_consult.php", { write: 1, message: textarea[idc].val(), r: Math.random() }, function(data) {
		messages[idc].html(data);
		messtimer = setTimeout( "refreshMess("+idc+")", 4000 );
		messages[idc].stop().scrollTo( { top: 4000, left: 0 } , 100 );
	});
}

function URLDecode(str){
    str2 = "";
    for(k=0;k<str.length;k++){
        str2 += '%' + chr[str.charAt(k)];
    }
    return str2;
}
function BasketOut(obj) {
	if(obj.src.indexOf("fullbasket.gif") > 0) {
		obj.src = "/_page/img/fullbasket.gif";
	} else {
		obj.src = "/_page/img/emptybasket.gif";
	}
}
function BasketOver(obj) {
	if(obj.src.indexOf("emptybasket.gif") > 0) {
		obj.src = "/_page/img/putinbasket.gif";
	}
}

	function setBrand( value ) {
		window.location.href = '/brand/f,' + value + '/' ;
	}

function GP(x)
{
	if(x)	document.location.href = x;
	else	alert("страница отсутствует!");
}

function sumBetter (sum) {
	return sum;
	sum = sum.toString();
	newSum = "";
	n = sum.length;
	for( i=3; i < n; i +=3 ) {
		newSum += sum.Substr(n-i, 3);
	}
	return newSum;
}

/**
*  COMMENTS
**/

	function addComment() {
		var pageid = $("#commid").val();
		var comment = $("#comment"+pageid).val(); 
		if( comment.length < 7 || comment == "Введите здесь свой комментарий" ) {
			alert("Введите, пожалуйста, текст отзыва!");
			return;
		}
		var answer = $("#answer").val(); 
		$.get("/project/phpfiles/_ajax.php", { action: 'comment', pageid: pageid, comment: comment, answer: answer }, function(data) {
			$("#comment-container").html(data);
			$("#comment"+pageid).val("");
		});
	}
	function commCite(data, date) {
		var pageid = $("#commid").val();
		$("#comment"+pageid).val( "-----------------------------<br>Цитирую "+date+"<br>----------------------------<br>"+data+"<br>----------------------------<br>" ); 
		return;
	}

	function commAnswer(id) {
		$("#answer").val( id ); 
		$("#to-answer").html("Отвечаем на пост # " + id); 
		return;
	}


function ShowHide(idname)
{
 if (document.getElementById(idname).style.display == "none")
 {
  document.getElementById(idname).style.display = "block";
 }
 else
 {
  document.getElementById(idname).style.display = "none";
 }
}


function ModTree( image, id, area, selected, type ) {
		var ajax = new sack();
       	ajax.requestFile = "/_page/phpfiles/_ajax.php";
		ajax.setVar("action", "modtree");	
		ajax.setVar("id", id);
		ajax.setVar("type", type);
		ajax.setVar("selected", selected);
		//ajax.setVar("treetype", type );	
       	ajax.method = "GET"; 
		//ajax.onCompletion = whenCompletedModTree;	
        	ajax.element = "tree" + area + "" + id; 
		document.getElementById("tree" + area + "" + id).innerHTML = '<img src="/_page/img/load.gif">';
       	ajax.runAJAX();

		ShowHide("tree" + area +""+ id);
		//var imgsrc = document.getElementById("image"+id).src.toString();
		if( imagesrc = document.getElementById("image"+id) ) {
			imagesrc.src = (imagesrc.src.indexOf('close')==-1) ? "/_img/catalog/tree_close.gif" : "/_img/catalog/tree_open.gif";
			document.getElementById("min"+id).src = (image.src.indexOf('plus')==-1) ? "/_img/catalog/plus.gif " : "/_img/catalog/min.gif ";
		}
}
function OpenVendor( page, id, name ) {
		var ajax = new sack();
       	ajax.requestFile = "/_page/phpfiles/_ajax.php";
		ajax.setVar("action", "openvendor");	
		ajax.setVar("vendor", id);
		ajax.setVar("page", page );
		ajax.setVar("name", name);
       	ajax.method = "GET"; 
        	ajax.element = "vendor" + id; 
		document.getElementById("vendor" + id).innerHTML = '<img src="/_page/img/load.gif">';
       	ajax.runAJAX();
		ShowHide( "vendor" + id );
		if( imagesrc = document.getElementById( "vimage" + id ) ) {
			imagesrc.src = (imagesrc.src.indexOf('plus')==-1) ? "/_img/catalog/plus.gif " : "/_img/catalog/min.gif ";
		}
}

function searchPriceLists( st ) {
		var ajax = new sack();
       	ajax.requestFile = "/_page/phpfiles/_ajax.php";
		ajax.setVar("action", "pricesearch");	
		ajax.setVar("st", URLDecode(st) );	
       	ajax.method = "GET"; 
        	ajax.element = "pricesearch"; 
		document.getElementById("pricesearch").innerHTML = '<img src="/_page/img/load.gif">';
       	ajax.runAJAX();
}

function calc_dalee(imgid,host)
{
  minus=host+'/images/'+imgid+'_on.jpg'; 
  plus=host+'/images/'+imgid+'_off.jpg';
  	if(document.getElementById(imgid).src==plus) {
	document.getElementById(imgid).src='/images/'+imgid+'_on.jpg';
	} else {
	document.getElementById(imgid).src='/images/'+imgid+'_off.jpg';
	}
}

function fixPNG(element, type)
{
  //???? ??????? IE ?????? 5.5-6
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
    var src;
    if (element.tagName=='IMG') //???? ??????? ??????? ???????? (??? IMG)
    {
      if (/\.png$/.test(element.src)) //???? ???? ???????? ????? ?????????? PNG
      {
        src = element.src;
        element.src = "/_img/serv/1x1.gif"; //???????? ??????????? ?????????? gif-??
      }
    }
    else //?????, ???? ??? ?? ???????? ? ?????? ???????
    {
	  //???? ? ???????? ?????? ??????? ????????, ?? ??????????? ???????? ???????? background-?mage ?????????? src
      src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
      if (src)
      {
        src = src[1]; //????? ?? ???????? ???????? background-?mage ?????? ????? ????????
        element.runtimeStyle.backgroundImage="none"; //??????? ??????? ???????????
      }
    }
    //????, src ?? ????, ?? ????? ????????? ??????????? ? ??????? ??????? AlphaImageLoader
	type = (type == 1) ? "crop" : "scale";

  if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='"+type+"')";
  }
}

function getElements(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}
function makePrice( index ) {
	var price = new Array();
	var p = getElements("input", "pricetrue"); 
	for(i=0; i<p.length;i++) {
		price[i] = p[i].value;
	}
	var p = getElements("span", "icoprice");
	for(i=0; i<p.length;i++) {
		p[i].innerHTML = '<img src="' + curimages[index] + '">';
	}
	var p = getElements("span", "price");
	for(i=0; i<p.length;i++) {
		p[i].innerHTML = Math.floor(100*price[i]/currents[index])/100;
	}
}

function switchMainBookmark(a, num, group) {
	try {
		var td, tr = a, div;
		var node, i, remJ = [], curTD = 0;
		var rbArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17];
		if (div = document.getElementById(group + num)) {
			div.style.display = "";
			for (i = 0; i < rbArray.length; i++) if (rbArray[i] != num){
				if(document.getElementById(group + rbArray[i])) {
					document.getElementById(group + rbArray[i]).style.display = "none";
				}
			}
		} else return false;
		if (!num) return false;
		while (tr.parentNode && tr.nodeName.toLowerCase() != "tr") {
			if (tr.nodeName.toLowerCase() == "td") td = tr;
			tr = tr.parentNode;
		}
		for (i = 0; i < tr.childNodes.length; i++) {
			node = tr.childNodes[i];
			if (node.nodeType != 1) continue;
			if (node.nodeName.toLowerCase() != "td") continue;
	                if (node.firstChild.className != "lft" && node.firstChild.className != "lft first" && node.firstChild.className != "lst") continue;
			if (node == td) {node.className = "act"; curTD = 1;} 
			else {node.className = curTD ? "aftact" : "pas"; curTD = 0;}
		}
		return false;
	} catch(e) {
		return false;
	}
}

function AddBack( ){
// проверка полей
	var must = Array('varc_0','varc_7','txt_2');
	var fld = new Array( 'varc_0','varc_1','varc_7','txt_2','id' );
	var bad = 0;
	for ( var i = 0; i < must.length; i++ ) {
		if(document.getElementById(must[i]).value == "" || document.getElementById(must[i]).value == "0") {
			var bad = 1;
		}
	}
	if( bad ) {
		alert("Не все обязательные поля заполнены!");
		return false; 
	}
// отправка формы
	var ajax = new sack();
    	ajax.requestFile = "/_page/phpfiles/_ajax.php";
	ajax.setVar("action", "addback");

	for ( var i = 0; i < fld.length; i++ ) {
	    ajax.setVar( fld[i], URLDecode( document.getElementById(fld[i]).value ));
	}
	if(document.getElementById("str")) {
		ajax.setVar( "configurator", URLDecode( document.getElementById("str").innerHTML ));
	}
	ajax.method = "GET";
   	ajax.runAJAX(); 
 	alert("Запрос отправлен!");
	tb_remove();
}



function openFloatForm( id, name ) {
    var xy = getScrollXY();
    var elem = $(window);
    var floatX = ( elem.width() - 450 ) / 2;
    var floatY =  (elem.height() / 2 - 200) + xy[1] ;
    $("#form-header").html( name );
    $("#tovarname").val( name );
    $("#form-question").css( {'position':'absolute','top': floatY,'left':floatX,'z-index':'200' } );
    $("#form-shadow").dropShadow({left: 10, top: 10, opacity: 0.2, blur: 0});
    $("#form-question").css({'visibility':'visible'});
}

function closeFloatForm( id ) {
    $("#form-progress").html(" ");
    $("#form-" + id ).css({'visibility':'hidden'});
}






