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")) {

    } else {

        safeclick = true;

    }

}



function selectDropDown(txt, drop) {

    var id = $("[class*=" + drop + "_span]").attr("id");

    var objInput = document.getElementById(id);

    objInput.value = txt;

}



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;

    }

});

$(document).ready(function() {

	$(".dropdownlist_item").click(function(){
		var lang = $(this).attr("id");
//		alert(lang);
//		alert(host);
//		var protocol = jQuery.url.attr("protocol");
		var host = jQuery.url.attr("host");
		var folder = jQuery.url.attr("directory");
		var file = jQuery.url.attr("file");
		var url = '';
		//check if in english, then switch to french
		
		if (lang.toLowerCase().indexOf('lang_fr') >= 0)		
		{
			url = 'http://www.medtronicdiabete.ca';
		}else
		{
			if (host.toLowerCase().indexOf('medtronicdiabete.ca') >= 0)
			{
				url = 'http://www.medtronicdiabetes.ca';
			}
		}

		
		if(folder=="/en/"&&lang=="lang_fr"&&(file==null||file=='index.html')){
			document.location.href = url + "/fr/index.html";
			//send user to french domain
		} else if(folder=="/en/"&&lang=="lang_fr"){
			document.location.href = url + "/fr/" + file;			
			//send user to french domain with filename appended
		}
		//check if in french, then switch to english
		if(folder=="/fr/"&&lang=="lang_en"&&file==null){
			//if user happens to be viewing french homepage in the /fr/ sub-folder off the root while on one of the english domains
			document.location.href = url + "/en/index.html";
			//send to english domain
		} else if(lang=="lang_en"&&file==null){
			//if user is viewing french homepage on the french domain
			document.location.href = url + "/en/";
			//send to english domain
		} else if(folder=="/fr/"&&lang=="lang_en"){
			//if user happens to be viewing french content in the /fr/ sub-folder off the root while on one of the english domains
			document.location.href = url + "/en/" + file;
			//send to english domain with filename appended
		}  else if(lang=="lang_en"){
			//if user is viewing french homepage on the french domain
			document.location.href = url + "/en/" + file;
			//send to english domain with filename appended
		}
	});	

});
