function color_bk(nform, nelement, color){
	document.forms[nform].elements[nelement].style.backgroundColor=color;
}
/* Autor: http://www.niquelao.net */
var forms =  document.getElementsByTagName("form");
var inputs = document.getElementsByTagName("input");
var textareas =  document.getElementsByTagName("textarea");
var valorinicial = new Array();
function formulario() {
	for (var i = 0; i < inputs.length; i++) {
		if((inputs[i].type == "text") || (inputs[i].type == "password")) { 
			valorinicial[inputs[i].id]=inputs[i].value;
			inputs[i].onfocus = function() {vacia(this.id,this.value)}
			inputs[i].onblur = function() {restaura(this.id,this.value)}
		}
	}
	for (var i = 0; i < textareas.length; i++) { 
		valorinicial[textareas[i].id]=textareas[i].value;
		textareas[i].onfocus = function() {vacia(this.id,this.value)}
		textareas[i].onblur = function() {restaura(this.id,this.value)}
	}
}
function vacia(id,valor){
    var targetElement = document.getElementById(id);
	var tipo = targetElement.type;
	switch ( tipo ) { 
		case "text":
			if (valorinicial[id] == valor)
				targetElement.value = "";
			break
		case "password":
			if (valorinicial[id] == valor)
				targetElement.value = "";
			break
		case "textarea":
			if (valorinicial[id] == valor) {
				targetElement.innerHTML = "";
				targetElement.value = "";
			}
			break
	}
}
function restaura(id){
    var targetElement = document.getElementById(id);
	var tipo = targetElement.type;
	switch ( tipo ) { 
		case "text":
			if (targetElement.value.replace(/ /g, '') == '')
				targetElement.value = valorinicial[id];
				break
		case "password":
			if (targetElement.value.replace(/ /g, '') == '')
				targetElement.value = valorinicial[id];
				break
		case "textarea":
			revisa = targetElement.value.replace(/ /g, '');
			// Eliminamos saltos de línea y tabulaciones
			revisa = revisa.replace(/\n/g, '')
			revisa = revisa.replace(/\t/g, '')
			revisa = revisa.replace(/\r/g, '')
			if (revisa == '') {
				targetElement.innerHTML = valorinicial[id];
				targetElement.value = valorinicial[id];
			}
			break
	}
}
function validarForm(){
	var f1=document.forms['fcontacto'];
	var wm = "Atención :\n\r\n";
	var noerror = 1;
	var t1=f1.txt_nombre; var t2=f1.txt_fono; var t3=f1.txt_email1; var t4=f1.txt_email2; var t5=f1.txt_mensaje;
	
	if(t1.value == "" || t1.value == " "){wm += "Falta indicar el nombre.\n\r"; noerror=0;}
	if(t2.value == "" || t2.value == " "){wm += "Falta indicar el teléfono.\n\r"; noerror=0;}
	if(t3.value == "" || t3.value == " "){wm += "Falta indicar el e-mail.\n\r"; noerror=0;}
	else{
		if(validar_email(t3.value)){
			if(t3.value != t4.value){
				wm+= "Debe escribir la misma dirección de e-mail.\n\r"; noerror=0;
			}
		}else{
			wm+= "Dirección de correo inválida.\n\r"; noerror=0;
		}
	}
	if(t5.value == "" || t5.value == " "){wm += "Falta indicar el mensaje.\n\r"; noerror=0;}
	if (noerror == 0) {
		alert(wm);
		return false;
		}	else return true;
	}
window.onload = formulario;
