//************************************************************************
// FLASH
//***********************************************************************

var MM_contentVersion = 6; // SETA A VERSÃO DO FLASH PLAYER NECESSÁRIA
var release = "6,0,67,0"; // SETA A SUB-VERSÃO DO FLASH PLAYER NECESSÁRIA

// CHECAR SE EXISTE O PLAYER
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0; 
if (plugin) { 
    var words = navigator.plugins["Shockwave Flash"].description.split(" "); 
    for (var i = 0; i < words.length; ++i) 
    { 
        if (isNaN(parseInt(words[i]))) 
        continue; 
        var MM_PluginVersion = words[i]; 
    } 
    var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion; 
} 
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0  && (navigator.appVersion.indexOf("Win") != -1)) 
{ 
    document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag 
    document.write('on error resume next \n'); 
    document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n'); 
    document.write('</SCR' + 'IPT\> \n'); 
} 


// FUNÇÃO QUE INSERE O FLASH
function InserirFlash(swf,flashVarString,width,height,bgcolor,menu,mode,qualidade,id) { 
	if ( MM_FlashCanPlay ) { 
		document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' 
		+'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+release+'" ' 
		+'width="'+width+'" height="'+height+'" id="'+id+'" align="">' 
		+'<param name="movie" value="'+swf+'">' 
		+'<param name="menu" value="'+menu+'"> ' 
		+'<param name="quality" value="'+qualidade+'"> ' 
		+'<param name="wmode" value="'+mode+'"> ' 
		+'<param name="bgcolor" value="'+bgcolor+'"> ' 
		+'<param name="flashvars" value="'+flashVarString+'"> ' 
		+'<embed src="'+swf+'" flashvars="'+flashVarString+'" menu="'+menu+'" quality="'+qualidade+'" wmode="'+mode+'" ' 
		+' bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'" name="'+swf+'" ' 
		+' align="" type="application/x-shockwave-flash" ' 
		+' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object> '); 
	} else { 

		document.write('É necessário o Flash Player '+MM_contentVersion+' ou superior para visualizar a animação. '); 
		document.write('<em><a href="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">'); 
		document.write('Clique aqui para instalá-lo agora..</a></em>'); 
	} 
}

// FUNÇÃO QUE REDIRECIONA A PÁGINA ENVIADA PELO FLASH
function Redireciona(pagina)
{
	if (pagina=="Home")
		document.location='../Home/';
	if (pagina=="SobreOProjeto")
		document.location='../Pagina/Sobre-o-Projeto,1';
	if (pagina=="ConhecaOAutor")
		document.location='../Pagina/Conheca-o-Autor,2';
	if (pagina=="AgendaDeEventos")
		document.location='../Pagina/Agenda-de-Eventos,3';
	if (pagina=="GaleriaDeFotos")
		document.location='../GaleriaFotos/Galeria-de-Fotos';
	if (pagina=="Imprensa")
		document.location='../Imprensa';
	if (pagina=="MuralDeRecados")
		document.location='../Mural-de-Recados';
	if (pagina=="Partituras")
		document.location='../Partituras';
	if (pagina=="LeveOMoacyr")
		document.location='../Programe-um-workshop-com-o-Moacyr';
    if (pagina=="Contato")
		document.location='../Contato/';
}




//************************************************************************
// TRIM
//***********************************************************************

function trim(inputString) {
		 // Removes leading and trailing spaces from the passed string. Also removes
		// consecutive spaces and replaces it with one space. If something besides
		// a string is passed in (null, custom object, etc.) then return the input.
		if (typeof inputString != "string") { return inputString; }
		var retValue = inputString;
		var ch = retValue.substring(0, 1);
		while (ch == " ") { // Check for spaces at the beginning of the string
			retValue = retValue.substring(1, retValue.length);
			ch = retValue.substring(0, 1);
		}
		ch = retValue.substring(retValue.length-1, retValue.length);
		while (ch == " ") { // Check for spaces at the end of the string
			retValue = retValue.substring(0, retValue.length-1);
			ch = retValue.substring(retValue.length-1, retValue.length);
		}
		while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
			retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
		}
		return retValue; // Return the trimmed string back to the user
}



//************************************************************************
// Formatar Data
//***********************************************************************

function FormataData(controle, teclapres) 
	{
	var tecla = teclapres.keyCode;
	vr = controle.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			controle.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			controle.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
	}
	
	
	
//******************************************************************************************************************************
// Verificação  CPF
//******************************************************************************************************************************

function ValidarCPF(cpf){
	
	var 
		char_valido = 0, 
		char_invalido = 0, 
		digito1, 
		digito2,msgaux,texto,erro,
		soma_digito1 = 0,
		soma_digito2 = 0;
	  
		msgaux = 'Volte ao campo correspondente e complete a informação, caso contrário seus dados não serão aceitos pelo servidor de cadastro.' 
		erro=false;

		//verifica sequencia de numeros repetidos.
		
		if (cpf.length==0)
			return true;
			
		if (cpf.length!=11)
			{
			alert('O nro. do CPF especificado e inválido !');
			return false;
			}
	
		if (cpf == '00000000000' || cpf == '11111111111' ||
	    	cpf == '22222222222' || cpf == '33333333333' ||
			cpf == '44444444444' || cpf == '55555555555' ||
			cpf == '66666666666' || cpf == '77777777777' || 
			cpf == '99999999999')
					
			{
				msgaux+='\n- CPF inválido;'       
				erro=true;
			}
			
			//verifica quantidade de caracteres
				
			if (cpf.length == 11)
				{
					
				//verifica se digitou apenas números
					
				for (var i = 0; i <= cpf.length - 1; i++)
					{
					if (cpf.charAt(i) >= '0' && cpf.charAt(i) <= '9')
						{
							char_valido = char_valido + 1;
						}
					else
						{
							char_invalido = char_invalido + 1;
						}
					}
      
				if (char_valido == cpf.length)
					{
					for (i = 0; i < 9; i++)
						{
							soma_digito1 += (10 - i) * (eval(cpf.charAt(i)));
						}
						digito1 = 11 - (soma_digito1 % 11);
						
						for (i = 0; i < 9; i++)
							{
								soma_digito2 += (11 - i) * (eval(cpf.charAt(i)));
							}		
						
						soma_digito2 += 2 * (eval(cpf.charAt(9)));
								
						digito2 = 11 - (soma_digito2 % 11);
								
						if ((soma_digito1 % 11) < 2)
							{
								digito1 = 0;
							}
						
						if ((soma_digito2 % 11) < 2)
							{
								digito2 = 0;
							}
						
						if (eval(cpf.charAt(9) != digito1) || eval(cpf.charAt(10) != digito2))
							{
								msgaux+='\n- CPF inválido;'       
								erro=true;
							}
						}
					else
						{
							msgaux+='\n- Digite apenas números no campo CPF;'       
							erro=true;
						}
					}

			if (erro)
			{ 
				alert(msgaux) 
				document.Form1.TXTCPF.focus();
			}

			return !(erro);
		
		}


//************************************************************************
// Verificar CNPJ
//************************************************************************
		
function ValidarCNPJ(cgc)
			{	
				var 
					char_valido = 0, 
					char_invalido = 0, 
					digito1, 
					digito2,
					soma_digito1 = 0,
					soma_digito2 = 0;
					msgaux='';

					cgc = cgc.replace(".","");
					cgc = cgc.replace(".","");
					cgc = cgc.replace(".","");
					cgc = cgc.replace(".","");
					cgc = cgc.replace(".","");
					cgc = cgc.replace(",","");
					cgc = cgc.replace(",","");
					cgc = cgc.replace(",","");
					cgc = cgc.replace(",","");
					cgc = cgc.replace(",","");
					cgc = cgc.replace("-","");
					cgc = cgc.replace("-","");
					cgc = cgc.replace("-","");
					cgc = cgc.replace("-","");
					cgc = cgc.replace("-","");
					cgc = cgc.replace("/","");
					cgc = cgc.replace("/","");
					cgc = cgc.replace("/","");
					cgc = cgc.replace("/","");
					cgc = cgc.replace("/","");
			
					if (cgc!="")    
						{
					    //verifica sequencia de caracteres repetidos
						    
						    if (cgc == '00000000000000' || cgc == '11111111111111' ||
								cgc == '22222222222222' || cgc == '33333333333333' ||
								cgc == '44444444444444' || cgc == '55555555555555' ||
								cgc == '66666666666666' || cgc == '77777777777777' ||
								cgc == '88888888888888' || cgc == '99999999999999')          
							
								{
									alert('\n- CNPJ inválido\n- Para continuar, digite corretamente o campo CNPJ.');
						            return false;
								}	
			
							//verifica quantidade de caracteres
							
							if (cgc.length == 14)
								{
									//verifica se digitou apenas números
									for (var i = 0; i <= cgc.length - 1; i++)
										{
											if (cgc.charAt(i) >= '0' && cgc.charAt(i) <= '9')
												{
													char_valido = char_valido + 1;
												}
											else
												{
													char_invalido = char_invalido + 1;
												}
										}
		     
									if (char_valido == cgc.length)
										{
											for (i = 0; i < 4; i++)
												{
													soma_digito1 += (5 - i) * (eval(cgc.charAt(i)));
												}	
											for (i = 0; i < 8; i++)
												{
													soma_digito1 += (9 - i) * (eval(cgc.charAt(i + 4)));
												}
											digito1 = 11 - (soma_digito1 % 11);
          
									        for (i = 0; i < 5; i++)
												{
													soma_digito2 += (6 - i) * (eval(cgc.charAt(i)));
												}
											for (i = 0; i < 7; i++)
												{
													soma_digito2 += (9 - i) * (eval(cgc.charAt(i + 5)));
												}
											soma_digito2 += 2 * (eval(cgc.charAt(12)));
											digito2 = 11 - (soma_digito2 % 11);
            
											if ((soma_digito1 % 11) < 2)
												{
													digito1 = 0;
												}
											if ((soma_digito2 % 11) < 2)
												{
													digito2 = 0;
												}
											if (eval(cgc.charAt(12) != digito1) || eval(cgc.charAt(13) != digito2))
												{
													alert('\n- CNPJ inválido\n- Para continuar, digite corretamente o campo CNPJ.'); 
													return false;
												}
										}
									else
										{
											alert('\n- Digite apenas números\n- Para continuar, digite corretamente o campo CNPJ.');       
											return false;
										}
							}
							else
								{
									alert('\n- Campo CNPJ deve ter 14 digitos\n- Para continuar, digite corretamente o campo CNPJ.');       
									return false;
								}
	
						}
			}



/**************************************************************************/
/* FORMATAR HORA														  */
/**************************************************************************/
function FormataHora(Controle,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = Controle.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		Controle.value = vr  ; }
	 	if ( (tam > 2) && (tam <= 4) ){
	 		Controle.value = vr.substr( 0, tam - 2 ) + ':' + vr.substr( tam - 2, tam ) ; }
	 	
	 	
	}		
	
}




/**************************************************************************/
/* FORMATAR VALOR														  */
/**************************************************************************/
function FormataValor(Controle,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = Controle.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		Controle.value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		Controle.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		Controle.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		Controle.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		Controle.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		Controle.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}		
		
}
