//-----------------------------------------------------------------------------------------------------------------------------------------------------------
// AJAX Class
function AjaxClass() {

	this.MakingQuery = false; 	
	this.TimeOut = 1; 		//таймаут перед отправкой очередного запроса
	this.variable='';
	this.XML = '';
	
	//метод создания HTTP-объекта
    this.CreateRequestObject = function() {
		    if (window.XMLHttpRequest) { 
                        this.httpRequest = new XMLHttpRequest();
						return this.httpRequest;
                } else if (window.ActiveXObject) { 
                    try {
						this.httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
					} catch (e) {
						try {
                            this.httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
						} catch (e) {}
                    }
                } 
                return this.httpRequest;
	}

		
	//метод формирования и отправки запроса		
	this.CreateQuery = function(URL, type, ID) {
	
		//проверка на существование данных	
		if(type!=undefined && ID!=undefined){
						
			//проверка состояния таймаута
			//if(this.MakingQuery == true){
			//	var objectThis = this;
			//	var func = function() {objectThis.CreateQuery(URL, type, ID);}
			//	window.setTimeout(func, this.TimeOut);
			//	return;
			//}
			
			response = this.CreateRequestObject();
			//для асинхронного
			//var objectThis = this;
			//response.onreadystatechange = function() { objectThis.CreateResponse(type, ID); }
			//response.open("GET", URL, true);
			//response.send(null);
			
			//для синхронного
			response.open("GET", URL, false);
			response.send(null);
			this.CreateResponse(type, ID);
								
			this.MakingQuery=true;
					
		}
		else if(type=='assArray'){
			if(this.MakingQuery == true){
				//проверка состояния таймаута
				var objectThis = this;
				var func = function() {objectThis.CreateQuery(URL, type, ID);}
				window.setTimeout(func, this.TimeOut);
				return;
			}
			
			response = this.CreateRequestObject();
			var objectThis = this;
			response.onreadystatechange = function() { objectThis.CreateResponse(type); }
			response.open("GET", URL, true);
			response.send(null);
					
					
			this.MakingQuery=true;
					
		}
		else if(type=='assArraySync'){
				response = this.CreateRequestObject();
				response.open("GET", URL, false);
				response.send(null);
				this.CreateResponse(type);
		}
		else if(type=='XML'){
					
				response = this.CreateRequestObject();
				response.open("GET", URL, false);
				response.send(null);
				this.CreateResponse(type);
				
		}
		else if(type=='XMLSynch'){
				response = this.CreateRequestObject();
				response.open("GET", URL, false);
				response.send(null);
				this.CreateResponse(type);
		}
		else{
		//alert('type=undefine'+'ID=undefine');
			if(this.MakingQuery == true){
				//проверка состояния таймаута
					var objectThis = this;
					var func = function() {objectThis.CreateQuery(URL, type, ID);}
					window.setTimeout(func, this.TimeOut);
					return;
			}
			
			response = this.CreateRequestObject();
			var objectThis = this;
			response.onreadystatechange = function() { objectThis.CreateResponse(); }
			response.open("GET", URL, true);
			response.send(null);
					
			this.MakingQuery=true;
		}
	}
		
	//метод чтения ответа и возвращения полученых данных в выбраном виде (text или XML)
	this.CreateResponse  = function(type, ID) { 
		
		if (response.readyState == 4)	{
		if (response.status == 200) {
			
			//проверка на существование данных
			if(type!=undefined && ID!=undefined){
			
				if (type=='text') {
					//alert(ID);
					//Text = response.responseText;
					
					//занесение полученных данных в эелемент с указанным ID
					//document.getElementById(ID).innerHTML = Text;
					
					document.getElementById(ID).innerHTML = response.responseText;
					document.body.style.cursor="default";
				} 
				else if(type=='input'){
					document.getElementById(ID).value = response.responseText;
				}
						
			}
			else if (type=='XML') {
				//alert("Type XML");
				this.XML = response.responseXML;
					if (this.XML==null){
					//если формат XML неправильный - вывод соответствующей ошибки
					//alert("Неправильный формат XML");
					}
					
			}
			
			else if (type=='assArray'){
				alert("Type: assArray");
				//выбран тип данных assArray
				//значения массива заносятся в элементы страницы, ID которых равны ключам элементов массива
				eval(response.responseText);
					for (key in DataArray) {
						document.getElementById(key).innerHTML = DataArray[key];
					}
			} 
						
			else if (type=='assArrayAsync'){
				//выбран тип данных assArray
				//значения массива заносятся в элементы страницы, ID которых равны ключам элементов массива
				eval(response.responseText);
					for (key in DataArray) {
												
						document.getElementById(key).innerHTML = DataArray[key];
												
					}
			}
								
		}
		else {
				alert("Error!"+response.statusText);
		}
		}
		this.MakingQuery=false;
	}
		


}
var ajax = new AjaxClass();

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function UserLogOut(){
	if(confirm('Вы действительно хотите выйти?'))
		document.getElementById('user_logout').submit();
	else
		return false;
}

function OpenBranch(BranchID, PointID, Param){
	//var ajax = new AjaxClass();
	
	if(	!(Branch=document.getElementById('branch_'+BranchID)) || 
		!(Parent=document.getElementById('parent_'+BranchID)))
		return false;
	
	if(Branch.style.display=='none'){
		if(Param){
			document.body.style.opacity="0.5";
			ajax.CreateQuery('AjaxTree.php?point_id='+PointID+'&param='+Param+'&id='+'branch_'+BranchID, 'text' ,'branch_'+BranchID);	
		}
		else{
			document.body.style.opacity="0.5";
			ajax.CreateQuery('AjaxTree.php?point_id='+PointID+'&id='+'branch_'+BranchID,'text','branch_'+BranchID);
		}
		document.body.style.opacity="1";
	}
	
	if(Branch.style.display=='none'){
		Branch.style.display='block';
		
		Parent.innerHTML='<div class="minus">&nbsp;</div>';
	}
	else {
		Branch.style.display='none';
		Parent.innerHTML='<div class="plus">&nbsp;</div>';
	}
	return 1;	
}

function DeleteObject(ObjectName){
	return confirm('Вы действительно хотите удалить: '+ObjectName+'?');
}

function DeleteFile(ObjectName){
	return confirm('Вы действительно хотите удалить файл: '+ObjectName+'?'+'\nВместе с файлом будут удалены все связанные запчасти из базы данных.');
}

function ShowFCKeditor(){
	if (window.opera && window.opera.version && parseFloat(window.opera.version()) < 9.5) 
		return;
	if(Content=document.getElementById('content'))
		Content.style.display='block';
}

function DisplayError(Error){
 	if(Error)alert(Error);
}

function Handle(Error){
	ShowFCKeditor();
	DisplayError(Error);
}

function Collapse(FormID){
	if(!(Form=document.getElementById(FormID)) || !(Arrow=document.getElementById(FormID+'_arrow')))
		return false;
	if(Form.style.display=='none'){
		Form.style.display='block';
		Arrow.className='collapser_opened';
	}
	else {
		Form.style.display='none';
		Arrow.className='collapser_closed';
	}
	return false;
}

function ChangeCheckbox(ID, TargetID){
	if(document.getElementById(ID).checked){
		//return true;
		if(document.getElementById(TargetID).disabled){
			document.getElementById(TargetID).disabled=false;
		}
	}
	else{
		if(!document.getElementById(TargetID).disabled){
			document.getElementById(TargetID).disabled=true;
		}
	}
	//else return false;
}

//----------------------------------------------------------------------------------------------------------------------------------------------
//Изменение коэффициента файла
function ChangeFileCoef(ID, Coef){
	ajax.CreateQuery('?type=ajax&data=singlefile&action=editcoef&id='+ID+'&coef='+Coef, 'input', ID);	
}

//----------------------------------------------------------------------------------------------------------------------------------------------
function ChangeConvertParam(){
	var ConvertCode=document.getElementById('part_code').value;
	var ConvertGoods=document.getElementById('part_name').value;
	var ConvertPrice=document.getElementById('part_price').value;
	if(ConvertCode!='0' && ConvertGoods!='0' && ConvertPrice!='0'){
		if(ConvertCode!=ConvertGoods && ConvertGoods!=ConvertPrice && ConvertCode!=ConvertPrice){
			document.getElementById('form_submit').disabled=false;
		}
		else{
		document.getElementById('form_submit').disabled=true;
		}
	}
	else{
		document.getElementById('form_submit').disabled=true;
	}
}


//--------------------------скрыть/показать информацию и ЗАПЧАСТЯХ в ЗАКАЗЕ
function ShowHidePartsInfo(ID){
	var Display = document.getElementById(ID).style.display;
	if(Display == 'none'){
		document.getElementById(ID).style.display = 'block';
	}
	else{
		document.getElementById(ID).style.display = 'none';
	}
	
}

//-------------------------ОТПРАВКА ЗАПРОСА AJAX ПРИ ИЗМЕНЕНИИ ДАННЫХ ПОЛЬЗОВАТЕЛЯ
function ChangeUserData(ID){
	var Discount = document.getElementById('user_discount_'+ID).value;
	var Pass = document.getElementById('user_pass_'+ID).value;
	ajax.CreateQuery('?type=ajax&data=user&action=ajaxedit&user_discount='+Discount+'&user_pass='+Pass+'&id='+ID, 'XML');	
	Result = ajax.XML.documentElement;
	Children = Result.childNodes;
	CountResult = Children.length;
	Error = true;
	Msg = '';
	for(i=0; i<CountResult; i++){
		if(Children[i].nodeType == 1){ 			 //если узел текстовый
			if(Children[i].tagName == 'error'){	 //если тег ошибка
				if(Children[i].firstChild.data == '1'){
					Error = true;
				}
				else{
					Error = false;
				}
			}
			else if(Children[i].tagName == 'msg'){//если тег сообщение
				if(Children[i].firstChild){
					Msg = Children[i].firstChild.data;
				}
			}
		}
	}
	
	if(Error == true){
		document.getElementById('user_pass_'+ID).style.borderColor = '#FF0000'
		document.getElementById('user_discount_'+ID).style.borderColor = '#FF0000'
		//document.getElementById('user_pass_'+ID).style.background = '#FFC0CB';
	}
	else{
		document.getElementById('user_pass_'+ID).style.borderColor = '#2368AD'
		document.getElementById('user_pass_'+ID).value = '';
		document.getElementById('user_discount_'+ID).style.borderColor = '#2368AD'
	}
	if(Msg != ''){
		if(Error == true){
			document.getElementById('OperationMessage').style.color = '#FF0000';
			document.getElementById('OperationMessage').innerHTML = Msg;
		}
		else{
			document.getElementById('OperationMessage').style.color = '#2368AD';
			document.getElementById('OperationMessage').innerHTML = Msg;

		}
	}
	
}


//---------------------отгрузить запчасть
function ShippedPart(ID, OrderID){
	if(confirm("Вы действительно хотите отгрузить товар? После отгрузки товар вернуть в исходное состояние невозможно.")){
		ajax.CreateQuery('?type=ajax&data=ordpart&action=shipped&id='+ID, 'XML');	
		Result = ajax.XML.documentElement;
		Children = Result.childNodes;
		CountResult = Children.length;
		Error = true;
		Msg = '';
		for(i=0; i<CountResult; i++){
			if(Children[i].nodeType == 1){ 			 //если узел текстовый
				if(Children[i].tagName == 'shipped'){	 //если тег ошибка
					if(Children[i].firstChild.data == '1'){
						document.getElementById('shipped_order_'+OrderID).checked=true;
						document.getElementById('shipped_order_'+OrderID).disabled=true;
					}
					else{
						document.getElementById('shipped_order_'+OrderID).checked=false;
						document.getElementById('shipped_order_'+OrderID).disabled=false;
					}
				}
				else if(Children[i].tagName == 'msg'){//если тег сообщение
					if(Children[i].firstChild){
						Msg = Children[i].firstChild.data;
						alert(Msg);
						document.getElementById('checkbox_shipped_'+ID).disabled=true;
					}
				}
			}
		}
	}
	else{
		document.getElementById('checkbox_shipped_'+ID).checked=false;
	}
}


//---------------------отгрузить заказ
function ShippedOrder(ID){
	if(confirm("Вы действительно хотите отгрузить все товары данного заказа? После отгрузки товары вернуть в исходное состояние невозможно.")){
		ajax.CreateQuery('?type=ajax&data=orders&action=shipped&id='+ID, 'XML');	
		Result = ajax.XML.documentElement;
		Children = Result.childNodes;
		CountResult = Children.length;
		Error = true;
		Msg = '';
		for(i=0; i<CountResult; i++){
			if(Children[i].nodeType == 1){ 			 //если узел текстовый
				if(Children[i].tagName == 'shipped'){	 //если тег ошибка
					if(Children[i].firstChild.data == '1'){
						document.getElementById('shipped_order_'+ID).checked=true;
						document.getElementById('shipped_order_'+ID).disabled=true;
						
					}
					else{
						document.getElementById('shipped_order_'+ID).checked=false;
						document.getElementById('shipped_order_'+ID).disabled=false;
					}
				}
				else if(Children[i].tagName == 'msg'){//если тег сообщение
					if(Children[i].firstChild){
						Msg = Children[i].firstChild.data;
						alert(Msg);
						document.getElementById('shipped_order_'+ID).disabled=true;
												
						for(k=0; k<ShippedCheckbox[ID].length; k++){
							CheckboxID = 'checkbox_shipped_'+ShippedCheckbox[ID][k];
							document.getElementById(CheckboxID).checked=true;
							document.getElementById(CheckboxID).disabled=true;
							
						}
					}
				}
			}
		}
	}
	else{
		document.getElementById('shipped_order_'+ID).checked=false;
	}
}


function SetPartCountPressKey(ID, E){
	if(E.keyCode==13){
		SetPartCount(ID);
	}
}



//------------------------ количество запчастей на странице поиска
function SetPartCount(ID){
//alert(1);
	var Count = document.getElementById('part_count_'+ID).value;
	var Store = document.getElementById('part_store_'+ID).innerHTML.replace(/[\s\n\r]+/,'');
	Store = Store.replace(/&gt;/,'>');
	var Reserve = document.getElementById('part_reserve_'+ID).innerHTML.replace(/[\s\n\r]+/,'');
	var QueryURL=Host+'?p=ajax&method=add_part_cart&id='+ID+'&count='+Count+'&store='+Store+'&reserve='+Reserve;
	ajax.CreateQuery(QueryURL,'XML');
	//QueryURL=QueryURL.replace(/[\s\r\n]+/im,'');
//alert('['+QueryURL+']');	
//return;
	
	//обработка результата
	Result = ajax.XML.documentElement;
	Children = Result.childNodes;
	CountResult = Children.length;
	Error = true;
	Store = '';
	Reserve = '';
	Msg = '';
	for(i=0; i<CountResult; i++){
		if(Children[i].nodeType == 1){ 			 //если узел текстовый
			//если тег ошибка
			if(Children[i].tagName == 'error'){	 
				if(Children[i].firstChild.data == '1'){
					Error = true;					
				}
				else{
					Error = false;
				}
			}
			
			//если тег сообщение
			if(Children[i].tagName == 'message'){
				if(Children[i].firstChild){
					Msg = Children[i].firstChild.data;
					if(Error == true){
						document.getElementById('part_count_'+ID).value='';
						alert(Msg);
					}
				}
			}
			
			//склад
			if(Children[i].tagName == 'store'){	 
				if(Children[i].firstChild.data)
					Store = Children[i].firstChild.data;
					//document.getElementById('part_store_'+ID).innerHTML=Store;
			}
			
			//резерв
			if(Children[i].tagName == 'reserve'){	 
				if(Children[i].firstChild.data)
					Reserve = Children[i].firstChild.data;		
					document.getElementById('part_reserve_'+ID).innerHTML=Reserve;
			}
			
		}
	}
	
	if(Error == false){
		if(Msg !='')
			document.getElementById('place_count_'+ID).innerHTML='<p style="font-size: 10px;">'+Msg+'</p>'
	}
}

//------------ функция удаления строки таблицы
function DeleteRow(TableName, r){
	var i=r.parentNode.parentNode.rowIndex;
	document.getElementById(TableName).deleteRow(i)
}

//------------ Удаление товара из корзины
function DeletePartFromCart(ID, RowIdent){
		
	var AllCountParts = document.getElementById('AllCountParts').innerHTML;
	var AllSummUAH = document.getElementById('AllSummUAH').innerHTML;
	var AllSummDiscountUAH = document.getElementById('AllSummDiscountUAH').innerHTML;
	var Earnings = document.getElementById('Earnings').innerHTML;
	var CurrentSummUAH = document.getElementById('summ_UAH_'+ID).innerHTML;
	var CurrentSummDiscountUAH = document.getElementById('summ_discount_UAH_'+ID).innerHTML;
	
	if(confirm("Вы действительно хотите удалить из корзины выбранный товар?")){
		ajax.CreateQuery(Host+'?p=ajax&method=del_part_cart&id='+ID+'&all_count_parts='+AllCountParts+'&all_summ_UAH='+AllSummUAH+'&all_summ_discount_UAH='+AllSummDiscountUAH+'&earnings='+Earnings+'&current_summ_uah='+CurrentSummUAH+'&current_summ_discount_uah='+CurrentSummDiscountUAH, 'XML');
		
		//обработка результата
	if(ajax.XML){
		Result = ajax.XML.documentElement;
		Children = Result.childNodes;
		CountResult = Children.length;
		Error = true;
		Store = '';
		Reserve = '';
		Msg = '';
		for(i=0; i<CountResult; i++){
			if(Children[i].nodeType == 1){ 			 //если узел текстовый
				//ВСЯ сумма
				if(Children[i].tagName == 'all_summ_uah'){	 
					if(Children[i].firstChild.data)
						AllSummUAH = Children[i].firstChild.data;
						document.getElementById('AllSummUAH').innerHTML=AllSummUAH;
				}
				
				//ВСЯ сумма со скидкой
				if(Children[i].tagName == 'all_summ_discount_uah'){	 
					if(Children[i].firstChild.data)
						AllSummDiscountUAH = Children[i].firstChild.data;
						document.getElementById('AllSummDiscountUAH').innerHTML=AllSummDiscountUAH;
				}
				
				//общее кол-во
				if(Children[i].tagName == 'count_all'){	 
					if(Children[i].firstChild.data)
						AllCountParts = Children[i].firstChild.data;
						document.getElementById('AllCountParts').innerHTML=AllCountParts;
				}
				
				//зароботок
				if(Children[i].tagName == 'earnings'){	 
					if(Children[i].firstChild.data)
						Earnings = Children[i].firstChild.data;
						document.getElementById('Earnings').innerHTML=Earnings;
				}
				
				//кол-во, если "0" , то корзина пуста
				if(Children[i].tagName == 'count_last'){	 
					if(Children[i].firstChild.data == '0'){
						document.getElementById('cart_table').innerHTML='';
						document.getElementById('cart_title').innerHTML='Корзина:';
						var CartTable = document.getElementById('cart_table');
						var Content = document.getElementById('content');
						var el0 = document.createElement('p'); 
					    el0.innerHTML="Корзина пуста.";
					    Content.insertBefore(el0, CartTable.nextSibling);
						return false;
					}
					/*if(document.getElementById('order_new_info')){
						document.getElementById('order_new_info').innerHTML = '';
					}*/
				}
				
			}
		}
	}
		
		//удаление строки таблицы
		DeleteRow('cart_table', RowIdent);
	}
}

function DeletePartFromNewOrder(ID, RowIdent){
		
	var AllCountParts = document.getElementById('AllCountParts').innerHTML;
	var AllSummUAH = document.getElementById('AllSummUAH').innerHTML;
	var AllSummDiscountUAH = document.getElementById('AllSummDiscountUAH').innerHTML;
	var Earnings = document.getElementById('Earnings').innerHTML;
	var CurrentSummUAH = document.getElementById('summ_UAH_'+ID).innerHTML;
	var CurrentSummDiscountUAH = document.getElementById('summ_discount_UAH_'+ID).innerHTML;
	
	if(confirm("Вы действительно хотите удалить из корзины выбранный товар?")){
		ajax.CreateQuery(Host+'?p=ajax&method=del_part_cart&id='+ID+'&all_count_parts='+AllCountParts+'&all_summ_UAH='+AllSummUAH+'&all_summ_discount_UAH='+AllSummDiscountUAH+'&earnings='+Earnings+'&current_summ_uah='+CurrentSummUAH+'&current_summ_discount_uah='+CurrentSummDiscountUAH, 'XML');
		
		//обработка результата
	if(ajax.XML){
		Result = ajax.XML.documentElement;
		Children = Result.childNodes;
		CountResult = Children.length;
		Error = true;
		Store = '';
		Reserve = '';
		Msg = '';
		for(i=0; i<CountResult; i++){
			if(Children[i].nodeType == 1){ 			 //если узел текстовый
				//ВСЯ сумма
				if(Children[i].tagName == 'all_summ_uah'){	 
					if(Children[i].firstChild.data)
						AllSummUAH = Children[i].firstChild.data;
						document.getElementById('AllSummUAH').innerHTML=AllSummUAH;
						document.getElementById('AllSummUAHSecond').innerHTML=AllSummUAH;
				}
				
				//ВСЯ сумма со скидкой
				if(Children[i].tagName == 'all_summ_discount_uah'){	 
					if(Children[i].firstChild.data)
						AllSummDiscountUAH = Children[i].firstChild.data;
						document.getElementById('AllSummDiscountUAH').innerHTML=AllSummDiscountUAH;
						document.getElementById('AllSummDiscountUAHSecond').innerHTML=AllSummDiscountUAH;
				}
				
				//общее кол-во
				if(Children[i].tagName == 'count_all'){	 
					if(Children[i].firstChild.data)
						AllCountParts = Children[i].firstChild.data;
						document.getElementById('AllCountParts').innerHTML=AllCountParts;
				}
				
				//зароботок
				if(Children[i].tagName == 'earnings'){	 
					if(Children[i].firstChild.data)
						Earnings = Children[i].firstChild.data;
						document.getElementById('Earnings').innerHTML=Earnings;
						document.getElementById('EarningsSecond').innerHTML=Earnings;
				}
				
				//кол-во, если "0" , то корзина пуста
				if(Children[i].tagName == 'count_last'){	 
					if(Children[i].firstChild.data == '0'){
						//document.getElementById('cart_table').innerHTML='<p align="center">Корзина пуста.</p>';
						document.getElementById('cart_table').innerHTML='';
						var CartTable = document.getElementById('cart_table');
						var Content = document.getElementById('content');
						var el0 = document.createElement('p'); 
						el0.innerHTML="Корзина пуста.";
						Content.insertBefore(el0, CartTable.nextSibling);
						document.getElementById('order_new_info').innerHTML = '';
						return false;
					}
				}
							
			}
		}
	}
		
		//удаление строки таблицы
		DeleteRow('cart_table', RowIdent);
	}
	
	return false;
}

//------------ Удаление товара из неподтвержденного заказа
function DeletePartFromTempOrder(TmpOrderPartID, TmpOrderID, RowIdent){
	var AllSummUAH = document.getElementById('AllSummUAH').innerHTML;
	var AllSummDiscountUAH = document.getElementById('AllSummDiscountUAH').innerHTML;
	var Earnings = document.getElementById('Earnings').innerHTML;
	var CurrentSummUAH = document.getElementById('summ_UAH_'+TmpOrderPartID).innerHTML;
	var CurrentSummDiscountUAH = document.getElementById('summ_discount_UAH_'+TmpOrderPartID).innerHTML;
	
	if(confirm("Вы действительно хотите удалить из корзины выбранный товар?")){
		ajax.CreateQuery(Host+'?p=ajax&method=del_part_temp&temp_order_id='+TmpOrderID+'&temp_order_part_id='+TmpOrderPartID+'&all_summ_UAH='+AllSummUAH+'&all_summ_discount_UAH='+AllSummDiscountUAH+'&earnings='+Earnings+'&current_summ_uah='+CurrentSummUAH+'&current_summ_discount_uah='+CurrentSummDiscountUAH, 'XML');
		
		//обработка результата
	if(ajax.XML){
		Result = ajax.XML.documentElement;
		Children = Result.childNodes;
		CountResult = Children.length;
		Error = true;
		Store = '';
		Reserve = '';
		Msg = '';
		for(i=0; i<CountResult; i++){
			if(Children[i].nodeType == 1){ 			 //если узел текстовый
				//ВСЯ сумма
				if(Children[i].tagName == 'all_summ_uah'){	 
					if(Children[i].firstChild.data)
						AllSummUAH = Children[i].firstChild.data;
						document.getElementById('AllSummUAH').innerHTML=AllSummUAH;
				}
				
				//ВСЯ сумма со скидкой
				if(Children[i].tagName == 'all_summ_discount_uah'){	 
					if(Children[i].firstChild.data)
						AllSummDiscountUAH = Children[i].firstChild.data;
						document.getElementById('AllSummDiscountUAH').innerHTML=AllSummDiscountUAH;
				}
				
				//общее кол-во
				if(Children[i].tagName == 'count_all'){	 
					if(Children[i].firstChild.data)
						AllCountParts = Children[i].firstChild.data;
						document.getElementById('AllCountParts').innerHTML=AllCountParts;
				}
				
				//зароботок
				if(Children[i].tagName == 'earnings'){	 
					if(Children[i].firstChild.data)
						Earnings = Children[i].firstChild.data;
						document.getElementById('Earnings').innerHTML=Earnings;
				}
				
				//если запчасть последняя 
				if(Children[i].tagName == 'last_part'){	
					if(Children[i].firstChild.data == '1'){
						alert('Заказ удален!');
						window.location=Host+'cabinet/orders/temp';
					}
				}
							
			}
		}
	}
		
		//удаление строки таблицы
		DeleteRow('order_table', RowIdent);
	}
}





//------------- Изменение кол-ва товаров в корзине
function UpdateCountPartInCart(ID, PriceUSD, PriceUAH, PartID){
	var Count = document.getElementById('part_count_'+ID).value;
	var Store = document.getElementById('part_store_'+ID).innerHTML;
	var Reserve = document.getElementById('part_reserve_'+ID).innerHTML;
	var AllCountParts = document.getElementById('AllCountParts').innerHTML;
	var AllSummUAH = document.getElementById('AllSummUAH').innerHTML;
	var AllSummDiscountUAH = document.getElementById('AllSummDiscountUAH').innerHTML;
	var Earnings = document.getElementById('Earnings').innerHTML;
	var CurrentSummUAH = document.getElementById('summ_UAH_'+ID).innerHTML;
	var CurrentSummDiscountUAH = document.getElementById('summ_discount_UAH_'+ID).innerHTML;
	
	if(Count == '')
		return false;
	
	ajax.CreateQuery(Host+'?p=ajax&method=update_count_part_cart&id='+ID+'&count='+Count+'&store='+Store+'&reserve='+Reserve+'&price_usd='+PriceUSD+'&price_uah='+PriceUAH+'&part_id='+PartID+'&all_count_parts='+AllCountParts+'&all_summ_UAH='+AllSummUAH+'&all_summ_discount_UAH='+AllSummDiscountUAH+'&earnings='+Earnings+'&current_summ_uah='+CurrentSummUAH+'&current_summ_discount_uah='+CurrentSummDiscountUAH, 'XML');	
	
	//обработка результата
	if(ajax.XML){
		Result = ajax.XML.documentElement;
		Children = Result.childNodes;
		CountResult = Children.length;
		Error = true;
		Store = '';
		Reserve = '';
		Msg = '';
		for(i=0; i<CountResult; i++){
			if(Children[i].nodeType == 1){ 			 //если узел текстовый
				//если тег ошибка
				if(Children[i].tagName == 'error'){	 
					if(Children[i].firstChild.data == '1'){
						Error = true;					
					}
					else{
						Error = false;
					}
				}
								
				//если тег сообщение
				if(Children[i].tagName == 'message'){
					if(Children[i].firstChild){
						Msg = Children[i].firstChild.data;
						if(Error == true){
							alert(Msg);
						}
					}
				}

				//колличество - исходное значение
				if(Children[i].tagName == 'count'){	 
					if(Children[i].firstChild.data){
						Count = Children[i].firstChild.data;		
						document.getElementById('part_count_'+ID).value=Count;
					}
				}
				
				//резерв
				if(Children[i].tagName == 'reserve'){	 
					if(Children[i].firstChild.data)
						Reserve = Children[i].firstChild.data;		
						document.getElementById('part_reserve_'+ID).innerHTML=Reserve;
				}
				
				
				//сумма грн 
				if(Children[i].tagName == 'summ_uah'){	 
					if(Children[i].firstChild.data)
						SummUAH = Children[i].firstChild.data;
						document.getElementById('summ_UAH_'+ID).innerHTML=SummUAH;
				}
				
				//сумма со скидкой
				if(Children[i].tagName == 'summ_discount'){	 
					if(Children[i].firstChild.data)
						SummUAHDiscount = Children[i].firstChild.data;
						document.getElementById('summ_discount_UAH_'+ID).innerHTML=SummUAHDiscount;
				}
							
				//ВСЯ сумма
				if(Children[i].tagName == 'all_summ_uah'){	 
					if(Children[i].firstChild.data)
						AllSummUAH = Children[i].firstChild.data;
						document.getElementById('AllSummUAH').innerHTML=AllSummUAH;
						if(document.getElementById('AllSummUAHSecond')){
							document.getElementById('AllSummUAHSecond').innerHTML=AllSummUAH;
						}
				}
				
				//ВСЯ сумма со скидкой
				if(Children[i].tagName == 'all_summ_discount_uah'){	 
					if(Children[i].firstChild.data)
						AllSummDiscountUAH = Children[i].firstChild.data;
						document.getElementById('AllSummDiscountUAH').innerHTML=AllSummDiscountUAH;
						if(document.getElementById('AllSummDiscountUAHSecond')){
							document.getElementById('AllSummDiscountUAHSecond').innerHTML=AllSummDiscountUAH;
						}
				}
				
				//общее кол-во
				if(Children[i].tagName == 'count_all'){	 
					if(Children[i].firstChild.data)
						AllCountParts = Children[i].firstChild.data;
						document.getElementById('AllCountParts').innerHTML=AllCountParts;
				}
				
				//зароботок
				if(Children[i].tagName == 'earnings'){	 
					if(Children[i].firstChild.data)
						Earnings = Children[i].firstChild.data;
						document.getElementById('Earnings').innerHTML=Earnings;
						if(document.getElementById('EarningsSecond')){
							document.getElementById('EarningsSecond').innerHTML=Earnings;
						}
				}
							
			}
		}
	}
}

//------------- Изменение кол-ва товаров в неподтвержденном заказе
function UpdateCountPartInTempOrder(ID, PriceUSD, PriceUAH, PartID){
	var Count = document.getElementById('part_count_'+ID).value;
	var Store = document.getElementById('part_store_'+ID).innerHTML;
	var Reserve = document.getElementById('part_reserve_'+ID).innerHTML;
	var AllCountParts = document.getElementById('AllCountParts').innerHTML;
	var AllSummUAH = document.getElementById('AllSummUAH').innerHTML;
	var AllSummDiscountUAH = document.getElementById('AllSummDiscountUAH').innerHTML;
	var Earnings = document.getElementById('Earnings').innerHTML;
	var CurrentSummUAH = document.getElementById('summ_UAH_'+ID).innerHTML;
	var CurrentSummDiscountUAH = document.getElementById('summ_discount_UAH_'+ID).innerHTML;
	
	if(Count == '')
		return false;
	
	ajax.CreateQuery(Host+'?p=ajax&method=update_count_part_temp&id='+ID+'&count='+Count+'&store='+Store+'&reserve='+Reserve+'&price_usd='+PriceUSD+'&price_uah='+PriceUAH+'&part_id='+PartID+'&all_summ_UAH='+AllSummUAH+'&all_summ_discount_UAH='+AllSummDiscountUAH+'&earnings='+Earnings+'&current_summ_uah='+CurrentSummUAH+'&current_summ_discount_uah='+CurrentSummDiscountUAH+'&all_count_parts='+AllCountParts, 'XML');	
	
	//обработка результата
	if(ajax.XML){
		Result = ajax.XML.documentElement;
		Children = Result.childNodes;
		CountResult = Children.length;
		Error = true;
		Store = '';
		Reserve = '';
		Msg = '';
		for(i=0; i<CountResult; i++){
			if(Children[i].nodeType == 1){ 			 //если узел текстовый
				//если тег ошибка
				if(Children[i].tagName == 'error'){	 
					if(Children[i].firstChild.data == '1'){
						Error = true;					
					}
					else{
						Error = false;
					}
				}
								
				//если тег сообщение
				if(Children[i].tagName == 'message'){
					if(Children[i].firstChild){
						Msg = Children[i].firstChild.data;
						if(Error == true){
							alert(Msg);
						}
					}
				}

				//колличество - исходное значение
				if(Children[i].tagName == 'count'){	 
					if(Children[i].firstChild.data){
						Count = Children[i].firstChild.data;		
						document.getElementById('part_count_'+ID).value=Count;
					}
				}
				
				//резерв
				if(Children[i].tagName == 'reserve'){	 
					if(Children[i].firstChild.data)
						Reserve = Children[i].firstChild.data;		
						document.getElementById('part_reserve_'+ID).innerHTML=Reserve;
				}
				
				
				//сумма грн 
				if(Children[i].tagName == 'summ_uah'){	 
					if(Children[i].firstChild.data)
						SummUAH = Children[i].firstChild.data;
						document.getElementById('summ_UAH_'+ID).innerHTML=SummUAH;
				}
				
				//сумма со скидкой
				if(Children[i].tagName == 'summ_discount'){	 
					if(Children[i].firstChild.data)
						SummUAHDiscount = Children[i].firstChild.data;
						document.getElementById('summ_discount_UAH_'+ID).innerHTML=SummUAHDiscount;
				}
							
				//ВСЯ сумма
				if(Children[i].tagName == 'all_summ_uah'){	 
					if(Children[i].firstChild.data)
						AllSummUAH = Children[i].firstChild.data;
						document.getElementById('AllSummUAH').innerHTML=AllSummUAH;
						document.getElementById('AllSummUAHSecond').innerHTML=AllSummUAH;
				}
				
				//ВСЯ сумма со скидкой
				if(Children[i].tagName == 'all_summ_discount_uah'){	 
					if(Children[i].firstChild.data)
						AllSummDiscountUAH = Children[i].firstChild.data;
						document.getElementById('AllSummDiscountUAH').innerHTML=AllSummDiscountUAH;
						document.getElementById('AllSummDiscountUAHSecond').innerHTML=AllSummDiscountUAH;
				}
				
				//общее кол-во
				if(Children[i].tagName == 'count_all'){	 
					if(Children[i].firstChild.data)
						AllCountParts = Children[i].firstChild.data;
						document.getElementById('AllCountParts').innerHTML=AllCountParts;
				}
				
				//зароботок
				if(Children[i].tagName == 'earnings'){	 
					if(Children[i].firstChild.data)
						Earnings = Children[i].firstChild.data;
						document.getElementById('Earnings').innerHTML=Earnings;
						document.getElementById('EarningsSecond').innerHTML=Earnings;
				}
							
			}
		}
	}
}


function CleanCart(){
	
	if(confirm("Вы действительно хотите очистить корзину?")){
		ajax.CreateQuery(Host+'?p=ajax&method=clean_cart', 'XML');	
		
		//обработка результата
		if(ajax.XML){
			Result = ajax.XML.documentElement;
			Children = Result.childNodes;
			CountResult = Children.length;
			Error = true;
			Store = '';
			Reserve = '';
			Msg = '';
			for(i=0; i<CountResult; i++){
				if(Children[i].nodeType == 1){ 			 //если узел текстовый
					//если тег ошибка
					if(Children[i].tagName == 'error'){	 
						if(Children[i].firstChild.data == '1'){
							Error = true;					
						}
						else{
							Error = false;
						}
					}
									
					//если тег сообщение
					if(Children[i].tagName == 'message'){
						if(Children[i].firstChild){
							Msg = Children[i].firstChild.data;
							if(Msg !='' )
								alert(Msg);
						}
					}
				}
			}
			
			if(Error == false){
				
				document.getElementById('cart_table').innerHTML='';
				document.getElementById('cart_title').innerHTML='Корзина:';
				
				var CartTable = document.getElementById('cart_table');
				var Content = document.getElementById('content');
				var el0 = document.createElement('p'); 
				el0.innerHTML="Корзина пуста.";
				Content.insertBefore(el0, CartTable.nextSibling);
				
		
				if(document.getElementById('order_new_info')){
					document.getElementById('order_new_info').innerHTML = '';
				}
				
				return false;
			}
			
		}
	}
}

function MakeTempOrder(){
	var CommentOrder = document.getElementById('comment_order').value;
	var Delivery = document.getElementById('delivery');
	if(!Delivery)
		return;
	DeliveryID = Delivery.options[Delivery.options.selectedIndex].value;
	if(confirm("Вы действительно хотите отложить заказ? Пожалуйста, дождитесь ответа от сервера об успешном оформлении заказа.")){
		ajax.CreateQuery(Host+'?p=ajax&method=make_temp&comment='+CommentOrder+'&delivery_id='+DeliveryID, 'XML');
		
		//обработка результата
		if(ajax.XML){
			Result = ajax.XML.documentElement;
			Children = Result.childNodes;
			CountResult = Children.length;
			Error = true;
			Store = '';
			Reserve = '';
			Msg = '';
			for(i=0; i<CountResult; i++){
				if(Children[i].nodeType == 1){ 			 //если узел текстовый
					//если тег ошибка
					if(Children[i].tagName == 'error'){	 
						if(Children[i].firstChild.data == '1'){
							Error = true;					
						}
						else{
							Error = false;
						}
					}
				}
				
				
			}
			
			if(Error == false){
				window.location=Host+'cabinet/orders/temp';
			}
		}
	}
}

function Temp2Current(OrderID){
	var CommentOrder = document.getElementById('comment_order').value;
	var AllSummDiscountUAH = document.getElementById('AllSummDiscountUAH').innerHTML; //сумма к оплате
	var Delivery = document.getElementById('delivery');
	if(!Delivery)
		return;
	DeliveryID = Delivery.value;
	if(confirm("Вы действительно хотите оформить заказ? Пожалуйста, дождитесь ответа от сервера об успешном оформлении заказа.")){
		ajax.CreateQuery(Host+'?p=ajax&method=temp_2_current&id='+OrderID+'&comment='+CommentOrder+'&summ='+AllSummDiscountUAH+'&delivery_id='+DeliveryID, 'XML');
		
		//обработка результата
		if(ajax.XML){
			Result = ajax.XML.documentElement;
			Children = Result.childNodes;
			CountResult = Children.length;
			Error = true;
			Store = '';
			Reserve = '';
			Msg = '';
			for(i=0; i<CountResult; i++){
				if(Children[i].nodeType == 1){ 			 //если узел текстовый
					//если тег ошибка
					if(Children[i].tagName == 'error'){	 
						if(Children[i].firstChild.data == '1'){
							Error = true;					
						}
						else{
							Error = false;
						}
					}
					
					//если тег сообщение
					if(Children[i].tagName == 'message'){
						if(Children[i].firstChild){
							Msg = Children[i].firstChild.data;
						}
					}
				}
				
				
			}
			
			if(Error == false){
				alert('Заказ успешно оформлен.');
				window.location=Host+'cabinet/orders/current';
			}
			else{
				if(Msg !='' ){
					alert(Msg);
				}
				else{
					alert('Ошибка!');
				}
			}
		}
	}
}


function Cart2Current(){
	var CommentOrder = document.getElementById('comment_order').value;
	var AllSummDiscountUAH = document.getElementById('AllSummDiscountUAH').innerHTML; //сумма к оплате
	var Delivery = document.getElementById('delivery');
	if(!Delivery)
		return;
	DeliveryID = Delivery.options[Delivery.options.selectedIndex].value;
	if(confirm("Вы действительно хотите оформить заказ? Пожалуйста, дождитесь ответа от сервера об успешном оформлении заказа.")){
		ajax.CreateQuery(Host+'?p=ajax&method=cart_2_current&comment='+CommentOrder+'&summ='+AllSummDiscountUAH+'&delivery_id='+DeliveryID, 'XML');
		
		//обработка результата
		if(ajax.XML){
			Result = ajax.XML.documentElement;
			Children = Result.childNodes;
			CountResult = Children.length;
			Error = true;
			Store = '';
			Reserve = '';
			Msg = '';
			for(i=0; i<CountResult; i++){
				if(Children[i].nodeType == 1){ 			 //если узел текстовый
					//если тег ошибка
					if(Children[i].tagName == 'error'){	 
						if(Children[i].firstChild.data == '1'){
							Error = true;					
						}
						else{
							Error = false;
						}
					}
					
					//если тег сообщение
					if(Children[i].tagName == 'message'){
						if(Children[i].firstChild){
							Msg = Children[i].firstChild.data;
						}
					}
				}
				
				
			}
			
			if(Error == false){
				alert('Заказ успешно оформлен.');
				window.location=Host+'cabinet/orders/current';
			}
			else{
				if(Msg !='' ){
					alert(Msg);
				}
				else{
					alert('Ошибка!');
				}
			}
		}
	}
}
