// JScript File
(function ($) {

    var DEFAULT_DROPDOWN_VALUE = '1';

    $.fillM = function () {
        $('#ddlMoto option').remove();
        $('#ddlMoto').attr('disabled', true);
        $('#ddlBrand').attr('disabled', true);
        //$('#ddlType').attr('disabled', true);

        if (DEFAULT_DROPDOWN_VALUE != "0") {
            if (DEFAULT_DROPDOWN_VALUE == "1") {
                $.ajax({
                    type: "GET",
                    url: "/sites/all/themes/transfermaster/js/hookjs/xml/Motors.xml",
                    dataType: "xml",
                    success: function (xml) {
                        $(xml).find('motoc').each(function () {
                            $('#ddlMoto').append($('<option></option>').val($(this).attr('mcid')).html($(this).attr('mcname')));
                        });
                    }
                });
            }
            $('#ddlMoto').removeAttr('disabled');
        }
    },

    $.fillS = function () {
        $('#ddlBrand option').remove();
        //$('#ddlType option').remove();
        $('#ddlBrand').attr('disabled', true);
        //$('#ddlType').attr('disabled', true);
        $('#ddlBrand').append('<option>Select Answer</option>');
        $('#ddlType').append('<option>Select Answer</option>');

        if ($('#ddlMoto').val() != "0") {
            if (DEFAULT_DROPDOWN_VALUE == "1") {
                $.ajax({
                    type: "GET",
                    url: "/sites/all/themes/transfermaster/js/hookjs/xml/Motors.xml",
                    dataType: "xml",
                    success: function (xml) {
                        $(xml).find('motocb').each(function () {
                            if ($(this).attr('mcid') == $('#ddlMoto').val())
                                $('#ddlBrand').append($('<option></option>').val($(this).attr('mcbid')).html($(this).attr('mcbname')));
                        });
                    }
                });
            }
            $('#ddlBrand').removeAttr('disabled');
        }
	
	if ($('#ddlMoto').val() == "3") window.location = '/content/institutions';		
    },

    //<input id="btnGo" type="button" onclick="$.redP()" value="Go" disabled="disabled"/>
    $.redP = function (url) {
	var urlSearch = "";

       if ($('#ddlMoto').val() > 0) urlSearch = "?q1=" + $('#ddlMoto option:selected').text();
       if ($('#ddlBrand').val() > 0) urlSearch = urlSearch + "&q2=" + $('#ddlBrand option:selected').text();
       //if ($('#ddlType').val() > 0) urlSearch = urlSearch + "&q3=" + $('#ddlType option:selected').text();

	urlSearch = url + urlSearch;
	//window.location = urlSearch;

	var toggleURL = $('#ddlBrand').val();
	if (toggleURL == "1" || toggleURL == "6") window.location = '/content/hi-low-beds';
	if (toggleURL == "2" || toggleURL == "3" || toggleURL == "4" || toggleURL == "5") window.location = '/content/bariatric-beds';
	if (toggleURL == "7" || toggleURL == "8" || toggleURL == "9" || toggleURL == "10") window.location = '/content/bariatric-beds';
    },
    $.redP2 = function (url) {
	var urlSearch = "";

       if ($('#topsearch').val() != '') urlSearch = "?q1=" + $('#topsearch').val();

	urlSearch = url + urlSearch;
	window.location = urlSearch;
    },
    $.fillK = function () {
	 //$('#ddlType option').remove();
        //$('#ddlType').attr('disabled', true);
        //$('#ddlType').append('<option>Select Answer</option>');

	/*
        if ($('#ddlBrand').val() != "Select Answer") {
            if (DEFAULT_DROPDOWN_VALUE == "1") {
                $.ajax({
                    type: "GET",
                    url: "/sites/all/themes/transfermaster/js/hookjs/xml/Motors.xml",
                    dataType: "xml",
                    success: function (xml) {
                        $(xml).find('motocb').each(function () {
                            if ($(this).attr('match') == $('#ddlBrand').val())
                                $('#ddlType').append($('<option></option>').val($(this).attr('match')).html($(this).attr('bedname')));
                        });
                    }
                });
            }
            $('#ddlType').removeAttr('disabled');
        }
	*/
    }

})(jQuery);


$(document).ready(function () {
    $.fillM();


$("#topsearch").keyup(function(event){
  if(event.keyCode == 13){
    $.redP2();
  }
});


});

