function change_models(brandId, elementToBeChangedId, preloadId) {
	$("#"+preloadId).css('visibility','visible');
	if(brandId == 0) {
		$("#"+elementToBeChangedId).html("<option value='0'> ---Избери Модел--- </option>");
		$("#"+preloadId).css('visibility','hidden');
	} else {
		$.get("/ajax_get.php?brand_id="+brandId+"&changeModels=true", function(data){
			if(data != "false") {
				$("#"+elementToBeChangedId).html(data);
			} else {
				$("#"+elementToBeChangedId).html("<option value='0'>-Грешка-</option>");
			}
			$("#"+preloadId).css('visibility','hidden');
		});
	}
	return;
}


function change_types(parentTypeId, elementToBeChangedId, preloadId) {
	$("#"+preloadId).css('visibility','visible');
	$.get("/ajax_get.php?parent_type_id="+parentTypeId+"&changeTypes=true", function(data){
		if(data != "false") {
			$("#"+elementToBeChangedId).html(data);
		} else {
			$("#"+elementToBeChangedId).html("<option value='0'>-Грешка-</option>");
		}
		$("#"+preloadId).css('visibility','hidden');
	});
	return;
}

function add_mail(inputId, preloadId) {
	$("#"+preloadId).css('visibility','visible');
	var mail = window.document.getElementById(inputId).value;
	$.get("/ajax_get.php?mailValue="+mail+"&addMail=true", function(data){
		if(data != "") {
			$("#div_"+inputId).html(data);
		}
		$("#"+preloadId).css('visibility','hidden');
	});
	return;
}

function miniGoToPage(brandId, modelId, listPage) {
	var brand = $("#"+brandId).val();
	var model = $("#"+modelId).val();
	$.get("/ajax_get.php?brand_id="+brand+"&model_id="+model+"&listPage="+listPage+"&goToPage=true", function(data){
		if(data != "false") {
			window.location.href=""+data+"";
		}
	});
	return;
}


function toggleForFirmDiv() {
	$("#forFirm").toggle('slow');
}

function changeListClass(type) {
	if(type == 'list') {
		if($('#partsListUl').attr("class") == 'horlist parts') {
			$('#partsListUl').removeClass( "horlist parts" );
			$("#partsListUl").addClass( "horlist-parts-rows" );
		}
	} else if(type == 'block') {
		if($('#partsListUl').attr("class") == 'horlist-parts-rows') {
			$('#partsListUl').removeClass( "horlist-parts-rows" );
			$("#partsListUl").addClass( "horlist parts" );
		}
	} else {
		return;
	}
}

var timeout    = 200;
var closetimer = 0;
var ddmenuitem = 0;
var tips = "validateTips";
function jsddm_open() {  
	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}
function jsddm_close() {
	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}
function jsddm_timer() {
	closetimer = window.setTimeout(jsddm_close, timeout);
}
function jsddm_canceltimer() {
	if(closetimer) {  
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

function init() {
	/////////////////////////////////////////////////////
	$('#jsddm > li').bind('mouseover', jsddm_open); 
	$('#jsddm > li').bind('mouseout',  jsddm_timer);
	/////////////////////////////////////////////////////
	$('.toolTips').cluetip({
		local: true,
		width: '500',
		tracking: true,
		//sticky: true,
		//closeText: "<b>[x] Затвори</b><br /><br />",
		showTitle: false // hide the clueTip's heading
	});
	/////////////////////////////////////////////////////							   
	$('.allModelsTip').cluetip({
		width: '400',
		sticky: true,
		closeText: "<b>[x] Затвори</b><br /><br />",
		showTitle: false // hide the clueTip's heading
	});
}
$(function() {
	init();
});
document.onclick = jsddm_close;
