buenas amigo el problema es que al utilizar 
 
valor = document.getElementById("nombre").value;  
si un elemento no existe o si hay otro elemento con el mismo id te dará error 
el caso tendrias que hacer algo parecid ha esto 
var nombre = document.getElementById("nombre");
if( nombre ){
   valor = nombre.value
}
var email= document.getElementById("email");
if( email){
   valor2 = email.value
} 
etc etc...  
pero en otro caso y lo haría de esta forma   
 Código PHP:
    <script type="text/javascript">
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^s+|s+$/g, '');
}
}
function validacion(){
    var input=new Array(
    {name:"nombre", error:"Por favor, Escriba su Nombre" },
    {name:"email", error:"Por favor, Escriba su Email"},
    {name:"email", isemail:true, error:"Por favor, Escriba un Email correcto"},
    {name:"localidad",error:"Por favor, Escriba su Localidad"},
    {name:"depar", error:"Por favor, Seleccione un Departamento"},
    {name:"asunto",error:"Por favor, Escriba su Asunto"},
    {name:"texto",error:"Por favor, Escriba su Mensaje"});
    for(var n  in input){
        var p = input[n];
        var obj = document.getElementById(p.name);
        if(!obj){
            alert(p.error);    
            return false;
        }else{
            var value = obj.value.trim();
            if(p.isemail) value=(/^[a-z0-9]+[a-z0-9_-.]*[a-z0-9]+@{1}[a-z0-9]{2,128}.([a-z0-9]{2,6}(.[a-z0-9]{2,4})?)$/i.test(value))?value:false;
            if(!value ){
                alert(p.error);    
                obj.focus();
                return false;
            }
        }
    }
}
</script>