//desenvolvido por kurole@kurole.com.br
function fecha_propaganda(){
	window.document.getElementById('propaganda').style.display='none';
}

function trava() {

		if (window.document.cadastra.c_user.value.length == 0){
			window.alert("O comentário está em branco!");
		return false;
		}
		
		if (window.document.cadastra.c_user.value.length < 3){
			window.alert("O comentário está muito curto!");
		return false;
		}

document.cadastra.Apagar.disabled = true;
document.cadastra.Enviar.disabled = true;
document.cadastra.submit();

}



function adiciona_produto() {

	document.cadastra_produtos.Apagar.disabled = true;
	document.cadastra_produtos.Enviar.disabled = true;
	document.cadastra_produtos.submit();

}



function trava2() {

document.cadastra.Apagar.disabled = true;
document.cadastra.Enviar.disabled = true;
document.cadastra.submit();

}

function iniciando_MP(tipo, dow){
	if (dow == 1){
	var msng = "mp3";
	}else{
	var msng = "wma";
	}
document.getElementById('kurole_ccb').innerHTML = '<object id="mediaPlayer" width="300" height="50" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject"><param name="FileName" value="hinos/'+ tipo + "." + msng +'"><param name="animationatStart" value="true"><param name="transparentatStart" value="true"><param name="autoStart" value="false"><param name="showControls" value="true"><param name="ShowStatusBar" value="true"><param name="loop" value="1"><embed type="application/x-mplayer2" pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" src="hinos/'+ tipo + "." + msng +'" width="300" height="50" autostart="0" displaysize="4" autosize="0" bgcolor="black" showcontrols="1" showtracker="0" ShowStatusBar="1" showdisplay="0" videoborder3d="0" designtimesp="5311" loop="1"></embed></object>';
}
function iniciando_MPA(tipo, dow){
	if (dow == 1){
	var msng = "mp3";
	}else{
	var msng = "wma";
	}
document.getElementById('kurole_ccb').innerHTML = '<object id="mediaPlayer" width="300" height="50" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject" ><param name="FileName" value="avulso/'+ tipo + "." + msng +'"><param name="autostart" value="false"><param name="animationatStart" value="true"><param name="transparentatStart" value="true"><param name="autoStart" value="false"><param name="showControls" value="true"><param name="ShowStatusBar" value="true"><param name="loop" value="1"><embed type="application/x-mplayer2" pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" src="avulso/'+ tipo + "." + msng +'" width="300" height="50" autostart="0" displaysize="4" autosize="0" bgcolor="black" showcontrols="1" showtracker="0" ShowStatusBar="1" showdisplay="0" videoborder3d="0" designtimesp="5311" loop="1"></embed></object>';
}
function iniciando_MPD(tipo, dow){
	if (dow == 1){
	var msng = "mp3";
	}else{
	var msng = "wma";
	}
document.getElementById('kurole_ccb').innerHTML = '<object id="mediaPlayer" width="590" height="50" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject" ><param name="FileName" value="quem_canta_este_hino/'+ tipo + "." + msng +'"><param name="autostart" value="false"><param name="animationatStart" value="true"><param name="transparentatStart" value="true"><param name="showControls" value="true"><param name="ShowStatusBar" value="true"><param name="loop" value="1"><embed type="application/x-mplayer2" pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" src="quem_canta_este_hino/'+ tipo + "." + msng +'" width="300" height="50" autostart="0" displaysize="4" autosize="0" bgcolor="black" showcontrols="1" showtracker="0" ShowStatusBar="1" showdisplay="0" videoborder3d="0" designtimesp="5311" loop="1"></embed></object>';
}


//modelo 2 de fromatar valor
//chamada da funcao
//onKeyDown="Formata_VALOR(this,11,event,2)"
//kurolewebdesign kurole@kurole.com.br

function Limpar(valor, validos) {
	// retira caracteres invalidos da string
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++) {
	aux = validos.indexOf(valor.substring(i, i+1));
	if (aux>=0) {
	result += aux;
	}
	}
	return result;
}


function Formata_VALOR(campo,tammax,teclapres,decimal) {
	
	var tecla = teclapres.keyCode;

	var vr = Limpar(campo.value,"0123456789");
	var tam = vr.length;
	var dec=decimal
	
	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 <= dec )
	{ campo.value = vr ; }

	if ( (tam > dec) && (tam <= 5) ){
	campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
	if ( (tam >= 6) && (tam <= 8) ){
	campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
	}
	
	if ( (tam >= 9) && (tam <= 11) ){
		campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
	if ( (tam >= 12) && (tam <= 14) ){
		campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
	if ( (tam >= 15) && (tam <= 17) ){
		campo.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 ) ;}
	}	

}	


 function formata_data(x,tecla){ 
        
        separador="/"; // Você pode definir o separador. Ex: "/" ou "-" ou "."
        
        tecla=tecla.keyCode; // Identifica a tecla, caso seja backspace
        
        valor=x.value.split(''); // Pega o valor do campo e transforma cada caractere em uma string
        formatado=""; // Variável para carregar formatação temporariamente
        
        i=0; // variável de controle
        
        while(i<valor.length){ // Loop para cada caractere do campo
            caractere=valor[i]; // Seleciona um caractere para ser formatado
            numeros=/^\d+$/; // Variavel contendo números positivos
                // Verifica se é número ou "barra"
            if(numeros.test(caractere) || caractere==separador){ formatado+=String(caractere);}
                // Verifica se precisa de barra, se a tecla for backspace, então a barra não é adicionada
                // Se for para adicionar barra, aumenta ++ variável de controle "i" para pular a barra adicionada
            if((formatado.length==2 || formatado.length==5) && tecla!=8){formatado+=separador; i++;}
                
            i++; // Se houver, passa para o próximo caractere
        }
        
        x.value=formatado; // Atribui o valor formatado ao campo
		if (formatado.length == 10){
		x.focus();
		}	
    }
	
	
function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function leech(v){
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}

function soNumeros(v){
    return v.replace(/\D/g,"")
}

function telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function cpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function cep(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function cnpj(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
    return v
}

function romanos(v){
    v=v.toUpperCase()             //Maiúsculas
    v=v.replace(/[^IVXLCDM]/g,"") //Remove tudo o que não for I, V, X, L, C, D ou M
    //Essa é complicada! Copiei daqui: http://www.diveintopython.org/refactoring/refactoring.html
    while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
        v=v.replace(/.$/,"")
    return v
}

function site(v){
    //Esse sem comentarios para que você entenda sozinho ;-)
    v=v.replace(/^http:\/\/?/,"")
    dominio=v
    caminho=""
    if(v.indexOf("/")>-1)
        dominio=v.split("/")[0]
        caminho=v.replace(/[^\/]*/,"")
    dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
    caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
    caminho=caminho.replace(/([\?&])=/,"$1")
    if(caminho!="")dominio=dominio.replace(/\.+$/,"")
    v="http://"+dominio+caminho
    return v
}


function msg_mural(kurole_div){
	var nome_navegador = navigator.appName;
	if (window.document.getElementById(kurole_div).style.display == 'none'){
		if (nome_navegador == 'Microsoft Internet Explorer'){
			window.document.getElementById(kurole_div).style.display='block';	
		}else{
			window.document.getElementById(kurole_div).style.display='table-row';
		}
			//window.parent.muda_frame('corpo');
	}else{
		window.document.getElementById(kurole_div).style.display = 'none';
	}
}

function validarMsgMural( x ){
		//vai ser enviado via php na mesma página.. kurole web design
		if (x.nome.value.length == 0){ alert('O campo nome está em branco!'); return false; }
		if (x.nome.value.length < 4){ alert('O campo nome está muito curto!'); return false; }
		if (x.email.value.length == 0){ alert('O campo e-mail está em branco!'); return false; }
		if (x.email.value.length < 4){ alert('O campo e-mail está muito curto!'); return false; }
		if (x.para.value.length == 0){ alert('O campo para está em branco!'); return false; }
		if (x.para.value.length < 4){ alert('O campo para está muito curto!'); return false; }
		if (x.msg.value.length == 0){ alert('O campo msg está em branco!'); return false; }
		if (x.msg.value.length < 10){ alert('O campo msg está muito curto!'); return false; }
		

		//Validando o e-mail
		var str = x.email.value; // email string
		var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
		var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
		if (!reg1.test(str) && reg2.test(str)) // if syntax is valid
		 {  }else{ alert(' O seu endereço de e-mail é inválido.'); return false; }				
		x.Submit.disabled=true;
		x.Submit.value = 'enviando por favor aguarde...';
		
	}
	
 
function enviasmile(img){
	var texto = document.getElementById('msg').value;
	//alert(texto);
	img = ':'+ img +':';
	document.getElementById('msg').value = texto + img;
	document.getElementById('msg').focus();
}

/* nao estou usando kurole   */
function coloca_smile(mensagem_rep){
	for(i = 1; i < 27; i++){
		while(mensagem_rep.indexOf(':'+ i +':') != -1){
			mensagem_rep = mensagem_rep.replace(':'+ i +':','<img src="img/smiles/'+ i +'.gif">');
		}
	}
	return mensagem_rep;
}

