function changeMenuImage(obj, idcompany, lang) {
	var control = obj.src.indexOf(obj.id+'_off.jpg');
	var bottomMenuItem = obj.id + '_bottom';
	obj.src = (control == -1)?'/usedcars/media/' + idcompany + '/images/'+obj.id+'_off.jpg':'/usedcars/media/' + idcompany + '/images/'+obj.id+'_on.jpg';
	$(bottomMenuItem).src = (control == -1)?'/usedcars/media/' + idcompany + '/images/menu_bottom_off.jpg':'/usedcars/media/' + idcompany + '/images/menu_bottom_on.jpg';

	if(control != -1) {
		$('message_div').innerHTML = topMenuMessage[(obj.id.substr(obj.id.lastIndexOf("_")+1,obj.id.length )-1)];

		var posMessageParent = $('menu_holder').cumulativeOffset();
		var posMessage = $(obj.id).cumulativeOffset();
		var tdSize = [Math.round(obj.getWidth() / 2), obj.getHeight()+2];

		var messageSize = Math.round($('message_div').getWidth() / 2);

		$('message_div').style.left = (posMessage[0]-posMessageParent[0]+tdSize[0] - messageSize)+'px';
		$('message_div').style.top = (posMessage[1]-posMessageParent[1]+tdSize[1])+'px';
		$('message_div').show();
	} else {
		$('message_div').hide();
	}
}
function menuLateralChange(obj) {
	var arrow = obj.id+'_arrow';
	if($(arrow).style.display == 'none'){
		$(arrow).style.display = '';
	} else {
		$(arrow).style.display = 'none';
	}
}
function searchLateralChange(obj, idcompany) {
	var arrow = obj.id+'_box';
	if($(arrow).src.indexOf('blue_box.jpg') == -1) {
		$(arrow).src = '/usedcars/media/' + idcompany + '/images/blue_box.jpg';
	} else {
		$(arrow).src = '/usedcars/media/' + idcompany + '/images/orange_box.jpg';
	}
}
function ConstructOportunitiesHTML(promotionCars, idCompany) {
	var carPromotion;
	var curCar=1;
	var curNav=1;
	var maxCarsInPage = 6;
	var strResult = '<table style="vertical-align: top;" border=\"0\">\n';
	strResult += '<tr valign="top">\n';
	strResult += '<td>\n';
	strResult += '<div id="carpromonav_'+ curNav + '" style="display:none;">\n';
	strResult += '<table style="vertical-align:top;">\n';
	while (curCar<promotionCars.length) {
		carPromotion = promotionCars[curCar];

		strResult += '<tr valign="top">\n';
		strResult += '\t<td></td>\n';
		strResult += '\t<td>\n';
		strResult += '\t\t<table cellpadding="0" cellspacing="0" style="vertical-align:top;">\n';
		strResult += '\t\t<tr>\n';
		strResult += '\t\t\t<td width="70" valign="top" align="left"><img src="' + carPromotion.path + carPromotion.promotionimage + '" width="67" height="49" /></td>\n';
		strResult += '\t\t\t<td width="92" class="oportunities">\n';
		strResult += '\t\t\t\t' + carPromotion.brand + '<br />\n';
		strResult += '\t\t\t\t' + carPromotion.model + '<br />\n';
		if (carPromotion.year!=0) {
			strResult += '\t\t\t\t' + carPromotion.year + '<br />\n';
		}
		strResult += '\t\t\t\t<strong>&euro; ' + carPromotion.price + '</strong><br />\n';
		strResult += '\t\t\t\t<a href="/usedcars/MainUsedCars?cmd=getcar&nrplate=' + carPromotion.nrplate + '"> + info</a>\n';
		strResult += '\t\t\t</td>\n';
		strResult += '\t\t</tr>\n';
		strResult += '\t\t</table>\n';
		strResult += '\t</td>\n';
		strResult += '\t<td></td>\n';
		strResult += '\t<td valign="top">\n';

		if (curCar!=promotionCars.size()-1) {
			curCar++;
			carPromotion = promotionCars[curCar];

			strResult += '\t\t<table cellpadding="0" cellspacing="0" style="vertical-align:top;">\n';
			strResult += '\t\t<tr>\n';
			strResult += '\t\t\t<td width="70" valign="top" align="left"><img src="' + carPromotion.path + carPromotion.promotionimage + '" width="67" height="49" /></td>\n';
			strResult += '\t\t\t<td width="92" class="oportunities">\n';
			strResult += '\t\t\t' + carPromotion.brand + '<br />\n';
			strResult += '\t\t\t' + carPromotion.model + '<br />\n';
			if (carPromotion.year!=0) {
				strResult += '\t\t\t' + carPromotion.year + '<br />\n';
			}
			strResult += '\t\t\t<strong>&euro; ' + carPromotion.price + '</strong><br />\n';
			strResult += '\t\t\t<a href="/usedcars/MainUsedCars?cmd=getcar&nrplate=' + carPromotion.nrplate + '"> + info</a>\n';
			strResult += '\t\t\t</td>\n';
			strResult += '\t\t</tr>\n';
			strResult += '\t\t</table>\n';
		}
		strResult += '\t</td>\n';
		strResult += '\t<td></td>\n';
		strResult += '</tr>\n';
		strResult += '<tr><td colspan="5" height="8"></td></tr>\n';

		//Criar nova página
		if (curCar%maxCarsInPage==0) {
			strResult += '</table>\n';
			strResult += '</div>\n';
			curNav++;
			if (curCar < (promotionCars.length-1)) {
				strResult += '<div id="carpromonav_'+ curNav + '" style="display:none;">\n';
				strResult += '<table>\n';
			}
		}
		curCar++;
	}
	if ((promotionCars.length-1)%maxCarsInPage!=0) {
		strResult += '</table>\n';
		strResult += '</div>\n';
	}
	strResult += '</td>\n';
	strResult += '</tr>\n';
	strResult += '</table>';
	$('htmloportunities').innerHTML = strResult;

	var totalNavs = (promotionCars.length-1)%maxCarsInPage==0 ? curNav -1 : curNav;
	ShowOportunitiesDIV(getRandomInt(1, totalNavs), totalNavs, idCompany);
	ShowHighlight(promotionCars, idCompany);
}
function ShowOportunitiesDIV(selOportunityNav, totalNavs, idCompany) {
	
	var strResult = '';
	for (var i = 1; i<=totalNavs; i++) {
		hide('carpromonav_' + i);
		if (i==selOportunityNav)
			strResult += ' | <img src="/usedcars/media/' + idCompany + '/images/up_white_arrow.jpg" width="10" height="10" style="vertical-align:middle" />';
		else
			strResult += ' | <a href="javascript:ShowOportunitiesDIV(' + i + ',' + totalNavs + ',' + idCompany + ');">' + i + '</a>';
	}
	strResult += ' |';
	$('htmloportunities_nav').innerHTML = strResult;
	show('carpromonav_' + selOportunityNav);
}
function ShowHighlight(promotionCars, idCompany) {
	var selCar = promotionCars[getRandomInt(1, promotionCars.length-1)];
	var curCar=1;
	var pos = 1;
	var carWithImages = new Array();
	while (curCar<promotionCars.length) {
		carPromotion = promotionCars[curCar];
		if (carPromotion.image!='nopicture.jpg') {
			carWithImages[pos++] = carPromotion;
		}
		curCar++;
	}
	//alert('carWithImages.length:' + carWithImages.length);
	if (carWithImages.length>1)
		selCar = carWithImages[getRandomInt(1, carWithImages.length-1)];

	if (selCar==undefined)
		return;

	//$('highlight_car_image').src = selCar.path + selCar.promotionimage;
	$('highlight_car_image').src = '/files/usedcars/' + idCompany + '/carimages/' + selCar.promotionimage;
	$('highlight_car_brandmodel').innerHTML = selCar.brand + "&nbsp;" + selCar.model;
	$('highlight_car_price').innerHTML = selCar.price;
	$('highlight_car_year').innerHTML = selCar.year;
	$('highlight_car_link').style.cursor = 'pointer';
	$('highlight_car_link').href ='/usedcars/MainUsedCars?cmd=getcar&nrplate=' + selCar.nrplate;
}
