(function ($) {var C = "";$.fn.dd = function (w) {$this = this;w = $.extend({height: 120, visibleRows: 7, rowHeight: 23, showIcon: true,style: ""}, w);var x = "";insideWindow = true;config = {postElementHolder: "_msddHolder", postID: "_msdd", postTitleID: "_title", postTitleTextID: "_titletext", postChildID: "_child", postAID: "_msa", postOPTAID: "_msopta", postInputID: "_msinput", postArrowID: "_arrow", postInputhidden: "_inp"};styles = {dd: "dd", ddTitle: "ddTitle", arrow: "arrow", ddChild: "ddChild", disbaled: 0.3};attributes = {actions: "onfocus,onblur,onchange,onclick,ondblclick,onmousedown,onmouseup,onmouseover,onmousemove,onmouseout,onkeypress,onkeydown,onkeyup", prop: "size,multiple,disabled,tabindex"};var y = $(this).attr("id");var z = $(this).attr("style");w.style += (z == undefined) ? "" : z;var A = $(this).children();var B = {};createDropDown();
function getPostID(a) {return y + config[a];}


function getOptionsProperties(a) {var b = a;var c = $(b).attr("style");return c;}


function createATags() {var r = A;var s = "";var t = getPostID("postAID");var u = getPostID("postOPTAID");var v = $("#" + y + " option:selected").text();r.each(function (i) {var j = r[i];if (j.nodeName == "OPTGROUP") {s += "<div class='opta'>";s += "<span style='font-weight:bold;font-style:italic; clear:both;'>" + $(j).attr("label") + "</span>";var k = $(j).children();k.each(function (a) {var b = k[a];var c = u + "_" + i + "_" + a;var d = $(b).attr("title");d = (d.length == 0) ? "" : "<img src=\"" + d + "\" align=\"left\" /> ";var e = $(b).text();var f = $(b).val();var g = ($(b).attr("disabled") == true) ? "disabled" : "enabled";B[c] = {html: d + e, value: f, text: e};var h = getOptionsProperties(b);if ($.trim(v) == $.trim(e)) {s += "<a href=\"javascript:void(0);\" class=\"selected " + g + "\"";} else {s += "<a  href=\"javascript:void(0);\" class=\"" + g + "\"";}if (h != false) {s += " style=\"" + h + "\"";}s += " id=\"" + c + "\">";s += d + e + "</a>";});s += "</div>";} else {var l = t + "_" + i;var m = $(j).attr("title");m = (m.length == 0) ? "" : "<img src=\"" + m + "\" align=\"left\" /> ";var n = $(j).text();var o = $(j).val();var p = ($(j).attr("disabled") == true) ? "disabled" : "enabled";B[l] = {html: m + n, value: o, text: n};var q = getOptionsProperties(j);if ($.trim(v) == $.trim(n)) {s += "<a href=\"javascript:void(0);\" class=\"selected " + p + "\"";} else {s += "<a  href=\"javascript:void(0);\" class=\"" + p + "\"";}if (q != false) {s += " style=\"" + q + "\"";}s += " id=\"" + l + "\">";s += m + n + "</a>";}});return s;}


function createTitleDiv() {var a = getPostID("postTitleID");var b = getPostID("postArrowID");var c = getPostID("postTitleTextID");var d = getPostID("postInputhidden");var e = $("#" + y + " option:selected").text();var f = $("#" + y + " option:selected").attr("title");f = (f.length == 0 || f == undefined || w.showIcon == false) ? "" : "<img src=\"" + f + "\" align=\"left\" /> ";var g = "<div id=\"" + a + "\" class=\"" + styles.ddTitle + "\"";g += ">";g += "<span id=\"" + b + "\" class=\"" + styles.arrow + "\"></span><span class=\"textTitle\" id=\"" + c + "\">" + f + e + "</span></div>";return g;}


function createDropDown() {var c = false;var d = getPostID("postID");var e = getPostID("postTitleID");var f = getPostID("postTitleTextID");var g = getPostID("postChildID");var h = getPostID("postArrowID");var i = $("#" + y).width();var j = w.style;if ($("#" + d).length > 0) {$("#" + d).remove();c = true;}var k = "<div id=\"" + d + "\" class=\"" + styles.dd + "\"";k += (j != "") ? " style=\"" + j + "\"" : "";k += ">";k += createTitleDiv();k += "<div id=\"" + g + "\" class=\"" + styles.ddChild + "\"";k += (j != "") ? " style=\"" + j + "\"" : "";k += ">";k += createATags();k += "</div>";k += "</div>";if (c == true) {var l = getPostID("postElementHolder");$("#" + l).after(k);} else {$("#" + y).after(k);}$("#" + d).css("width", 120 + "px");$("#" + g).css("width", (120 - 2) + "px");if (A.length > w.visibleRows) {var m = parseInt($("#" + g + " a:first").css("padding-bottom")) + parseInt($("#" + g + " a:first").css("padding-top"));var n = (w.rowHeight * w.visibleRows) - m;$("#" + g).css("height", n + "px");}if (c == false) {setOutOfVision();addNewEvents(y);}if ($("#" + y).attr("disabled") == true) {$("#" + d).css("opacity", styles.disbaled);} else {applyEvents();$("#" + e).bind("mouseover", function (a) {hightlightArrow(1);});$("#" + e).bind("mouseout", function (a) {hightlightArrow(0);});$("#" + g + " a.enabled").bind("click", function (a) {$("#" + g).unbind("mouseover");setInsideWindow(false);$("#" + g + " a.selected").removeClass("selected");$(this).addClass("selected");var b = (w.showIcon == false) ? $(this).text() : $(this).html();setTitleText(b);setValue();closeMe();});$("#" + g + " a.disabled").css("opacity", styles.disbaled);$("#" + g).bind("mouseout", function (a) {setInsideWindow(false);});$("#" + e).bind("click", function (b) {setInsideWindow(false);if ($("#" + g + ":visible").length == 1) {$("#" + g).unbind("mouseover");} else {$("#" + g).bind("mouseover", function (a) {setInsideWindow(true);});openMe();}});$("#" + e).bind("mouseout", function (a) {setInsideWindow(false);});}}


function addNewEvents(a) {document.getElementById(a).refresh = function (e) {$("#" + this.id).dd(w);};}


function setInsideWindow(a) {insideWindow = a;}


function getInsideWindow() {return insideWindow;}


function applyEvents() {var b = getPostID("postID");var c = attributes.actions.split(",");for (var d = 0; d < c.length; d++) {var e = c[d];var f = $("#" + y).attr(e);if (f != undefined) {switch (e) {case "onfocus":$("#" + b).bind("mouseenter", function (a) {document.getElementById(y).focus();});break;case "onclick":$("#" + b).bind("click", function (a) {document.getElementById(y).onclick();});break;case "ondblclick":$("#" + b).bind("dblclick", function (a) {document.getElementById(y).ondblclick();});break;case "onmousedown":$("#" + b).bind("mousedown", function (a) {document.getElementById(y).onmousedown();});break;case "onmouseup":$("#" + b).bind("mouseup", function (a) {document.getElementById(y).onmouseup();});break;case "onmouseover":$("#" + b).bind("mouseover", function (a) {document.getElementById(y).onmouseover();});break;case "onmousemove":$("#" + b).bind("mousemove", function (a) {document.getElementById(y).onmousemove();});break;case "onmouseout":$("#" + b).bind("mouseout", function (a) {document.getElementById(y).onmouseout();});break;default:;}}}}


function setOutOfVision() {var a = getPostID("postElementHolder");$("#" + y).after("<div style='height:0px; overflow:hidden' id='" + a + "'></div>");$("#" + y).appendTo($("#" + a));}


function setTitleText(a) {var b = getPostID("postTitleTextID");$("#" + b).html(a);}


function next() {var a = getPostID("postTitleTextID");var b = getPostID("postChildID");var c = $("#" + b + " a.enabled");for (var d = 0; d < c.length; d++) {var e = c[d];var f = $(e).attr("id");if ($(e).hasClass("selected") && d < c.length - 1) {$("#" + b + " a.selected").removeClass("selected");$(c[d + 1]).addClass("selected");var g = $("#" + b + " a.selected").attr("id");var h = (w.showIcon == false) ? B[g].text : B[g].html;setTitleText(h);if (parseInt(($("#" + g).position().top + $("#" + g).height())) >= parseInt($("#" + b).height())) {$("#" + b).scrollTop($("#" + b).scrollTop() + $("#" + g).height() + $("#" + g).height());}break;}}}


function previous() {var a = getPostID("postTitleTextID");var b = getPostID("postChildID");var c = $("#" + b + " a.enabled");for (var d = 0; d < c.length; d++) {var e = c[d];var f = $(e).attr("id");if ($(e).hasClass("selected") && d != 0) {$("#" + b + " a.selected").removeClass("selected");$(c[d - 1]).addClass("selected");var g = $("#" + b + " a.selected").attr("id");var h = (w.showIcon == false) ? B[g].text : B[g].html;setTitleText(h);if (parseInt(($("#" + g).position().top + $("#" + g).height())) <= 0) {$("#" + b).scrollTop(($("#" + b).scrollTop() - $("#" + b).height()) - $("#" + g).height());}break;}}}


function setValue() {var a = getPostID("postChildID");var b = $("#" + a + " a.selected").text();var c = $("#" + a + " a.selected").attr("id");var d = B[c].value;$("#" + y + " option:selected").text($.trim(b));$("#" + y + " option:selected").val(d);}


function openMe() {var c = getPostID("postChildID");if (C != "" && c != C) {$("#" + C).slideUp("fast");}if ($("#" + c).css("display") == "none") {x = B[$("#" + c + " a.selected").attr("id")].text;$(document).bind("keydown", function (a) {var b = a.keyCode;if (b == 39 || b == 40) {a.preventDefault();a.stopPropagation();next();}if (b == 37 || b == 38) {a.preventDefault();a.stopPropagation();previous();}if (b == 27 || b == 13) {closeMe();setValue();}if ($("#" + y).attr("onkeydown") != undefined) {document.getElementById(y).onkeydown();}});$(document).bind("keyup", function (a) {if ($("#" + y).attr("onkeyup") != undefined) {document.getElementById(y).onkeyup();}});$(document).bind("mouseup", function (a) {if (getInsideWindow() == false) {closeMe();}});$("#" + c).slideDown("fast");if (c != C) {C = c;}}}


function closeMe() {var b = getPostID("postChildID");$(document).unbind("keydown");$(document).unbind("keyup");$(document).unbind("mouseup");$("#" + b).slideUp("fast", function (a) {checkMethodAndApply();});}


function checkMethodAndApply() {var b = getPostID("postChildID");if ($("#" + y).attr("onchange") != undefined) {var c = B[$("#" + b + " a.selected").attr("id")].text;if (x != c) {document.getElementById(y).onchange();}}if ($("#" + y).attr("onmouseup") != undefined) {document.getElementById(y).onmouseup();}if ($("#" + y).attr("onblur") != undefined) {$(document).bind("mouseup", function (a) {$("#" + y).focus();$("#" + y)[0].blur();setValue();$(document).unbind("mouseup");});}}


function hightlightArrow(a) {var b = getPostID("postArrowID");if (a == 1) {$("#" + b).css({backgroundPosition: "0 0"});} else {$("#" + b).css({backgroundPosition: "0 0"});}}

};$.fn.msDropDown = function (a) {var b = $(this);for (var c = 0; c < b.length; c++) {var d = $(b[c]).attr("id");if (a == undefined) {$("#" + d).dd();} else {$("#" + d).dd(a);}}};}(jQuery));