function activate(id) {
	var table = document.getElementById(id);
	if (table == null) return;
	table.className = table.rows[0].cells[1].className = 'menuOn';
	table.rows[0].cells[0].className = 'pointOn';
	var imgs = table.rows[0].cells[0].getElementsByTagName('img');
	imgs[0].src = 'images/pointOn.gif';
}

function computeLeasing(engineId, type, a, b, c) {
	if(document.getElementById('eg_' + engineId + '_promotion_cipprice'))
	{
		window.location.href = 'leasingCalculator.php?type=' + type + '&price=' + document.getElementById('eg_' + engineId + '_promotion_cipprice2').value + '&model=' + a + '&echipare=' + b + '&motorizare=' + c;
	}
	else
	{
	window.location.href = 'leasingCalculator.php?type=' + type + '&price=' + document.getElementById('eg_' + engineId + '_cipprice').value + '&model=' + a + '&echipare=' + b + '&motorizare=' + c;
	}
}

var zones = [
	'se',
	'oe'
];

function viewTechData(equipmentId, engineId) {
	for (i=0; i<zones.length; i++) {
		//document.getElementById('accessories').style.display = 'none';
		document.getElementById('eq_' + zones[i] + '_' + equipmentId).style.display = 'none';
		document.getElementById('eq_link_' + zones[i] + '_' + equipmentId).className = 'btt';
		document.getElementById('eq_buton_' + zones[i] + '_' + equipmentId).className = 'buton';
	}
	for (i=0; i<engines[equipmentId].length; i++) {
		document.getElementById('eq_' + equipmentId + '_en_td_' + engines[equipmentId][i]).style.display = 'none';
	}
	document.getElementById('eq_' + equipmentId + '_en_td_' + engineId).style.display = 'block';
}

function viewProductPhoto(id, width, height) {
	xwin ('viewProductPhoto.php?id=' + id, 'viewProductPhoto', width, height);
}

function _print() {
	xwin ('printPage.php', 'printPage', 770, 660);
}

function fade(object, type) {
	object.style.background = type == 'in' ? '#FAFAFA' : '#FFFFFF';
}

function checkAll (object) {
	var elems = object.form.elements;
	for (var i = 0; i < elems.length; i++) {
		var elem = elems[ i ];
		if (elem.type == 'checkbox' && elem != this) {
			elem.checked = object.checked;
		}
	}
}

function debugElement (elem) {
	str = "";
	j = 0;
	for (i in elem) {
		str+=i + "\n";
		j++;
		if (j==20) {
			alert(str);
			str="";
			j = 0;
		}
	}
}

function xwin (url, name, width, height, features){
	var l = (window.screen.availWidth) ? (window.screen.availWidth - width)/2 : 0;
	var t = (window.screen.availHeight) ? (window.screen.availHeight - height)/2 : 0;
	if (typeof(features) == 'string')
		features = ',' + features;

	var w = window.open (
		url,
		name,
		'top=' + t +
		', left=' + l +
		', height=' +
		height + ', width=' +
		width +
		', scrollbars=auto' +
		features);
	if (!w) return;

	w.resizeTo (width, height);
	return w;
}

function updatePrice(valueA, valueB, field){
	if (valueB.indexOf('.') != -1)
		valueB = valueB.replace ('.', '');

	var returnValue = Math.round(Math.round (valueA) + Math.round (valueB));

	var tva = 19.9 / 100;
	field.value = group_digits (returnValue);
}

function group_digits(nr){
   var intNr = nr;
   var s = [];
   var l = String(nr).indexOf('.') != -1 ? String(nr).indexOf('.') : String(nr).length;
   var j = 0;
   var t = 0;
   for (var i = 0; i < l; i++){
      s[t] = nr % 10;
      nr = Math.floor(nr / 10);

      j++;
      if (j == 3 && i < (l - 1)){
	 s[++t] = '.';
	 j = 0;
      }
      t++;
   }

   var number = s.reverse().join('');

   return roundDec (number, intNr);
}

function roundDec (number, intNumber) {
   if (String(intNumber).indexOf('.') == -1) return number;
   else {
	var l = String(number).indexOf('.');
	var str = String(number);
	str2 = str.substring (0, l + 2);
	str2 += str.substring (l + 3, l + 4) < 5 ? str.substring (l + 2, l + 3) : Math.floor(Math.floor(str.substring (l + 2, l + 3)) + 1);
   	number = str2;
	return number;
   }
}

