/*
 *Document.Model.Remake
 *Please see readme.html in this folder for more information
 */
 if(!Array.prototype.forEach){
  Array.prototype.forEach=function(fun){
    var len=this.length;
    if(typeof fun!="function")
      throw new TypeError();
    var thisp=arguments[1];
    for (var i=0;i<len;i++){
      if (i in this)
        fun.call(thisp,this[i],i,this);
    }
  }
}
var dmr = {
	version : '0.6b',
	buildDate : '17/12/2007',
	author : 'Diego Martins da Rocha',
	email : 'diego.rocha.br@gmail.com',
	
	id : function(v){
		return (document.getElementById(v));
	},
	tag : function(v){
		return (document.getElementsByTagName(v));
	},
	name : function(v){
		return (document.getElementsByName(v));
	},
	classe : function(v){
		if(!document.getElementsByClassName){
			document.getElementsByClassName=function(searchClass,node,tag){
				var classElements=new Array();
				if(node==null)
					node=document;
				if(tag==null )
					tag='*';
				var els=node.getElementsByTagName(tag);
				var elsLen=els.length;
				var pattern=new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
				for(i=0,j=0;i<elsLen;i++){
					if(pattern.test(els[i].className)){
						classElements[j]=els[i];
						j++;
					}
				}
				return classElements;
			}
		}
		return document.getElementsByClassName(v);
	},
	trim : function(v){
		return v.replace(/^\s*/, "").replace(/\s*$/, "");
	},
	browser : {
		ie : function(){
			if (navigator.appVersion.indexOf("MSIE")!=-1){
				var v=navigator.userAgent.indexOf("MSIE")+5;
				return parseInt(navigator.userAgent.charAt(v));
			}
			return false;
		},
		ff : function(){
			if(navigator.userAgent.indexOf("Firefox")!=-1){
				var v=navigator.userAgent.indexOf("Firefox")+8;
				return parseInt(navigator.userAgent.charAt(v));
			}
			return false;
		},
		op : function(){
			if(navigator.userAgent.indexOf("Opera")!=-1){
				var v=navigator.userAgent.indexOf("Opera")+6;
				return parseInt(navigator.userAgent.charAt(v));
			}
			return false;
		},
		sf : function(){
			if(navigator.userAgent.indexOf('Safari') != -1){
				var v=navigator.userAgent.indexOf('Version')+8;
				return parseInt(navigator.userAgent.charAt(v));
			}
			return false;
		}
	},
	addEvent : function(obj,evt,fn){
		if(!obj){
			obj = dmr.id(obj);
		};
		if(obj.addEventListener){
			obj.addEventListener(evt, fn, false);
		}else if(obj.attachEvent){
			if(evt == 'DOMContentLoaded'){
				var onContent = function(f){
					var a,b=navigator.userAgent,d=document,w=window,
					c="__onContent__",e="addEventListener",o="opera",r="readyState",
					s="<scr".concat("ipt defer src='//:' on",r,"change='if(this.",r,"==\"complete\"){this.parentNode.removeChild(this);",c,"()}'></scr","ipt>");
					w[c]=(function(o){return function(){w[c]=function(){};for(a=arguments.callee;!a.done;a.done=1)f(o?o():o)}})(w[c]);
					if(d[e])d[e]("DOMContentLoaded",w[c],false);
					if(/WebKit|Khtml/i.test(b)||(w[o]&&parseInt(w[o].version())<9))
					(function(){/loaded|complete/.test(d[r])?w[c]():setTimeout(arguments.callee,1)})();
					else if(/MSIE/i.test(b))d.write(s);
				}
				onContent(fn);
			}else{
				obj.attachEvent('on'+evt,fn);
			}
		}
	},
	popup : function(pg,w,h){
		if(typeof w == 'undefined'){
			w = screen.width/2;
		}
		if(typeof h == 'undefined'){
			h = screen.height/2;
		}
		return window.open(pg,'_blank','height=' + h + ',width=' + w + ', top='+((screen.height/2)-(h/2))+', left='+((screen.width/2)-(w/2))+',location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=0').focus();
	},
	confirmURL : function(v,msg){
		if(typeof msg == 'undefined')
			msg = 'Ir para '+v;
		if (confirm(msg)){
			document.location = v;
			return true;
		}else{
			return false;
		}
	},
	utf8 : {
		encode: function(s){
			for(var a, b, c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;)
				s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i];
			return s.join("");
		},
		decode: function(s){
			for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
				((a = s[i][c](0)) & 0x80) &&
				(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
				o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
			);
			return s.join("");
		}
	},
	htmlentities : function(v){
		var i,carac,letra,novo='';
		for(i=0;i<v.length;i++){
			carac = v[i].charCodeAt(0);
			if((carac>47&&carac<58)||(carac>62&&carac<127)){
				novo+=v[i];
			}else{
				novo+="&#"+v[i].charCodeAt(0)+ ";";
			}
		}
		return novo;
	},
	js : function(v){
		var d = document.createElement('script');
		d.setAttribute('type','text/javascript');
		d.setAttribute('charset','iso-8859-1');
		d.setAttribute('src',v);
		dmr.tag('head')[0].appendChild(d);
	},
	css : function(v,media,prior){
		var d = document.createElement('link');
		d.setAttribute('type','text/css');
		d.setAttribute('rel','stylesheet');
		d.setAttribute('charset','iso-8859-1');
		if(typeof(media) == 'undefined'){
			d.setAttribute('media','all');
		}else{
			d.setAttribute('media',media);
		}
		d.setAttribute('href',v);
		if(typeof(prior) == 'undefined'){
			dmr.tag('head')[0].insertBefore(d, dmr.tag('title')[0].nextSibling);
		}else{
			dmr.tag('head')[0].insertBefore(d, dmr.tag('head')[0].firstChild);
		}
	},
	ajax : {
		connect : function(){
			if(window.XMLHttpRequest){
				return new XMLHttpRequest();
			}else if(window.ActiveXObject){
				return new ActiveXObject('Microsoft.XMLHTTP');
			}else{
				return false;
			}
		},
		get : function(v){
			var d=new dmr.ajax.connect();
			v.replace(/&amp;/g,"&");
			d.open('POST',v,true);
			d.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
			d.onreadystatechange=function(){
				if(d.readyState==4){
					if(d.status==200||d.status==0){
						eval(d.responseText);
					}else{
						alert('ERRO:\n'+d.statusText);
					}
				}
			}
			d.send(v);
		}
	},
	load : function(){
		var v = dmr.tag("script");
		for(var i = 0; i < v.length;i++){
			if(v[i].src.match(/dmr\.js(\?.*)?$/)){
				dmr.path = v[i].src.replace(/dmr\.js(\?.*)?$/,'');
				var includes = v[i].src.match(/\?.*load=([a-z,]*)/);
				if(includes){
					var plugin = includes[1].split(',');
					for(var j = 0; j < plugin.length; j++){
						dmr.js(dmr.path+'plugins/'+plugin[j]+'/'+plugin[j]+'.js');
					}
				}
				return;
			}
		}
	},
	go : function(){
		if (arguments.callee.done) return;
		arguments.callee.done = true;
		dmr.load();
		dmr.css(dmr.path+'plugins/resetcss/yahoo_reset.css','all',true);
		if(dmr.browser.ie()){
			if(dmr.browser.ie() < 7){
				dmr.js(dmr.path+'plugins/iepngfix/iepngfix.js');
				dmr.js(dmr.path+'plugins/csshover/csshover.js');
			}
		}
	}
}
dmr.go();