

$(document).ready(function() {
	
	function openWin(src){
	var w = $(window).width()-100;
	var h = $(window).height()-100;
	
	var html = '<div id="box" style="display:none;"><div class="lightBox" style="vertical-align: middle"> </div><div class="containerPlus draggable resizable" buttons="c" content="'+src+'" icon="browser.png"  skin="default" width="'+w+'" height="'+h+'" iconized="false" style="top:50px; left:50px;"><div class="no"><div class="ne"><div class="n">Подбор запчастей по производителю</div></div><div class="o"><div class="e"><div class="c">		<div class="mbcontainercontent">  </div></div></div><div ><div class="so"><div class="se"><div class="s"> </div></div></div> </div></div></div></div></div>'
	
	$('body').append(html);

	$(".lightBox").click(function(){
		$("#box").remove();
	});
	
	$(".lightBox").animate({ 
        opacity: 0.4
      }, 0 );

	$('#box').show();
	
	$(".containerPlus").buildContainers({
        containment:"document",
        elementsPath:"/elements/",
        onResize:function(o){
			setIframeHeight();
		},
        onClose:function(o){
			$("#box").remove();
		},
        onCollapse:function(o){},
        onIconize:function(o){},
        onDrag:function(o){},
        onRestore:function(o){}
      });
	  
	  
     $(function() {
		$("#dialog").dialog({
			bgiframe: true,
			height: 140,
			modal: true
		});
	});
	
	//	myWindow=window.open(src,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=960, height=700");
		//myWindow.document.write("This is 'myWindow'");
		//myWindow.focus();
		return false;
	}

	function openInfoWin(src, text, w, h){
	var html = '<div id="dialog">aaaaaaaaaaaaaaaaaaa</div>'
	
    
	
	$('body').append(html);
   
		$("#dialog").dialog({
			bgiframe: true,
			modal: true,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
	


	/*$(".lightBox").click(function(){
		$("#dialog").remove();
	});
	
	$(".lightBox").animate({ 
        opacity: 0.4
      }, 0 );

	$('#box').show();
	
	$(".containerPlus").buildContainers({
        containment:"document",
        elementsPath:"/elements/",
        onClose:function(o){
			$("#box").remove();
		},
        onCollapse:function(o){},
        onIconize:function(o){},
        onDrag:function(o){},
        onRestore:function(o){}
      });
	  */
	  
	
	//	myWindow=window.open(src,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=960, height=700");
		//myWindow.document.write("This is 'myWindow'");
		//myWindow.focus();
		return false;
	}
	
//	$(".car, .korobka").pngfix({});
/*$('#art_search').focus(function(){
		
		if($(this).val() == 'номер детали'){
			$(this).val("");
		}
	});
	*/
	
	
	$("#products_list tr").hover(
			  function () {				
			    $(this).addClass("hover");
			  },
			  function () {
			    $(this).removeClass("hover");
			  }
			);

	
	$('.infoview').click(function(){
		var src = $(this).attr('href');
		var text = $(this).attr('top_text');
		var w = $(this).attr('w');
		var h = $(this).attr('h');
		openInfoWin(src,text,w,h);
		return false;
	})
	
 	$('.tab-page').hide();
 	$('#tabs-1').show();
 	$('#tabs>ul>li:first').addClass('on');
 	
 	$('#tabs>ul>li>a').click(function(){
 		$('.tab-page').hide();
 		$($(this).attr('href')).show();
 		$('#tabs>ul>li').removeClass();
 		$(this).parent().addClass('on');
 		return false;
 	})
 	
 	
 	$('.addvhcl').click(function(){
 		var jElm = $(this);
 		var iID = parseInt(jElm.attr("vhclId"));
 		var inextID = iID+1;
 		$('#vehicl_'+inextID).show();
 		$("#mfa_"+inextID).removeAttr("disabled");
 		$(this).hide();
 		return false;
 	})
	 
 	$('.delvhcl').live('click',function(){
 		var jElm = $(this);
 		var iID = parseInt(jElm.attr("vhclId"));
 		var iLastID = iID-1;
		$("#mfa_"+iID).attr("disabled","disabled");
		$('#vehicl_'+iID).hide();
		$('#more'+iLastID).show();
 		return false;
 	})
	
 	$('#showprice').click(function(){
      var foo = [];
      var siz = [];
      $('#select_price').each(function(i, selected){
          siz[i] = $(selected).val();
      });
      
      //$('span').hide();
      $("span[title='my']").hide();
      
      $('#select_price :selected').each(function(i, selected){
          foo[i] = $(selected).val();
      });
 		for (var i = 0; i < foo.length; i++) {
 				$('.group_'+foo[i]).show();
 				$('.m'+foo[i]).show();
	  }
	  setCookie ('select_price',foo, 3600, "/");
	  return false;
 	})


	$('.autoxp').click(function(){
		$('#content tr td div.main-frame').html('<iframe frameborder="0" id="autoxp" class="autoxp-frame" src="http://app.autoxp.ru/pscomplex/catalog.aspx?clstep=catalog&mark=' + $(this).attr('mark') + '&salerind=152"></iframe>');
		
		return false	
	})
	
	function windowWidth() {
		var de = document.documentElement;
		return self.innerWidth || ( de && de.clientWidth ) || document.body.clientWidth;
	} 
	
	function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
	}
	


	$('#dialog_info').dialog({
			autoOpen: false,
			bgiframe: true,
			modal:true,
			width: 600
			});
	$('#dialog_image').dialog({
			autoOpen: false,
			width: 600,
			bgiframe: true,
			modal:true
			});
	$('#dialog_cart').dialog({
			autoOpen: false,
			width: 400,
			bgiframe: true,
			modal:true
			});
	$('#dialog_constr').dialog({
			autoOpen: false,
			width: 300,
			bgiframe: true,
			modal:true
			});
	
				// Dialog Link
		$('.popup').click(function(){
           $('#dialog').dialog({
    			autoOpen: false,
    			width: $(window).width()-100,
    	        height: $(window).height()-100,			
    			bgiframe: true,
    			modal:true,
    			resize : function (o){
    				setIframeHeight();
                },
                close: function(){
                    //$('#dialog').dialog('destroy');
                }
			});            
            
            $('#dialog').dialog('option', 'width', $(window).width()-100);
            $('#dialog').dialog('option', 'height', $(window).height()-100);
            
			$('#'+$(this).attr('param')).dialog('open');
			$('#'+$(this).attr('param')).html('<img src="design/tekauto/images/ajax-loader.gif">');
			$('#'+$(this).attr('param')).load($(this).attr('href'));
			
				return false;
			});

});

// standart string replace functionality
function str_replace(haystack, needle, replacement) {
	var temp = haystack.split(needle);
	return temp.join(replacement);
}



function delVhcl()
{
	this._sSelAreaId = "sysSelUsers";
	
	this.del = function (elm)
	{
		var jElm = j(elm);
		var iID = parseInt(jElm.attr("vhclId"));
		
		$("#mfa_"+iID).attr("disabled","disabled");

		return false;
	}
	
}
function getCookie(name) {
		var cookie = " " + document.cookie;
		var search = " " + name + "=";
		var setStr = null;
		var offset = 0;
		var end = 0;
		if (cookie.length > 0) {
			offset = cookie.indexOf(search);
			if (offset != -1) {
				offset += search.length;
				end = cookie.indexOf(";", offset)
				if (end == -1) {
					end = cookie.length;
				}
				setStr = unescape(cookie.substring(offset, end));
					}
				}
		return(setStr);
		}

function Showprises(price) 
{
	if (price)
	{
		arr = price.split(',')
 		for (var i = 0; i < arr.length; i++) {
 				$('.group_'+arr[i]).show();
 				$('.m'+arr[i]).show();
	  }
	}
	  return false;
 }


