function getIframeDocument(iframeNode){
	if (iframeNode.contentDocument) return iframeNode.contentDocument
	if (iframeNode.contentWindow) return iframeNode.contentWindow.document
	return iframeNode.document
}
function setIframeSrc(iframeNode, src){
	if (typeof iframeNode == 'string') {
		iframeNode = document.getElementById(iframeNode)
	}
	var doc = getIframeDocument(iframeNode)
	doc.location.replace(src)
}
function handleDigit(digit,div){
	//var s = document.createElement('span')
	//s.innerHTML = digit+' '
	//document.getElementById(div).appendChild(s)
	if (digit>=100){
	document.getElementById(div).innerHTML=' <div style="width:300px;height:16px;border: 0px solid rgb(0, 0, 0);color:rgb(0, 100, 100);background: #8888ff;">100%</div>'
	endlessFrameStop()
	}
	else{
	if (document.getElementById(div)){
	document.getElementById(div).innerHTML=' <div style="width:'+digit*3+'px;height:16px;border: 0px solid rgb(0, 0, 0);color:rgb(0, 100, 100);background: #8888ff;">'+digit+'%</div>'
	}
	}
}
function endlessFrameRun(padding,div,iframe){
	document.getElementById(div).innerHTML=''
	var p='pbar.php?dv='+div+(padding ? '&padding=1':'')
	//setIframeSrc(iframe,p)
	handleDigit(10,div)
}
function endlessFrameStop(div,iframe){
	setIframeSrc(iframe,'javascript:""')
	document.getElementById(div).innerHTML=''
	handleDigit(70,div)
	//document.getElementById(div).innerHTML=''
}
var res;
function insrt(){
document.getElementById("news").innerHTML = res;
document.body.style.cursor = "auto";
}

function show(rezim) {
data = new Date ()
ef = data.getTime()
efd = "efd"+ef;
	if (rezim==3){
		my_array = {
			flag: 2,
			efd:ef,
			url: document.URL
		}
	}
	else
	if ( rezim == 2 ){
		my_array = {
				section: document.getElementById("section").value,
				month: document.getElementById("month").value,
				year: document.getElementById("year").value,
				podr: document.getElementById("podr").value,
				ann: document.getElementById("ann").value,
				sost_zak: document.getElementById("sost_zak").value,
				el_zak: document.getElementById("el_zak").value,
				id_nom: document.getElementById("id_nom").value,
				flag: 2,
				dot_dd: document.getElementById("dot_dd").value,
				dot_mm: document.getElementById("dot_mm").value,
				dot_yy: document.getElementById("dot_yy").value,
				dza_dd: document.getElementById("dza_dd").value,
				dza_mm: document.getElementById("dza_mm").value,
				dza_yy: document.getElementById("dza_yy").value,
				dpi_d1: document.getElementById("dpi_d1").value,
				dpi_d2: document.getElementById("dpi_d2").value,
				dpi_m1: document.getElementById("dpi_m1").value,
				dpi_m2: document.getElementById("dpi_m2").value,
				dpi_y1: document.getElementById("dpi_y1").value,
				dpi_y2: document.getElementById("dpi_y2").value,
				efd:ef,
				url: document.URL
				}
	}
	else {
		my_array = {
				section: document.getElementById("section").value,
				month: document.getElementById("month").value,
				year: document.getElementById("year").value,
				podr: document.getElementById("podr").value,
				ann: document.getElementById("ann").value,
				sost_zak: document.getElementById("sost_zak").value,
				el_zak: document.getElementById("el_zak").value,
				id_nom: document.getElementById("id_nom").value,
				flag: document.getElementById("flag").value,
				dot_dd: document.getElementById("dot_dd").value,
				dot_mm: document.getElementById("dot_mm").value,
				dot_yy: document.getElementById("dot_yy").value,
				dza_dd: document.getElementById("dza_dd").value,
				dza_mm: document.getElementById("dza_mm").value,
				dza_yy: document.getElementById("dza_yy").value,

				dpi_d1: document.getElementById("dpi_d1").value,
				dpi_d2: document.getElementById("dpi_d2").value,
				dpi_m1: document.getElementById("dpi_m1").value,
				dpi_m2: document.getElementById("dpi_m2").value,
				dpi_y1: document.getElementById("dpi_y1").value,
				dpi_y2: document.getElementById("dpi_y2").value,
				efd:ef,
				url: document.URL
		}
	}
	if(document.getElementById("debug")){
		if (document.getElementById("id_nom")){
		if (document.getElementById("id_nom").value != ""){
			document.title = "ТГК-4 // Закупка №" + document.getElementById("id_nom").value;
		}
		else {
			document.title = "ТГК-4 // Закупки";
		}
		}
		try {
		document.getElementById("news").innerHTML = "Подождите, идет загрузка...<div id='"+efd+"' style='width:300px;height:16px;border: 1px solid rgb(0, 0, 0);color:rgb(0, 100, 100);padding:0px;background: #bbbbff;'></div>";
		if(document.getElementById(efd) && document.getElementById("endless_iframe")){
        		endlessFrameRun(1,efd,"endless_iframe");
        		}
        	else {
        	}
		if (document.getElementById("id_nom")){
		        document.getElementById("msearch").value = "Ждите. Выполняется запрос!";
			document.getElementById("msearch").style.backgroundColor = '#ff8080';
//			document.getElementById("news").innerHTML = "<img src=/img/wait.gif>";
			}
		document.body.style.cursor = "wait";
	        JsHttpRequest.query('/purchase/purchasev.php', my_array,
	            function(result, errors) {
			endlessFrameStop(efd,"endless_iframe");
			if ( errors )
				alert (errors);
			if (result==null){
				//document.getElementById("news").innerHTML="Ошибка"
				show(3)
			}
			else {
				res = result["str"];
				setTimeout("insrt();",100);
				document.getElementById("pr_ver").innerHTML = result["str_pr"];
				////document.getElementById("debug").innerHTML = errors;
			}
	            },
	            false
	        );
		}
		catch(e){
			document.getElementById("news").innerHTML = "Ошибка выполнения запроса!";
		}
	}
	if (rezim==3){
	return;
	}
	if(document.getElementById("div_prod")){
		try {
	        document.getElementById("msearch").value = "Ждите. Выполняется запрос!";
		document.getElementById("msearch").style.backgroundColor = '#ff8080';
		document.getElementById("news").innerHTML = "<img src=/img/wait.gif>";
	        JsHttpRequest.query('/purchase/prod.php', my_array,
	            function(result, errors) {
					if ( errors )
						alert (errors);
					////document.getElementById("debug").innerHTML = errors;
	                document.getElementById("news").innerHTML = result["str"];
	                document.getElementById("pr_ver").innerHTML = result["str_pr"];
	            },
	            false
	        );
		}
		catch(e){
			document.getElementById("news").innerHTML = "Ошибка выполнения запроса!";
		}
	}
	if(document.getElementById("debug1")){
	        document.getElementById("msearch").value = "Выполняется запрос!";
		document.getElementById("news1").innerHTML = "<img src=/img/wait.gif>";
        	JsHttpRequest.query('/purchase/complete_purchase.php', my_array,
            		function(result, errors) {
                	document.getElementById("news1").innerHTML = result["str"];
                	document.getElementById("pr_ver").innerHTML = result["str_pr"];
			},
			true
	        );
	}
}

function show_default() {
data = new Date ()
ef = data.getTime()
	my_array = {url:document.URL,efd:ef}
	if(document.getElementById("debug")){
		efd = "efd"+ef;
	//alert (efd)
		//if(document.getElementById("endless_frame_div") && document.getElementById("endless_iframe")){
		//document.getElementById("news").innerHTML = "<img src=/img/wait.gif>";
		document.getElementById("news").innerHTML = "Подождите, идет загрузка...<div id='"+efd+"' style='width:300px;height:16px;border: 1px solid rgb(0, 0, 0);color:rgb(0, 100, 100);padding:0px;background: #bbbbff;'></div>";
		if(document.getElementById(efd) && document.getElementById("endless_iframe")){
        		endlessFrameRun(1,efd,"endless_iframe");
        		}
	    	JsHttpRequest.query(
	    		'/purchase/purchasev.php', my_array,
	        	function(result, errors) {
				endlessFrameStop(efd,"endless_iframe");
				if (result==null){
					document.getElementById("news").innerHTML="Ошибка"
					show(3)
				}
				else {
					res = result["str"];
					setTimeout("insrt();",100);
        		        	//document.getElementById("news").innerHTML="";
					document.getElementById("pr_ver").innerHTML = result["str_pr"];
				}
            		},
	        	true
        	);
	}
	if(document.getElementById("div_prod")){
		document.getElementById("news").innerHTML = "<img src=/img/wait.gif>";
	    	JsHttpRequest.query('/purchase/prod.php', my_array,
        	function(result, errors) {
                	document.getElementById("news").innerHTML = result["str"];
                	document.getElementById("pr_ver").innerHTML = result["str_pr"];
            		},
        	true
        	);
	}
	if(document.getElementById("debug1")){
		document.getElementById("news1").innerHTML = "<img src=/img/wait.gif>";
        	JsHttpRequest.query('/purchase/complete_purchase.php', my_array,
            	function(result, errors) {
                	document.getElementById("news1").innerHTML = result["str"];
                	document.getElementById("pr_ver").innerHTML = result["str_pr"];
            		},
            	true
 		);
	}

}

function show_doc_id(doc_id){
	my_array = {section: document.getElementById("section").value,
			month: document.getElementById("month").value,
			year: document.getElementById("year").value,
			podr: document.getElementById("podr").value,
			ann: document.getElementById("ann").value,
			docid: doc_id,
			title: document.getElementById("t" + doc_id).value,
			t1: document.getElementById("t1_" + doc_id).value,
			t2: document.getElementById("t2_" + doc_id).value
			}
	if(document.getElementById("id" + doc_id)){
		if ( document.getElementById("id" + doc_id).innerHTML == "" ){
			document.getElementById("im_" + doc_id).src="/i/minus.gif";
			JsHttpRequest.query('/purchase/konc.php', my_array,
				function(result, errors) {
					document.getElementById("debug").innerHTML = errors;
					document.getElementById("id" + doc_id).innerHTML = result["str"];
	            },
	            true
	        );
		}
		else {
			document.getElementById("id" + doc_id).innerHTML = "";
			document.getElementById("im_" + doc_id).src="/i/plus.gif";
		}
	}
}

function show_doc_id_p(doc_id){
	my_array = {section: document.getElementById("section").value,
				month: document.getElementById("month").value,
				year: document.getElementById("year").value,
				podr: document.getElementById("podr").value,
				ann: document.getElementById("ann").value,
				docid: doc_id,
				title: document.getElementById("t" + doc_id).value,
				t1: document.getElementById("t1_" + doc_id).value,
				t2: document.getElementById("t2_" + doc_id).value
				}
	if(document.getElementById("id" + doc_id)){
		if ( document.getElementById("id" + doc_id).innerHTML == "" ){
			document.getElementById("im_" + doc_id).src="/i/minus.gif";
	        JsHttpRequest.query('/purchase/konc.php', my_array,
	            function(result, errors) {
			document.getElementById("div_prod").innerHTML = errors;
	                document.getElementById("id" + doc_id).innerHTML = result["str"];
	            },
	            false
	        );
		}
		else {
			document.getElementById("id" + doc_id).innerHTML = "";
			document.getElementById("im_" + doc_id).src="/i/plus.gif";
		}
	}
}

function hide_att(doc_id,tag,hide){
var div="h"+doc_id+"_"+tag;
if(document.getElementById(div)){
	my_array = {
		docid: doc_id,
		t1: tag,
		vid: hide,
		adduch: 86
		}
	JsHttpRequest.query
		(
		'/purchase/konc.php',
		my_array,
		function(result, errors) {
			document.getElementById(div).innerHTML = result["str"];
		},
		true
		);
	}
	else {
	alert("@@@@2")
	}
}

function del_doc_att(doc_id, descr, tag){
if (confirm("Удалить файл: `"+ descr +"`?")){
	my_array = {
		docid: doc_id,
		title: descr,
		t1: tag,
		adduch: 10
		}
tag1 = doc_id + "_" + tag;
tag = "d" + tag1;
	if(document.getElementById(tag)){
	        JsHttpRequest.query('/purchase/konc.php', my_array,
	            function(result, errors) {
			//document.getElementById(tag).innerHTML = errors;
	                document.getElementById(tag).innerHTML = result["str"];
			document.getElementById("s" + tag1).innerHTML = "";
			document.getElementById("f" + tag1).innerHTML = result["strf"];
	            },
	            false
	        );
	}
}
}

function ed_doc_att(doc_id, descr, tag){
my_array = {
	docid: doc_id,
	title: descr,
	t1: tag,
	adduch: 11
	}
tag1 = doc_id + "_" + tag;
tag = "d" + tag1;
	if(document.getElementById(tag)){
		if ( document.getElementById(tag)){
	        JsHttpRequest.query('/purchase/konc.php', my_array,
	            function(result, errors) {
			//document.getElementById(tag).innerHTML = errors;
			document.getElementById("f" + tag1).innerHTML = result["str"];
			document.getElementById("e" + tag1).innerHTML = result["stre"];
	                //document.getElementById(tag).innerHTML = result["str"];
	            },
	            false
	        );
		}
		else {
			document.getElementById(tag).innerHTML = "";
			//document.getElementById("im_" + doc_id).src="/i/plus.gif";
		}
	}
}

function del_doc_cab(doc_id, descr, tag){
if (document.getElementById("dl" + tag + doc_id).innerHTML == "&nbsp;"){
	return;
}
//if (confirm("Удалить файл?" + document.getElementById("dl" + tag + doc_id).innerHTML)){
if (confirm("Удалить файл?")){

	my_array = {
		docid: doc_id,
		title: descr,
		t1: tag,
		adduch: 20
		}
	if(document.getElementById("dl" + tag + doc_id)){
	        JsHttpRequest.query('/purchase/konc.php', my_array,
	            function(result, errors) {
			//document.getElementById(tag).innerHTML = errors;
	                //document.getElementById("ad" + tag + doc_id).innerHTML = result["str"];
			document.getElementById("dl" + tag + doc_id).innerHTML = "&nbsp;";
			document.getElementById("vi" + tag + doc_id).innerHTML = "&nbsp;";
			//document.getElementById("vi" + tag + doc_id).innerHTML = result["str"];
	            },
	            false
	        );
	}
}
}

function load_file_cab(docid,tag){
if (document.getElementById("if" + docid + tag)){
    var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		//document.getElementById("ifp" + docid + tag).innerHTML = req.responseJS.str;
		document.getElementById("vi" + tag + docid).innerHTML = req.responseJS.sz;
		document.getElementById("dl" + tag + docid).innerHTML = req.responseJS.sd;
        }
    }
comstr ="?adduch="+21+
	"&docid="+docid+
	"&title="+tag;
//alert("!!! " + comstr);
req.open(null, '/purchase/konc.php'+comstr, true);
req.send( { q: document.getElementById("if" + docid + tag) } );
}
}

function sa_doc_att(doc_id, descr, tag){
my_array = {
	docid: doc_id,
	title: descr,
	t1: tag,
	adduch: 12
	}
tag1 = doc_id + "_" + tag;
tag = "d" + tag1;
	if(document.getElementById(tag)){
		if ( document.getElementById(tag)){
	        JsHttpRequest.query('/purchase/konc.php', my_array,
	            function(result, errors) {
			//document.getElementById(tag).innerHTML = errors;
			document.getElementById("f" + tag1).innerHTML = result["str"];
			document.getElementById("e" + tag1).innerHTML = result["stre"];
	                //document.getElementById(tag).innerHTML = result["str"];
	            },
	            false
	        );
		}
		else {
			document.getElementById(tag).innerHTML = "";
			//document.getElementById("im_" + doc_id).src="/i/plus.gif";
		}
	}
}

function ch_fl(id){
	if (document.getElementById("mim" + id)){
		if ( document.getElementById("hid_" + id).value == 0 ){
			document.getElementById("mim" + id).src="/i/ok.gif";
			document.getElementById("hid_" + id).value = 1;
		}
		else if ( document.getElementById("hid_" + id).value == 1 ) {
			document.getElementById("mim" + id).src="/i/notr.gif";
			document.getElementById("hid_" + id).value = 2;
		}
		else if ( document.getElementById("hid_" + id).value == 2 ) {
			document.getElementById("mim" + id).src="/i/no.gif";
			document.getElementById("hid_" + id).value = 0;
		}
	}
}

function ch_fla(id){
	if (document.getElementById("mima" + id)){
		if ( document.getElementById("hida_" + id).value == 0 ){
			document.getElementById("mima" + id).src="/i/ok.gif";
			document.getElementById("hida_" + id).value = 1;
		}
		else if ( document.getElementById("hida_" + id).value == 1 ) {
			document.getElementById("mima" + id).src="/i/notr.gif";
			document.getElementById("hida_" + id).value = 2;
		}
		else if ( document.getElementById("hida_" + id).value == 2 ) {
			document.getElementById("mima" + id).src="/i/no.gif";
			document.getElementById("hida_" + id).value = 0;
		}
	}
}

function ch_fl_lot(id,lot){
	if (document.getElementById("mim"+id+"-"+lot)){
		if ( document.getElementById("hid_"+id+"-"+lot).value == 0 ){
			document.getElementById("mim"+id+"-"+lot).src="/i/ok.gif";
			document.getElementById("hid_"+id+"-"+lot).value = 1;
		}
		else if ( document.getElementById("hid_"+id+"-"+lot).value == 1 ) {
			document.getElementById("mim"+id+"-"+lot).src="/i/notr.gif";
			document.getElementById("hid_"+id+"-"+lot).value = 2;
		}
		else if ( document.getElementById("hid_"+id+"-"+lot).value == 2 ) {
			document.getElementById("mim"+id+"-"+lot).src="/i/no.gif";
			document.getElementById("hid_"+id+"-"+lot).value = 0;
		}
	}
}

function ch_fla_lot(id,lot){
	if (document.getElementById("mima"+id+"-"+lot)){
		if ( document.getElementById("hida_"+id+"-"+lot).value == 0 ){
			document.getElementById("mima"+id+"-"+lot).src="/i/ok.gif";
			document.getElementById("hida_"+id+"-"+lot).value = 1;
		}
		else if ( document.getElementById("hida_"+id+"-"+lot).value == 1 ) {
			document.getElementById("mima"+id+"-"+lot).src="/i/notr.gif";
			document.getElementById("hida_"+id+"-"+lot).value = 2;
		}
		else if ( document.getElementById("hida_"+id+"-"+lot).value == 2 ) {
			document.getElementById("mima"+id+"-"+lot).src="/i/no.gif";
			document.getElementById("hida_"+id+"-"+lot).value = 0;
		}
	}
}

function ch_fl_st(){
	if (document.getElementById("status")){
		if ( document.getElementById("status").value == 2 ){
			document.getElementById("im_st").src="/i/ok.gif";
			document.getElementById("im_st").caption = "Подписан";
			document.getElementById("im_st").title = "Подписан";
			document.getElementById("status").value = 1;
		}
		else if ( document.getElementById("status").value == 0 ) {
			document.getElementById("im_st").src="/i/await.gif";
			document.getElementById("im_st").caption = "Ждет рассмотрения";
			document.getElementById("im_st").title = "Ждет рассмотрения";
			document.getElementById("status").value = 2;
		}
		else if ( document.getElementById("status").value == 1 ) {
			document.getElementById("im_st").src="/i/no.gif";
			document.getElementById("im_st").caption = "Не подписан";
			document.getElementById("im_st").title = "Не подписан";
			document.getElementById("status").value = 0;
		}
	}
}

function show_add_uch(doc_id){
	my_array = {	
			docid: doc_id,
			adduch: 1
			}
	if(document.getElementById("adduch")){
		if ( document.getElementById("adduch").innerHTML == "" ){
			document.getElementById("adduchgif").src="/i/minus.gif";
			JsHttpRequest.query(
				'/purchase/konc.php',
				my_array,
				function(result) {
					document.getElementById("adduch").innerHTML = result["str"];
	            		},
	            		false
	        	);
		}
		else {
			document.getElementById("adduch").innerHTML = "";
			document.getElementById("adduchgif").src="/i/plus.gif";
		}
	}
}

function show_uch_inn(docid){
	if (document.getElementById("inp_inn")){
		my_array = {	
			docid : docid,
			inpinn: document.getElementById("inp_inn").value,
			inp_reg_id: document.getElementById("inp_reg_id").value,
			inp_org: document.getElementById("inp_org").value,
			inp_fio: document.getElementById("inp_fio").value,
			inp_limit: document.getElementById("inp_limit").value,
			adduch: 2
			}
		JsHttpRequest.query(
			'/purchase/konc.php',
			my_array,
			function(result) {
				document.getElementById("show_by_inn").innerHTML = result["str"];
            		},
            		false
        	);
	}
}

function add_uch(id_reg){
	my_array = {	
			id_reg: id_reg,
			adduch: 3
			}
	if(document.getElementById("adduch")){
		if ( document.getElementById("adduch").innerHTML == "" ){
			document.getElementById("adduchgif").src="/i/minus.gif";
			JsHttpRequest.query(
				'/purchase/konc.php',
				my_array,
				function(result) {
					document.getElementById("adduch").innerHTML = result["str"];
	            		},
	            		false
	        	);
		document.getElementById(divn).innerHTML = "!";
		}
		else {
			document.getElementById("adduch").innerHTML = "";
			document.getElementById("adduchgif").src="/i/plus.gif";
		}
	}
}
///////////////////////////////////////////////////////////////////////////////
function p_save(doc_id, tag, adduch){
	divn = "ps_"+doc_id+"_"+tag;

	if(document.getElementById("s_"+divn)){
		comstr ="?adduch="+adduch+
			"&docid="+doc_id+
			"&foper=save&oper=edit&fname="+document.getElementById("f"+divn).value+
			"&descr="+document.getElementById("d"+divn).value+
			"&tag="+tag;
		//alert("comstr: " + comstr);
		var req = new JsHttpRequest();
		req.onreadystatechange = function() {
			//alert("comstr: " + comstr);
			//alert("req.readyState: " + req.readyState);

			if (req.readyState == 4) {
				//alert("req.readyState: " + req.readyState);
				//alert("comstr: " + comstr + "    adduch:" + adduch + "             -                  divn: " + divn );
				document.getElementById("s_"+divn).innerHTML = req.responseJS.str;
				document.getElementById("v_"+divn).innerHTML = req.responseJS.str_v;
				document.getElementById("d_"+divn).innerHTML = req.responseJS.str_d;
				document.getElementById("f_"+divn).innerHTML = req.responseJS.str_f;
				//document.getElementById('debug').innerHTML = req.responseText;
				if (adduch==14 /*&& req.readyState == 1*/){
					setTimeout('document.forms["fpere"].pere.click()', 1000);
					document.forms["fpere"].err_num.value = req.responseJS.str_e;
				}
			}
			else {
				//alert("req.readyState: " + req.readyState);
			}
		}
		req.open(null, '/purchase/konc.php'+comstr, false);
		ddd = req.send( { q: document.getElementById("f"+divn) } );
		//alert("ddd: " + ddd);

		//alert("comstr: " + comstr);
		//alert("req.readyState: " + req.readyState + " fname:" + document.getElementById("f"+divn).value);
	}
	else {
		//alert("req.readyState: " + req.readyState);
		document.getElementById("s_"+divn).innerHTML = "?--?";
	}

	if (adduch==14 /*&& req.readyState == 1*/){
//		setTimeout('document.forms["fpere"].pere.click()', 1000);
		//cstr = "purch.php" + "?oper=edit&doc_id="+doc_id;
		//alert("!!! ----- comstr: " + comstr + "req.readyState:" + req.readyState);
	}

}
///////////////////////////////////////////////////////////////////////////////
function save_lot(docid,nlot){
	if (document.getElementById("ilot" + docid)){
		my_array = {	
			docid : docid,
			vid: nlot,
			adduch: 30
			}
		//alert(docid)
		JsHttpRequest.query(
			'/purchase/konc.php',
			my_array,
			function(result) {
				document.getElementById("ilot" + docid).src=result["img"];
				document.getElementById("lot" + docid).innerHTML=result["str"];
            		},
            		true
        	);
	}
}
///////////////////////////////////////////////////////////////////////////////
function save_ank(idank,docid,idreg){
	if (document.getElementById("cr_" + idank)){
		var str = document.getElementById("i_" + idank).src;
		var ok = str.indexOf('ok.gif');
		var edit = str.indexOf('edit.gif');
		if (ok != -1){
			adduch=100;
		}
		else{
			adduch=101;
		}
		my_array = {	
			idank: idank,
			docid : docid,
			idreg: idreg,
			txt: document.getElementById("tcr_" + idank).value,
			adduch: adduch
			}
		JsHttpRequest.query(
			'/purchase/konc.php',
			my_array,
			function(result) {
				document.getElementById("cr_" + idank).innerHTML = result["str"];
				document.getElementById("i_" + idank).src=result["img"];
            		},
            		false
        	);
	}
}

function show_ank(docid){
if (document.getElementById("ank")){
	//alert(docid);
	my_array = {	
		doc_id : docid,
		vid: 0
		}
	if (document.getElementById("ank").innerHTML != ""){
		document.getElementById("ank").innerHTML = "";
		document.getElementById('i_ank').src = "/i/plus.gif";
	}
	else {
		document.body.style.cursor = "wait";
		document.getElementById("dv"+docid).style.cursor = "wait";
		JsHttpRequest.query(
			'/purchase/konc_anketa.php',
			my_array,
			function(result) {
				document.getElementById("ank").innerHTML = result["str"];
				document.getElementById("i_ank").src = "/i/minus.gif";
				document.getElementById("dv"+docid).style.cursor = "pointer";
				document.body.style.cursor = "auto";
       			},
           		true
       		);
	}
 }
}

function show_ank_id(docid){
	if (document.getElementById("ank" + docid)){
		//alert(docid);
		my_array = {	
			doc_id : docid,
			vid: 0
			}
		if (document.getElementById("ank"+docid).innerHTML != ""){
			document.getElementById("ank"+docid).innerHTML = "";
			document.getElementById('i_ank'+docid).src = "/i/plus.gif";
		}
		else {
			document.body.style.cursor = "wait";
			document.getElementById("dv"+docid).style.cursor = "wait";
			JsHttpRequest.query(
				'/purchase/konc_anketa.php',
				my_array,
				function(result) {
					document.getElementById("ank"+docid).innerHTML = result["str"];
					document.getElementById("i_ank"+docid).src = "/i/minus.gif";
					document.getElementById("dv"+docid).style.cursor = "pointer";
					document.body.style.cursor = "auto";
            			},
	            		true
        		);
		}
	}
}

function change_doc_att_vo(doc_id,vid,nstr,lot){
if(document.getElementById("vsegor"+vid)){
	if (nstr==0){
		s = document.getElementById("vsegor"+vid).value+"."+document.getElementById("vsegok"+vid).value;
		tag = "s"+doc_id+"-"+vid;
		im = "im_vs"+vid;
	}
	else {
		s = document.getElementById("ndsr"+vid).value+"."+document.getElementById("ndsk"+vid).value;
		tag = "sn"+doc_id+"-"+vid;
		im = "im_nds"+vid;
	}
	my_array = {
		docid: doc_id,
		vid: vid,
		idank: lot,
		sum: s,
		adduch: 83+nstr
	}
        JsHttpRequest.query('/purchase/konc.php', my_array,
            function(result, errors) {
                document.getElementById(tag).innerHTML = result["str"];
		document.getElementById(im).src = result["img"];
            },
            false
        );
}
}

function del_doc_att_vo(doc_id, vid, lot){
if (confirm("Удалить файл c документацией?")){
	my_array = {
		docid: doc_id,
		vid: vid,
		idank: lot,
		adduch: 82
		}
tag1 = doc_id + "_" + vid;
tag = "d" + tag1;
	if(document.getElementById(tag)){
	        JsHttpRequest.query('/purchase/konc.php', my_array,
	            function(result, errors) {
			//document.getElementById(tag).innerHTML = errors;
	                document.getElementById(tag).innerHTML = result["str"];
			document.getElementById("s" + tag1).innerHTML = "";
			document.getElementById("f" + tag1).innerHTML = result["strf"];
	            },
	            true
	        );
	}
}
}

function show_ank_id_reg(docid,vid,id_reg,lot){
	if (document.getElementById("ank"+vid+"-"+docid)){
		if (document.getElementById("ank"+vid+"-"+docid).innerHTML != ""){
//			alert("show_ank_id_reg:"+lot);
			my_array = {	
				doc_id : docid,
				vid: vid,
				nlot: lot,
				oper: 'regclose'
				}
			document.body.style.cursor = "wait";
			document.getElementById("dv"+vid+"-"+docid).style.cursor = "wait";
			JsHttpRequest.query(
				'/purchase/konc_anketa.php',
				my_array,
				function(result) {
					document.getElementById("ank"+vid+"-"+docid).innerHTML = "";
					//document.getElementById("ank"+docid).innerHTML = result["str"];
					document.getElementById("i" + vid + "_ank"+docid).src = result["img"];
					document.getElementById("dv"+vid+"-"+docid).style.cursor = "pointer";
					document.body.style.cursor = "auto";
            			},
	            		true
        		);
//			document.getElementById('i' + vid + '_ank'+docid).src = "/i/plus.gif";
		}
		else {
			//alert("show_ank_id_reg!!:"+lot);
			my_array = {	
				doc_id : docid,
				vid: vid,
				nlot: lot,
				oper: 'reg'
				}
			document.body.style.cursor = "wait";
			document.getElementById("dv"+vid+"-"+docid).style.cursor = "wait";
			JsHttpRequest.query(
				'/purchase/konc_anketa.php',
				my_array,
				function(result) {
					document.getElementById("ank"+vid+"-"+docid).innerHTML = result["str"];
					document.getElementById("i" + vid + "_ank"+docid).src = result["img"];
					document.getElementById("dv"+vid+"-"+docid).style.cursor = "pointer";
					document.body.style.cursor = "auto";
            			},
	            		true
        		);
		}
	}
}

function getSum(docid,vid,nocache,nstr,lot){
	if (document.getElementById("div"+docid+"-"+vid+"-"+nstr)){
		my_array = {	
			docid : docid,
			vid: vid,
			nstr: nstr,
			idank: lot,
			adduch: 85
			}
			//alert("lot:"+lot)
		JsHttpRequest.query(
			'/purchase/konc.php',
			my_array,
			function(result) {
				document.getElementById("div"+docid+"-"+vid+"-"+nstr).innerHTML= result["str"];
				//alert(result["str"]);
            		},
            		nocache
        	);
	}
}

function save_anketa(docid,idank,vid,lot){
	if (document.getElementById("inp"+vid+"-"+idank)){
		var str = document.getElementById("inp"+vid+"-"+idank).value;
		my_array = {	
			idank: idank,
			docid : docid,
			nlot: lot,
			txt: str,
			vid: vid,
			adduch: 80
			}
		JsHttpRequest.query(
			'/purchase/konc.php',
			my_array,
			function(result) {
				document.getElementById("inp"+vid+"-"+idank).value = result["str"];
				document.getElementById("im"+vid+"-"+idank).src= result["img"];
				document.getElementById("err"+vid).innerHTML= result["err"];
				//document.getElementById("i_" + dank).src= result["img"];
				document.getElementById("i"+vid+"_ank"+docid).src= result["imgt"];
				if (vid==0){
					getSum(docid,vid,true,0,lot);
					getSum(docid,vid,true,1,lot);
					getSum(docid,vid,true,2,lot);
				}
				else {
					getSum(docid,vid,true,0,lot);
					getSum(docid,vid,true,1,lot);
					getSum(docid,vid,true,2,lot);
				}
            		},
            		true
        	);
        	
	}
}

function load_file_reg(docid,vid,lot){
if (document.getElementById("if" + docid + "_" + vid)){
    var req = new JsHttpRequest();
	document.body.style.cursor = 'wait'; 
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		//document.getElementById("ifp" + docid + "_" + vid).innerHTML = req.responseJS.str;
		document.getElementById("f" + docid + "_" + vid).innerHTML = req.responseJS.str;
		document.getElementById("s" + docid + "_" + vid).innerHTML = req.responseJS.sz;
		document.getElementById("d" + docid + "_" + vid).innerHTML = req.responseJS.sd;
	document.body.style.cursor = 'auto'; 
        }
    }
if (document.getElementById("in" + docid + "_" + vid)){
	t1=document.getElementById("in" + docid + "_" + vid).value;
}
else{
	t1="Документация";
}

comstr ="?adduch="+81+
	"&docid="+docid+
	"&t1="+t1+
	"&idank="+lot+
	"&title="+vid;

req.open(null, '/purchase/konc.php'+comstr, false);
req.send( { q: document.getElementById("if" + docid + "_" + vid) } );
}
}

function load_file(docid,tag){
if (document.getElementById("if" + docid + "_" + tag)){
	document.body.style.cursor = 'wait'; 
    var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		//document.getElementById("ifp" + docid + "_" + tag).innerHTML = req.responseJS.str;
		document.getElementById("f" + docid + "_" + tag).innerHTML = req.responseJS.str;
		document.getElementById("s" + docid + "_" + tag).innerHTML = req.responseJS.sz;
		document.getElementById("d" + docid + "_" + tag).innerHTML = req.responseJS.sd;
		document.body.style.cursor = "auto";
        }
    }
if (document.getElementById("in" + docid + "_" + tag)){
t1=document.getElementById("in" + docid + "_" + tag).value;
}
else{
t1="Документация";
}

comstr ="?adduch="+90+
	"&docid="+docid+
	"&t1="+t1+
	"&title="+tag;

req.open(null, '/purchase/konc.php'+comstr, false);
req.send( { q: document.getElementById("if" + docid + "_" + tag) } );
}
}

function save_descr(docid,tag,descr){
if (document.getElementById("if" + docid + "_" + tag)){
	//alert(descr);
	document.getElementById("im" + docid + "_" + tag).src="/img/null.gif";

	my_array = {	
		docid : docid,
		title: tag,
		t1: descr,
		adduch: 91
	}
	JsHttpRequest.query(
		'/purchase/konc.php',
		my_array,
		function(result) {
			document.getElementById("ifp" + docid + "_" + tag).innerHTML =	result["str"];
       		},
       		false
       	);
	s = "№ doc: " + docid + "_" + tag;
	//alert(s);
}
}
///////////////////////////////////////////////////////////////////////////////
function menuhide(menunum){
    var currentmenu = document.getElementById('navbody' + menunum);
    currentmenu.style.visibility = 'hidden';
}
	
function menushow(menunum){
    var currentmenu = document.getElementById('navbody' + menunum);
    currentmenu.style.visibility = 'visible';
}
///////////////////////////////////////////////////////////////////////////////
function openWin(url){
	window.open(url, "wind1", "toolbar=no,resizable=yes,scrollbars=yes,menubar=no,location=no");
}

function openWinS(url){
window.open(url, 'wind2',config='width=300,height=200,top=200,left=300,resizable=yes,scrollbars=yes');
}
function openWinS_(url){
window.open(url, 'wind2',config='width=320,height=200,top=200,left=300,resizable=yes,scrollbars=yes');
}
function closeWinS(url){
'wind2'.close;
}