// JavaScript Document
var statusImg = 0;
var arrImg = new Array();
arrImg[0] = new Array('confirmacao_topo_01.png', 'confirmacao_topo_02.png', 'confirmacao_topo_03.png', 'confirmacao_topo_04.png');
arrImg[1] = new Array('confirmacao_topo_b_01.png', 'confirmacao_topo_b_02.png', 'confirmacao_topo_b_03.png', 'confirmacao_topo_b_04.png');

function $2(obj) {
    return document.getElementById(obj);
}

function qtdMenus() {
    var resultado = $2('PassosConteudo').getElementsByTagName("div").length;
    return resultado;
}

function abaDetalhes(nomeAbas, indice, abaMenu) {
    for (i = 1; i <= qtdMenus(); i++) {
		if($2(abaMenu + i)){
			$2(abaMenu + i).className = "abaConteudo";	
			$2(nomeAbas + i).style.display = "none";
		}
    }
	$2(abaMenu + indice).className = "abaConteudoSelecionado";    
	$2(nomeAbas + indice).style.display = "block";
	$2(nomeAbas + indice).style.width = "100%";
}

function abaProdDetalhes(nomeAbas, indice, abaProd) {
    for (i = 1; i <= 2; i++) {
		if($2(abaProd + i)){
			$2(abaProd + i).className = "abaProdConteudo";	
			$2(nomeAbas + i).style.display = "none";
		}
    }
	if($2(abaProd+indice)){
		$2(abaProd+indice).className = "abaProdConteudoSelecionado";    
		$2(nomeAbas+indice).style.display = "block";
	}
}

// str_replace

function str_replace (search, replace, subject, count) {
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
     for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
			temp = s[i] + '';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;
			}
		}
    }
    return sa ? s : s[0];
}

// WMV, FLV e Youtube Video Player para Produtos

function writeYoutube(id,width,height){
	document.write('<object width="' + width + '" height="' + height + '"><param name="wmode" value="transparent"></param><param name="movie" value="http://www.youtube.com/v/' + id + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + id + '&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + width + '" height="' + height + '" wmode="transparent"></embed></object>');	
}

function writeErro(str){
	document.write('<span style="font-family:verdana; font-size:10px; color:#990000;">' + str + '</span>');
}

function addProdPlayer(url,w,h,codInit,codEnd){
	
	url = str_replace(' ','',url);
	
	if(w){
		var width = w;
	} else {
		var width = 320;
	}
	if(h){
		var height = h;
	} else {
		var height = 265;
	}
	
	var type = null;
	
	var lowerURL = url.toLowerCase();
	var myRegExp = new Array('v=','/v/','.flv','.wmv','.mp4');
	for(i = 0; i < myRegExp.length; i++) {
		mySearch = lowerURL.search(myRegExp[i]);
		if(mySearch != -1) {
			type = myRegExp[i];			
		}	
	}
	
	if(codInit){
		document.write(codInit);
	} else {
		document.write('<div style="display:block; float:right; margin-bottom:20px; margin-left:20px; width:' + width + '; height:' + height + ';">');
	}
	
	switch(type){
		case "v=":
			var youtube_id = url.split('v=')[1];
			var ampersandPosition = youtube_id.indexOf('&');
			if(ampersandPosition != -1) {
				youtube_id = youtube_id.substring(0, ampersandPosition);
			}
			writeYoutube(youtube_id,width,height);
			break;
		case "/v/":
			var youtube_id = url.split('/v/')[1];
			var ampersandPosition = youtube_id.indexOf('/');
			if(ampersandPosition != -1) {
				youtube_id = youtube_id.substring(0, ampersandPosition);
			}
			writeYoutube(youtube_id,width,height);
			break;
		case ".flv":
			var swf = "/prodplayer/flvplayer.swf?flv=" + url + "&autonext=0&playonload=0&margin=0&bgcolor1=000000&bgcolor2=cccccc&showvolume=1&showopen=0&showplayer=always&showfullscreen=1&loadingcolor=cccccc&buffer=10&showtitlebackground=never";
			document.write('<object width="' + width + '" height="' + height + '"><param name="wmode" value="transparent"></param><param name="movie" value="' + swf + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="' + swf + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + width + '" height="' + height + '" wmode="transparent"></embed></object>');
			break;
		case ".wmv":
			addPlayer(width,height,url,'','stop');
			break;
		case ".mp4":
			addPlayer(width,height,url,'','stop');
			break;
		default:
			writeErro('URL do vídeo ou tipo de arquivo não suportado.');
			break;
	}
	
	if(codEnd){
		document.write(codEnd);
	} else {
		document.write('</div>');
	}

}
