function MM_openBrWindow(theURL,winName,features) {
   window.open(theURL,winName,features);
}
function SetHtmlElementByName( id, newValue )
{

	if( document.getElementsByName )
	{
		var htmlElm = document.getElementsByName( id );
		if( htmlElm && htmlElm != undefined && htmlElm.length > 0 )
		{
			for( i=0;i<htmlElm.length;i++ )
			{
				htmlElm[i].innerHTML = newValue;
			}
		}
	}
}


var all_sum = 0;
function ShowElement(sender) {  
	el = document.getElementById(sender);   
	var elm_id = sender.id;
	var index;
	elm_id = elm_id.substring(3, 10);
	index = elm_id.split('_');
	obj_select = 'name_c' + index[0];
   if (sender.type == "radio") {
		if (showProductPrice == 1) {
			SetHtmlElementByName(obj_select , prices[index[0]][index[1]][1] + "&nbsp;" + prices[index[0]][index[1]][0] + "&nbsp;" + currency);
		} else {
			SetHtmlElementByName(obj_select , prices[index[0]][index[1]][1]);
		}
	} else {
		/*for(a in )
		if (showProductPrice == 1) {
			SetHtmlElementByName(obj_select , prices[index[0]][index[1]][1] + "&nbsp;" + prices[index[0]][index[1]][0] + "&nbsp;" + currency);
		} else {
			SetHtmlElementByName(obj_select , prices[index[0]][index[1]][1]);
		}*/	
	}
	SumAll();
}
function FormatFloat(X) {
	with (new Object(Math.round(100*X)+'')) {
    	return substring(0,length-2) + '.' + substring(length-2,length)
	}
}

function SumAll() {	
	all_sum = 0.0;
	all_sum1 = 0.0;
	// check radio
	for (i=0; i < prices.length; i++) {
		for (j=0; j<prices[i].length; j++) {
			var obj = 'pr_' + i + '_' + j;
			el = document.getElementById (obj)         
			obj = 'count_' + i + '_' + j;
			var amount = (document.getElementById(obj))?document.getElementById(obj).value:1;			
			if (el.checked) {					
           	all_sum += (amount * prices[i][j][0]);
				all_sum1 += (amount * prices[i][j][2]);
         } // if
			//set all sums
			obj  = 'total_' + i + '_' + j;
			var total = document.getElementById(obj);
			if (total) {
				total.value = FormatFloat(amount * prices[i][j][0]);
			}
		} 
	}

   for (i=0; i < more_products.length; i++) {
		var obj = 'more_pr_' + i;
		el = document.getElementById(obj)
			if (el.checked) {
				all_sum += more_products[i];
				all_sum1 += more_products[i];
			}
	}
   //remove dds	
	/*if (haveDDS == 0) {
		all_sum -= all_sum*0.20;
		all_sum1 -= all_sum1*0.20;
		alert("dds-" + all_sum);
	}*/
	
	SetHtmlElementByName( "sale_price" , FormatFloat(all_sum - globalDiscount) + "&nbsp;");	
    
	p = new Payment();
	p.currency = currencyb;
	p.us2bg = us2bg;	  	
	p.Pay(parseFloat(all_sum), 12);	
	
	if (p.instalment != -1) {		
		SetHtmlElementByName( "payment" , "Лизинг 12 вноски по: " + FormatFloat(p.instalment) + "&nbsp;лв");
	} else {
		SetHtmlElementByName( "payment" , "");	
	}
	
	if (all_sum1 > (all_sum - globalDiscount)) {
		SetHtmlElementByName( "sale_price1" , FormatFloat(all_sum1) + "&nbsp;" + currency);
		SetHtmlElementByName( "sale_priceDiff" , "Отстъпка: " + FormatFloat(all_sum1 - all_sum + globalDiscount) +  "&nbsp;" + currency);		
    } else {
    	SetHtmlElementByName( "sale_price1" , "");
		SetHtmlElementByName( "sale_priceDiff", "");		
    }
	
	

}