function trava() {
document.cadastra.Enviar.disabled = true;
document.cadastra.submit();
}

function trava_proprietario(id_proprietario) {
	if (document.cadastra.cliente_vinculado.value=='XXX'){
		document.cadastra.Sprop_nome.disabled = false;
		document.cadastra.Sprop_endereco.disabled = false;
		document.cadastra.Sprop_numero.disabled = false;
		document.cadastra.Sprop_cep.disabled = false;	
		document.cadastra.Sprop_bairro.disabled = false;	
		document.cadastra.Sprop_cidade.disabled = false;	
		document.cadastra.Sprop_estado.disabled = false;	
		document.cadastra.Sprop_email.disabled = false;	
		document.cadastra.Sprop_fone.disabled = false;	
		document.cadastra.Sprop_celular.disabled = false;	
		document.cadastra.Sprop_rg.disabled = false;	
		document.cadastra.Sprop_celular.disabled = false;	
		document.cadastra.Sprop_cpf.disabled = false;	
		retorna_usuario(id_proprietario);
		
	}else{
		retorna_usuario(id_proprietario);
		//alert(document.cadastra.cliente_vinculado.value);
		document.cadastra.Sprop_nome.disabled = true;
		document.cadastra.Sprop_endereco.disabled = true;
		document.cadastra.Sprop_numero.disabled = true;
		document.cadastra.Sprop_cep.disabled = true;	
		document.cadastra.Sprop_bairro.disabled = true;	
		document.cadastra.Sprop_cidade.disabled = true;	
		document.cadastra.Sprop_estado.disabled = true;	
		document.cadastra.Sprop_email.disabled = true;	
		document.cadastra.Sprop_fone.disabled = true;	
		document.cadastra.Sprop_celular.disabled = true;	
		document.cadastra.Sprop_rg.disabled = true;	
		document.cadastra.Sprop_celular.disabled = true;	
		document.cadastra.Sprop_cpf.disabled = true;	
		
	}
}


		function objXMLHttp(){
		if (window.XMLHttpRequest){ //monzila, safari
			var objetoXMLHttp = new XMLHttpRequest();
			return objetoXMLHttp;
		}else if (window.ActiveXObject){ //ie
			//todas as versoes de ie
			var versoes = ["MSXML2.XMLHttp.6.0","MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp.2.0","Microsoft.XMLHttp"];
		
					for ( var i=0; i<versoes.length; i++){
							try{
							var objetoXMLHttp = new ActiveXObject(versoes[i]);
							return objetoXMLHttp;
							} catch(ex){
							//nada aqui //kuroleweb design
							}//end try
					}//end for	
		}			
		return false;	
		} // end objXMLHttp
		
		
function retorna_usuario(formulario){
				
		var dados = "id_proprietario="+formulario;
		
		var oXMLHttp = objXMLHttp();
			oXMLHttp.open("POST", "add_retorna_proprietario.php", true);
			oXMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			oXMLHttp.onreadystatechange = function(){
				if (oXMLHttp.readyState == 4){
					if (oXMLHttp.status == 200){
						
						var results = oXMLHttp.responseText.split(",");		
						//$novo_resultado = (results.length-1);

								var string = results[1].split( "|" );
								
	
								if (string[0] == "nome"){
									window.document.forms[0].Sprop_nome.value = string[1];
								}else{
									window.document.forms[0].Sprop_nome.value = "";
								}
								var string = results[2].split( "|" );
								if (string[0] == "endereco"){
									window.document.forms[0].Sprop_endereco.value = string[1];
								}else{
									window.document.forms[0].Sprop_endereco.value = "";
								}						
								var string = results[3].split( "|" );
								if (string[0] == "numero"){
									window.document.forms[0].Sprop_numero.value = string[1];
								}else{
									window.document.forms[0].Sprop_numero.value = "";
								}
								var string = results[4].split( "|" );
								if (string[0] == "cep"){
									window.document.forms[0].Sprop_cep.value = string[1];
								}else{
									window.document.forms[0].Sprop_cep.value = "";
								}
								var string = results[5].split( "|" );
								if (string[0] == "bairro"){
									window.document.forms[0].Sprop_bairro.value = string[1];
								}else{
									window.document.forms[0].Sprop_bairro.value = "";
								}						
								var string = results[6].split( "|" );
								if (string[0] == "cidade"){
									window.document.forms[0].Sprop_cidade.value = string[1];
								}else{
									window.document.forms[0].Sprop_cidade.value = "";
								}
								var string = results[7].split( "|" );
								if (string[0] == "estado"){
									window.document.forms[0].Sprop_estado.value = string[1];
								}else{
									window.document.forms[0].Sprop_estado.value = "";
								}														
								var string = results[8].split( "|" );
								if (string[0] == "email"){
									window.document.forms[0].Sprop_email.value = string[1];
								}else{
									window.document.forms[0].Sprop_email.value = "";
								}	
								var string = results[9].split( "|" );
								if (string[0] == "fone"){
									window.document.forms[0].Sprop_fone.value = string[1];
								}else{
									window.document.forms[0].Sprop_fone.value = "";
								}
								var string = results[10].split( "|" );
								if (string[0] == "celular"){
									window.document.forms[0].Sprop_celular.value = string[1];
								}else{
									window.document.forms[0].Sprop_celular.value = "";
								}
								var string = results[11].split( "|" );
								if (string[0] == "rg"){
									window.document.forms[0].Sprop_rg.value = string[1];
								}else{
									window.document.forms[0].Sprop_rg.value = "";
								}
								var string = results[12].split( "|" );
								if (string[0] == "cpf"){
									window.document.forms[0].Sprop_cpf.value = string[1];
								}else{
									window.document.forms[0].Sprop_cpf.value = "";
								}
								
					
					}else{
						//window.alert('Erro ao adicionar!');
						//mensagem("Ocorreu um erro: "+oXMLHttp.statusText);
					}
				}
			};//end function onreadystatechange
			oXMLHttp.send(dados);
			return false;
	
	}//end function enviar formulario
	
	
//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 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
}