	Dim FileSize
	Dim novajanela
	Dim LastTime
	Dim Palavra
	
	Sub btn1_OnClick
		Midiocx.Play
	End Sub

	Sub btn2_OnClick
		Midiocx.Stop
	End Sub

	Sub btn3_OnClick
		Midiocx.Pause
	End Sub

	Sub Localizar_OnClick()
		Palavra = inputbox("Digite a palavra a ser localizada na lista." + chr(10) + "Tecle 'F8' para localizar a próxima.", "Karaoke On-Line")
		if trim(Palavra) = "" then exit sub
		for i = 0 to ListFiles.length -1
			if instr(lcase(listfiles(i).text), lcase(Palavra)) > 0 then
				listfiles.selectedindex = i
				document.focus
				exit sub
			End If
		next
		Msgbox "Esta palavra não foi encontrada na lista", vbInformation, "Karaoke On-Line"
		document.focus
	End Sub

	Sub LocalizarProxima()
		if trim(Palavra) = "" then exit sub 
		for i = listfiles.selectedindex + 1 to ListFiles.length -1
			if instr(lcase(listfiles(i).text), lcase(Palavra)) > 0 then
				listfiles.selectedindex = i
				document.focus
				exit sub
			End If
		next
		Msgbox "A pesquisa chegou ao final da lista", vbInformation, "Karaoke On-Line"
		document.focus
	End Sub
	
	Sub MonitoraKey()
		if self.event.keyCode = 119 then
			LocalizarProxima
		End if
		document.focus
	End Sub	
	
	Sub ListFiles_ondblclick()
		Abrir_onClick
	End Sub
	
	Sub Midiocx_ReadingFromWeb(Value)
	
		if FileSize = 0 then FileSize = 1
		CellStatus.innerText = "Carregando... " & cstr(int((Value * 100) / FileSize)) + "%"
	
	End Sub
	
	Sub Abrir_onClick()

		if not TestDomain() then
			Msgbox "Este domímio não está autorizado a utilizar este karaoke on line", vbInformation, "Aviso:" 
			exit sub
		end if
		
		If listfiles.selectedindex = -1 then exit sub
		FileSize = listfiles(listfiles.selectedindex).value
		if FileSize = 0 then exit sub
		CellTitulo.innerText = ""
		midiocx.stop
		Midiocx.Close
		CellStatus.innerText = "Carregando..."
		if Midiocx.OpenFromWeb("http://www.karaokeonline.com.br/Codigo/" + categoriaHidden.value + "/" + listfiles(listfiles.selectedindex).text) then
			Velocidade.selectedindex  = 5
			Transpose.selectedindex  = 5
			img1.width = 0
			Titulo = "  " + midiocx.GetTitles(0) + chr(13) + chr(10)
			Titulo = Titulo + "  " + midiocx.GetTitles(1) + chr(13) + chr(10)
			Titulo = Titulo + "  " + midiocx.GetTitles(2)
			CellTitulo.innerText = Titulo
			Midiocx.Play
		End if
		CellTime.innerText = "00:00:00 de " + midiocx.GetHMSLength 
		CellStatus.innerText = "Concluído"
		
	End Sub

	Sub SelectCategoria()
		If Midiocx.GetStatus = 2 Then
			StartNota = 0
			Midiocx.Stop
		End if
		location.assign "http://www.karaokeonline.com.br/karaoke.asp?categoria=" &  ListCategorias(ListCategorias.selectedIndex).value
	End Sub
	
	Sub Midiocx_OnTextKar(Text, TextStart, Phrase, NextPhrase, PhraseIndex)
		Phrase = Phrase & "  "
		str = "<font color='#00FF00'><strong>" + left(Phrase, TextStart-1) + "</font><font color='#FFFF00'>" + Text + "</font><font color='#00FF00'>" + Right(Phrase, Len(Phrase) - ((TextStart) + Len(Text)-1)) + "</font>"
		CellText1.innerText = ""
		CellText1.insertAdjacentHTML "BeforeEnd", str 
		CellText2.innerText = NextPhrase	
	End Sub
	
	Sub Midiocx_Progress(MidiTicks, Hour, Minute, Second, Percent)
		if Second <> LastTime then
			CellPercent.innerText = CStr(Percent)
			CellTime.innerText = FormatDateTime(CStr(Hour) + ":" + CStr(Minute) + ":" + CStr(Second), 3) + " de " + midiocx.GetHMSLength 
			img1.width = int(((CellProgress.offsetWidth - 8) / 100) * Percent)
			LastTime = Second
		End if
	End Sub

	Sub Midiocx_Status(Value)
	    Select Case Value
	        Case 0
				CellText1.innerText = ""
				CellText2.innerText = ""
				CellPercent.innerText = "0"
				CellTime.innerText = "00:00:00 de " + midiocx.GetHMSLength
				CellStatus.innerText = "Parado"
				img1.Width = 0
	        Case 1
				CellStatus.innerText = "Pausado"
	        Case 2
				CellStatus.innerText = "Reproduzindo..."
				StartNota = 1
		    Case 5
				CellStatus.innerText = "Carregando..."
		    Case 6
				CellStatus.innerText = "Concluído!"
	    End Select

	End Sub

	Function GetComentario(Value)
			If Value < 50 then GetComentario = "Muito fraco, precisa melhorar muito..."
			if value >= 50 and Value <= 70 then GetComentario = "Razoável, precisa só mais um pouquinho de treino..."
			if value >= 71 and Value <= 80 then GetComentario = "Muito bom... Voce canta muito bem!"
			if value >= 81 and Value <= 90 then GetComentario = "Quase profissional..."
			if value >= 91 and Value <= 99 then GetComentario = "Excelente! Cantor assim não se encontra todos os dias..."
			if value >= 100 then GetComentario = "Parabéns!!! Voce é profissional..."
	End Function
	
	Sub Midiocx1_MidiError(ErrNum)
	
	    Select Case ErrNum
	        Case 100
	            msg = "The file is not open."
	        Case 101
	            msg = "Error opening file,"
	        Case 102
	            msg = "File is not a standard midi file."
	        Case 103
	            msg = "There not is possible recover the midi track."
	        Case 104
	            msg = "Error opening device."
	        Case 105
	            msg = "There isn't more memory space to stream."
	        Case 106
	            msg = "Error on out stream buffer."
	        Case 107
	            msg = "Error on clean buffers."
	        Case 600
	            msg = "Can't open file"
	        Case 601
	            msg = "OpenUrl failed"
	    End Select
		MsgBox msg, "Erro"
		
	End Sub
	
	Sub GetText_OnClick()
		
		lft = cstr((screen.Width / 2) - 250)
		tp  = cstr((screen.Height / 2) - 190)
	    For i = 0 To Midiocx.GetPhraseCount -1
	        Texto = Texto + Midiocx.GetPhrase(i) + "<BR>"
	    Next
		criteria = "http://www.karaokeonline.com.br/Codigo/letra.asp"
		criteria = criteria + "?Title1=" + midiocx.GetTitles(0) +"&"
		criteria = criteria + "Title2=" + midiocx.GetTitles(1) +"&"
		criteria = criteria + "Title3=" + midiocx.GetTitles(2) +"&"
		criteria = criteria + "Letra=" + Texto
		window.open criteria, null, "left = " + lft + ", top = " + tp + ",width=500, height=380, scrollbars = 1"
		
	End Sub
	
	Sub bdy_onload()
		Dim opt

		if not TestDomain() then
			Msgbox "Este domímio não está autorizado a utilizar este karaoke on line", vbInformation, "Aviso:" 
			exit sub
		end if
		StartNota = 0
		for i = 0 to midiocx.GetNumDevices -1
			set Opt = document.createElement("OPTION") 
			opt.value = cstr(i)
			opt.text = midiocx.GetDeviceName(i)
			device.add Opt
		next
		device_onchange	
		document.focus
	End Sub
	
	Sub device_onchange()
		If Midiocx.GetStatus = 2 Then
			StartNota = 0
			Midiocx.Stop
		End if
		Midiocx.SetDevice device(device.selectedindex).value
		Volume.selectedIndex = midiocx.MasterVolume
		Balanco.selectedIndex = midiocx.MasterBalance + 5
	End Sub
	
	Sub Volume_onchange()
		MidiOcx.MasterVolume = Volume(Volume.selectedindex).Value
	End Sub	
	
	Sub Balanco_onchange()
		MidiOcx.MasterBalance = Balanco(Balanco.selectedindex).Value
	End Sub	

	Sub Velocidade_onchange()
		midiocx.Velocity = Velocidade(Velocidade.selectedindex).Value
	End Sub	

	Sub Transpose_onchange()
		midiocx.Transpose = transpose(Transpose.selectedindex).Value
	End Sub	

	Sub ProcessImage()
		self.event.returnValue=false
	End Sub	

	Sub ProcessSelectStart()
		self.event.returnValue=false 
	End Sub	

	Sub ProcessMouseMove(cellName , Value)
		if self.event.offsetx > cellName.offsetWidth - 8 then exit sub
		if self.event.button = 1 then
			img1.width = self.event.offsetx-1
		end if
	End Sub

	Sub ProcessMouseDown(cellName)
		if self.event.offsetx > cellName.offsetWidth - 8  then exit sub
		img1.width = self.event.offsetx-1
		if CellName.Id = "CellProgress" Then
			StartNota = 0
			Midiocx.Stop 
		End if
	End Sub

	Sub ProcessMouseUp(cellName , Value)
		if self.event.offsetx > cellName.offsetWidth - 8 then exit sub
		img1.width = self.event.offsetx-1
		Value = int((self.event.offsetx * 101)/ (cellName.offsetWidth - 8))
		Select Case CellName.Id
			Case "CellProgress"
				ProcessAction 1, Value
		End Select
	End Sub

	Sub ProcessAction(ActionID, Value)
	    On Error Resume Next
		if ActionID = 1 then
		    Midiocx.MoveTo Int((Value * Midiocx.GetLength) / 100)
    		Midiocx.Play
		End if
	End Sub

	Function TestDomain() 
		if self.location.hostname = "www.karaokeonline.com.br" then
			TestDomain = True
		else
			TestDomain = False
		End if
	End Function	
	

