$(document).ready(function() {
	bindHighlightEvent('make-select', 'make-lbl', 'select');
	bindHighlightEvent('model-select', 'model-lbl', 'select');
	bindHighlightEvent('price-select', 'price-lbl', 'select');
	bindHighlightEvent('admission-select', 'admission-lbl', 'select');
	bindHighlightEvent('mileage-select', 'mileage-lbl', 'select');
	bindHighlightEvent('fuel-select', 'fuel-lbl', 'select');
	bindHighlightEvent('zip-input', 'zip-lbl', 'input');
	bindHighlightEvent('radius-select', 'radius-lbl', 'select');
});

bindHighlightEvent = function(ctrlId, lblId, nodeName)
{
	var elm = $('#' + ctrlId + ' ' + nodeName);
	if(elm[0] != null)
	{
		elm.bind('focus', function() {$('#' + lblId + ' label').addClass('active')});
		elm.bind('blur', function() {$('#' + lblId + ' label').removeClass('active')});
	}
}

var checkCount = 0;
var intervalId = null;
checkMediumRectangleAsync = function()
{
	if(checkCount > 14)
	{
		window.clearInterval(intervalId);
	}
	
  if ($(".medium-rectangle-home:eq(0)").height() > 30) 
  {
	  $(".home-advert-head")[0].style.visibility = "visible";
	  $(".home-advert-head")[0].style.display = "block";
	  $(".medium-rectangle-home")[0].style.display = "block";
	  window.clearInterval(intervalId);
  }
		
	checkCount++;
}

checkMediumRectangle = function()
{
	if ($(".medium-rectangle-home:eq(0)").height() > 30) 
	{
			$(".home-advert-head")[0].style.visibility = "visible";
			$(".medium-rectangle-home")[0].style.display = "block";        
	}
	else
	{
		intervalId = window.setInterval(checkMediumRectangleAsync, 500);
		$(".home-advert-head")[0].style.display = "none";
		$(".medium-rectangle-home")[0].style.display = "none";
	}
}

$(function() {
    var makeObj = $('[id$=makeSelect]');
    if (makeObj.length == 0) {
        return;
    }

    if (makeObj[0].selectedIndex > 0) {
        var modelObj = $('[id$=modelSelect]');
        var modelCaption = $('[id$=modelCaption]');
        if (makeObj[0].id && modelObj.length > 0 && modelObj[0].id && modelCaption.length > 0 && modelCaption[0].id) {
            var selModInd = modelObj[0].selectedIndex; // save this because chooseMake will reset it
            chooseMake(true, makeObj[0].id, modelObj[0].id, true, modelCaption[0].id);

            modelObj[0].selectedIndex = selModInd;
            if (modelObj.length > 0 && modelObj[0].id && modelObj[0].selectedIndex && modelObj[0].selectedIndex > 0) {
                onSelectionChanged(modelObj[0].id, 'selectedmodelvalue', '');
            }
        }
    }
});