﻿// JScript File
var liteweb = {
    vroot: "",
    _pageInit: [],
    _pageLoad: [],
    _SearchMsg: "Search Site...",
    _Newsletter: "Type your E-mail",
    _StatusMsg: "Share your status...",
    AppendInit: function (obj) {
        liteweb._pageInit.push(obj);
    },
    AppendLoad: function (obj) {
        liteweb._pageLoad.push(obj);
    },
    load: function ($) {
        for (var i = 0; i < liteweb._pageLoad.length; i++)
            if ("function" == typeof liteweb._pageLoad[i])
                liteweb._pageLoad[i]();
    },
    init: function (vroot, $) {
        liteweb.vroot = vroot;
        liteweb._init($);
        try {
            liteweb._initSiteSearch();
        } catch (e) { }
    },
    _init: function () {
        for (var i = 0; i < liteweb._pageInit.length; i++)
            if ("function" == typeof liteweb._pageInit[i])
                liteweb._pageInit[i]();
    },
    CheckSiteSearch: function (f, ac) {
        if ("focus" == ac && f.value.Trim() == liteweb._SearchMsg) {
            f.value = '';
            f.style.color = f.oldColor;
        }
        if ("blur" == ac && f.value.Trim() == '') {
            f.oldColor = f.style.color;
            f.value = liteweb._SearchMsg;
            f.style.color = "#a0a0a0";
        }
    },
    CheckNewsletter: function (f, ac) {
        if ("focus" == ac && f.value.Trim() == liteweb._Newsletter) {
            f.value = '';
            f.style.color = f.oldColor;
        }
        if ("blur" == ac && f.value.Trim() == '') {
            f.oldColor = f.style.color;
            f.value = liteweb._Newsletter;
            f.style.color = "#a0a0a0";
        }
    },
    CheckStatus: function (f, ac) {
        if ("focus" == ac && f.value.Trim() == liteweb._StatusMsg) {
            f.value = '';
            f.style.color = f.oldColor;
        }
        if ("blur" == ac && f.value.Trim() == '') {
            f.oldColor = f.style.color;
            f.value = liteweb._StatusMsg;
            f.style.color = "#f1f1f1";
        }
    },
    _initSiteSearch: function () {
        var sq = $("input[name=q]");
        sq.bind("focus", function () {
            liteweb.CheckSiteSearch(this, 'focus');
        });
        sq.bind("blur", function () {
            liteweb.CheckSiteSearch(this, 'blur');
        });
        sq[0].value = "";
        liteweb.CheckSiteSearch(sq[0], 'blur');
        var sf = document.forms["SearchForm"];
        sf.onsubmit = function () {
            var err = sq[0].value.Trim() == liteweb._SearchMsg ||
				sq[0].value.Trim() == "";
            if (err) {
                alert("Please enter your search query!");
                sq[0].focus();
                return false;
            }

        }
    },
    _initNewsletter: function () {
        var sq = $("input[name=newsletter-email]");
        sq.bind("focus", function () {
            liteweb.CheckNewsletter(this, 'focus');
        });
        sq.bind("blur", function () {
            liteweb.CheckNewsletter(this, 'blur');
        });
        sq[0].value = "";
        liteweb.CheckNewsletter(sq[0], 'blur');
        var sf = document.forms["Newsletter"];
        sf.onsubmit = function () {
            var err = sq[0].value.Trim() == liteweb._Newsletter ||
				sq[0].value.Trim() == "";
            if (err) {
                alert("Please enter your email address!");
                sq[0].focus();
                return false;
            }
            err = liteweb_Val.ValEmail(sq[0].value);
            if (!err) {
                alert("Please enter a correct email address!");
                sq[0].focus();
                return false;
            }
            return true;
        }
    },
    _initStatus: function () {
        var sq = $("input[name=status]");
        if ($("input[name=status]")[0].value == "") {
            sq.bind("focus", function () {
                liteweb.CheckStatus(this, 'focus');
            });
            sq.bind("blur", function () {
                liteweb.CheckStatus(this, 'blur');
            });
            sq[0].value = "";
            liteweb.CheckStatus(sq[0], 'blur');
        }
    }
};
