function hideshow(showdiv) {

    $(".hideshowlist div.hideshowlistitem").removeClass("show").addClass("hide");

    $(".hideshowlist #hideshowlistitem" + showdiv).removeClass("hide").addClass("show");

    if (typeof doBodySifr == "function") {

        doBodySifr();

    }

}

function makeSelected(selectedDiv) {

    oldA = $(".left_nav li.selected .sIFR-alternate a")

    oldA.removeClass("white")

    $(".left_nav li.selected .sIFR-alternate").html(oldA)

    temp = sIFR.getReplacementByFlashElement($(".left_nav li.selected .sIFR-flash")[0])

    temp.replaceText($(".left_nav li.selected .sIFR-alternate").html());



    $(".left_nav li").removeClass("selected");



    $(".left_nav #itemLI" + selectedDiv).addClass("selected");

    newA = $(".left_nav #itemLI" + selectedDiv + " .sIFR-alternate a")

    $(".left_nav #itemLI" + selectedDiv + " .sIFR-alternate").html(newA)

    html = $(".left_nav #itemLI" + selectedDiv + " .sIFR-alternate").html();

    html = html.replace('<A', '<a').replace('<a class=""', '<a class="white"')

    temp = sIFR.getReplacementByFlashElement($(".left_nav #itemLI" + selectedDiv + " .sIFR-flash")[0])

    temp.replaceText(html);

}



var safeclick = false;

var safeclick2 = false;



function toggleDropDown2(drop) {

    if (safeclick2 == false) {

        if ($("#" + drop + "_list").hasClass("hide")) {

            $(".dropdownlist").addClass("hide");

        }

        $("#" + drop + "_list").toggleClass("hide")

        if ($("#" + drop + "_list").hasClass("hide")) {

        } else {

            safeclick = true;

        }

    }

}

function toggleDropDown(drop) {

    safeclick2 = true;

    if ($("#" + drop + "_list").hasClass("hide")) {

        $(".dropdownlist").addClass("hide");

    }

    $("#" + drop + "_list").toggleClass("hide")

    if ($("#" + drop + "_list").hasClass("hide")) {
		$("." + drop + "_select").removeClass("layer");

	if(drop=='destination'){
		var theID = $("#id").val();
//		alert(theID);
		document.location.href = "quote.php?id=" + theID;
	}
	
	} else {
		$("." + drop + "_select").addClass("layer");
        safeclick = true;

    }

}



function selectDropDown(txt, drop) {

    //var id = $("[class*=" + drop + "_span]").attr("id");

    var objInput = document.getElementById(drop);

    objInput.value = txt;

    if (drop.startsWith('state_selector')) {
        var selector = 'country_selector';
        if (drop.endsWith('2')) {
            selector += "2";
        }
        else if (drop.endsWith('3')) {
            selector += "3";
        }

        //var countryid = $("[class*=" + selector + "_span]").attr("id");
        var language = $("#" + drop).attr("lang");

        var objCountryInput = document.getElementById(selector);
        if (language == 'es' && txt == 'Otra') {
            objCountryInput.value = 'Seleccione un Pa&iacute;s';
        }
        else if (txt == 'Other') {
            objCountryInput.value = 'Select A Country';
        }
        else if (txt == 'Alberta' || txt == 'British Columbia' || txt == 'Manitoba' || txt == 'New Brunswick' || txt == 'Newfoundland' || txt == 'Northwest Territories' || txt == 'Nova Scotia' || txt == 'Ontario' || txt == 'Prince Edward Island' || txt == 'Quebec' || txt == 'Saskatchewan' || txt == 'Yukon') {
            objCountryInput.value = 'Canada';
        }
        else {
            objCountryInput.value = 'United States';
        }
    }
    else if (drop.startsWith('country_selector')) {
        var selector = 'state_selector';
        if (drop.endsWith('2')) {
            selector += "2";
        }
        else if (drop.endsWith('3')) {
            selector += "3";
        }

        //var countryid = $().attr("id");
        var language = $("#" + drop).attr("lang");

        var objStateInput = document.getElementById(selector);
        if (txt == 'Canada') {
            objStateInput.value = 'Alberta';
        }
        else if (txt == 'United States') {
            objStateInput.value = 'Alabama';
        }
        else if (language == 'es') {
            objStateInput.value = 'Otra';
        }
        else {
            objStateInput.value = 'Other';
        }
    } 
}



function selectDropDownValue(txt, val, drop) {

    var id = $("[class*=" + drop + "_span]").attr("id");

    var objInput = document.getElementById(id);

    objInput.value = txt;



    var idHid = $("[class*=" + drop + "_hidden]").attr("id");

    var objHid = document.getElementById(idHid);

    objHid.value = val;

}



$(document.body).click(function() {

    if (safeclick == false && $.fn != null) {

        $(".dropdownlist").addClass("hide");

    } else {

        safeclick = false;

        safeclick2 = false;

    }

});

String.prototype.endsWith = function (str)
{ return (this.match(str + "$") == str) }

String.prototype.startsWith = function (str)
{ return (this.match("^" + str) == str) }
