var xmlarray = new Array(); // основной массив, в который будут забиваться данные о доставки
var dindex=0;



 
function unparseit(did,dname,dprice,inxml) {

	if (inxml!='') {
		dminprice='';
		dmaxprice='';
		dfullname='';
		dinvoice='';
		//получаем позиции в строке
		posSMPbegin = inxml.indexOf('<ShippingMinPrice>');
		posSMPend = inxml.indexOf('</ShippingMinPrice>');
		posSMxPbegin = inxml.indexOf('<ShippingMaxPrice>');
		posSMxPend = inxml.indexOf('</ShippingMaxPrice>');
		posSFNbegin = inxml.indexOf('<ShippingFullName>');
		posSFNend = inxml.indexOf('</ShippingFullName>');
		posSMIbegin = inxml.indexOf('<ShippingPrintInvoice>');
		posSMIend = inxml.indexOf('</ShippingPrintInvoice>');
		
		//по позициям выдираем данные 
		dminprice=inxml.substring(posSMPbegin+18,posSMPend);
		dmaxprice=inxml.substring(posSMxPbegin+18,posSMxPend);
		if (dmaxprice=='1') dmaxprice='99999999';
		dfullname=inxml.substring(posSFNbegin+18,posSFNend);
		dfullname=dfullname.replace(";", ".<br>");
		dfullname=dfullname.replace(";", "&nbsp;");

		dinvoice=inxml.substring(posSMIbegin+22,posSMIend);
		
	//	if (dminprice!=''&&dmaxprice!=''&&dfullname!=''&&dinvoice!='') {
	//		// если данные все есть  - заполняем очередной элемент массива
			xmlarray[dindex] = new Array(7);
			
			xmlarray[dindex][0]=did; //пишем id доставки
			xmlarray[dindex][1]=dname; //пишем короткое доставки
			xmlarray[dindex][2]=dprice; //пишем стоимость доставки
			xmlarray[dindex][3]=dminprice; //пишем мин цену
			xmlarray[dindex][4]=dmaxprice; //пишем макс цену
			xmlarray[dindex][5]=dfullname; //пишем полное имя
			xmlarray[dindex][6]=dinvoice; //пишем флаг печати
			dindex=dindex+1;
	
	//	}
	
	}

}

function changeSumit(allsum,dostsum,iddost) {
tekship=iddost;
letgo=1;
var sub1but = document.getElementById('sub1but');
var sub2but = document.getElementById('sub2but');
if (sub1but!=null) sub1but.disabled=0;
if (sub2but!=null) sub2but.disabled=0;


	allsum=allsum*1;
	dostsum=dostsum*1;
	var i = allsum + dostsum;
	
	i = normalize(i);
	sumForPreview = i;
	
	var obj = document.getElementById("sumD");
	if ( obj != null ) {
		i = roundprice(i,'ret'); // убираем копейки
	
		obj.innerHTML = i;
		
	}	
	



}


function showdostavka(goodssum, curdost) {

	
	for ( i = 0; i < dindex; i++ ) {
		
		
		
		if (curdost!='0') { 
		//для второго этапа регистрации (превью).
			if (curdost==xmlarray[i][0]) {
			
					if (xmlarray[i][2]=='0.00') tempprice='Бесплатно';
					else {
					
					tempprice =roundprice(xmlarray[i][2],'ret')+'&nbsp;руб.';
					
					}
			
			
			
				document.write('<tr>');	
				document.write("<td>"+xmlarray[i][5]+"</td><td align=center>"+tempprice+"</td>");		
				document.write('</tr>');

			changeSumit(xmlarray[i][2],goodssum);
			document.regform.shippmode.value = xmlarray[i][0];	
			}
		}
		else {
			
			
			minpr=xmlarray[i][3]*1;
			maxpr=xmlarray[i][4]*1;
			itsum=goodssum*1;
			
			if (minpr<=itsum&&itsum<=maxpr) {
				
				//теперь если выбрали строку
				if (xmlarray[i][2]!='1.00') {
					tempprice='';
					if (xmlarray[i][2]=='0.00') tempprice='Бесплатно';
					else {
					
					tempprice =roundprice(xmlarray[i][2],'ret')+'&nbsp;руб.';
					
					}
					
					
					//document.write("<td>"+xmlarray[i][5]+"</td><td align=center>"+tempprice+"</td><td align=center><input type=radio onclick='changeSumit("+xmlarray[i][2]+","+goodssum+"); document.regform.shippmode.value = this.value; tekship="+xmlarray[i][0]+";' name=sum_deliv value='"+xmlarray[i][0]+"'></td>");		
					document.write("<td>"+xmlarray[i][5]+"</td><td align=center>"+tempprice+"</td><td align=center><input type=radio onclick='changeSumit("+xmlarray[i][2]+","+goodssum+","+xmlarray[i][0]+"); document.regform.shippmode.value = this.value;' name=sum_deliv value='"+xmlarray[i][0]+"'></td>");		
					document.write('</tr>');	
				}
				else {
					document.write('<tr>');	
					document.write("<td style=\"color: #BDBDBD;\">"+xmlarray[i][5]+"</td><td style=\"color: #BDBDBD;\" align=center>&nbsp;</td><td align=center><input type=radio disabled name=sum_deliv value='"+xmlarray[i][0]+"'></td>");		
					document.write('</tr>');	

				}				
				
			}
			
			
			
			
			
			
			
			
			
		}
	}


}
sumForPreview=0;

function printinvoice(statproc,statpay,updtstat,orderid,ordernum,shipid,OrderPay) {
//printinvoice('#ORDER_STAT_PROC#','#ORDER_STAT_PAY#','#FIELD(UpdateStatus)#','#NUM_ORDER#','#FIELD(ShippingID)#');
	var retVal="";
	invoiceflag='True';
	for ( i = 0; i < dindex; i++ ) {
		curid=xmlarray[i][0]+'';
		if (curid==shipid) {
			invoiceflag=xmlarray[i][6]+'';
		}
	}
//alert("statproc=" + statproc + ", statpay=" + statpay + ", updtstat=" + updtstat + ", invoiceflag=" + invoiceflag);
	if (statproc=='да' && statpay=='нет' && updtstat!='2' && invoiceflag!='False')
	{
		retVal = '<a href="javascript:show_win(300,570,\'/epay.html?ido='+orderid+'&sum='+ normalize(OrderPay) +'&c=print\')" alt="Оплатить заказ" style="color:red;"><img src="/i/pay.gif" border=0 alt="Оплатить заказ" class="oplzak"></a>';
//alert("1");
	}
	else
	{
		retVal = '&nbsp;';	
//alert("2");
	}
	return retVal;
}

var curOrderID=0;
function orders_action(c, OrderID)
{
	var st = "???";
	if (c=="delorder")
		st = "Отказаться";
	if (c=="reaorder")
		st = "Восстановить";
	document.write("<a style=\"color:#fd2a00;\" href=\"javascript:orders_actionDo('" + c + "', " + OrderID + ")\">" + st + "</a>");
}

function orders_actionDo(c, OrderID)
{
	var objForm = document.getElementById("myForm" + OrderID);
	if (objForm==null)
	{
		alert("Ошибка orders_actionDo: Не найден объект myForm" + OrderID);
		return false;
	}
	objForm.c.value=c;
	objForm.submit();
}
 
