var Custom = {

	GalleryThumbs: {

		aImages: null,
		iIndex: 0,
		Interval: null,

		Init: function() {

			var aImages = $("#gallery-thumbs").children().css("display","none");

			Custom.GalleryThumbs.aImages = aImages;
			aImages.filter(":first").css("display","block");

			Custom.GalleryThumbs.Interval = setInterval(Custom.GalleryThumbs.Next,1500);

		},
		Next: function() {

			var aImages = Custom.GalleryThumbs.aImages;
			aImages.filter(":eq("+Custom.GalleryThumbs.iIndex+")").fadeOut("slow");
			if (Custom.GalleryThumbs.iIndex+1 == aImages.length)
				Custom.GalleryThumbs.iIndex = 0;
			else
				Custom.GalleryThumbs.iIndex++;
			aImages.filter(":eq("+Custom.GalleryThumbs.iIndex+")").fadeIn("slow");

			try
			{
				clearInterval(Custom.GalleryThumbs.Interval);	
			}
			catch (e)
			{
			}

		},
		Prev: function() {

			var aImages = Custom.GalleryThumbs.aImages;
			aImages.filter(":eq("+Custom.GalleryThumbs.iIndex+")").fadeOut("slow");
			if (Custom.GalleryThumbs.iIndex-1 < 0)
				Custom.GalleryThumbs.iIndex = aImages.length-1;
			else
				Custom.GalleryThumbs.iIndex--;
			aImages.filter(":eq("+Custom.GalleryThumbs.iIndex+")").fadeIn("slow");
			
			try
			{
				clearInterval(Custom.GalleryThumbs.Interval);	
			}
			catch (e)
			{
			}

		}

	},

	Menu: {
		Interval: null,
		Init: function() {
			$("#lstMenu").children().bind("mouseover",function() {

				try	{clearInterval(Custom.Menu.Interval);}
				catch (e) {}

				$("#lstMenu").find(".popup").css("display","none");
			
				if ($(this).find(".popup").find("UL LI").length || $(this).parents(".Marker").length)
				{
					$(this).find(".popup").css("display","block");
				}
			
			}).bind("mouseout",function() {
				var This = this;
				Custom.Menu.Interval = setInterval(function() {
					clearInterval(Custom.Menu.Interval);
					$(This).find(".popup").css("display","none");
				},300);
			});
		}
	},

	Login: {
		TryLogin: function() {
			var sUsername = $("#loginUsername").val();
			var sPassword = $("#loginPassword").val();

			if ($.trim(sUsername) == "" || $.trim(sPassword) == "" )
			{
				alert("חובה למלא שם משתמש וסיסמה");
				return;
			}


			$.ajax({
			   type: "POST",
			   cache: false,
			   url: "/he/getStream.aspx?obj=LoginBox&sFunc=Log_In&sUsername="+escape(sUsername)+"&sPassword="+escape(sPassword),
			   dataType: "data",
			   success: function(txt) {

				   if (txt == "success")
				   {
					   location.href = location.href;
				   } else {
						alert("שם משתמש ואו סיסמה שגויים");
						$("#loginUsername").val("");
						$("#loginPassword").val("");
				   }

			   }
			});
		}


	},

	NewMessage: {

	

		Groups: {

			GetGroups: function() {


				$("#lstAvailableGroups").html("<option value=\"-1\" selected=\"selected\">בחר קבוצה</option>");

				$.ajax({
				   type: "POST",
				   cache: false,
				   url: "/he/getStream.aspx?obj=Admin_Users&sFunc=GetGroups",
				   dataType: "data",
				   success: function(data) {
						
						var bHasResults = false;
						if (data != "")
						{
							var aGroups = data.split("***");
							for (var i=0;i<aGroups.length;i++)
							{
								if (aGroups[i] != "")
								{

									var iGroupID = aGroups[i].split(",")[0];
									var sGroupName = aGroups[i].split(",")[1];

									$("#lstAvailableGroups").append("<option value=\""+iGroupID+"\">"+sGroupName+"</option>");
								
								}
							}
						}


				   }
				});

			},

			GetGroupMembers: function() {

				tGroupsTree.ClearObjects();
				tGroupsTree.Dispose("groupsTree");

				var oSelect = $("#lstAvailableGroups").get(0);
				var oOption = oSelect.options[oSelect.selectedIndex];
				iCurrentGroupID = parseInt(oOption.value);

				$.ajax({
				   type: "POST",
				   cache: false,
				   url: "/he/getStream.aspx?obj=Admin_Users&sFunc=GetGroupMembers&GroupID="+oOption.value,
				   dataType: "data",
				   success: function(data) {
						
						var bHasResults = false;
						if (data != "")
						{
							var aGroups = data.split("***");
							for (var i=0;i<aGroups.length;i++)
							{
								if (aGroups[i] != "")
								{
									bHasResults = true;
									var iGroupID = aGroups[i].split(",")[0];
									var sGroupName = aGroups[i].split(",")[1];
									tGroupsTree.AddChild(parseInt(iGroupID),sGroupName,"Group");
									tGroupsTree.Dispose("groupsTree");
								}
							}
						}

						$("#managroups").css("display","block");

				   }
				});
			},

			AddRecipients: function(options) {

				var aGroups = tGroupsTree.getChilds();
				for (var i=0;i<aGroups.length;i++)
				{
				
					var oH = tGroupsTree.oH[aGroups[i]];
					var oSelectValue = oH[0];
					var oSelectText = oH[1];

					if ($("#replica").find("SPAN[id='rc"+oSelectValue+"']").length)
						return;

					if (!(options && options.officer))
					{
						if ($("#replica").find("SPAN").length == 7)
						{
							alert("ניתן להוסיף עד 7 מכותבים");
							return;
						}
					}

					$("#replica").append("<span id='rc"+oSelectValue+"'>"+oSelectText+"</span>");
				}

				Custom.NewMessage.Groups.CloseWin();

			
			},

			CloseWin: function() {
				$("#WinGroups").fadeOut();
			},

			OpenWin: function() {
				$("#WinGroups").fadeIn();
			},

			Remove: function() {

				var oSelect = $("#lstAvailableGroups").get(0);
				var oOption = oSelect.options[oSelect.selectedIndex];

				if (parseInt(oOption.value) == -1)
				{
					
					alert("בחר קבוצה למחיקה");
					return;
				}

				$.ajax({
				   type: "POST",
				   cache: false,
				   url: "/he/getStream.aspx?obj=Admin_Users&sFunc=RemoveGroup&GroupID="+oOption.value,
				   dataType: "data",
				   success: function(data) {
						$(oOption).remove();
						$("#managroups").css("display","none");
						iCurrentGroupID = -1;
						alert("הקבוצה נמחקה בהצלחה");
				   }
				});
			},

			CreateNew: function() {

				var txtNewGroup = $("#txt_newgroup").val();

				if (txtNewGroup.replace(/\s/gi,"") == "")
				{
					alert("לא ניתן ליצור קבוצה ריקה");
					return;
				}

				var bFound = false;
				$("#lstAvailableGroups").children("OPTION").each(function() {
					if (this.innerHTML == txtNewGroup)
					{
						bFound = true;
						return false;
					}
				});

				if (bFound)
				{
					alert("כבר קיימת קבוצה כזו");
					return;
				}

				$.ajax({
				   type: "POST",
				   cache: false,
				   url: "/he/getStream.aspx?obj=Admin_Users&sFunc=AddGroup&GroupName="+escape(txtNewGroup),
				   dataType: "data",
				   success: function(data) {
						
						$("#lstAvailableGroups").append("<option value=\""+data+"\">"+txtNewGroup+"</option>");
						alert("הקבוצה נוצרה בהצלחה");
						$("#txt_newgroup").val("צור קבוצה חדשה");


				   }
				});
			}

		},

		iRecipients: {},
		AddRecipient: function(options) {

			var oSelectValue = $("#lst1").val();
			var oSelectText = $("#lst1").attr("valuetext");

			if (oSelectValue == "")
			{
				alert("לא בחרת מכותב להוספה");
				return;
			}

			if ($("#replica").find("SPAN[id='rc"+oSelectValue+"']").length)
				return;

			if (!(options && options.officer))
			{
				if ($("#replica").find("SPAN").length == 7)
				{
					alert("ניתן להוסיף עד 7 מכותבים");
					return;
				}
			}

			$("#replica").append("<span id='rc"+oSelectValue+"'>"+oSelectText+"</span>");
			
		},

		OpenGroupsPane: function() {
			
		},

		Remove: function(ev) {
			var oEl = window.addEventListener ? ev.target : ev.srcElement;
			if (oEl.tagName == "SPAN")
				$(oEl).remove();
		},

		SendToAll: function(bToAll) {
			if (bToAll)
				$("#lstRecipients,#ls2,#SelectBox_Occu").css("display","none");
			else {
				$("#lstRecipients,#ls2").css("display","inline");
				$("#SelectBox_Occu").css("display","block");
			}
		},

		Add: function() {

			var aRecipientsIds = [];

			$("#replica").children().each(function() {
				aRecipientsIds.push(this.id.replace(/\D/gi,""));
			});

			if ($("#sendtoall").length && $("#sendtoall").is(":checked"))
			{
				aRecipientsIds = [];
				
				SelectBox.ohSelectArray["SelectBox_Occu"].toString().replace(/value\=(\d+)/gi,function(s1,s2,s3) {
					aRecipientsIds.push(s2);
				});
			}

			if (!aRecipientsIds.length) {
				alert("יש להוסיף מכותבים על מנת לשלוח הודעה");
				return;
			}

			$("#recipients").val(aRecipientsIds);
			$("#frmNewOne").get(0).submit();

		}
	},

	Inbox: {
		Show: function() {

			$.ajax({
			   type: "POST",
			   cache: false,
			   url: "/he/getStream.aspx?obj=LoggedBox&sFunc=GetInbox",
			   dataType: "data",
			   success: function(html) {

					$("#inboxcont").html(html);

					$("#tblMessages").children("TBODY").children(":even").bind("click",function() {
						$(this).next().css("display",$(this).next().css("display")=="none"?"table-row":"none");
					});
			   }
			});

		},

		Remove: function() {

			var aCheckedIds = [];
			$("#tblMessages").find(":checked").each(function() {
				aCheckedIds.push(this.value);
			});

			if (!aCheckedIds.length)
				return;

			$.ajax({
			   type: "POST",
			   cache: false,
			   url: "/he/getStream.aspx?obj=LoggedBox&sFunc=RemoveMessage&iMessageID="+aCheckedIds,
			   dataType: "data",
			   success: function(html) {
					location.href = location.href;
			   }
			});
		},

		Reply: function(iFrom,sSubject) {
			location.href = "/he/כתוב_הודעה.aspx?iFrom="+iFrom+"&sSubject="+escape(sSubject);
		}
	},

	Outbox: {
		Show: function() {

			$.ajax({
			   type: "POST",
			   cache: false,
			   url: "/he/getStream.aspx?obj=LoggedBox&sFunc=GetOutbox",
			   dataType: "data",
			   success: function(html) {

					$("#outboxcont").html(html);

					$("#tblMessages").children("TBODY").children(":even").bind("click",function() {
						$(this).next().css("display",$(this).next().css("display")=="none"?"table-row":"none");
					});
			   }
			});

		},

		Remove: function() {

			var aCheckedIds = [];
			$("#tblMessages").find(":checked").each(function() {
				aCheckedIds.push(this.value);
			});

			if (!aCheckedIds.length)
				return;

			$.ajax({
			   type: "POST",
			   cache: false,
			   url: "/he/getStream.aspx?obj=LoggedBox&sFunc=RemoveMessageFromOutbox&iMessageID="+aCheckedIds,
			   dataType: "data",
			   success: function(html) {
					location.href = location.href;
			   }
			});
		}
	},

	ChangeDetails: {
		
		Submit: function() {

			if ($("#sUsername").val().replace(/\s/gi,"") == "")
			{
				alert("חובה למלא שם משתמש");
				return;
			}

			if ($("#sEmail").val().replace(/\s/gi,"") == "")
			{
				alert("חובה למלא דואר אלקטרוני");
				return;
			}

			if ($("#sFullname").val().replace(/\s/gi,"") == "")
			{
				alert("חובה למלא שם מלא");
				return;
			}

			$("#frmnewmessage").get(0).submit();
		}
	},

	ForgotPassword: {
		Submit: function() {

			$("#newpasserror").html("&nbsp;");

			if ($.trim($("#currentpass").val()) == "") {
				$("#newpasserror").html("חובה למלא סיסמה נוכחית");
				return;
			}

			$.ajax({
			   type: "POST",
			   cache: false,
			   url: "/he/getStream.aspx?obj=LoggedBox&sFunc=PassOK&sPass="+escape($("#currentpass").val()),
			   dataType: "data",
			   success: function(txt) {

				   if (txt != "success")
				   {
					   alert("הסיסמה הנוכחית לא תואמת לסיסמה הקיימת");
					   return;
				   }

					if ($.trim($("#newpass").val()) == "") {
						$("#newpasserror").html("חובה למלא סיסמה חדשה");
						return;
					}

					if ($.trim($("#newpassvalid").val()) == "") {
						$("#newpasserror").html("חובה לאמת את הסיסמה החדשה");
						return;
					}
					
					if ($("#newpass").val() != $("#newpassvalid").val())
					{
						$("#newpasserror").html("שגיאה: שדה סיסמה חדשה לא תואם לשדה האימות");
						return;
					}

					$.ajax({
					   type: "POST",
					   cache: false,
					   url: "/he/getStream.aspx?obj=LoggedBox&sFunc=SaveNewPassword&sPass="+escape($("#newpass").val()),
					   dataType: "data",
					   success: function(txt) {
							alert("השינויים נשמרו בהצלחה");
							$("#frmchangepass").get(0).reset();	
					   }
					});
			   }
			});
		}
	},

	Gallery: {
		iIndex: 0,
		iLength: 0,
		oImages: 0,
		bInPlaying: false,
		oIntervalPlaying: null,
		Next: function() {
			Custom.Gallery.oImages.filter(":eq("+Custom.Gallery.iIndex+")").fadeOut("slow");
			Custom.Gallery.iIndex = (Custom.Gallery.iIndex < (Custom.Gallery.iLength-1)) ? ++Custom.Gallery.iIndex : 0;
			Custom.Gallery.oImages.filter(":eq("+Custom.Gallery.iIndex+")").fadeIn("slow");
		},
		Prev: function() {
			Custom.Gallery.oImages.filter(":eq("+Custom.Gallery.iIndex+")").fadeOut("slow");
			Custom.Gallery.iIndex = (Custom.Gallery.iIndex > 0) ? --Custom.Gallery.iIndex : Custom.Gallery.iLength-1;
			Custom.Gallery.oImages.filter(":eq("+Custom.Gallery.iIndex+")").fadeIn("slow");
		},
		Slide: function() {

			if (Custom.Gallery.bInPlaying)
			{
				$("#gal_slide").get(0).src = '/images/gal/play.gif';
				Custom.Gallery.bInPlaying = false;
				try
				{
					clearInterval(Custom.Gallery.oIntervalPlaying);
				}
				catch (e)
				{
				}
			} else {
				$("#gal_slide").get(0).src = '/images/gal/pause.gif';
				Custom.Gallery.bInPlaying = true;
				Custom.Gallery.oIntervalPlaying = setInterval(function() {
					Custom.Gallery.Next();
				},2000);
			}

		},
		Init: function() {

			Custom.Gallery.oImages = $("#gal-images").find("IMG.big");
			Custom.Gallery.iLength = Custom.Gallery.oImages.length;

			Custom.Gallery.oImages.filter(":eq(0)").css("display","block");

			$("#gal_prev").bind("click",Custom.Gallery.Prev);
			$("#gal_slide").bind("click",Custom.Gallery.Slide);
			$("#gal_next").bind("click",Custom.Gallery.Next);

		}
	},

	BreadCrumbs: {
		Init: function() {

			var sLocation = location.href;
			var sPage = sLocation.substring(sLocation.lastIndexOf("/")+1,sLocation.length);

			var sFirstLink = "";
			var sFirstLinkHref = "";

			var sSecondLink = "";
			var sSecondLinkHref = "";

			var bFound = false;
			$("#lstMenu").find(".popup").find("A").each(function() {
				var sMenuPage =  this.href.substring(this.href.lastIndexOf("/")+1,this.href.length);
				if (sPage == sMenuPage)
				{

					sFirstLink = $(this).parents("LI:eq(1)").find("A:first").get(0).innerHTML;
					sFirstLinkHref = $(this).parents("LI:eq(1)").find("A:first").get(0).href;

					sSecondLink = this.innerHTML;
					sSecondLinkHref = this.href;

					bFound = true;
					return false;
				}
			});
			
			if (!bFound)
			{
				$("#lstMenu").children().children("A").each(function() {
					var sMenuPage =  this.href.substring(this.href.lastIndexOf("/")+1,this.href.length);
					if (sPage == sMenuPage)
					{
						sFirstLink = this.innerHTML;
						sFirstLinkHref = this.href;
						return false;
					}
				});
			}

			if (sFirstLink != "")
				$("#lstBreadCrumbs").append("<li><a href=\""+sFirstLinkHref+"\">"+sFirstLink+"</a></li>");

			if (sSecondLink != "")
				$("#lstBreadCrumbs").append("<li class=\"last\"><a href=\""+sSecondLinkHref+"\">"+sSecondLink+"</a></li>");
		}
	},

	AddTalkback: function() {

		var sName = jQuery.trim($("#sTalkback_name").val()),
			sTitle = jQuery.trim($("#sTalkback_title").val()),
			sContent = jQuery.trim($("#sTalkback_content").val()),
			sCaptcha = jQuery.trim($("#sTalkback_captcha").val()),
			sPage = location.href.substring(location.href.lastIndexOf("/")+1,location.href.length);

		if (sName == "")
		{
			alert("חובה למלא שם");
			return;
		} else if (sTitle == "")
		{
			alert("חובה למלא כותרת");
			return;
		} else if (sCaptcha == "")
		{
			alert("חובה למלא את הקוד המוצג בתמונה");
			return;
		}

		$.ajax({
			type: "POST",
			url: "/he/getStream.aspx",
			dataType: "text",
			data: "obj=Talkback&sFunc=Add&sTitle="+escape(sTitle)+"&sName="+escape(sName)+"&sComment="+escape(sContent)+"&sCaptcha="+sCaptcha+"&sPage="+sPage,
			success: function(txt) { 
			
				if (txt == "0")
				{
					alert("הקוד המוצג למטה לא תקין, נסה שוב");
				} else if (txt != "2")
				{
					alert("חלה שגיאה, נסה מאוחר יותר");
				} else {
					alert("תגובתך התקבלה במערכת");
					location.href = location.href;
				}
			
			}
		});

	},

	OpenCloseTalkback: function(obj) {

		var oObj = $(obj).parents("LI:first");
		if (oObj.hasClass("opened"))
			oObj.removeClass("opened");
		else
			oObj.addClass("opened");

	}


}

var SelectBox = {
    bSelectBoxOpened: false,
    OpenSelectBox: function(sID, bCloseIfOpen, bRestart, sInputID) {

        var oPopup = $("#" + sID).find(".selectbox-popup").get(0);

        if (bRestart) {
            var oInput = $("#" + sID).find(".selectboxSideR").find("INPUT").get(0);
            oInput.value = $(oInput).attr("sOldValue");
            $(oInput).removeClass("hover").removeClass("ValueSelected");
            $("#" + sInputID).val("");
        }

        if (oPopup.style.display == "block" && bCloseIfOpen) {
            oPopup.style.display = "none";
            SelectBox.bSelectBoxOpened = false;
        } else {
            $("body").find(".selectbox-popup").css("display", "none");
            oPopup.style.display = "block";
            SelectBox.bSelectBoxOpened = true;

            if (bCloseIfOpen) {
                var oInput = $("#" + sID).find(".selectboxSideR").children("INPUT:first");
                if (!oInput.hasClass("ValueSelected")) {
                    var sValue = oInput.val();
                    oInput.val("");
                    SelectBox.SelectBox_Type(oInput.get(0), sID, sInputID);
                    oInput.val(sValue);
                }
            }

            var oSpans = $("#" + sID).find(".d-scroll:first").children("SPAN");
            if (oSpans.length > 6) {
                $("#" + sID).find(".selectbox-popup:first").css("height", (7 * 18 + 11) + "px").children(".d-scroll").css("height", (7 * 18) + "px");
            } else {
                $("#" + sID).find(".selectbox-popup:first").css("height", (oSpans.length * 18 + 11) + "px").children(".d-scroll").css("height", (oSpans.length * 18) + "px");
            }

        }
    },

    CloseSelectBox: function(sID) {
        var oPopup = $("#" + sID).find(".selectbox-popup").get(0);
        oPopup.style.display = "none";
        SelectBox.bSelectBoxOpened = false;
    },

    ohSelectArray: {},
    SelectBox_Initialize: function(sID, oProperties, sInputID, fOnChange) {

        var bInitizlized = !SelectBox.ohSelectArray[sID];
        SelectBox.ohSelectArray[sID] = [];

        if (fOnChange)
            SelectBox.ohSelectArray[sID + "-fChange"] = fOnChange;

        var oDScroll = $("#" + sID).find(".d-scroll:first");

        oDScroll.get(0).onclick = function() {
            var oEvent = window.addEventListener ? arguments[0] : event;
            SelectBox.SelectBox_Change(oDScroll.get(0), sInputID, oEvent, sID)
        }

        oDScroll.find("SPAN").each(function() {
            SelectBox.ohSelectArray[sID].push($(this).html());
            this.parentNode.removeChild(this);
        });

        var oSelectBoxSideR = $(document.body).find(".selectboxSideR");

        var oInput;

        if (bInitizlized) {
            oInput = document.createElement("INPUT");
        } else {
            oInput = oSelectBoxSideR.children("INPUT:first").get(0);
        }


        oInput.onkeyup = function() {
            SelectBox.SelectBox_Type(this, sID, sInputID);
        }

        oSelectBoxSideR.get(0).appendChild(oInput);

        if (oProperties.Title) {
            oInput.value = oProperties.Title;
            oInput.setAttribute("sOldValue", oProperties.Title);
            oInput.onfocus = function() {

                $(this).attr("OldDefaultValue", this.value);
                this.value = "";
                $("#" + sInputID).val("");
                $("#" + sInputID).attr("valueid", "0");
                $(this).addClass("hover");

            }
            oInput.onblur = function() {
                if (this.value.replace(/\s/gi, "") == "") {
                    if (this.getAttribute("OldDefaultValue") && this.getAttribute("OldDefaultValue") != "") {
                        this.value = this.getAttribute("OldDefaultValue");
                        $("#" + sInputID).val(this.value);
                    } else {
                        this.value = oProperties.Title;
                        $("#" + sInputID).val("");
                        $("#" + sInputID).attr("valueid", "0");
                        $(this).removeClass("hover");
                    }

                }
            }
        }
    },

    SelectBox_Type: function(oInput, sID, sInputID) {
        if (!SelectBox.ohSelectArray[sID]) {
            alert("SelectBox " + sID + " not intialized...");
        } else {
            var aReturnedMatchedElements = SelectBox.ohSelectArray[sID].getPartialMatched(oInput.value, { first: true });
            if (aReturnedMatchedElements.length) {
                aReturnedMatchedElements = SelectBox.ohSelectArray[sID].getPartialMatched(oInput.value)
                if (aReturnedMatchedElements.length) {
                    $("#" + sID).find(".d-scroll:first").html("<span>" + aReturnedMatchedElements.join("</span><span>") + "</span>");
                    SelectBox.OpenSelectBox(sID);
                }
            } else {
                $("#" + sID).find(".d-scroll:first").html("<span class=\"NoSuggestions\">אין הצעות</span>");
                SelectBox.OpenSelectBox(sID);
            }

            if (sInputID) {
                $("#" + sInputID).val(oInput.value);
            }

        }
    },

    SelectBox_IsValueExists: function(sID, sValue) {
        if (!sValue) sValue = $("#" + sID).prev().val();
        return SelectBox.ohSelectArray[sID].join(',').indexOf(sValue) > -1;
    },

    SelectBox_GetValue: function(sID) {
        return $("#" + sID).find(".selectboxSideR").children("INPUT").val();
    },

    SelectBox_GetValueId: function(sID) {
        return $("#" + sID).prev().attr("valueid");
    },

    SelectBox_SetValue: function(sID, sValue, idValue, sInputID) {
        if (SelectBox.SelectBox_IsValueExists(sID, sValue)) {
            var oInput = $("#" + sID).find(".selectboxSideR").children("INPUT").val(sValue);
            $("#" + sInputID).attr("valueid", idValue);
            $("#" + sInputID).val(sValue);
            if (!oInput.hasClass("ValueSelected"))
                oInput.addClass("ValueSelected", "true");
            if (!oInput.hasClass("hover"))
                $(oInput).addClass("hover");
        }
    },

    SelectBox_GetDefaultValue: function(sID) {
        return $("#" + sID).find(".selectboxSideR").children("INPUT").attr("sOldValue");
    },

    SelectBox_Change: function(oEl, sInputID, oEvent, sID) {
        var oEventEl = window.addEventListener ? oEvent.target : oEvent.srcElement;
        if (oEventEl.tagName == "SPAN" && oEventEl.className.indexOf("NoSuggestions") == -1) {
            var oInput = $(oEl).parents(".selectbox").find(".selectboxSideR").children("INPUT").val($(oEventEl).text());
            if (!oInput.hasClass("ValueSelected"))
                oInput.addClass("ValueSelected", "true");
            if (!oInput.hasClass("hover"))
                $(oInput).addClass("hover");
            $(oEl).parents(".selectbox").find(".selectbox-popup").css("display", "none");
            oInput.val($(oEventEl).text());
			$("#" + sInputID).val($(oEventEl).children("input:first").val());
            $("#" + sInputID).attr("valuetext", $(oEventEl).text());
            SelectBox.bSelectBoxOpened = false;

            if (SelectBox.ohSelectArray[sID + "-fChange"])
                SelectBox.ohSelectArray[sID + "-fChange"](oEventEl.innerHTML);
        }
    },

    SelectBox_Hover: function(oEvent) {
        var oEventEl = window.addEventListener ? oEvent.target : oEvent.srcElement;
        if (oEventEl.tagName == "SPAN" && oEventEl.className.indexOf("NoSuggestions") == -1)
            oEventEl.className = "hover";
    },

    SelectBox_Out: function(oEvent) {
        var oEventEl = window.addEventListener ? oEvent.target : oEvent.srcElement;
        if (oEventEl.tagName == "SPAN" && oEventEl.className.indexOf("NoSuggestions") == -1)
            oEventEl.className = "";
    },

    _arrFuncs: [],
    AddClickEvent: function(sFunc) {
        SelectBox._arrFuncs.push(sFunc);
    },

    BodyClick: function(oEvent) {
        for (var i = 0; i < SelectBox._arrFuncs.length; i++)
            SelectBox._arrFuncs[i](oEvent);
    },

    BodyClick_HideDropDowns: function(oEvent) {
        var src = oEvent.srcElement || oEvent.target;
        var bInDropDown = false;
        if (SelectBox.bDropDownOpened) {
            if (src) {
                do {
                    if (src.className && src.className.indexOf("dropdown") > -1) {
                        bInDropDown = true;
                        break;
                    }
                    src = src.parentNode;
                }
                while (src && src.tagName != "BODY");
            }


            if (SelectBox.bDropDownOpened && !bInDropDown) {
                $(".dropdown-popup").css("display", "none");
                SelectBox.bDropDownOpened = false;
            }
        }
    },

    BodyClick_HideSelectBoxes: function(oEvent) {
        var src = oEvent.srcElement || oEvent.target;
        var bInSelectBox = false;
        if (SelectBox.bSelectBoxOpened) {
            if (src) {
                do {
                    if (src.className && src.className.indexOf("selectbox") > -1) {
                        bInSelectBox = true;
                        break;
                    }
                    src = src.parentNode;
                }
                while (src && src.tagName != "BODY");
            }

            if (SelectBox.bSelectBoxOpened && !bInSelectBox) {
                $(".selectbox-popup").css("display", "none");
                SelectBox.bSelectBoxOpened = false;
            }
        }
    }
}


