﻿// JScript File
var liteweb = {
    vroot: "",
    _pageInit: [],
    _pageLoad: [],
    _SearchMsg: "Search Site...",
    _Newsletter: "Type your E-mail",
    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";
        }
    },
    _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;
        }
    }
};

var lw = {};
liteweb.AppendInit(function() {
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-6104796-12']);
	_gaq.push(['_trackPageview']);

	(function() {
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
	})();
});
