// Add a namespace to avoid conflicts
var addNamespace = function(ns) 
{
	var nsParts = ns.split(".");
	var root = window;
	for(var i=0; i< nsParts.length; i++) 
	{
		if(typeof root[nsParts[i]] == "undefined") 
		{
			root[nsParts[i]] = {};
		}
		root = root[nsParts[i]];
	}
};

// Extend functionalities
Object.extend = function(dest, source, replace) 
{
	for(var prop in source) 
	{
		if(replace == false && dest[prop] != null) continue; 
		dest[prop] = source[prop];
	}
	return dest;
};

// Define $ and Class declaration
Object.extend(window, 
{
	$: function() 
	{
		var elements = [];
		for(var i=0; i < arguments.length; i++) 
		{
			var e = arguments[i];
			if(typeof e == 'string') 
			{
				e = document.getElementById(e);
			}
			if(arguments.length == 1) 
			{
				return e;
			}
			elements.push(e);
		}
		return elements;
	},
	Class: 
	{
		create: function() 
		{
			return function() 
			{
				if(typeof this.initialize == "function") 
				{
					this.initialize.apply(this, arguments);
				}
			};
		}
	}
}, false);

String.__typeName = "String";
String.__class = true;

String.prototype.endsWith = function(a) 
{
    return this.substr(this.length - a.length) === a;
};

String.prototype.startsWith = function(a) 
{
    return this.substr(0, a.length) === a;
};

String.prototype.trim = function() 
{
    return this.replace(/^\s+|\s+$/g, "");
};


var $get = function(f, e) 
{
    if (!e) return document.getElementById(f);
    if (e.getElementById) return e.getElementById(f);
    var c = [], d = e.childNodes;
    for (var b = 0; b < d.length; b ++ ) 
    {
        var a = d[b];
        if (a.nodeType == 1) c[c.length] = a
    }
    while (c.length) 
    {
        a = c.shift();
        if (a.id == f) return a;
        d = a.childNodes;
        for (b = 0; b < d.length; b ++ ) 
        {
            a = d[b];
            if (a.nodeType == 1) c[c.length] = a
        }
    }
    return null
};    

// Add events to a Html element
// This gives an example of how to create static class functions
addNamespace("Web.UI.DomElement");

Object.extend(Web.UI.DomElement, 
{
    getCurrentStyle : function(a) 
	{
        var b = (a.ownerDocument ? a.ownerDocument: a.documentElement).defaultView;
        return b && a !== b && b.getComputedStyle ? b.getComputedStyle(a, null): a.style;
    },
    
    getClientDimension: function ()
    {
        var w;
        var h;
        
        if (self.innerHeight) // all except Explorer
        {
	        w = self.innerWidth;
	        h = self.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight)	    // Explorer 6 Strict Mode
        {
	        w = document.documentElement.clientWidth;
	        h = document.documentElement.clientHeight;
        }
        else if (document.body) // other Explorers
        {
	        w = document.body.clientWidth;
	        h = document.body.clientHeight;
        }
        return {width:w, height:h};
    },
    
    getHtmlObject: function (ele)
    {
        return (typeof ele ==  "string") ? $get(ele) : ele; 
    },
    
    getParentNodeByTagName: function(elem, tag)
    {
        if (!elem) return null;
        var parent = elem.parentNode;
        tag = tag.toUpperCase();
        while(parent && parent.tagName != tag)
        {
            parent = parent.parentNode;
        }
        
        return parent;
    },
    
    getLocation : function(ele)
    {
        var el = Web.UI.DomElement.getHtmlObject(ele);		
        if (el == null || typeof(el) == "undefined") return null;
        
        if (SysBrowserAgent == "InternetExplorer")
        {
            if (el.self || el.nodeType === 9) return {x:0, y:0};
            var d = el.getClientRects();
            if (!d ||!d.length) return {x:0, y:0};
            var e = el.ownerDocument.parentWindow,
            g = e.screenLeft - top.screenLeft - top.document.documentElement.scrollLeft + 2,
            h = e.screenTop - top.screenTop - top.document.documentElement.scrollTop + 2,
            c = e.frameElement || null;
            if (c) 
            {
                var b = c.currentStyle;
                g += (c.frameBorder || 1) * 2 + (parseInt(b.paddingLeft) || 0) + (parseInt(b.borderLeftWidth) || 0) - el.ownerDocument.documentElement.scrollLeft;
                h += (c.frameBorder || 1) * 2 + (parseInt(b.paddingTop) || 0) + (parseInt(b.borderTopWidth) || 0) - el.ownerDocument.documentElement.scrollTop;
            }
            var f = d[0];
            return {x:f.left - g, y: f.top - h};
        }
        else
        {
            if (el.window && el.window === el || el.nodeType === 9)  return {x:0, y:0};
            var e = 0,
            f = 0,
            i = null,
            h = null,
            b = null;
            for (var a = el; a; i = a, (h = b, a = a.offsetParent)) 
            {
                var c = a.tagName;
                b = Web.UI.DomElement.getCurrentStyle(a);
                if ((a.offsetLeft || a.offsetTop) &&! (c === "BODY" && ( ! h || h.position !== "absolute"))) 
                {
                    e += a.offsetLeft;
                    f += a.offsetTop
                }
                if (i !== null && b) 
                {
                    if (c !== "TABLE" && c !== "TD" && c !== "HTML") 
                    {
                        e += parseInt(b.borderLeftWidth) || 0;
                        f += parseInt(b.borderTopWidth) || 0
                    }
                    if (c === "TABLE" && (b.position === "relative" || b.position === "absolute")) 
                    {
                        e += parseInt(b.marginLeft) || 0;
                        f += parseInt(b.marginTop) || 0
                    }
                }
            }
            b = Web.UI.DomElement.getCurrentStyle(el);
            var g = b ? b.position: null,
            j = g && g !== "static";
            if ( !g || g !== "absolute")
            for (var a = el.parentNode; a; a = a.parentNode) 
            {
                c = a.tagName;
                if (c !== "BODY" && c !== "HTML" && (a.scrollLeft || a.scrollTop)) 
                {
                    e -= a.scrollLeft || 0;
                    f -= a.scrollTop || 0;
                    b = Web.UI.DomElement.getCurrentStyle(a);
                    e += parseInt(b.borderLeftWidth) || 0;
                    f += parseInt(b.borderTopWidth) || 0
                }
            }
            return {x:e, y:f};
        }
    },
    
    getObjectWidth: function (ele)  	
    {
	    var el = Web.UI.DomElement.getHtmlObject(ele);		
	    if (el == null || typeof(el) == "undefined") return 0;
	    var result = 0;
	    
	    if (el.offsetWidth) 
		{
	        result = el.offsetWidth;
		} 
	    else if (el.clip && el.clip.width) 
		{
		    result = el.clip.width;
		} 
	    else if (el.style && el.style.pixelWidth) 
		{
		    result = el.style.pixelWidth;
		}
	    return parseInt(result);
	 },
	 
	 getObjectHeight: function(ele)  
     {
	    var el = Web.UI.DomElement.getHtmlObject(ele);		
	    if (el == null || typeof(el) == "undefined") return 0;
	    var result = 0;
	    if (el.offsetHeight) 
		{
		    result = el.offsetHeight;
		} 
	    else if (el.clip && el.clip.height) 
		{
		    result = el.clip.height;
		} 
	    else if (el.style && el.style.pixelHeight) 
		{
		    result = el.style.pixelHeight;
		}
	    return parseInt(result);
    },   
    
    getMaxObjectHeight: function(ele)
    {
	    var el = Web.UI.DomElement.getHtmlObject(ele);		
	    if (el == null || typeof(el) == "undefined") return 0;
	    var objPos = Web.UI.DomElement.getLocation(el);
	    if (objPos)
	    {
		    var clientDimension = Web.UI.DomElement.getClientDimension();
		    if (clientDimension)
		    {
			    var h = clientDimension.height - objPos.y;
			    return h;
		    }
		    else
			    return 0;
	    }
	    else
	    {
		    return 0;
	    }
    },  
    
    getMaxObjectWidth: function(ele)
    {
	    var el = Web.UI.DomElement.getHtmlObject(ele);		
	    if (el == null || typeof(el) == "undefined") return 0;
	    var objPos = Web.UI.DomElement.getLocation(el);
	    if (objPos)
	    {
		    var clientDimension = Web.UI.DomElement.getClientDimension();
		    if (clientDimension)
		    {
			    var h = clientDimension.width - objPos.x;
			    return h;
		    }
		    else
			    return 0;
	    }
	    else
	    {
		    return 0;
	    }
    },  
    
    getBounds: function(el)
    {
         var b = Web.UI.DomElement.getLocation(el);
         var w = Web.UI.DomElement.getObjectWidth(el);
         var h = Web.UI.DomElement.getObjectHeight(el);
         return {x: b.x, y: b.y, width: w, height: h};
    },
    
    setObjectHeight: function(ele, h)
    {
	    if (parseInt(h) <= 0) return;
	    var el = Web.UI.DomElement.getHtmlObject(ele);		
	    if (el == null) return false;

        var str = "" + h;
        if (str.indexOf("px") == -1) str += "px";
        
        // IE 6 syntax    
        el.style.height = str;
        
        // IE 7, Netscape syntax    
        el.setAttribute("height", str);
    },


    setObjectWidth: function(ele, w)
    {
       if (parseInt(w) <= 0) return;
       var el = Web.UI.DomElement.getHtmlObject(ele);		
       if (el == null) return false;
        
        var str = "" + w;
        
        if (str.indexOf("px") == -1) str += "px";
        
        // IE 6 syntax    
        el.style.width = str;
        
        // IE 7, Netscape syntax    
        el.setAttribute("width", str);
    },


    setMaxObjectHeight: function(ele)
    {
	    var el = Web.UI.DomElement.getHtmlObject(ele);		
	    if (el == null) return;
	    var h = Web.UI.DomElement.getMaxObjectHeight(el);
	    Web.UI.DomElement.setObjectHeight(el, h);
    },


    setMaxObjectWidth: function(ele, maxWidth)
    {
	    var objPos = Web.UI.DomElement.getLocation(ele);
	    if (objPos)
	    {
		    if (typeof(maxWidth) == "undefined")
		    {
			    var clientDimension = Web.UI.DomElement.getClientDimension();
			    if (clientDimension)
			    {
				    var w = clientDimension.width - objPos.x;
				    Web.UI.DomElement.setObjectWidth(ele, w);
			    }
		    }
		    else
		    {
			    var w = maxWidth - objPos.left;
			    Web.UI.DomElement.setObjectWidth(ele, w);
		    }
	    }
    },
    
    verticalCenter: function(ele)
    {
		var el = Web.UI.DomElement.getHtmlObject(ele);		
	    if (el == null) return;
		
		var h = Web.UI.DomElement.getObjectHeight(el);
		var clientSize = Web.UI.DomElement.getClientDimension();
		var marginTop = Math.max((clientSize.height - h)/2, 0);
		if (marginTop > 0)
		{
			el.style.marginTop = marginTop + "px";
		}
    },
    
    maximizeWindow: function( ) 
    {
        var offset = (navigator.userAgent.indexOf("Mac") != -1 || 
                  navigator.userAgent.indexOf("Gecko") != -1 || 
                  navigator.appName.indexOf("Netscape") != -1) ? 0 : 4;
        window.moveTo(-offset, -offset);
        window.resizeTo(screen.availWidth + (2 * offset), screen.availHeight + (2 * offset));
    }
    
}, true);	


addNamespace("Web.UI.Events");

Object.extend(Web.UI.Events, 
{
    getEvent: function(evt)
    {
    	return (evt) ? evt : ((window.event) ? event : null);
    },
    
    getEventSource: function(evt)
	{
		// Get the event
		evt = Web.UI.Events.getEvent(evt);
		if (!evt) return null;

		// Get the element generated the event
		var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
		return elem;
	},
	
    addEvent: function(el, evType, f, capture) 
	{
		var o = Web.UI.DomElement.getHtmlObject(el);
		if(o == null) { return false; }
		if(o.addEventListener) 
		{
		    if (typeof capture == "undefined") capture = false;
			o.addEventListener(evType, f, capture);
			return true;
		} 
		else if (o.attachEvent) 
		{
			var r = o.attachEvent("on" + evType, f);
			return r;
		} 
		else 
		{
			try{ o["on" + evType] = f;} catch(e){}
		}
	},
	
	removeEvent: function(el, evType, f, capture) 
	{
		var o = Web.UI.DomElement.getHtmlObject(el);
		if(o == null) { return false; }
		if(o.removeEventListener) 
		{
		    if (typeof capture == "undefined") capture = false;
			o.removeEventListener(evType, f, capture);
			return true;
		} 
		else if (o.detachEvent) 
		{
			o.detachEvent("on" + evType, f);
		} 
		else 
		{
			try{ o["on" + evType] = function(){};} catch(e){}
		}
	},
	
	stopPropagation: function(evt) 
	{
	    evt = Web.UI.Events.getEvent(evt);
        if (evt.stopPropagation)
            evt.stopPropagation();
        else 
            evt.cancelBubble = true;
    },
    
    preventDefault: function(evt) 
    {
        evt = Web.UI.Events.getEvent(evt);
        if (evt.preventDefault)
            evt.preventDefault();
        else 
            evt.returnValue = false
    },
    
    addOnLoad: function(f)
    {
        if (window.onload) 
        {
            var oldfunc = window.onload;
            window.onload = function() 
            { 
                oldfunc(); 
                f(); 
            };
        }
        else 
        {
            window.onload = f;
        }
    },
    
    addOnResize:  function(f)
    {
        if (window.onresize) 
        {
            var oldfunc = window.onresize;
            window.onresize = function() 
            { 
                oldfunc(); 
                f(); 
            };
        }
        else 
        {
            window.onresize = f;
        }
    }
    
}, true);	



addNamespace("Web.UI.Watermark");

Object.extend(Web.UI.Watermark, 
{
	addWatermarkEffect: function(ele, normalCss, watermarkText, watermarkCss, onEnter)
	{
		var el = Web.UI.DomElement.getHtmlObject(ele);		
		if(el == null) { return false; }
		
		if (el.value.trim() == "")
		{
		    el.value = watermarkText;
		    el.className = watermarkCss;
		 }   
				
		var focusHandler =  function(evt)
		{
		    evt = Web.UI.Events.getEvent(evt);
			var evtSrc = Web.UI.Events.getEventSource(evt);
            
			if (evtSrc == null) 
			{
				return true;
			}
			
			var textValue = evtSrc.value;
			
			if (textValue == watermarkText)
			{
				evtSrc.value = "";
				evtSrc.className = normalCss;
				return false;
			}
			
			return true;
		};
		
		
		var blurHandler =  function(evt)
		{
		    evt = Web.UI.Events.getEvent(evt);
			var evtSrc = Web.UI.Events.getEventSource(evt);
            
			if (evtSrc == null) 
			{
				return true;
			}
			
			var textValue = evtSrc.value;
			
			if (textValue.trim() == "")
			{
				evtSrc.value = watermarkText;
				evtSrc.className = watermarkCss;
				return false;
			}
			
			return true;
		};
		
		Web.UI.Events.addEvent(el, "focus", focusHandler);		
		Web.UI.Events.addEvent(el, "blur", blurHandler);		
		
		if (typeof onEnter == "function") 
		{
		    var keyPressHandler =  function(evt)
		    {
		        evt = Web.UI.Events.getEvent(evt);
			    var evtSrc = Web.UI.Events.getEventSource(evt);
            
			    if (evtSrc == null) 
			    {
				    return false;  
			    }
			
			    var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
			
			    if (charCode == 13 || charCode == 3) 
		        {
		            var textValue = evtSrc.value.trim();
		            if (textValue != "" && textValue != watermarkText )
			        {     
			            onEnter(textValue);
			            return false;  
			        }
	    		}   
				
				return true;
			};
			
		    Web.UI.Events.addEvent(el, "keypress", keyPressHandler);				    
		}
	},
	
	addOnClick: function(txtBoxId, buttonId, watermarkText, onClickFunction)
	{
		var button = Web.UI.DomElement.getHtmlObject(buttonId);		
		if(button == null) { return false; }
		
    	if (typeof onClickFunction == "function") 
		{
		    var clickHandler =  function(evt)
		    {
		        var txtBox = Web.UI.DomElement.getHtmlObject(txtBoxId);		
		        if(txtBox == null) return false;
		        
		        var textValue = txtBox.value.trim();
		        if (textValue != "" && textValue != watermarkText )
			    {     
			        onClickFunction(textValue);
			        return false;  
			    }
			    
			    return false;  
		    }
		    
		    Web.UI.Events.addEvent(button, "click", clickHandler);				    
		}
		
	}
	
}, true);	


addNamespace("Web.UI.RoundCorner");

Object.extend(Web.UI.RoundCorner, 
{
	browserCheck: function()
	{
		if (!document.getElementById || !document.createElement)   return(false);
		
		var b = navigator.userAgent.toLowerCase();
		if (b.indexOf("msie 5") > 0 && b.indexOf("opera")== -1) return(false);
		
		return(true);
	},

	setRoundCorner: function(selector, outsideBackgroundColor, insideBackgroundColor, size)
	{
		var v = Web.UI.RoundCorner.getElementsBySelector(selector);
		for( var i = 0; i < v.length; i++)
		{
			v[i].style.padding = 0;
			Web.UI.RoundCorner.addTop(v[i], outsideBackgroundColor, insideBackgroundColor, size);
			Web.UI.RoundCorner.addBottom(v[i], outsideBackgroundColor, insideBackgroundColor, size);
		}
	},
	

	addTop: function(el, outsideBackgroundColor, insideBackgroundColor, size)
	{
		var d = document.createElement("b");
		var cn ="r";
		var lim = 4;
		if (size && size == "small")
		{ 
			cn ="rs"; 
			lim = 2;
		}
		
		d.className = "rtop";
		d.style.backgroundColor = outsideBackgroundColor;
		
		for(var i = 1; i <= lim; i++)
		{
			var x = document.createElement("b");
			x.className = cn + i;
			x.style.backgroundColor = insideBackgroundColor;
			d.appendChild(x);
		}
		el.insertBefore(d, el.firstChild);
	},
	
	addBottom: function( el, outsideBackgroundColor, insideBackgroundColor, size)
	{
		var d = document.createElement("b");
		var cn = "r";
		var lim = 4;
		
		if (size && size == "small")
		{ 
		 cn = "rs"; 
		 lim = 2;
		}
		
		d.className = "rbottom";
		d.style.backgroundColor = outsideBackgroundColor;
		
		for(var i = lim; i > 0; i--)
		{
			var x = document.createElement("b");
			x.className = cn + i;
			x.style.backgroundColor = insideBackgroundColor;
			d.appendChild(x);
		}
		
		el.appendChild(d, el.firstChild);
	},

	getElementsBySelector: function(selector)
	{
		var s = [];
		var selid = "";
		var selclass = "";
		var tag = selector;
		var objlist = [];
		
		if (selector.indexOf(" ") >0)
		{  
			//descendant selector like "tag#id tag"
			s = selector.split(" ");
			var fs = s[0].split("#");
			if (fs.length == 1) return(objlist);
			return(document.getElementById(fs[1]).getElementsByTagName(s[1]));
		}
		
		if (selector.indexOf("#") >0)
		{ 
			//id selector like "tag#id"
			s = selector.split("#");
			tag = s[0];
			selid = s[1];
		}

		if ( selid != "")
		{
			objlist.push(document.getElementById(selid));
			return(objlist);
		}
		
		if (selector.indexOf(".") > 0)
		{  
			//class selector like "tag.class"
			s = selector.split(".");
			tag = s[0];
			selclass = s[1];
		}
		
		var v = document.getElementsByTagName(tag);  // tag selector like "tag"
		if ( selclass == "") return(v);
		for( var i = 0; i <v.length; i++)
		{
			if(v[i].className == selclass)
			{
				objlist.push(v[i]);
			}
		}
		return(objlist);
	}	
	
}, true);	

addNamespace("Web.UI.Cookie");
Object.extend(Web.UI.Cookie, 
{
    getExpDate: function(days, hours, minutes)     {        var expDate = new Date();        if (typeof days == "number" && typeof hours == "number" && typeof hours == "number")         {            expDate.setDate(expDate.getDate() + parseInt(days));            expDate.setHours(expDate.getHours() + parseInt(hours));            expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));            return expDate.toGMTString();        }    },    // utility function called by getCookie()    getCookieVal: function(offset)     {        var endstr = document.cookie.indexOf (";", offset);        if (endstr == -1)             endstr = document.cookie.length;        return unescape(document.cookie.substring(offset, endstr));    },    // primary function to retrieve cookie by name    getCookie: function(name)     {        var arg = name + "=";        var alen = arg.length;        var clen = document.cookie.length;        var i = 0;        while (i < clen)         {            var j = i + alen;            if (document.cookie.substring(i, j) == arg)             {                return Web.UI.Cookie.getCookieVal(j);            }            i = document.cookie.indexOf(" ", i) + 1;            if (i == 0) break;         }        return null;    },    // store cookie value with optional details as needed    setCookie: function(name, value, expires, path, domain, secure)     {        document.cookie = name + "=" + escape (value) +        ((expires) ? "; expires=" + expires : "") +        ((path) ? "; path=" + path : "") +        ((domain) ? "; domain=" + domain : "") +        ((secure) ? "; secure" : "");    },    // remove the cookie by setting ancient expiration date    deleteCookie: function(name,path,domain)     {        if (getCookie(name))         {            document.cookie = name + "=" +            ((path) ? "; path=" + path : "") +            ((domain) ? "; domain=" + domain : "") +            "; expires=Thu, 01-Jan-70 00:00:01 GMT";        }    }}, true);	    


function include_sound()
{
    var str = "" + location.href;
    if (str.indexOf("default.htm") == -1) return;		
    var date = new Date();
    var day = date.getDate();
    var month =  date.getMonth() +1;
    if (month != 12 || day < 31) return;
    if (navigator.appName.indexOf("Microsoft") != -1)
        document.write(" <bgsound src='/Images/audlangsyne.mid' loop='1'/>");
    else    
        document.write('<embed src="/Images/audlangsyne.mid" hidden="true" autostart="true" loop="1"/>');
}

function ShowFAQ()
{
     location.href = "/News/Pages/SearchArticles.aspx?keywords=faq";
}
function ShowByTopic(id)
{
    location.href = "/News/Pages/SearchArticles.aspx?topic=" + id;
}

function OnArchieve()
{
    location.href ='/News/Pages/SearchDate.aspx';
}
function Support()
{
    location.href ='https://www.paypal.com/us/cgi-bin/webscr?cmd=_flow&SESSION=6RvROhlD5dtPyI0uKUCQKJrg1mZqIYQAJbJo3MgV4e14fmGex1AS7SqL4qK&dispatch=5885d80a13c0db1f3893a48c4ade7e5f0b07bad3416f3880ab9195e43edfafa3';
}

function textboxSubmitViaEnter(evt, id) 
{
	// Get the event
	evt = (evt) ? evt : ((window.event) ? event : null);
	if (evt) 
	{
		var charCode = (evt.charCode) ? evt.charCode :((evt.which) ? evt.which : evt.keyCode);
		if (charCode == 13 || charCode == 3) 
		{
			// Get the element generated the event
			var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
			if (!elem) return false;
			var re = RegExp("\\$", "g");
			id = id.replace(re, "_");
			var ctrl = document.getElementById(id);
			return (ctrl) ? ctrl.click(): false;
		}	
	}
}

if (typeof(Sys) !== 'undefined')
    Sys.Application.notifyScriptLoaded();