function validateForm(form) {
    var elem = form.elements;
    var valid = true;
    for (var i = 0; i < elem.length; i++) {
        spn = document.getElementById(elem[i].id + "Obrig");
		inp = document.getElementById(elem[i].id + "");
        if (spn != null) {
            if (elem[i].value == "") {            	
                spn.style.display = "inline-block";
				inp.style.borderColor = "#ffd392";
                valid = false;
                elem[i].onblur = function() { validarControle(this); }
            }
        }
    }
    return valid;
}

function validarControle(controle) {
    spn = document.getElementById(controle.id + "Obrig");
	inp = document.getElementById(controle.id);
    if(controle.value == ""){
    	spn.style.display = "inline-block";
		inp.style.borderColor = "#ffd392";
    }
    else{
    	spn.style.display = "none";
		inp.style.borderColor = "";
    }
}

function mascaraTexto(e, mascara, somenteNumeros){  
    
	   var campo, valor, i, tam, caracter;  

	   if(somenteNumeros){
		   var code;
		   if (!e) var e = window.event;
		   if (e.keyCode) code = e.keyCode;
		   else if (e.which) code = e.which;
		   if (code == 8 || code == 9)
		   { }
		   else {
		       if (code > 47 && code < 58) {
		    	   if (document.all) // Internet Explorer  
		    		      campo = e.srcElement;  
		    		   else // Nestcape, Mozzila  
		    		       campo= e.target;  
		    		         
		    		   valor = campo.value;  
		    		   tam = valor.length;  
		    		     
		    		   for(i=0;i<mascara.length;i++){  
		    		      caracter = mascara.charAt(i);  
		    		      if(caracter!="9")   
		    		         if(i<tam & caracter!=valor.charAt(i))  
		    		            campo.value = valor.substring(0,i) + caracter + valor.substring(i,tam);                   
		    		   } 
		       }
		       else {
		           return false;
		       }
		   }        
	   }
	   else{
		   if (document.all) // Internet Explorer  
			      campo = e.srcElement;  
			   else // Nestcape, Mozzila  
			       campo= e.target;  
			         
			   valor = campo.value;  
			   tam = valor.length;  
			     
			   for(i=0;i<mascara.length;i++){  
			      caracter = mascara.charAt(i);  
			      if(caracter!="9")   
			         if(i<tam & caracter!=valor.charAt(i))  
			            campo.value = valor.substring(0,i) + caracter + valor.substring(i,tam);                   
			   } 	   
	   }	   	  
} 
