/**
 * Copyright (c) 2008, Decadium Studios Game Developer. All rights reserved.
 * All code are property of Decadium Studios, unless those with specific copyright notes
 */

/**
 * @copyright Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br
 */
function ajaxGet(url,parameters,elemento_retorno,method,exibe_carregando, function_callback){
	/******
	* ajaxGet - Coloca o retorno de uma url em um elemento qualquer
	* Use a vontade mas coloque meu nome nos créditos. Dúvidas, me mande um email.
	* Versão: 1.2 - 20/04/2006
	* Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br
	* Parametros:
	* url: string; parameters: parametros; elemento_retorno: object||string; method:GET, POST; exibe_carregando:boolean
	*  - Se elemento_retorno for um elemento html (inclusive inputs e selects),
	*    exibe o retorno no innerHTML / value / options do elemento
	*  - Se elemento_retorno for o nome de uma variavel
	*    (o nome da variável deve ser declarado por string, pois será feito um eval)
	*    a função irá atribuir o retorno à variável ao receber a url.
	*******/

	var ajax1 = pegaAjax();
	if(ajax1){
		url = antiCacheRand(url);
		ajax1.onreadystatechange = ajaxOnReady;
		if ((method).toUpperCase() == 'GET') {
			ajax1.open("GET", url + (parameters != '' ? '&'+ parameters : '') ,true);
			ajax1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");			
			ajax1.setRequestHeader("Cache-Control", "no-cache");
			ajax1.setRequestHeader("Pragma", "no-cache");			
			ajax1.send(null);
		} else {
			ajax1.open('POST', url, true);
			ajax1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			ajax1.setRequestHeader("Content-length", parameters.length);
			ajax1.setRequestHeader("Connection", "close");
			ajax1.send(parameters);
		}
		if(exibe_carregando){ put('<center><img src="img/icone_carregando.gif" align="absmiddle" border="0" height="16" width="16" /> carregando</center>')    }
		return true;
	}else{
		return false;
	}
	function ajaxOnReady(){
		if (ajax1.readyState==4){
			if(ajax1.status == 200){
				var texto=ajax1.responseText;
				if(texto.indexOf(" ")<0) texto=texto.replace(/\+/g, " ");
				//texto=unescape(texto); //descomente esta linha se tiver usado o urlencode no php ou asp
				if (typeof (function_callback) == "undefined") {
					put(texto);
				} else {
					function_callback(texto, elemento_retorno);
				}
				extraiScript(texto);
				//				extraiStyle(texto);
			}else{
				if(exibe_carregando){put("Falha no carregamento. " + httpStatus(ajax1.status));}
			}
			ajax1 = null
		}else if(exibe_carregando){//para mudar o status de cada carregando
			put('<center><img src="img/icone_carregando.gif" align="absmiddle" border="0" height="16" width="16" /> carregando</center>')
		}
	}
	function put(valor){ //coloca o valor na variavel/elemento de retorno
		//			alert(elemento_retorno.innerHTML+"\n tagname: "+elemento_retorno.tagName+"\n valor: "+valor);
		if((typeof(elemento_retorno)).toLowerCase()=="string"){ //se for o nome da string
			if(valor!="Falha no carregamento"){
				eval(elemento_retorno + '= unescape("' + escape(valor) + '")')
			}
		}else /*if((typeof(elemento_retorno)).toLowerCase()=="function"){ //se for o nome de funcao
		elemento_retorno(valor);
		}else*/ if(elemento_retorno.tagName.toLowerCase()=="input" ||
		elemento_retorno.tagName.toLowerCase()=="textarea"){
			valor = escape(valor).replace(/\%0D\%0A/g, "");
			elemento_retorno.value = unescape(valor);
		}else if(elemento_retorno.tagName.toLowerCase()=="select"){
			alteraInnerHTML(elemento_retorno,valor)
		}else if(elemento_retorno.tagName){
			elemento_retorno.innerHTML = valor;
		}
	}
	function pegaAjax(){ //instancia um novo xmlhttprequest
		//baseado na getXMLHttpObj que possui muitas cópias na net e eu nao sei quem é o autor original
		if(typeof(XMLHttpRequest)!='undefined'){return new XMLHttpRequest();}
		var axO=['Microsoft.XMLHTTP','Msxml2.XMLHTTP','Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0'];
		for(var i=0;i<axO.length;i++){ try{ return new ActiveXObject(axO[i]);}catch(e){} }
		return null;
	}
	function httpStatus(stat){ //retorna o texto do erro http
		switch(stat){
			case 0: return "Erro desconhecido de javascript";
			case 400: return "400: Solicita&ccedil;&atilde;o incompreensível"; break;
			case 403: case 404: return "404: N&atilde;o foi encontrada a URL solicitada"; break;
			case 405: return "405: O servidor n&atilde;o suporta o m&eacute;todo solicitado"; break;
			case 500: return "500: Erro desconhecido de natureza do servidor"; break;
			case 503: return "503: Capacidade m&aacute;xima do servidor alcançada"; break;
			default: return "Erro " + stat + ". Mais informa&ccedil;&otilde;es em http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html"; break;
		}
	}
	function antiCacheRand(aurl){
		var dt = new Date();
		if(aurl.indexOf("?")>=0){// já tem parametros
			return aurl + "&" +dt.getTime();
		}else{ return aurl + "?"+dt.getTime(); }
	}
}

/**
 * @copyright Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br
 */
function alteraInnerHTML(objeto,innerHTML){
	/******
	* alteraInnerHTML - altera o innerHTML de um select independente se é FF ou IE
	* Corrige o problema de não ser possível usar o innerHTML no IE corretamente
	* Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
	* Use a vontade mas coloque meu nome nos créditos. Dúvidas, me mande um email.
	* Versão: 1.0 - 06/04/2006
	* Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br
	* Parametros:
	* objeto(tipo object): o select a ser alterado
	* innerHTML(tipo string): o novo valor do innerHTML
	*******/
	objeto.innerHTML = ""
	var selTemp = document.createElement("micoxselect")
	var opt;
	selTemp.id="micoxselect1"
	document.body.appendChild(selTemp)
	selTemp = document.getElementById("micoxselect1")
	selTemp.style.display="none"
	if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto
		innerHTML = "<option>" + innerHTML + "</option>"
	}
	innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span")
	selTemp.innerHTML = innerHTML
	for(var i=0;i<selTemp.childNodes.length;i++){
		if(selTemp.childNodes[i].tagName){
			opt = document.createElement("OPTION")
			for(var j=0;j<selTemp.childNodes[i].attributes.length;j++){
				opt.setAttributeNode(selTemp.childNodes[i].attributes[j].cloneNode(true))
			}
			opt.value = selTemp.childNodes[i].getAttribute("value")
			opt.text = selTemp.childNodes[i].innerHTML
			if(document.all){ //IEca
				objeto.add(opt)
			}else{
				objeto.appendChild(opt)
			}
		}
	}
	document.body.removeChild(selTemp)
	selTemp = null
}

/**
 * @copyright SkyWalker.TO (http://forum.imasters.com.br/index.php?showtopic=165277)
 * @copyright Micox - micoxjcg@yahoo.com.br
 */
function extraiScript(texto){
	//Maravilhosa função feita pelo SkyWalker.TO do imasters/forum
	//http://forum.imasters.com.br/index.php?showtopic=165277&
	// inicializa o inicio ><
	var ini = 0;
	// loop enquanto achar um script
	while (ini!=-1){
		// procura uma tag de script
		ini = texto.indexOf('<script', ini);
		// se encontrar
		if (ini >=0){
			// define o inicio para depois do fechamento dessa tag
			ini = texto.indexOf('>', ini) + 1;
			// procura o final do script
			var fim = texto.indexOf('</script>', ini);
			// extrai apenas o script
			codigo = texto.substring(ini,fim);
			// executa o script
			//eval(codigo);
			/**********************
			* Alterado por Micox - micoxjcg@yahoo.com.br
			* Alterei pois com o eval não executava funções.
			***********************/
			novo = document.createElement("script")
			novo.text = codigo;
			document.body.appendChild(novo);
		}
	}
}

/**
 * @copyright SkyWalker.TO (http://forum.imasters.com.br/index.php?showtopic=165277)
 * @copyright Micox - micoxjcg@yahoo.com.br
 */
function extraiStyle(texto){
	//Maravilhosa função feita pelo SkyWalker.TO do imasters/forum
	//http://-- link para outro fórum não permitido --.com.br/index.php?showtopic=165277&
	// inicializa o inicio ><
	var ini = 0;
	// loop enquanto achar um script
	while (ini!=-1){
		// procura uma tag de script
		ini = texto.indexOf('<style', ini);
		// se encontrar
		if (ini >=0){
			// define o inicio para depois do fechamento dessa tag
			ini = texto.indexOf('>', ini) + 1;
			// procura o final do script
			var fim = texto.indexOf('</style>', ini);
			// extrai apenas o script
			codigo = texto.substring(ini,fim);
			// executa o script
			//eval(codigo);
			/**********************
			* Alterado por Micox - micoxjcg@yahoo.com.br
			* Alterei pois com o eval não executava funções.
			***********************/
			novo = document.createElement("style")
			novo.text = codigo;
			//			alert(codigo);
			document.body.appendChild(novo);
		}
	}
}

/**
* Objeto converte todos os parametros de dentro de um form em uma string em get
* para ser enviado junto com a funcao ajaxGet
*
* @param obj objeto form que deve ser varrido para buscar as informacoes
* @return String em formato get
* exemplo de uso: <input type="button" name="button" value="Submit" onclick="javascript:alert(converteFormGET(this.parentNode));">
*/
function converteFormGET(obj) {
	var getstr = "";
	for (var i=0;i<obj.length;i++)
	{
		if(obj.elements[i].name == ''){
			//nada a fazer
		}else if (obj.elements[i].type == "text" ||
		obj.elements[i].type == "hidden" ||
		obj.elements[i].type == "password") {
			getstr += obj.elements[i].name + "=" + obj.elements[i].value + "&";
		}else  if (obj.elements[i].type == "checkbox") {
			if (obj.elements[i].checked) {
				getstr += obj.elements[i].name + "=" + obj.elements[i].value + "&";
			}/* else {
			getstr += obj.elements[i].name + "=&";
			}*/
		}else  if (obj.elements[i].type == "radio") {
			if (obj.elements[i].checked) {
				getstr += obj.elements[i].name + "=" + obj.elements[i].value + "&";
			}
		}else  if (obj.elements[i].tagName == "SELECT") {
			var sel = obj.elements[i];
			getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
		} else if (obj.elements[i].tagName == "TEXTAREA") {
			getstr += obj.elements[i].name + "=" + obj.elements[i].value + "&";
		} else {
			getstr += obj.elements[i].name + "=" + obj.elements[i].value + "&";
		}
	}
	
	return getstr;
}


/**
* Retorna um array contendo os elementos do retorno
*
* @param str a string no formato get de retorno
* @return Array contendo os valores do get de retorno
*/
function getErrorToArray(str) {
	var inicio = str.indexOf('?');
	var tamanho = str.length;
	var retorno = new Array();

	while(inicio >= 0 && inicio < tamanho) {
		var final = str.indexOf('&', inicio+1);
		if(final < 0) {
			final = tamanho;
		}
		var valor = str.slice(inicio+1,final);
		retorno.push(valor);
		inicio = final;
	}
	return retorno;
}


/**
 * Alterna o status de visibilidade do elemento
 */
function alternaEstado(elemento) {
	if (elemento.style.display == 'none') {
		blocoAbre(elemento);
	} else {
		blocoFecha(elemento) ;
	}
}

function blocoAbre(elemento) {
	elemento.style.display = 'block';
}

function blocoFecha(elemento) {
	elemento.style.display = 'none';
}

function $(theNomeElemento) {
	return document.getElementById(theNomeElemento);
}

function $$(theNomeElemento) {
	return window.opener.document.getElementById(theNomeElemento);
}

function tamanhoTela() {
	var aWidth = 0, aHeight = 0;
	
	if(typeof( window.innerWidth) == 'number' ) {
	  aWidth = window.innerWidth;
	  aHeight = window.innerHeight;
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
	  aWidth = document.documentElement.clientWidth;
	  aHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	  aWidth = document.body.clientWidth;
	  aHeight = document.body.clientHeight;
	}
	return new Array(aWidth, aHeight);
}


function atualizaCamposDataInicioExtratoTransacoes(type, args, obj) 
{ 
	var dates = args[0]; 
	var date = dates[0]; 
	var year = date[0], month = date[1], day = date[2]; 

	var diaInicio = document.getElementById("diaInicio");
	var mesInicio = document.getElementById("mesInicio");
	var anoInicio = document.getElementById("anoInicio");

	diaInicio.value = day;
	mesInicio.value = month;
	anoInicio.value = year;
} 


function atualizaCamposDataFimExtratoTransacoes(type, args, obj) 
{ 
	var dates = args[0]; 
	var date = dates[0]; 
	var year = date[0], month = date[1], day = date[2]; 

	var diaFim = document.getElementByName("diaFim");
	var mesFim = document.getElementByName("mesFim");
	var anoFim = document.getElementByName("anoFim");

	diaFim.value = day;
	mesFim.value = month;
	anoFim.value = year;
} 
/**
 * glossy.js 1.21 (21-Jun-2007)
 * (c) by Christian Effenberger 
 * All Rights Reserved
 * Source: glossy.netzgesta.de
 * Distributed under NSL
 * License permits free of charge
 * use on non-commercial and 
 * private web sites only 
**/

var tmp = navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf('Opera') < 1 ? 1 : 0;
if(tmp) var isIE = document.namespaces ? 1 : 0;
    
if(isIE) {
	var stl = document.createStyleSheet();
	stl.addRule("v\\:*", "behavior: url(#default#VML);"); 
	document.namespaces.add("v", "urn:schemas-microsoft-com:vml"); 
}

function getImages(className){
	var children = document.getElementsByTagName('img'); 
	var elements = new Array(); var i = 0;
	var child; var classNames; var j = 0;
	for (i=0;i<children.length;i++) {
		child = children[i];
		classNames = child.className.split(' ');
		for (var j = 0; j < classNames.length; j++) {
			if (classNames[j] == className) {
				elements.push(child);
				break;
			}
		}
	}
	return elements;
}

function getClasses(classes,string){
	var temp = '';
	for (var j=0;j<classes.length;j++) {
		if (classes[j] != string) {
			if (temp) {
				temp += ' '
			}
			temp += classes[j];
		}
	}
	return temp;
}

function getClassValue(classes,string){
	var temp = 0; var pos = string.length;
	for (var j=0;j<classes.length;j++) {
		if (classes[j].indexOf(string) == 0) {
			temp = Math.min(classes[j].substring(pos),100);
			break;
		}
	}
	return Math.max(0,temp);
}

function getClassColor(classes,string){
	var temp = 0; var str = ''; var pos = string.length;
	for (var j=0;j<classes.length;j++) {
		if (classes[j].indexOf(string) == 0) {
			temp = classes[j].substring(pos);
			str = '#' + temp.toLowerCase();
			break;
		}
	}
	if(str.match(/^#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i)) {
		return str;
	}else {
		return 0;
	}
}

function getClassAttribute(classes,string){
	var temp = 0; var pos = string.length;
	for (var j=0;j<classes.length;j++) {
		if (classes[j].indexOf(string) == 0) {
			temp = 1; break;
		}
	}
	return temp;
}

function roundedRect(ctx,x,y,width,height,radius,nopath){
	if (!nopath) ctx.beginPath();
	ctx.moveTo(x,y+radius);
	ctx.lineTo(x,y+height-radius);
	ctx.quadraticCurveTo(x,y+height,x+radius,y+height);
	ctx.lineTo(x+width-radius,y+height);
	ctx.quadraticCurveTo(x+width,y+height,x+width,y+height-radius);
	ctx.lineTo(x+width,y+radius);
	ctx.quadraticCurveTo(x+width,y,x+width-radius,y);
	ctx.lineTo(x+radius,y);
	ctx.quadraticCurveTo(x,y,x,y+radius);
	if (!nopath) ctx.closePath();
}

function addRadialStyle(ctx,x1,y1,r1,x2,y2,r2,opacity) {
	var tmp = ctx.createRadialGradient(x1,y1,r1,x2,y2,r2);
	var opt = Math.min(parseFloat(opacity+0.1),1.0);
	tmp.addColorStop(0,'rgba(0,0,0,'+opt+')');
	tmp.addColorStop(0.25,'rgba(0,0,0,'+opacity+')');
	tmp.addColorStop(1,'rgba(0,0,0,0)');
	return tmp;
}

function addLinearStyle(ctx,x,y,w,h,opacity) {
	var tmp = ctx.createLinearGradient(x,y,w,h);
	var opt = Math.min(parseFloat(opacity+0.1),1.0);
	tmp.addColorStop(0,'rgba(0,0,0,'+opt+')');
	tmp.addColorStop(0.25,'rgba(0,0,0,'+opacity+')');
	tmp.addColorStop(1,'rgba(0,0,0,0)');
	return tmp;
}

function addBright(ctx,x,y,width,height,radius,opacity) {
	var style = ctx.createLinearGradient(0,y,0,y+height);
	style.addColorStop(0,'rgba(254,254,254,'+opacity+')');
	style.addColorStop(1,'rgba(254,254,254,0.1)');
	ctx.beginPath();
	ctx.moveTo(x,y+radius);
	ctx.lineTo(x,y+height-radius);
	ctx.quadraticCurveTo(x,y+height,x+radius,y+height);
	ctx.lineTo(x+width-radius,y+height);
	ctx.quadraticCurveTo(x+width,y+height,x+width,y+height-radius);
	ctx.lineTo(x+width,y+radius);
	ctx.quadraticCurveTo(x+width,y,x+width-radius,y);
	ctx.lineTo(x+radius,y);
	ctx.quadraticCurveTo(x,y,x,y+radius);
	ctx.closePath();
	ctx.fillStyle = style;
	ctx.fill();
}

function addDark(ctx,x,y,width,height,radius,opacity) {
	var style = ctx.createLinearGradient(0,y,0,y+height);
	style.addColorStop(0,'rgba(0,0,0,0)');
	style.addColorStop(1,'rgba(0,0,0,'+opacity+')');
	ctx.beginPath();
	ctx.moveTo(x,y);
	ctx.lineTo(x,y+height-radius);
	ctx.quadraticCurveTo(x,y+height,x+radius,y+height);
	ctx.lineTo(x+width-radius,y+height);
	ctx.quadraticCurveTo(x+width,y+height,x+width,y+height-radius);
	ctx.lineTo(x+width,y);
	ctx.lineTo(x,y);
	ctx.closePath();
	ctx.fillStyle = style;
	ctx.fill();
}

function addFrame(ctx,x,y,width,height,radius,opacity) {
	roundedRect(ctx,x,y,width,height,radius);
	var style = ctx.createLinearGradient(0,0,0,height);
	style.addColorStop(0,'rgba(254,254,254,'+opacity+')');
	style.addColorStop(1,'rgba(0,0,0,'+opacity+')');
	ctx.lineWidth = (radius+x)/2;
	ctx.strokeStyle = style;
	ctx.stroke();
}

function glossyShadow(ctx,x,y,width,height,radius,opacity){
	var style; var os = radius/2;
	ctx.beginPath();
  	ctx.rect(x+radius,y,width-(radius*2),y+os);
	ctx.closePath();
	style = addLinearStyle(ctx,x+radius,y+os,x+radius,y,opacity);
	ctx.fillStyle = style;
	ctx.fill();
	ctx.beginPath();
  	ctx.rect(x,y,radius,radius);
	ctx.closePath();
	style = addRadialStyle(ctx,x+radius,y+radius,radius-os,x+radius,y+radius,radius,opacity);
	ctx.fillStyle = style;
	ctx.fill();
	ctx.beginPath();
  	ctx.rect(x,y+radius,os,height-(radius*2));
	ctx.closePath();
	style = addLinearStyle(ctx,x+os,y+radius,x,y+radius,opacity);
	ctx.fillStyle = style;
	ctx.fill();
	ctx.beginPath();
  	ctx.rect(x,y+height-radius,radius,radius);
	ctx.closePath();
	style = addRadialStyle(ctx,x+radius,y+height-radius,radius-os,x+radius,y+height-radius,radius,opacity);
	ctx.fillStyle = style;
	ctx.fill();
	ctx.beginPath();
  	ctx.rect(x+radius,y+height-os,width-(radius*2),os);
	ctx.closePath();
	style = addLinearStyle(ctx,x+radius,y+height-os,x+radius,y+height,opacity);
	ctx.fillStyle = style;
	ctx.fill();
	ctx.beginPath(); 
  	ctx.rect(x+width-radius,y+height-radius,radius,radius);
	ctx.closePath();
	style = addRadialStyle(ctx,x+width-radius,y+height-radius,radius-os,x+width-radius,y+height-radius,radius,opacity);
	ctx.fillStyle = style;
	ctx.fill();
	ctx.beginPath();
  	ctx.rect(x+width-os,y+radius,os,height-(radius*2));
	ctx.closePath();
	style = addLinearStyle(ctx,x+width-os,y+radius,x+width,y+radius,opacity);
	ctx.fillStyle = style;
	ctx.fill();
	ctx.beginPath();
  	ctx.rect(x+width-radius,y,radius,radius);
	ctx.closePath();
	style = addRadialStyle(ctx,x+width-radius,y+radius,radius-os,x+width-radius,y+radius,radius,opacity);
	ctx.fillStyle = style;
	ctx.fill();
}

function addIEGlossy() {
	var theimages = getImages('glossy');
	var image; var object; var canvas; var context; var i;
	var iradius = null; var sradius = null; var noshadow = 0;
	var ibgcolor = null; var igradient = null; var horizontal = 0;
	var factor = 0.25; var classes = ''; var newClasses = ''; 
	var maxdim = null; var inset = 0; var offset = 0; var style = '';
	var width = 0; var height = 0; var vml = null; var flt = null;
	var display = null; var xradius = null; var angle;
	var head; var foot; var fill; var shade; var tmp;
	for(i=0;i<theimages.length;i++) {	
		image = theimages[i]; object = image.parentNode; 
		head = ''; foot = ''; fill = ''; shade = ''; tmp = '';
		if(image.width>=16 && image.height>=16) {
			classes = image.className.split(' '); 
			horizontal = 0; igradient = 0; factor = 0.25;
			noshadow = 0; iradius = 0; ibgcolor = 0;
			iradius = getClassValue(classes,"iradius");
			ibgcolor = getClassColor(classes,"ibgcolor");
			igradient = getClassColor(classes,"igradient");
			noshadow = getClassAttribute(classes,"noshadow");
			horizontal = getClassAttribute(classes,"horizontal");
			newClasses = getClasses(classes,"glossy");
			width = image.width; height = image.height;
			maxdim = Math.min(width,height)/2; angle = 0;
			factor = iradius>0?Math.min(Math.max(iradius,20),50)/100:factor;
			iradius = Math.round(45*factor);
			xradius = Math.round(Math.max(Math.round(maxdim*factor),4)/4)*4;
			if(noshadow<1) {
				offset = xradius/4; sradius = iradius*0.75;
				inset = offset; radius = sradius; sradius = radius*0.75;
		        shade = '<v:roundrect arcsize="' + radius + '%" strokeweight="0" filled="t" stroked="f" fillcolor="#000000" style="filter:Alpha(opacity=60), progid:dxImageTransform.Microsoft.Blur(PixelRadius=' + inset + ', MakeShadow=false); zoom:1;margin:-1px 0 0 -1px;padding: 0;display:block;position:absolute;top:' + inset + 'px;left:0px;width:' + (width-(2*inset)) + 'px;height:' + (height-(3*inset)) + 'px;"><v:fill color="#000000" opacity="1" /></v:roundrect>';
				tmp = '<v:rect strokeweight="0" filled="t" stroked="f" fillcolor="#ffffff" style="zoom:1;margin:-1px 0 0 -1px;padding: 0;display:block;position:absolute;top:0px;left:0px;width:' + width + 'px;height:' + height + 'px;"><v:fill color="#ffffff" opacity="0.0" /></v:rect>';
			}else {
				radius = iradius; inset = 0; 
				offset = xradius/4; sradius = iradius*0.75;
			}
			if(isNaN(ibgcolor)) {
				fill = '<v:roundrect arcsize="' + radius + '%" strokeweight="0" filled="t" stroked="f" fillcolor="#ffffff" style="zoom:1;margin:-1px 0 0 -1px;padding: 0;display:block;position:absolute;top:0px;left:' + inset + 'px;width:' + (width-(2*inset)) + 'px;height:' + (height-(2*inset)) + 'px;">';
				if(isNaN(igradient)) {
					if(horizontal>0) angle = 90;
		        	fill = fill + '<v:fill method="sigma" type="gradient" angle="' + angle + '" color="' + igradient + '" color2="' + ibgcolor + '" /></v:roundrect>';
				}else {
		        	fill = fill + '<v:fill color="' + ibgcolor + '" /></v:roundrect>';
				}
			}
	        display = (image.currentStyle.display.toLowerCase()=='block')?'block':'inline-block';        
	        vml = document.createElement(['<var style="zoom:1;overflow:hidden;display:' + display + ';width:' + width + 'px;height:' + height + 'px;padding:0;">'].join(''));
	        flt = image.currentStyle.styleFloat.toLowerCase();
	        display = (flt=='left'||flt=='right')?'inline':display;
	        head = '<v:group style="zoom:1; display:' + display + '; margin:-1px 0 0 -1px; padding:0; position:relative; width:' + width + 'px;height:' + height + 'px;" coordsize="' + width + ',' + height + '">' + tmp;
	        foot = '<v:roundrect arcsize="' + radius + '%" strokeweight="0" filled="t" stroked="f" fillcolor="#ffffff" style="zoom:1;margin:-1px 0 0 -1px;padding: 0;display:block;position:absolute;top:0px;left:' + inset + 'px;width:' + (width-(2*inset)) + 'px;height:' + (height-(2*inset)) + 'px;"><v:fill src="' + image.src + '" type="frame" /></v:roundrect><v:roundrect arcsize="' + (sradius*2) + '%" strokeweight="0" filled="t" stroked="f" fillcolor="#ffffff" style="zoom:1;margin:-1px 0 0 -1px;padding: 0;display: block;position:absolute;top:' + offset + 'px;left:' + (offset+inset) + 'px;width:' + (width-(2*offset)-(2*inset)) + 'px;height:' + ((height/2)-offset-inset) + 'px;"><v:fill method="linear" type="gradient" angle="0" color="#ffffff" opacity="0.1" color2="#ffffff" o:opacity2="0.75" /></v:roundrect><v:roundrect arcsize="' + (radius*2) + '%" strokeweight="0" filled="t" stroked="f" fillcolor="#000000" style="zoom:1;margin:-1px 0 0 -1px;padding: 0;display: block;position:absolute;top:' + ((height/2)-inset) + 'px;left:' + inset + 'px;width:' + (width-(2*inset)) + 'px;height:' + ((height/2)-inset) + 'px;"><v:fill method="sigma" type="gradient" angle="180" color="#000000" opacity="0.0" color2="#000000" o:opacity2="0.5" /></v:roundrect></v:group>';
			vml.innerHTML = head + shade + fill + foot;
			vml.className = newClasses;
			vml.style.cssText = image.style.cssText;
	        vml.title = image.getAttribute('alt') || image.getAttribute('title') || '';
			object.replaceChild(vml,image);
        }
	}
}

function addGlossy() {
	var theimages = getImages('glossy');
	var image; var object; var canvas; var context; var i;
	var iradius = null; var sradius = null; var noshadow = 0;
	var ibgcolor = null; var igradient = null; var horizontal = 0;
	var factor = 0.25; var classes = ''; var newClasses = ''; 
	var maxdim = null; var inset = 0; var offset = 0; var style = '';
	for(i=0;i<theimages.length;i++) {	
		image = theimages[i]; object = image.parentNode; 
		canvas = document.createElement('canvas');
		if(canvas.getContext && image.width>=16 && image.height>=16) {
			classes = image.className.split(' '); 
			horizontal = 0; igradient = 0; factor = 0.25;
			noshadow = 0; iradius = 0; ibgcolor = 0;
			iradius = getClassValue(classes,"iradius");
			ibgcolor = getClassColor(classes,"ibgcolor");
			igradient = getClassColor(classes,"igradient");
			noshadow = getClassAttribute(classes,"noshadow");
			horizontal = getClassAttribute(classes,"horizontal");
			newClasses = getClasses(classes,"glossy");
			canvas.className = newClasses;
			canvas.style.cssText = image.style.cssText;
			canvas.style.height = image.height+'px';
			canvas.style.width = image.width+'px';
			canvas.height = image.height;
			canvas.width = image.width;
			maxdim = Math.min(canvas.width,canvas.height)/2;
			factor = iradius>0?Math.min(Math.max(iradius,20),50)/100:factor;
			iradius = Math.max(Math.round(maxdim*factor),4);
			if(noshadow<1) {
				iradius = Math.round(iradius/4)*4;
				offset = iradius/4; sradius = iradius*0.75;
				inset = offset; radius = sradius; sradius = radius*0.75;
			}else {
				radius = iradius; inset = 0;
				offset = iradius/4; sradius = iradius*0.75;
			}
			context = canvas.getContext("2d");
			object.replaceChild(canvas,image);
			context.clearRect(0,0,canvas.width,canvas.height);
			if(noshadow<1) glossyShadow(context,0,0,canvas.width,canvas.height,iradius,0.5);
			context.save();
			globalCompositeOperation = "source-in";
			roundedRect(context,inset,0,canvas.width-(inset*2),canvas.height-(inset*2),radius);
			context.clip();
			if(isNaN(ibgcolor)) {
				if(isNaN(igradient)) {
					if(horizontal>0) {
						style = context.createLinearGradient(0,0,canvas.width,0);
					}else {
						style = context.createLinearGradient(0,0,0,canvas.height-(inset*2));
					}
					style.addColorStop(0,ibgcolor); 
					style.addColorStop(1,igradient);
					context.beginPath();
  					context.rect(0,0,canvas.width,canvas.height-(inset*2));
					context.closePath();
					context.fillStyle = style;
					context.fill();
				}else {
					context.fillStyle = ibgcolor;
					context.fillRect(0,0,canvas.width,canvas.height-(inset*2));
				}
			}else {
				context.clearRect(0,0,canvas.width,canvas.height);
			}
			context.drawImage(image,inset,0,canvas.width-(inset*2),canvas.height-(inset*2));
			addBright(context,offset+inset,offset,canvas.width-(2*(offset+inset)),(canvas.height/2)-offset,sradius,0.75);
			addDark(context,inset,(canvas.height/2)-inset,canvas.width-(2*inset),(canvas.height/2)-inset,sradius,0.5);
			addFrame(context,inset,0,canvas.width-(inset*2),canvas.height-(inset*2),radius,0.25)
		}
	}
}

var glossyOnload = window.onload;
window.onload = function () { if(glossyOnload) glossyOnload(); if(isIE){addIEGlossy(); }else {addGlossy();}}