var Most = {

    oElHovered: null,
    oElToHide: null,
    IntervalHide: null,
    InitMenu: function() {
        var oMainMenu = $("#mainmenu").children();
        oMainMenu.each(function() {

            if ($(this).children(".menuhover:first").find("A").length > 0) {
                this.onmouseover = function() {

                    if (this.tagName == "LI" || this.parentNode.tagName == "LI") {
                        try { clearInterval(Most.IntervalHide); }
                        catch (e) { }
                        if (Most.oElToHide)
                            $(Most.oElToHide).removeClass("hover");
                    }

                    if (this.className.indexOf("hover") == -1)
                        $(this).addClass("hover");
                    Most.oElHovered = this;

                    var oMenuHover = $(Most.oElHovered).find(".menuhover");
                    if (oMenuHover.attr("calculated") != "true")
                        oMenuHover.css("width", (oMenuHover.find("ol").get(0).offsetWidth + 30) + "px").attr("calculated", "true");
                }

                this.onmouseout = function() {
                    Most.oElToHide = this;
                    Most.oElHovered = null;
                    Most.IntervalHide = setInterval(function() {
                        if (Most.oElToHide != Most.oElHovered)
                            $(Most.oElToHide).removeClass("hover");
                        clearInterval(Most.IntervalHide);
                    }, 300);
                }

            } else {
                this.onmouseover = function() {

                    if (this.tagName == "LI" || this.parentNode.tagName == "LI") {
                        try { clearInterval(Most.IntervalHide); }
                        catch (e) { }
                        if (Most.oElToHide)
                            $(Most.oElToHide).removeClass("hover");
                    }

                }
            }
        });

        if (oMainMenu.length > 1)
            $("#mainmenu").children(":last").find("A:first").addClass("lastmainlink");

    },

    ContactForm_Send: function() {

        var bErrors = false;
        var aFields = [];
        $("#contact-form").find(".fcontrol").each(function() {
            if (this.className.indexOf("req") > -1 && this.value.replace(/\s/gi, "") == "")
                bErrors = true;
            aFields.push(this.id + "=" + escape(this.value));
        });

        if (bErrors) {
            alert("Please fill all required fields");
        } else {

            $.ajax({
                type: "POST",
                cache: false,
                url: "/he/getXML.aspx",
                dataType: "xml",
                data: "obj=MailSender&sFunc=SendContactForm&" + aFields.join("&"),
                success: function(xml) {
                    alert("Your request was successfuly sent. Thank you.");
                    location.href = location.href;
                }
            });
        }

    },

    ContactFormRight_JobInjuryChanged: function() {

        var oSelect = $("#JobInqury").get(0);
        var sValue = oSelect.options[oSelect.selectedIndex].value;

        if (jQuery.trim(sValue) == "Job Inquiry") {
            $("#JobInquiry").fadeIn(200);
        } else {
            $("#JobInquiry").fadeOut(200);
        }

    },



    ContactFormRight_Send: function() {

        var sError_Message_ID = "Homepage_Contact_ErrorMsg";
        var arrFields = ["Homepage_Contact_sMessage", "Homepage_Contact_sName", "Homepage_Contact_sEmail", "Homepage_Contact_sCompany"];
        var bErrors = false;
        var aFields = [];

        for (var i = 0; i < arrFields.length; i++) {

            if (document.getElementById(arrFields[i]).value == document.getElementById(arrFields[i]).name.replace(/\_/gi, " ")) {
                bErrors = true;
                break;
            }
            aFields.push(arrFields[i] + "=" + escape(document.getElementById(arrFields[i]).value));
        }

        var oSelect = $("#JobInqury").get(0);
        var sValue = oSelect.options[oSelect.selectedIndex].value;
        if (sValue == "") {
            alert("Please select your request type");
            return;
        }

        if (bErrors) {
            $("#" + sError_Message_ID).css("display", "none").css("visibility", "visible").fadeIn(200);
        } else {
            $("#" + sError_Message_ID).css("display", "none");


            $("#frmContactRight").get(0).submit();
            /*
            $.ajax({
            type: "POST",
            cache: false,
            url: "/he/getXML.aspx",
            dataType: "xml",
            data: "obj=MailSender&sFunc=SendContactForm&" + aFields.join("&"),
            success: function(xml) {
            $("#Homepage_Contact_BtnSend").css("display", "none");
            $("#SuccessMessage").html("Thank you for contacting MOST Technologies").css("display", "none").css("visibility", "visible").fadeIn(250);
            },
            error: function(aa) {
            alert("err " + aa);
            }
            });*/


        }
    },




    /*
    ContactFormRight_Send: function() {

        var Contact_Name = $("#Contact_Name").val(),
    Contact_Email = $("#Contact_Email").val(),
    Contact_Company = $("#Contact_Company").val(),
    Contact_Message = $("#Contact_Message").val();

        if (Contact_Name == "Name" || Contact_Email == "E-mail" || Contact_Company == "Company" || Contact_Message == "Your Message") {
    alert("Please fill all fields");
    return;
    }

        var sFields = "Homepage_Contact_sMessage=" + escape(Contact_Message) + "&Homepage_Contact_sName=" + escape(Contact_Name) + "& Homepage_Contact_sEmail=" + escape(Contact_Email) + "&Homepage_Contact_sCompany=" + escape(Contact_Company);

        $("#contact_send_message").css("display", "block");
    $("#frmContactRight").get(0).submit();
        
        
    $.ajax({
    type: "POST",
    cache: false,
    url: "/he/getXML.aspx",
    dataType: "xml",
    data: "obj=MailSender&sFunc=SendContactForm&" + sFields,
    success: function(xml) {
    alert("Your request was successfuly sent. Thank you.");
    location.href = location.href;
    }
    });
        


    },
    */


    InitCareers: function() {

        $("#Careers").children().each(function() {
            this.onclick = function() {
                if ($(this).hasClass("selected")) {
                    $(this).removeClass("selected").children(".des").css("display", "none"); ;
                } else {
                    $(this.parentNode).children(".selected").each(function() {
                        $(this).removeClass("selected");
                        $(this).children(".des").css("display", "none");
                    });
                    $(this).addClass("selected").children(".des").css("display", "block"); ;
                }
            }
        });

    },

    ResizeFont: function(bLarge) {
        var oText = document.getElementById('txtdescription');
        if (oText)
            oText.style.fontSize = (bLarge ? "12" : "11") + "px";

        var now = new Date();
        now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 7); // week...
        setCookie("ResizeFont", bLarge, now);
    },

    FixResize: function() {
        var oText = document.getElementById('txtdescription');
        if (oText) {
            var xTemp = oText.style.fontSize;
            oText.style.fontSize = "12px";
            oText.style.fontSize = xTemp;
        }
    },

    CheckResize: function() {
        if ((getCookie("ResizeFont") && getCookie("ResizeFont").toString() == "true") && (document.getElementById('txtdescription') != null)) {
            document.getElementById('txtdescription').style.fontSize = "12px";
        }
        setTimeout(Most.FixResize, 200);
        setTimeout(Most.FixResize, 550);
        if (document.getElementById('txtdescription') && $("#txtdescription").attr("intvled") != "true") {
            $("#txtdescription").attr("intvled", "true");
            setInterval(Most.FixResize, 1100);
        }
    },


    SendContactForm: function() {

        var sError_Message_ID = "Homepage_Contact_ErrorMsg";
        var arrFields = ["Homepage_Contact_sMessage", "Homepage_Contact_sName", "Homepage_Contact_sEmail", "Homepage_Contact_sCompany"];
        var bErrors = false;
        var aFields = [];

        for (var i = 0; i < arrFields.length; i++) {

            if (document.getElementById(arrFields[i]).value == document.getElementById(arrFields[i]).name.replace(/\_/gi, " ")) {
                bErrors = true;
                break;
            }
            aFields.push(arrFields[i] + "=" + escape(document.getElementById(arrFields[i]).value));
        }

        if (bErrors) {
            $("#" + sError_Message_ID).css("display", "none").css("visibility", "visible").fadeIn(200);
        } else {
            $("#" + sError_Message_ID).css("display", "none");
            $.ajax({
                type: "POST",
                cache: false,
                url: "/he/getXML.aspx",
                dataType: "xml",
                data: "obj=MailSender&sFunc=SendContactForm&" + aFields.join("&"),
                success: function(xml) {
                    $("#Homepage_Contact_BtnSend").css("display", "none");
                    $("#SuccessMessage").html("Thank you for contacting MOST Technologies").css("display", "none").css("visibility", "visible").fadeIn(250);
                },
                error: function(aa) {
                    alert("err " + aa);
                }
            });

        }
    },

    Close_SelectBoxes: function() {

        var oEl = window.addEventListener ? arguments[0].target : event.srcElement;

        if (!$(oEl.parentNode.parentNode).hasClass("selectbox")) {
            $(".popup").css("display", "none");
            document.body.onmouseup = null;
        } else {
            setTimeout(function() {
                $(".popup").css("display", "none");
                document.body.onmouseup = null;
            }, 80);
        }
    },

    Open_SelectBox: function(oEl) {

        $(oEl.parentNode).children(".popup").css("display", "block");
        document.body.onmouseup = Most.Close_SelectBoxes;
    }


}