function fieldColorSet(id)
{
 document.getElementById(id).style.backgroundColor = "#ced7f9";
}

function fieldColorOut(id)
{
 document.getElementById(id).style.backgroundColor = "white";
}


function openWinCentered(loc, winname, widthh, heightt, params)
{
    var tp = Math.ceil((screen.height - heightt) / 2);
    var lf = Math.ceil((screen.width - widthh) / 2);
    if (params.length > 0)
	    params = "," + params;

    var win = window.open(loc, "_blank", "width=" + widthh + ",height=" + heightt + ",top=" + tp + ",left=" + lf + params);
    win.focus();
    return win;
}

function addFile()
{
	var div = document.createElement("div");
	div.innerHTML = "<div><input type=\"file\" name=\"file0[]\" size=\"30\" />&nbsp;<input name=\"buttonDel\" value=\"Отменить\" type=\"button\" onclick=\"javascript:delFile(this);\" /></div>";
	document.getElementById("filesField").appendChild(div);
}

function delFile(a)
{
	var contDiv = a.parentNode;
	contDiv.parentNode.removeChild(contDiv);
}

var lotNum = 0;

function addLot()
{
	var div = document.createElement("div");
	lotNum++;
	div.innerHTML = "<div style='border-top: 4px solid #dddddd'><table><tr><td align='center' class='l'><em>Лот</em></td><td><input name='buttonDel' value='Удалить' type='button' onclick='javascript:delLot(this);' /></td></tr><tr><td style='border:0'>Предмет контракта&nbsp;<span style='color:red;'>*</span>&nbsp;</td><td style='border:0'><textarea name='lot_name[]' style='width:400px' rows='3'></textarea></td></tr><tr><td style='border:0'>Цена лота&nbsp;</td><td style='border:0'><input type='text' name='lot_cost[]' size='58' value=''>&nbsp;<em>руб.</em></td></tr><tr><td align='center' style='border:0'>&nbsp;</td><td style='border:0' class='l'><em>Позиции лота</em>&nbsp;<input name='buttonAdd' value='Добавить' type='button' onclick='javascript:addPos("+lotNum+");' /></td></tr><tr><td align='center' style='border:0'>&nbsp;</td><td style='border:0;padding-left:45px'><div id='possField"+lotNum+"'></div></td></tr></table></div>";
	document.getElementById("lotsField").appendChild(div);	
}

function delLot(a)
{
	var contDiv = a.parentNode.parentNode.parentNode.parentNode.parentNode;
	contDiv.parentNode.removeChild(contDiv);
}

function addPos(i)
{
	var div = document.createElement("div");
	div.innerHTML = "<div style='border-top: 1px solid #dddddd'>Позиция&nbsp;<span style='color:red;'>*</span>&nbsp;<input type='text' name='pos_name["+(i-1)+"][]' size='31' value=''>&nbsp;<input name='buttonDel' value='Удалить' type='button' onclick='javascript:delPos(this);' /><br />Количество&nbsp;<input type='text' name='pos_num["+(i-1)+"][]' size='10' value=''><br />Ед.&nbsp;измерения&nbsp;<input type='text' name='pos_num_type["+(i-1)+"][]' size='7' value=''></div>";
	document.getElementById("possField"+i).appendChild(div);
}

function delPos(a)
{
	var contDiv = a.parentNode;
	contDiv.parentNode.removeChild(contDiv);
}

function toggleFieldSelector(){
	$('#js-fieldSelectorBox').toggle();
	
	if($('#js-fieldSelectorBox').is(':hidden')){
		$('img[name=plusField]').attr('src', '/img/plus.gif');
	} else {
		$('img[name=plusField]').attr('src', '/img/minus.gif');
	}
}

function openField2()
{
	var a = document.getElementById('fieldsField2').style.display;	
	if('none' == a) 
		{
		 document.getElementById('fieldsField2').style.display = '';
		 document.images["plusField2"].src = '../img/minus.gif';
		}
	else 
		{
		 document.getElementById('fieldsField2').style.display = 'none';
		 document.images["plusField2"].src = '../img/plus.gif';
		}
}

function resetPayment(user_id, user_name) {
	Bc.Dialog.confirm({
		title: 'Удаление оплаты из напомнинаний',
		body: 'Вы уверены, что не хотите больше видеть в напоминаниях совершенные к этому моменту оплаты ' + user_name + '?',
		handler: function(){
			location.href = '/crm/contactnotices-payment-reset'+user_id+'.html';
		}
	});
}
