/*
 +-------------------------------------------------------------------+
 |                  S C R I P T S - J S   (v1.0)                     |
 |                                                                   |
 | Criado: Ago 28, 2009             Última Modificação: Ago 28, 2009 |
 +-------------------------------------------------------------------+
 |              Criado por Adriano Chamelet Paladini                 |
 |              adrianopaladini@puc-campinas.edu.br                  |
 +-------------------------------------------------------------------+

======================================================================================================
 Este Script foi testado nos seguintes navegadores:

 - IE 5.5/6/7/8, Firefox 3, Opera 9/10, Safari 3, Chrome 1/2/3

======================================================================================================
*/

var IE6 = false;
if(navigator.appName.indexOf("Internet Explorer")>0) {
	var temp = navigator.appVersion;
	temp = temp.split('MSIE');
	if(parseInt(temp[1]) < 7) {
		var IE6 = true;
	}
}

var PastaImgEgresso;


/*----------------------------------------------------------------------------------------------------
 * Função para transformar todos os input button
 *----------------------------------------------------------------------------------------------------*/
function CriaBotoes(ev){
	var el;
	var cl;
	var eBotao;
	var CorBotaoEgresso;

	var NovoStyle = document.createStyleSheet();
	
	var NomeCorEgresso = ['', 'Vermelho', 'Verde'];
	for(var i=0;i<NomeCorEgresso.length;i++){
		CorBotaoEgresso = NomeCorEgresso[i];
		NovoStyle.addRule('.Botao' + CorBotaoEgresso, ' border: 0px !important');
		NovoStyle.addRule('.PCBotao' + CorBotaoEgresso, ' width:auto; height: 31px; color:#fff; padding:0 2px; background:url('+PastaImgEgresso+'botao_cen_'+CorBotaoEgresso+'.png) repeat-x 0 0; cursor:pointer; border:none; font:10px/26px Tahoma, Arial, Helvetica, sans-serif; font-weight:bold; vertical-align:middle; border: 0px !important; display:inline !important; ');
		NovoStyle.addRule('.PCBotaoEsq' + CorBotaoEgresso, ' width: 6px; height: 31px; vertical-align:middle; background:url('+PastaImgEgresso+'botao_esq_'+CorBotaoEgresso+'.png) no-repeat 0 0; margin: 0 0 0 0 !important;');
		NovoStyle.addRule('.PCBotaoDir' + CorBotaoEgresso, ' width: 6px; height: 31px; vertical-align:middle; background:url('+PastaImgEgresso+'botao_dir_'+CorBotaoEgresso+'.png) no-repeat 0 0; margin: 0 0 0 0 !important;');
		NovoStyle.addRule('.PCBotaoEsqOn' + CorBotaoEgresso, ' width: 6px; height: 31px; vertical-align:middle; background:url('+PastaImgEgresso+'botao_esq_'+CorBotaoEgresso+'.png) no-repeat; background-position: 0 -31px; margin: 0 0 0 0 !important;');
		NovoStyle.addRule('.PCBotaoDirOn' + CorBotaoEgresso, ' width: 6px; height: 31px; vertical-align:middle; background:url('+PastaImgEgresso+'botao_dir_'+CorBotaoEgresso+'.png) no-repeat; background-position: 0 -31px; margin: 0 0 0 0 !important;');
		NovoStyle.addRule('.PCBotaoOn' + CorBotaoEgresso, ' width:auto; height: 31px; color:#fff; padding:0 2px; cursor:pointer; border:none; font:10px/26px Tahoma, Arial, Helvetica, sans-serif; font-weight:bold; vertical-align:middle; background:url('+PastaImgEgresso+'botao_cen_'+CorBotaoEgresso+'.png) repeat-x; background-position: 0 -31px; border: 0px !important; display:inline !important;');
		NovoStyle.addRule('.PCBotao6' + CorBotaoEgresso, ' width:auto; height: 31px; color:#fff; padding:0 2px; background:url('+PastaImgEgresso+'botao_cen_'+CorBotaoEgresso+'.gif) repeat-x 0 0; cursor:pointer; border:none; font:10px/26px Tahoma, Arial, Helvetica, sans-serif; font-weight:bold; vertical-align:middle; border: 0px !important; display:inline !important;');
		NovoStyle.addRule('.PCBotaoEsq6' + CorBotaoEgresso, ' width: 6px; height: 31px; vertical-align:middle; background:url('+PastaImgEgresso+'botao_esq_'+CorBotaoEgresso+'.gif) no-repeat 0 0; margin: 0 0 0 0 !important;');
		NovoStyle.addRule('.PCBotaoDir6' + CorBotaoEgresso, ' width: 6px; height: 31px; vertical-align:middle; background:url('+PastaImgEgresso+'botao_dir_'+CorBotaoEgresso+'.gif) no-repeat 0 0; margin: 0 0 0 0 !important;');
		NovoStyle.addRule('.PCBotaoEsqOn6' + CorBotaoEgresso, ' width: 6px; height: 31px; vertical-align:middle; background:url('+PastaImgEgresso+'botao_esq_'+CorBotaoEgresso+'.gif) no-repeat; background-position: 0 -31px; margin: 0 0 0 0 !important;');
		NovoStyle.addRule('.PCBotaoDirOn6' + CorBotaoEgresso, ' width: 6px; height: 31px; vertical-align:middle; background:url('+PastaImgEgresso+'botao_dir_'+CorBotaoEgresso+'.gif) no-repeat; background-position: 0 -31px; margin: 0 0 0 0 !important;');
		NovoStyle.addRule('.PCBotaoOn6' + CorBotaoEgresso, ' width:auto; height: 31px; color:#fff; padding:0 2px; cursor:pointer; border:none; font:10px/26px Tahoma, Arial, Helvetica, sans-serif; font-weight:bold; vertical-align:middle; background:url('+PastaImgEgresso+'botao_cen_'+CorBotaoEgresso+'.gif) repeat-x; background-position: 0 -31px; border: 0px !important; display:inline !important;');	
	}
	var inputNodes = document.getElementsByTagName('input');
    for (var i = 0; i < inputNodes.length; i++) {
        el = inputNodes[i];
        if(el.type!='button') {
			if(el.type!='submit') {
				continue;
			}
		}
		
		
		cl = el.className.toString().split(" ");
		eBotao = false
		for (var k = 0; k < cl.length; k++) {
			if(cl[k].substring(0,5) == 'Botao') {
				eBotao = true;
				CorBotaoEgresso=cl[k].substring(5);
				break;
			}
		}
		if(eBotao==false) {continue;}
				
		el.left = document.createElement('img');
		el.left.src = PastaImgEgresso+'botao_branco.gif';
		
		if(IE6) {
			el.left.className = "PCBotaoEsq6"+CorBotaoEgresso;
		}else{
			el.left.className = "PCBotaoEsq"+CorBotaoEgresso;
		}
		
		el.right = document.createElement('img');
		el.right.src = PastaImgEgresso+'botao_branco.gif';
		
		if(IE6) {
			el.right.className = "PCBotaoDir6"+CorBotaoEgresso;
		}else{
			el.right.className = "PCBotaoDir"+CorBotaoEgresso;
		}

		if(IE6) {
			el.className = el.className.replace("Botao"+CorBotaoEgresso,"PCBotao6"+CorBotaoEgresso);
		}else{
			el.className = el.className.replace("Botao"+CorBotaoEgresso,"PCBotao"+CorBotaoEgresso);
		}
		el.parentNode.insertBefore(el.left, el);
		el.parentNode.insertBefore(el.right, el.nextSibling);
		
		el.onmouseover = function() {
			if(IE6) {
				CorBotaoAtual=this.className.replace("PCBotao6","");
				this.className = this.className.replace("PCBotao6"+CorBotaoAtual,"PCBotaoOn6"+CorBotaoAtual);
				this.left.className = "PCBotaoEsqOn6"+CorBotaoAtual;
				this.right.className = "PCBotaoDirOn6"+CorBotaoAtual;
			}else{
				CorBotaoAtual=this.className.replace("PCBotao","");
				this.className = this.className.replace("PCBotao"+CorBotaoAtual,"PCBotaoOn"+CorBotaoAtual);
				this.left.className = "PCBotaoEsqOn"+CorBotaoAtual;
				this.right.className = "PCBotaoDirOn"+CorBotaoAtual;
			}
		}
		el.onmouseout = function() {
			if(IE6) {
				CorBotaoAtual=this.className.replace("PCBotaoOn6","");
				this.className = this.className.replace("PCBotaoOn6"+CorBotaoAtual,"PCBotao6"+CorBotaoAtual);
				this.left.className = "PCBotaoEsq6"+CorBotaoAtual;
				this.right.className = "PCBotaoDir6"+CorBotaoAtual;
			}else{
				CorBotaoAtual=this.className.replace("PCBotaoOn","");
				this.className = this.className.replace("PCBotaoOn"+CorBotaoAtual,"PCBotao"+CorBotaoAtual);
				this.left.className = "PCBotaoEsq"+CorBotaoAtual;
				this.right.className = "PCBotaoDir"+CorBotaoAtual;			
			}
		}
		
	}
}

function EventoCarregarEgresso(fnc){
	if(typeof window.addEventListener!="undefined" ) {
		window.addEventListener( "load", fnc, false );
	}else if(typeof window.attachEvent!="undefined" ){
		window.attachEvent( "onload", fnc );
	}else{
		if(window.onload!=null){
			var oldOnload=window.onload;
			window.onload=function(e){
				oldOnload(e);
				window[fnc]();
			};
		}else{
			window.onload = fnc;
		}
	}

}

/*
Função auxiliar para adicionar estilo no Firefox, Chrome, Safari e Opera
*/
if(typeof document.createStyleSheet === 'undefined') {
	document.createStyleSheet = (function() {
		function createStyleSheet(href) {
			if(typeof href !== 'undefined') {
				var element = document.createElement('link');
				element.type = 'text/css';
				element.rel = 'stylesheet';
				element.href = href;
			}else {
				var element = document.createElement('style');
				element.type = 'text/css';
			}
			document.getElementsByTagName('head')[0].appendChild(element);
			var sheet = document.styleSheets[document.styleSheets.length - 1];
			if(typeof sheet.addRule === 'undefined')
				sheet.addRule = addRule;
			if(typeof sheet.removeRule === 'undefined')
				sheet.removeRule = sheet.deleteRule;
			return sheet;
		}
		function addRule(selectorText, cssText, index) {
			if(typeof index === 'undefined')
				index = this.cssRules.length;
			this.insertRule(selectorText + ' {' + cssText + '}', index);
		}
		return createStyleSheet;
	})();
}

// Inicia
EventoCarregarEgresso(CriaBotoes);
