﻿var domReadyEvent={name:"domReadyEvent",events:{},domReadyID:1,bDone:false,DOMContentLoadedCustom:null,add:function(handler){if(!handler.$$domReadyID){handler.$$domReadyID=this.domReadyID++;if(this.bDone){handler();}this.events[handler.$$domReadyID]=handler;}},remove:function(handler){if(handler.$$domReadyID){delete this.events[handler.$$domReadyID];}},run:function(){if(this.bDone){return;}this.bDone=true;for(var i in this.events){this.events[i]();}},schedule:function(){if(this.bDone){return;}if(/KHTML|WebKit/i.test(navigator.userAgent)){if(/loaded|complete/.test(document.readyState)){this.run();}else{setTimeout(this.name+".schedule()",100);}}else if(document.getElementById("__ie_onload")){return true;}if(typeof this.DOMContentLoadedCustom==="function"){if(typeof document.getElementsByTagName!=='undefined'&&(document.getElementsByTagName('body')[0]!==null||document.body!==null)){if(this.DOMContentLoadedCustom()){this.run();}else{setTimeout(this.name+".schedule()",250);}}}return true;},init:function(){if(document.addEventListener){document.addEventListener("DOMContentLoaded",function(){domReadyEvent.run();},false);}setTimeout("domReadyEvent.schedule()",100);function run(){domReadyEvent.run();}if(typeof addEvent!=="undefined"){addEvent(window,"load",run);}else if(document.addEventListener){document.addEventListener("load",run,false);}else if(typeof window.onload==="function"){var oldonload=window.onload;window.onload=function(){domReadyEvent.run();oldonload();};}else{window.onload=run;}}};
domReadyEvent.init();

var Phizz = {
	Version: "1.0",
	toString: function() {
		return "Phizz Javascript Library Version ".concat(this.Version);
	}
};

Phizz.Dom = {
    ByID: function(id) {
        return document.getElementById(id);
    },

    ByName: function(name) {
        return document.getElementsByName(name);
    },

    ByTagName: function(tagName) {
        return document.getElementsByTagName(tagName);
    },

    ByClass: function(strClass, strTag, objContElm) {
        strTag = strTag || "*";
        objContElm = objContElm || document;
        var objColl = objContElm.getElementsByTagName(strTag);
        if (!objColl.length && strTag == "*" && objContElm.all) objColl = objContElm.all;
        var arr = new Array();
        var delim = strClass.indexOf('|') != -1 ? '|' : ' ';
        var arrClass = strClass.split(delim);
        for (var i = 0, j = objColl.length; i < j; i++) {
            var arrObjClass = objColl[i].className.split(' ');
            if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
            var c = 0;
            comparisonLoop:
            for (var k = 0, l = arrObjClass.length; k < l; k++) {
                for (var m = 0, n = arrClass.length; m < n; m++) {
                    if (arrClass[m] == arrObjClass[k]) c++;
                    if ((delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
                        arr.push(objColl[i]);
                        break comparisonLoop;
                    }
                }
            }
        }
        return arr;
    },

    GetAbsolutePosition: function(obj) {
        var x = 0;
        var y = 0;
        if (obj.offsetParent) {
            x = obj.offsetLeft;
            y = obj.offsetTop;
            while (obj = obj.offsetParent) {
                x += obj.offsetLeft;
                y += obj.offsetTop;
            }
        }
        return { x: x, y: y };
    },

    GetScrollPosition: function() {
        var x = window.pageXOffset ? window.pageXOffset : 0;
        if (document.documentElement && document.documentElement.scrollLeft > x) x = document.documentElement.scrollLeft;
        if (document.body && document.body.scrollLeft > x) x = document.body.scrollLeft;
        var y = window.pageYOffset ? window.pageYOffset : 0;
        if (document.documentElement && document.documentElement.scrollTop > y) y = document.documentElement.scrollTop;
        if (document.body && document.body.scrollTop > y) y = document.body.scrollTop;
        return { x: x, y: y };
    },

    GetScrollSize: function() {
        var xScroll, yScroll;
        if (window.innerHeight && window.scrollMaxY) {
            xScroll = document.body.scrollWidth;
            yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }
        return { x: xScroll, y: yScroll };
    },

    GetWindowSize: function() {
        var windowWidth, windowHeight;
        if (self.innerHeight) {	// all except Explorer
            windowWidth = self.innerWidth;
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }

        return { width: windowWidth, height: windowHeight };
    },

    GetDocumentSize: function() {
        var scrollSize = Phizz.Dom.GetScrollSize();
        var windowSize = Phizz.Dom.GetWindowSize();

        // for small pages with total height less then height of the viewport
        if (scrollSize.y < windowSize.height) {
            pageHeight = windowSize.height;
        } else {
            pageHeight = scrollSize.y;
        }

        // for small pages with total width less then width of the viewport
        if (scrollSize.x < windowSize.width) {
            pageWidth = windowSize.width;
        } else {
            pageWidth = scrollSize.x;
        }

        return { width: pageWidth, height: pageHeight };
    },

    AlignToWindowCenter: function(obj) {
        if (obj.style.visibility == "visible") {
            var scrollPosition = Phizz.Dom.GetScrollPosition();
            var windowSize = Phizz.Dom.GetWindowSize();
            var left = scrollPosition.x + (windowSize.width * 0.5) - (obj.offsetWidth * 0.5);
            var top = scrollPosition.y + (windowSize.height * 0.5) - (obj.offsetHeight * 0.5);
            obj.style.left = left + "px";
            obj.style.top = top + "px";
        }
    },

    GetEventTarget: function(e) {
        var obj;
        if (!e) e = window.event;
        if (e.target) {
            obj = e.target;
        } else if (e.srcElement) {
            obj = e.srcElement;
        }
        if (obj.nodeType == 3) obj = obj.parentNode;
        return obj;
    },

    CancelEventPropagation: function(e) {
        if (!e) e = window.event;
        e.cancelBubble = true;
        if (e.stopPropagation) e.stopPropagation();
    },

    RegisterDOMReadyEvent: function(objFunction) {
        domReadyEvent.add(objFunction);
    },

    RegisterWindowLoadEvent: function(objFunction) {
        var existingHandler = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = objFunction;
        } else {
            window.onload = function() {
                if (existingHandler) existingHandler();
                objFunction();
            }
        }
    },

    RegisterWindowResizeEvent: function(objFunction) {
        var existingHandler = window.onresize;
        if (typeof window.onresize != 'function') {
            window.onresize = objFunction;
        } else {
            window.onresize = function() {
                if (existingHandler) existingHandler();
                objFunction();
            }
        }
    },

    RegisterWindowBlurEvent: function(objFunction) {
        var existingHandler = window.onblur;
        if (typeof window.onblur != 'function') {
            window.onblur = objFunction;
        } else {
            window.onblur = function() {
                if (existingHandler) existingHandler();
                objFunction();
            }
        }
    },

    RegisterWindowScrollEvent: function(objFunction) {
        var existingHandler = window.onscroll;
        if (typeof window.onscroll != 'function') {
            window.onscroll = objFunction;
        } else {
            window.onscroll = function() {
                if (existingHandler) existingHandler();
                objFunction();
            }
        }
    },

    RegisterDocumentClickEvent: function(objFunction) {
        var existingHandler = document.onclick;
        if (typeof document.onclick != 'function') {
            document.onclick = objFunction;
        } else {
            document.onclick = function() {
                if (existingHandler) existingHandler();
                objFunction();
            }
        }
    },

    RegisterDocumentOnMouseDownEvent: function(objFunction) {
        var existingHandler = document.onmousedown;
        if (typeof document.onmousedown != 'function') {
            document.onmousedown = objFunction;
        } else {
            document.onmousedown = function() {
                if (existingHandler) existingHandler();
                objFunction();
            }
        }
    },

    RegisterDocumentOnMouseUpEvent: function(objFunction) {
        var existingHandler = document.onmouseup;
        if (typeof document.onmouseup != 'function') {
            document.onmouseup = objFunction;
        } else {
            document.onmouseup = function() {
                if (existingHandler) existingHandler();
                objFunction();
            }
        }
    },

    RegisterDocumentOnMouseMouseEvent: function(objFunction) {
        var existingHandler = document.onmousemouse;
        if (typeof document.onmousemouse != 'function') {
            document.onmousemouse = objFunction;
        } else {
            document.onmousemouse = function() {
                if (existingHandler) existingHandler();
                objFunction();
            }
        }
    },

    GetMouseCoordinates: function(e) {
        var x = 0;
        var y = 0;
        if (!e) e = window.event;
        if (e.pageX || e.pageY) {
            x = e.pageX;
            y = e.pageY;
        } else if (e.clientX || e.clientY) {
            x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
            y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
        }
        return { x: x, y: y }
    },

    GetMouseCoordinatesInElement: function(obj, e) {
        var p = Phizz.Dom.GetMouseCoordinates(e);
        var p2 = Phizz.Dom.GetAbsolutePosition(obj);
        p.x -= p2.x;
        p.y -= p2.y;
        return p;
    },

    Dropdown: {
        AddOption: function(obj, value, text) {
            var objOption = document.createElement("option");
            objOption.value = value;
            objOption.text = text;
            try { obj.add(objOption, null); } catch (ex) { obj.add(objOption); }
        },
        RemoveAllOptions: function(obj, maintainPrompt) {
            while (obj.options.length > maintainPrompt ? 1 : 0) obj.remove(obj.options.length - 1);
        }
    },

    CheckboxList: {
        GetCheckedObject: function(name) {
            var objs = Phizz.Dom.ByName(name);
            if (objs == null || objs.length == 0) return null;
            for (var i = 0; i < objs.length; i++) {
                if (objs[i].checked) return objs[i];
            }
        },
        GetCheckedValue: function(name) {
            var objs = Phizz.Dom.ByName(name);
            if (objs == null || objs.length == 0) return null;
            var value = "";
            for (var i = 0; i < objs.length; i++) {
                if (objs[i].checked) value += (value.length > 0 ? "," : "") + objs[i].value;
            }
            return value;
        },
        SetCheckedValue: function(name, value) {
            var objs = Phizz.Dom.ByName(name);
            for (var i = 0; i < objs.length; i++) {
                if (objs[i].value == value) objs[i].checked = true;
            }
        },
        SetCheckStatus: function(name, isChecked) {
            var objs = Phizz.Dom.ByName(name);
            for (var i = 0; i < objs.length; i++) objs[i].checked = isChecked;
        }
    }
};



Phizz.Browser = {
	IsIE: navigator.appVersion.indexOf("MSIE") > -1,
	IsIE6: navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion.indexOf("MSIE 6") > -1 || navigator.appVersion.indexOf("MSIE 5.5") > -1),
	IsIE7: navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion.indexOf("MSIE 7") > -1),
	IsKonqueror: navigator.userAgent.indexOf("Konqueror") > -1,
	IsMozilla: navigator.userAgent.indexOf("Gecko") > -1 && !(navigator.userAgent.indexOf("Konqueror") > -1) && !(navigator.appVersion.indexOf("Safari") > -1),
	IsOpera: navigator.userAgent.indexOf("Opera") > -1,
	IsSafari: navigator.appVersion.indexOf("Safari") > -1,
	IsWebKit: RegExp(" AppleWebKit/").test(navigator.userAgent)
};


Phizz.Css = {
	SetOpacity: function(obj, percentage) {
		obj.style.opacity = percentage * 0.01;
		obj.style.MozOpacity = percentage * 0.01;
		obj.style.KhtmlOpacity = percentage * 0.01;
		obj.style.filter = "alpha(opacity=".concat(percentage, ")");
	}
};


Phizz.Navigation = {
    Go: function(url) {
        //alert(url);
        if (window.event) window.event.returnValue = false;
        window.location.href = url;
    },

    GoAndMaintainQueryString: function(url) {
        var currentUrl = window.location.href;
        if (currentUrl.indexOf("#") > -1) currentUrl = currentUrl.substr(0, currentUrl.indexOf("#"));
        if (currentUrl.indexOf("?") > -1) {
            Phizz.Navigation.Go(url.concat("?", currentUrl.split("?")[1]));
        } else {
            Phizz.Navigation.Go(url);
        }
    },

    Back: function() {
        window.history.back();
    },

    GetPageTitle: function() {
        var objTitle = document.getElementsByTagName("title")[0];
        if (window.sidebar) {
            return objTitle.textContent;
        } else {
            return objTitle.innerText;
        }
    },

    AddBookmark: function() {
        var title = this.GetPageTitle();
        var url = window.location.href;
        if (window.sidebar) {
            window.sidebar.addPanel(title, url, "");
        } else if (window.external) {
            window.external.AddFavorite(url, title);
        }
    },

    OpenWindow: function(url, preferredWidth, preferredHeight, windowName, forceScroll) {
        var usedWidth = Math.min(preferredWidth, screen.width - 80);
        var usedHeight = Math.min(preferredHeight, screen.height - 120);
        if (windowName == null) windowName = "w" + Math.round(Math.random() * 10000);
        window.open(url, windowName, "width=" + usedWidth + ", height=" + usedHeight + ", top=" + (screen.height / 2 - usedHeight / 2 - 20) + ", left=" + (screen.width / 2 - usedWidth / 2) + ", location=no, menubar=no, resizable=yes, status=no, toolbar=no, scrollbars=" + (forceScroll || (usedWidth < preferredWidth || usedHeight < preferredHeight) ? "yes" : "no"));
    },

    OpenCustomWindow: function(url, preferredWidth, preferredHeight, windowName, showLocationBar, showMenuBar, isResizable, showStatusBar, showToolbar, showScrollBars) {
        var usedWidth = Math.min(preferredWidth, screen.width - 80);
        var usedHeight = Math.min(preferredHeight, screen.height - 120);
        if (windowName == null) windowName = "w" + Math.round(Math.random() * 10000);
        window.open(url, windowName, "width=" + usedWidth + ", height=" + usedHeight + ", top=" + (screen.height / 2 - usedHeight / 2 - 20) + ", left=" + (screen.width / 2 - usedWidth / 2) + ", location=" + (showLocationBar ? "yes" : "no") + ", menubar=" + (showMenuBar ? "yes" : "no") + ", resizable=" + (isResizable ? "yes" : "no") + ", status=" + (showStatusBar ? "yes" : "no") + ", toolbar=" + (showToolbar ? "yes" : "no") + ", scrollbars=" + (showScrollBars ? "yes" : "no"));
    },

    CreateCookie: function(name, value, days) {
        var expires;
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            expires = "; expires=" + date.toGMTString();
        }
        else expires = "";
        document.cookie = name + "=" + value + expires + "; path=/";
    },

    ReadCookie: function(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    },

    EraseCookie: function(name) {
        createCookie(name, "", -1);
    }
};



Phizz.Navigation.QueryString = {
    _values: null,
    newUrl: window.location.href,

    Parse: function() {
        var url = window.location.href;
        this._values = new Array();
        if (url.indexOf("?") > -1) {
            var qs = url.substr(url.indexOf("?") + 1);
            var pairs = qs.split("&");
            qs = "";
            for (var i = 0; i < pairs.length; i++) {
                var nEquals = pairs[i].indexOf("=");
                var key = pairs[i].substr(0, nEquals);
                var value = pairs[i].substr(nEquals + 1);
                if (this._values[key] != null && this._values[key].length > 0) {
                    this._values[key] = this._values[key].concat(",", value);
                } else {
                    this._values[key] = value;
                }
            }
        }
    },

    HasKey: function(key) {
        if (this._values == null) this.Parse();
        return this._values[key] != null;
    },

    Get: function(key) {
        if (this._values == null) this.Parse();
        return this._values[key];
    },

    Set: function(key, value, cancelNavigation) {
        var url = this.newUrl;
        var qs = "";
        if (url.indexOf("?") > -1) {
            qs = url.substr(url.indexOf("?") + 1);
            var pairs = qs.split("&");
            qs = "";
            for (var i = 0; i < pairs.length; i++) {
                if (pairs[i].substr(0, key.length + 1) != (key + "=")) qs += (qs.length == 0 ? "?" : "&") + pairs[i];
            }
            url = url.substr(0, url.indexOf("?")) + qs;
        }
        this.newUrl = url + (qs.length == 0 ? "?" : "&") + encodeURIComponent(key) + "=" + encodeURIComponent(value);
        if (!cancelNavigation) Phizz.Navigation.Go(this.newUrl);
    },

    SetMultiple: function(keyArray, valueArray, cancelNavigation) {
        if (keyArray.length != valueArray.length) alert("ERROR : Phizz.QueryString.SetMultiple() : keyArray and valueArray must be the same length.");
        var url = this.newUrl;
        var qs = "";
        if (url.indexOf("?") > -1) {
            qs = url.substr(url.indexOf("?") + 1);
            var pairs = qs.split("&");
            qs = "";
            for (var i = 0; i < pairs.length; i++) {
                var keyInUse = false;
                for (var j = 0; j < keyArray.length; j++) {
                    if (pairs[i].substr(0, keyArray[j].length + 1) == (keyArray[j] + "=")) {
                        keyInUse = true; break;
                    }
                }
                if (!keyInUse) {
                    //var keyAndValue = pairs[i].split("=");
                    qs += (qs.length == 0 ? "?" : "&") + pairs[i]; //keyAndValue[0] + "=" + encodeURIComponent(keyAndValue[1]);
                }
            }
            url = url.substr(0, url.indexOf("?")) + qs;
        }
        var newPairs = "";
        for (var i = 0; i < keyArray.length; i++) newPairs += (newPairs.length == 0 ? "" : "&") + encodeURIComponent(keyArray[i]) + "=" + encodeURIComponent(valueArray[i]);
        this.newUrl = url + (qs.length == 0 ? "?" : "&") + newPairs;
        if (!cancelNavigation) Phizz.Navigation.Go(this.newUrl);
    },

    Delete: function(key, cancelNavigation) {
        var url = this.newUrl;
        var qs = "";
        if (url.indexOf("?") > -1) {
            qs = url.substr(url.indexOf("?") + 1);
            var pairs = qs.split("&");
            qs = "";
            for (var i = 0; i < pairs.length; i++) {
                if (pairs[i].substr(0, key.length + 1) != (key + "=")) qs += (qs.length == 0 ? "?" : "&") + pairs[i];
            }
            url = url.substr(0, url.indexOf("?")) + qs;
        }
        this.newUrl = url;
        if (!cancelNavigation) Phizz.Navigation.Go(this.newUrl);
    },

    DeleteMultiple: function(keyArray, cancelNavigation) {
        var url = this.newUrl;
        var qs = "";
        if (url.indexOf("?") > -1) {
            qs = url.substr(url.indexOf("?") + 1);
            var pairs = qs.split("&");
            qs = "";
            for (var i = 0; i < pairs.length; i++) {
                var keyInUse = false;
                for (var j = 0; j < keyArray.length; j++) {
                    if (pairs[i].substr(0, keyArray[j].length + 1) == (keyArray[j] + "=")) {
                        keyInUse = true; break;
                    }
                }
                if (!keyInUse) qs += (qs.length == 0 ? "?" : "&") + pairs[i];
            }
            url = url.substr(0, url.indexOf("?")) + qs;
        }
        this.newUrl = url;
        if (!cancelNavigation) Phizz.Navigation.Go(this.newUrl);
    }
};


Phizz.Tools = {
    ParseKeyValuePairs: function(s) {
        var a = new Array();
        var pairs = s.split("&");
        for (var i = 0; i < pairs.length; i++) {
            var keyAndValue = pairs[i].split("=");
            a[keyAndValue[0]] = keyAndValue[1];
        }
        return a;
    },

    _PreloadedImages: new Array(),
    PreloadImage: function(src, width, height) {
        this._PreloadedImages.push(new Image(width, height));
        this._PreloadedImages[this._PreloadedImages.length - 1].src = src;
    },

    EnableIE6ImageTransparency: function(objImage, blankImageUrl) {
        if (objImage == null) return;
        if (blankImageUrl == null || blankImageUrl.length == 0) blankImageUrl = "/i/_.gif";
        var src = objImage.src;
        objImage.src = blankImageUrl;
        objImage.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', src='" + src + "')";
    },

    EnableIE6BackgroundTransparency: function(obj, imageUrl) {
        if (obj == null) return;
        obj.style.backgroundImage = "none";
        obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='crop', src='" + imageUrl + "')";
    },

    EnableIE6ImageTransparencyForSrc: function(reSrc, blankImageUrl) {
        if (blankImageUrl == null || blankImageUrl.length == 0) blankImageUrl = "/i/_.gif";
        var objsImages = Phizz.Dom.ByTagName("IMG");
        for (var i = 0; i < objsImages.length; i++) {
            if (reSrc.test(objsImages[i].src)) {
                var src = objsImages[i].src;
                objsImages[i].src = blankImageUrl;
                objsImages[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', src='" + src + "')";
            }
        }
    },

    ShowIE6Foreground: function() {
        var objsObject = document.getElementsByTagName("OBJECT");
        for (var i = 0; i < objsObject.length; i++) objsObject[i].style.visibility = "visible";
        var objsSelect = document.getElementsByTagName("SELECT");
        for (var i = 0; i < objsSelect.length; i++) objsSelect[i].style.visibility = "visible";
    },

    HideIE6Foreground: function() {
        var objsObject = document.getElementsByTagName("OBJECT");
        for (var i = 0; i < objsObject.length; i++) objsObject[i].style.visibility = "hidden";
        var objsSelect = document.getElementsByTagName("SELECT");
        for (var i = 0; i < objsSelect.length; i++) objsSelect[i].style.visibility = "hidden";
    },

    IsItemInArray: function(value, array) {
        for (var i = 0; i < array.length; i++) if (array[i] == value) return true;
        return false;
    },

    TrimString: function(s) {
        return s.replace(/(^[\s\xA0]+)|([\s\xA0]+$)/g, "");
    },

    ParseDDMMMYYYYDate: function(s) {
        if (Phizz.Validation.IsDDMMMYYYYDate(s)) {
            if (s[0] == "0") s = s.substr(1);
            var dateParts = s.split("-");
            var m = new Array(); m["Jan"] = 0; m["Feb"] = 1; m["Mar"] = 2; m["Apr"] = 3; m["May"] = 4; m["Jun"] = 5; m["Jul"] = 6; m["Aug"] = 7; m["Sep"] = 8; m["Oct"] = 9; m["Nov"] = 10; m["Dec"] = 11;
            return new Date(parseInt(dateParts[2]), m[dateParts[1]], parseInt(dateParts[0]));
        } else {
            return null;
        }
    },

    FormatDateAsDDMMMYYYY: function(date) {
        return date.getDate() + "-" + ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][date.getMonth()] + "-" + date.getFullYear();
    }
};


Phizz.Validation = {
    DisplayFunction: function(s) { alert(s) },
    objFocus: null,

    ReturnFocus: function() {
        if (this.objFocus == null) return;
        this.objFocus.focus();
        this.objFocus = null;
    },

    Value: function(id) {
        var obj = Phizz.Dom.ByID(id);
        if (Phizz.Tools.TrimString(obj.value).length == 0) {
            this.DisplayFunction("Please provide a value for the " + obj.title + " field.");
            (this.objFocus = obj).focus();
            return false;
        } else {
            return true;
        }
    },

    Regex: function(id, regExp, errorMessage, allowEmpty) {
        var obj = Phizz.Dom.ByID(id);
        if (allowEmpty && obj.value.length == 0) return true;
        if (!regExp.test(obj.value)) {
            this.DisplayFunction(errorMessage);
            (this.objFocus = obj).focus();
            return false;
        } else {
            return true;
        }
    },

    Equivalent: function(id1, id2) {
        var obj1 = Phizz.Dom.ByID(id1);
        var obj2 = Phizz.Dom.ByID(id2);
        if (Phizz.Tools.TrimString(obj1.value) != Phizz.Tools.TrimString(obj2.value)) {
            this.DisplayFunction("The " + obj1.title + " and " + obj2.title + " field values must be equivalent. Please check and try again.");
            obj1.focus();
            return false;
        } else {
            return true;
        }
    },

    Email: function(id, allowEmpty) {
        var obj = Phizz.Dom.ByID(id);
        if (allowEmpty && obj.value.length == 0) return true;
        if (!Phizz.Validation.IsEmail(obj.value)) {
            this.DisplayFunction("Please enter a valid email address in the " + obj.title + " field.");
            (this.objFocus = obj).focus();
            return false;
        } else {
            return true;
        }
    },

    IsEmail: function(s) {
        return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(s);
    },

    Integer: function(id, allowEmpty) {
        var obj = Phizz.Dom.ByID(id);
        if (allowEmpty && obj.value.length == 0) return true;
        if (!Phizz.Validation.IsInteger(obj.value)) {
            this.DisplayFunction("Please enter a valid whole number value in the " + obj.title + " field.");
            (this.objFocus = obj).focus();
            return false;
        } else {
            return true;
        }
    },

    IsInteger: function(s) {
        return /^-?\d+$/.test(s);
    },

    Decimal: function(id, allowEmpty) {
        var obj = Phizz.Dom.ByID(id);
        if (allowEmpty && obj.value.length == 0) return true;
        if (!Phizz.Validation.IsDecimal(obj.value)) {
            this.DisplayFunction("Please enter a valid numeric value in the " + obj.title + " field.");
            (this.objFocus = obj).focus();
            return false;
        } else {
            return true;
        }
    },

    IsDecimal: function(s) {
        return /^-?\d+(\.\d+)?$/.test(s);
    },

    DDMMMYYYYDate: function(id, allowEmpty) {
        var obj = Phizz.Dom.ByID(id);
        if (allowEmpty && obj.value.length == 0) return true;
        if (!Phizz.Validation.IsDDMMMYYYYDate(obj.value)) {
            this.DisplayFunction("Please enter a valid date value in the " + obj.title + " field, in the format [dd-Mmm-yyyy]. If unsure, please use the Date Picker.");
            (this.objFocus = obj).focus();
            return false;
        } else {
            return true;
        }
    },

    IsDDMMMYYYYDate: function(s) {
        var isValid = true;
        var dateParts = (s.indexOf("-") > -1 ? s.split("-") : new Array());
        if (dateParts.length != 3) isValid = false;
        if (isValid) {
            var dayPart = dateParts[0]; if (dayPart.length == 2 && dayPart.substr(0, 1) == "0") dayPart = dayPart.substr(1, 1);
            var monthPart = dateParts[1].toLowerCase(); monthPart = monthPart.substr(0, 1).toUpperCase() + monthPart.substr(1);
            var yearPart = dateParts[2];
            if (!/^[0-9]{1,2}$/.test(dayPart) || !/^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)$/.test(monthPart) || !/^[1-9]{1}[0-9]{3}$/.test(yearPart)) isValid = false;
            if (isValid) {
                dayPart = parseInt(dayPart);
                yearPart = parseInt(yearPart);
                if (dayPart < 1 || dayPart > 31 || (dayPart > 30 && /^(Apr|Jun|Sep|Nov)$/.test(monthPart)) || (dayPart > 29 && monthPart == "Feb") || (dayPart == 29 && monthPart == "Feb" && !IsLeapYear(yearPart))) isValid = false;
            }
        }
        return isValid;
    },

    IsLeapYear: function(year) {
        if (year % 4 == 0) {
            if (year % 100 == 0) {
                return (year % 400 == 0);
            } else {
                return true;
            }
        } else {
            return false;
        }
    },

    Dropdown: function(id, allowEmpty) {
        var obj = Phizz.Dom.ByID(id);
        if (obj.selectedIndex == 0 || (!allowEmpty && obj.options[obj.selectedIndex].value.length == 0)) {
            this.DisplayFunction("A value must be selected for the " + obj.title + " field.");
            this.objFocus = obj;
            if (obj.style.visibility != "hidden") obj.focus();
            return false;
        } else {
            return true;
        }
    },

    CheckboxList: function(name, customMessage) {
        var objs = Phizz.Dom.ByName(name);
        if (objs == null || objs.length == 0) return true;
        var checked = false;
        for (var i = 0; i < objs.length; i++) {
            if (objs[i].checked) { checked = true; break; }
        }
        if (!checked) {
            if (customMessage != null) {
                this.DisplayFunction(customMessage);
            } else {
                this.DisplayFunction("A value must be selected for the " + objs[0].title + " field.");
            }
            objs[0].focus();
            return false;
        } else {
            return true;
        }
    },

    HexColor: function(id, allowEmpty) {
        var obj = Phizz.Dom.ByID(id);
        if (allowEmpty && obj.value.length == 0) return true;
        if (!Phizz.Validation.IsHexColor(Phizz.Tools.TrimString(obj.value))) {
            this.DisplayFunction("Please enter a valid 3 or 6 digit hexadecimal colour value in the " + obj.title + " field. If you are unsure, use the colour chooser provided." + (allowEmpty ? "\r\rIf you do not want to give a value for this field, please leave it blank." : ""));
            (this.objFocus = obj).focus();
            return false;
        } else {
            return true;
        }
    },

    IsHexColor: function(s) {
        return /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(s);
    }
};

Phizz.Blackout = {
	N: 0,
	objBlackout: null,
	
	Create: function(hexColor) {
		this.objBlackout = document.createElement("div");
		this.objBlackout.style.cssText = "position:absolute;z-index:5;visibility:hidden;width:100%;height:1px;top:0px;left:0px;background-color:#" + (hexColor != null && /^[0-9A-Fa-f]{6}$/.test(hexColor) ? hexColor : "303132") + ";opacity:0.87;-moz-opacity:0.87;filter:alpha(opacity=87);";
		this.objBlackout.appendChild(document.createTextNode(" "));
		document.body.appendChild(this.objBlackout);
		Phizz.Dom.RegisterWindowResizeEvent(function() {Phizz.Blackout.Render();});
	},
	
	Show: function(hexColor) {
		if (this.objBlackout == null) this.Create(hexColor);
		if (this.N == 0) {
			if (Phizz.Browser.IsIE6) Phizz.Tools.HideIE6Foreground();
			this.objBlackout.style.visibility = "visible";
			this.Render();
		}
		this.N++;
	},
	
	Render: function() {
		if (this.objBlackout != null && this.objBlackout.style.visibility == "visible") {
			this.objBlackout.style.height = "1px";
			this.objBlackout.style.height = Phizz.Dom.GetDocumentSize().height + "px";
		}
	},

	Hide: function() {
		if (this.N == 1) {
			this.objBlackout.style.visibility = "hidden";
			if (Phizz.Browser.IsIE6) Phizz.Tools.ShowIE6Foreground();
		}
		this.N--;
	}
};
