window.addEvent('domready', function() {

    var array = $$('.CornerRollover');
    array.each(function(el, i, a) {

        var color = "#ffffff";
        el.addEvents({
            mouseenter: function() {
                el.setStyle('background-position', 'bottom');
            },

            mouseleave: function() {

                el.setStyle('background-position', 'top');

            }
        });
    });
      //Cycle menu, and highlight where appropriate
    var MenuItems = $("menu").getFirst().getChildren("li");

    var urlArray = document.location.toString().split("/");


    if (urlArray.length == 3 || urlArray[3] == "" || urlArray[3] == "Default.aspx") {
        //Highlight home page link
        var firstLink = MenuItems[0].getFirst();

        firstLink.setStyle("background", "url(/Resources/images/menuBg.png)");
        firstLink.setStyle("background-repeat", "repeat-x");
        firstLink.setStyle("background-position", "top");
    }
   
    MenuItems.each(function(e, i, a) {
        //alert(e.getFirst().getProperty("href"));
        var urlArrayLink = e.getFirst().getProperty("href").split("/");

        if (urlArrayLink.length > 3) {
            if (urlArrayLink[3].toLowerCase() == urlArray[3].toLowerCase()) {
                // Highlight e (the li) as link)
                var linkitem = e.getFirst();

                linkitem.setStyle("background", "url(/Resources/images/menuBg.png)");
                linkitem.setStyle("background-repeat", "repeat-x");
                linkitem.setStyle("background-position", "top");
            }
        }
    });
 

    // Call me Back Form Starts here
    $("emailAddress").addEvent("focus", function() {
        if ($("emailAddress").getProperty("value") == "Email Address  *") {
            $("emailAddress").setProperty("value", "");
            $$(".callMebackEmailTitle").setStyle("visibility", "visible");
        }
    });

    $("emailAddress").addEvent("blur", function() {
        if ($("emailAddress").getProperty("value") == "") {
            $("emailAddress").setProperty("value", "Email Address  *");
            $$(".callMebackEmailTitle").setStyle("visibility", "hidden");
        }
    });


    $("telephone").addEvent("focus", function() {
        if ($("telephone").getProperty("value") == "Telephone  *") {
            $("telephone").setProperty("value", "");
            $$(".callMebackTelephoneTitle").setStyle("visibility", "visible");
        }
    });

    $("telephone").addEvent("blur", function() {
        if ($("telephone").getProperty("value") == "") {
            $("telephone").setProperty("value", "Telephone  *");
            $$(".callMebackTelephoneTitle").setStyle("visibility", "hidden");
        }
    });


    $("fullName").addEvent("focus", function() {
        if ($("fullName").getProperty("value") == "Full Name *") {
            $("fullName").setProperty("value", "");
            $$(".callMebackNameTitle").setStyle("visibility", "visible");
        }
    });

    $("fullName").addEvent("blur", function() {
        if ($("fullName").getProperty("value") == "") {
            $("fullName").setProperty("value", "Full Name *");
            $$(".callMebackNameTitle").setStyle("visibility", "hidden");
        }
    });


    $('contactSubmit').addEvent("click", function() {
        return ValidateForm();
    });
});


function ValidateForm() {
    var msg = "";
    //alert(msg);

    if ($("emailAddress").getProperty("value") == "Email Address  *" || $("emailAddress").getProperty("value") == "") {

        $("emailAddress").focus();
        $("emailAddress").morph({ "background-color": ["#b95eff", "#ffffff"] });
        msg = msg + "You must enter an email address\n"
    }

    if ($("telephone").getProperty("value") == "Telephone  *" || $("telephone").getProperty("value") == "") {

        $("telephone").focus();
        $("telephone").morph({ "background-color": ["#b95eff", "#ffffff"] });
        msg = msg + "You must enter a phone number\n"
    }

    if ($("fullName").getProperty("value") == "Full Name *" || $("fullName").getProperty("value") == "") {

        $("fullName").focus();
        $("fullName").morph({ "background-color": ["#b95eff", "#ffffff"] });
        msg = msg + "You must enter your name\n"
    }

    if (msg.length > 0) {
        //alert(msg);
        return false;
    }

    return true;
} 
	

