
var strPage = '';
window.onresize = position_menus;

function position_menus(){
	if(getID('divSubMenuStoc'))
        getID('divSubMenuStoc').style.left = findPosX(getID('tdMenuStoc')) + 'px';
	if(getID('divSubMenuOferta'))
        getID('divSubMenuOferta').style.left = (findPosX(getID('tdMenuOferta')) - 1) + 'px';
	if(getID('divSubMenuSecondHand'))
        getID('divSubMenuSecondHand').style.left = (findPosX(getID('tdMenuSecondHand')) - 1) + 'px';
	if(getID('divSubMenuFinantare'))
        getID('divSubMenuFinantare').style.left = (findPosX(getID('tdMenuFinantare')) - 1) + 'px';
}

var blMenuVisible = false;
var toID = null;
function show_menu(menu){
    close_menu();

    blMenuVisible = true;
	getID('tdMenu' + menu).style.background = 'url(\'images/top_menu_bg_on.gif\') repeat-x 0px 0px';
	if(getID('divSubMenu' + menu))
		getID('divSubMenu' + menu).style.display = 'block';

	if(toID!=null)
		clearTimeout(toID);
	toID = setTimeout('hide_menu(\'' + menu + '\')', 1000);
}

function hide_menu(menu){
    close_menu();

	if(blMenuVisible==false){
		getID('tdMenu' + menu).style.background = 'url(\'images/top_menu_bg_off.gif\') repeat-x 0px 0px';
		if(getID('divSubMenu' + menu))
            getID('divSubMenu' + menu).style.display = 'none';
	}else{
		getID('tdMenu' + menu).style.background = 'url(\'images/top_menu_bg_on.gif\') repeat-x 0px 0px';
		if(getID('divSubMenu' + menu))
			getID('divSubMenu' + menu).style.display = 'block';

		if(toID!=null)
			clearTimeout(toID);
        toID = setTimeout('hide_menu(\'' + menu + '\')', 1000);
	}
}

function close_menu(){
	if(strPage!='Stoc')
		getID('tdMenuStoc').style.background = 'url(\'images/top_menu_bg_off.gif\') repeat-x 0px 0px';
	if(getID('divSubMenuStoc'))
		getID('divSubMenuStoc').style.display = 'none';
	if(strPage!='Oferta')
		getID('tdMenuOferta').style.background = 'url(\'images/top_menu_bg_off.gif\') repeat-x 0px 0px';
	if(getID('divSubMenuOferta'))
		getID('divSubMenuOferta').style.display = 'none';
	if(strPage!='SecondHand')
		getID('tdMenuSecondHand').style.background = 'url(\'images/top_menu_bg_off.gif\') repeat-x 0px 0px';
	if(getID('divSubMenuSecondHand'))
		getID('divSubMenuSecondHand').style.display = 'none';
	if(strPage!='Livrare')
		getID('tdMenuLivrare').style.background = 'url(\'images/top_menu_bg_off.gif\') repeat-x 0px 0px';
	if(strPage!='Finantare')
		getID('tdMenuFinantare').style.background = 'url(\'images/top_menu_bg_off.gif\') repeat-x 0px 0px';
	if(getID('divSubMenuFinantare'))
		getID('divSubMenuFinantare').style.display = 'none';
	if(strPage!='Contact')
		getID('tdMenuContact').style.background = 'url(\'images/top_menu_bg_off.gif\') repeat-x 0px 0px';
}

function get_models(obj){
	if(obj.selectedIndex>0){
		http.open('get', './inc/get_models.php?action=get_models&id=' + obj.options[obj.selectedIndex].value + '&ref=' + Math.random());
		http.onreadystatechange = handle_models;
		http.send(null);
	}else{
        getID('ddlModel').length = 0;

		var objOption = new Option('-', '', true);
		try{
			getID('ddlModel').add(objOption, null);
		}catch(ex){
			getID('ddlModel').add(objOption);
		}
	}
}

function handle_models(){
	if(http.readyState == 4){
		var response = http.responseText;
		eval(response);
	}
}

function check_search(){
	if(getID('ddlMarca').selectedIndex==0){
		alert('Campul "Marca" este obligatoriu!');
		getID('ddlMarca').focus();
		return false;
	}else{
		if(getID('ddlModel').selectedIndex==0){
			getID('frmSearch').action = './?page=modele&marca=' + getID('ddlMarca').options[getID('ddlMarca').selectedIndex].value;
		}else{
			getID('frmSearch').action = './?page=detalii&model=' + getID('ddlModel').options[getID('ddlModel').selectedIndex].value;
		}
        getID('frmSearch').submit();
	}
}


