function exchange_add_new()
{
	document.getElementById('div_exchange').innerHTML = document.getElementById('div_exchange').innerHTML + "<br><input name='cc_exchange[]' class='input'>";
}

function interest_add_new()
{
	var new_input = document.createElement("input");
	new_input.name = "interest[]";
	new_input.className = "input";
	
	var br = document.createElement("br");
	
	document.getElementById('div_interest').appendChild(br);
	document.getElementById('div_interest').appendChild(new_input);
}

function image_open(img)
{
	window.open('image_open.php?img='+img,'','width=0, height=0');
}

$(document).ready(function()
{
function liFormat (row, i, num) {
	var result = row[0] + '<p class=qnt>' + row[1] + ' шт.</p>';
	return result;
}

function selectItem(li) {
	var sValue = li.selectValue;
	document.location.href="classifieds.php?type="+li.extra[1]+"&search="+sValue.split(" ").join("%20");
}

function selectItemInterest(li) {
	var sValue = li.selectValue;
	document.location.href="cabinet_customers_interest.php?i_title="+sValue+"#cabinet_section";
}

// --- Автозаполнение2 ---
$("#p_name1").autocomplete("autocomplete.php", {
	delay:10,
	minChars:2,
	matchSubset:1,
	autoFill:false,
	matchContains:1,
	cacheLength:0,
	selectFirst:true,
	formatItem:liFormat,
	maxItemsToShow:10,
	extraParams:{type:2},
	onItemSelect:selectItem
}); 

$("#p_name2").autocomplete("autocomplete.php", {
	delay:10,
	minChars:2,
	matchSubset:1,
	autoFill:false,
	matchContains:1,
	cacheLength:0,
	selectFirst:true,
	formatItem:liFormat,
	maxItemsToShow:10,
	extraParams:{type:1},
	onItemSelect:selectItem
}); 

$("#interest_search").autocomplete("interest.php", {
	delay:10,
	minChars:2,
	matchSubset:1,
	autoFill:false,
	matchContains:1,
	cacheLength:0,
	selectFirst:true,
	formatItem:liFormat,
	maxItemsToShow:10,
	onItemSelect:selectItemInterest
}); 
}); 

function preload(images) {
    if (typeof document.body == "undefined") return;
    try {
        var div = document.createElement("div");
        var s = div.style;
        s.position = "absolute";
        s.top = s.left = 0;
        s.visibility = "hidden";
        document.body.appendChild(div);
        for (var i = 0; i < images.length; i++) div.innerHTML += "<img src=\"" + images[i] + "\" />";
    } catch(e) {
    }
}