﻿String.prototype.matches = function(v) { var r=new RegExp(v,"gm"); return (r.test(this)); r=null; };

var support = {

    addStyleRule : function(selector,styles,index)
    {
        index=(!index)?0:index;
        ss=document.styleSheets[index];
        
        if(ss.insertRule)
        {
            ss.insertRule(selector+' {'+styles+'}',ss.cssRules.length);
        }
        else if(ss.addRule)
        {
            ss.addRule(selector,styles);
        }
        else return false;
        
        return true;
    },

    getReal : function(el,type,value)
    {
        var t=el;
        while((t!=null)&&(t.tagName.toLowerCase()!="body"))
        {
            if((t[type]==value)||(t[type].indexOf(value)>-1))
            {
                el=t;return el;
            }
            t=t.parentNode;
        };
        return el;
    },
    
    getElsByAttVal : function(o, t, a, v)
    {
        a = (a=="class") ? "className" : a;
        o = (o) ? o : document;
        
        var rtn=[];
        var els = o.getElementsByTagName(t);
        
        for(var i=0;i<els.length;i++)
        {
            var el = els[i];
            
            if ((el[a]==v) || (el.getAttribute(a)==v) || (new String(el[a]).matches("(^|\\s)"+v+"(\\s|$)")))
            {
                rtn[rtn.length]=el; 
            }
        }
        
        return rtn;
    },
    
    createEl : function(p, n, a, s, t, h)
    {
        var e = document.createElement(n);
        if (a)
        {
            for (k in a)
            {
                if (k=="class") { e.className = a[k]; }
                else if	(k=="id") { e.id = a[k]; }
                else { e[k]=a[k]; }
            }
        }
        if (s)
        {
            for (k in s) { e.style[k] = s[k]; }
        }
        if (t) { e.appendChild(document.createTextNode(t)); }
        if (h) { e.innerHTML = h; }
        if (p) { p.appendChild(e); }
		
        return e;
    }
}

var DomLoaded =
{
    onload: [],
    loaded: function()
    {
	    if (arguments.callee.done) return;
	    arguments.callee.done = true;
	    for (i = 0;i < DomLoaded.onload.length;i++) DomLoaded.onload[i]();
    },
    load: function(fireThis)
    {
	    this.onload.push(fireThis);
	    if (document.addEventListener) 
		    document.addEventListener("DOMContentLoaded", DomLoaded.loaded, null);
	    if (/KHTML|WebKit/i.test(navigator.userAgent))
	    { 
		    var _timer = setInterval(function()
		    {
			    if (/loaded|complete/.test(document.readyState))
			    {
				    clearInterval(_timer);
				    delete _timer;
				    DomLoaded.loaded();
			    }
		    }, 10);
	    }
	    /*@cc_on @*/
	    /*@if (@_win32)
	    var proto = "src='javascript:void(0)'";
	    if (location.protocol == "https:") proto = "src=//0";
	    document.write("<scr"+"ipt id=__ie_onload defer " + proto + "><\/scr"+"ipt>");
	    var script = document.getElementById("__ie_onload");
	    script.onreadystatechange = function() {
	        if (this.readyState == "complete") {
	            DomLoaded.loaded();
	        }
	    };
	    /*@end @*/
       window.onload = DomLoaded.loaded;
    }
};

function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
    	window.onload = func;
	} 
	else 
	{
		window.onload = function()
		{
		    oldonload();
		    func();
        }
	}
}