(function() {
    var userArticles = window.userArticles = function() {
        return new userArticles.prototype.init();
    };

    if (!window.userArticles) {
        window.userArticles = userArticles;
    }

    userArticles.proto = userArticles.prototype = {
        init: function() {
            return new userArticles();
        }
    }
    userArticles.getQSValue = function(q) {
        if (!qsObj) { loadCurrentQS(); }
        return qsObj[q];
    }
    userArticles.SetTextAutoComplete = function(text) {
        text = text.replace("+", "\\+");
        text = text.replace("*", "\\*");
        return text;
    }
    userArticles.setCookie = function(name, value, expires, path, domain, secure) {
        var today = new Date();
        today.setTime(today.getTime());

        if (expires) {
            expires = expires * 1000 * 60 * 60 * 24;
        }
        var expires_date = new Date(today.getTime() + (expires));

        document.cookie = name + "=" + escape(value) +
		((expires) ? ";expires=" + expires_date.toGMTString() : "") +
		((path) ? ";path=" + path : "") +
		((domain) ? ";domain=" + domain : "") +
		((secure) ? ";secure" : "");
    }
    userArticles.getCookie = function(name) {
        var dc = document.cookie;
        if (dc.indexOf(name) != -1 && dc.substr(dc.indexOf(name) + name.length, 1) == '=') {
            if (dc.indexOf(";", dc.indexOf(name)) != -1) {
                var EndOfCookie = dc.indexOf(";", dc.indexOf(name));
                var CookieName = dc.indexOf(name) + name.length + 1;
                var CookieValue = EndOfCookie - CookieName;
                return dc.substr(dc.indexOf(name) + name.length + 1, CookieValue)
            }
            else {
                return dc.substr(dc.indexOf(name) + name.length + 1, dc.length)
            }
        }
    }
    userArticles.startLoader = function(divName) {
        var loader = $("#loader" + divName)[0];
        var div = $("#" + divName);
        if (!loader) {
            loader = document.createElement("div");
            loader.id = "loader" + divName;
            loader.className = "loader";
            loader.innerHTML = "<img src='CssImages/loading1.gif' class='imgloader' />";
            div.before(loader);
        }
        if (div.length > 0) {
            loader.style.width = div[0].offsetWidth + "px";
            loader.style.height = parseInt(div[0].offsetHeight) + "px";
            $(loader).show();
        }
    }
    userArticles.inputOut = function(fld, value) {
        if (fld.value == '') {
            fld.value = value;
        }
    }
    userArticles.inputIn = function(fld, value) {
        if (fld.value == value) {
            fld.value = '';
        };
    }
    userArticles.showPrompt = function(title, divname, pname, width, height, opacityValue, data) {
        if (data != null) {
            $("#" + pname).html(data);
        }
        $("#" + divname).dialog({
            height: height,
            width: width,
            modal: true,
            draggable: false,
            resizable: false,
            title: title,
            overlay: { opacity: opacityValue, background: "#dfdfdf" }
        });
    }
    var qsObj;
    function loadCurrentQS() {
        qsObj = new Object()
        var url = location.href;
        if (url.indexOf("?") > -1) {
            var strParams = url.split("?")[1].split("&");
            for (var i = 0; i < strParams.length; i++) {
                var qsParam = strParams[i].split("=");
                qsObj[qsParam[0]] = qsParam[1];
            }
        }
    }
    userArticles.validation = {
        isEmpty: function(txt) {
            if (txt.value.replace(/ /g, '') == '') {
                txt.style.borderColor = 'red';
                return true;
            }
            else {
                txt.style.borderColor = 'green';
                return false;
            }
        },
        isValueEmpty: function(Value) {
            if (Value.replace(/ /g, '') == '') {
                return true;
            }
            else {
                return false;
            }
        },
        isHaveHTML: function(txt) {
            var InvalidHTML = new Array();
            InvalidHTML[0] = "<font";
            InvalidHTML[1] = "font-size";
            InvalidHTML[2] = "color:";
            InvalidHTML[3] = "line-height:";
            InvalidHTML[4] = "class=";
            InvalidHTML[5] = "color=";
            InvalidHTML[6] = "line-height=";
            InvalidHTML[7] = "face=";
            InvalidHTML[8] = "size=";
            var haveHTML = false;
            for (var i = 0; i < InvalidHTML.length; i++) {
                if (txt.indexOf(InvalidHTML[i]) >= 0) {
                    haveHTML = true;
                }
            }
            return haveHTML;
        },
        validateFont: function() {
            $('font[size]').each(function() {
                var fontSize = this.size;
                $(this).attr("size", "");
            });
            $('font[face]').each(function() {
                $(this).attr('face', '');
            });
            $('font[color]').each(function() {
                $(this).attr('color', '');
            });
            $('lang').each(function() {
                $(this).attr('lang', '');
            });
            var cssObj = {
                'font-weight': '',
                'font-size': '',
                'face': '',
                'color': '',
                'lang': ''
            }
            $('font').css(cssObj);
            $('.artical span').css(cssObj);
            $('.artical p').css(cssObj);
        },
        isKeywordsEmpty: function(txt) {
            var Keywordsval = txt.value.replace(/,/g, '').replace(/ /g, '');
            if (Keywordsval == '') {
                txt.style.borderColor = 'red';
                return true;
            }
            else {
                txt.style.borderColor = 'green';
                return false;
            }
        },
        istxtSearchEmpty: function(txt, defaultvalue) {
            // alert(defaultvalue);
            var txtSearchval = $('#' + txt).val().replace(defaultvalue, '').replace(/ /g, '');
            //alert(txtSearchval);
            if (txtSearchval == '') {
                document.getElementById(txt).style.borderColor = 'red';
                return true;
            }
            else {
                document.getElementById(txt).style.borderColor = 'green';
                return false;
            }
        },
        isSelected: function(sel) {
            if (sel.selectedIndex > 0) {
                sel.style.borderColor = 'green';
                return true;
            }
            else {
                sel.style.borderColor = 'red';
                return false;
            }
        },
        isNumeric: function(txt) {
            var num = txt.value;
            num = num * 1;
            if (num == num) {
                txt.style.borderColor = 'green';
                return true;
            }
            else {
                txt.style.borderColor = 'red';
                return false;
            };
        },
        ValidateWordLength: function(text) {
            text = text.toString().toLowerCase().replace(/&lt;br&gt/g, ' ').replace(/<br>/g, ' ').replace(/<\/p>/g, ' ').replace(/<p>/g, ' ').replace(/&nbsp;/g, ' ').replace(/ /g, ' ');
            var text_array = text.split(" ");
            var validLength = true;
            $(text_array).each(function() {
                if ($(this).length > 50) {
                    validLength = false;
                }
            })
            return validLength;
        },
        validateEmails: function(field) {
            var delimiter = ',';
            var filter = /([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+>?$/;
            var error = true;

            // Create an array by splitting the field along the delimiter
            var aEmails = field.value.split(';');

            // For each of the emails
            for (index = 0; index < aEmails.length; index++) {
                // Trim spaces from the ends
                aEmails[index] = (aEmails[index].replace(/^\s+/, '')).replace(/\s+$/, '');
                // Check whether an email is present
                if (aEmails[index] != '' && aEmails[index].search(filter) == -1)
                    error = false;
            }
            if (error == true) {
                field.style.borderColor = 'green';
                return true;
            }
            else {
                field.style.borderColor = 'red';
                return false;
            }
        }
    }

    String.prototype.format = function() {
        var str = this;
        for (var i = 0; i < arguments.length; i++) {
            var re = new RegExp('\\{' + (i) + '\\}', 'gm');
            str = str.replace(re, arguments[i]);
        }
        return str;
    }



})();





