//función descargada de internet, agrega la función trim() al objeto string de javascript,
//la cual sirve para eliminar los espacios iniciales y finales de una cadena de caracteres
String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g, '' ); };

// Script descargado de http://www.gamarod.com.ar/
var message="Derechos reservados de Hands Care Center, Febrero 2007";
function clickIE() {
	if (document.all) {
		(message);return false;
	
	}
}
function clickNS(e) {
	if (document.layers||(document.getElementById&&!document.all)) {
		if (e.which==2||e.which==3) {
			//alert(message);
			return false;
		}
	}
}
if (document.layers) {
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=clickNS;
}else{
		document.onmouseup=clickNS;
		document.oncontextmenu=clickIE;
}
document.oncontextmenu=new Function("return false");
//función descargada desde 
//http://www.webtaller.com/construccion/lenguajes/javascript/lecciones/comprobar-email-javascript.php
function mail(texto){
	var mailres = true;            
	var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
	var arroba = texto.indexOf("@",0);
	var punto = texto.lastIndexOf(".");
	
	if ((texto.lastIndexOf("@")) != arroba) arroba = -1;
	
	for (var contador = 0 ; contador < texto.length ; contador++){
		if (cadena.indexOf(texto.substr(contador, 1),0) == -1){
			mailres = false;
			break;
		}
	}
	
	if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1))
		mailres = true;
	else
		mailres = false;
	
	return mailres;
} 

function validar(tipo){
	var mensaje = new String();
	if(tipo==0){
		mensaje= "Ocurrieron los siguientes errores:\n";
		mensaje+=((document.getElementById("t_nombre").value.trim()=="")?"> Debe indicar su nombre \n":"");
		mensaje+=((document.getElementById("t_apellido").value.trim()=="")?"> Debe indicar su apellido \n":"");
		mensaje+=((document.getElementById("t_ciudad").value.trim()=="")?"> Debe indicar la ciudad donde reside \n":"");
		mensaje+=((document.getElementById("t_pais").value.trim()=="")?"> Debe indicar el país donde reside \n":"");
		mensaje+=((document.getElementById("t_mail").value.trim()=="")?"> Debe indicar su correo electrónico \n":"");
		mensaje+=((document.getElementById("t_zona").value.trim()=="")?"> Debe indicar la zona de interés \n":"");
		mensaje+=((document.getElementById("t_mensaje").value.trim()=="")?"> Debe indicar el mensaje que desea enviar \n":"");
		mensaje+=((mail(document.getElementById("t_mail").value.trim()))?"":"> El formato de correo no es válido \n");
		if (mensaje!="Ocurrieron los siguientes errores:\n") alert(mensaje);
		return (mensaje=="Ocurrieron los siguientes errores:\n");
	}else{
		mensaje= "The following mistakes happened:\n";
		mensaje+=((document.getElementById("t_nombre").value.trim()=="")?"> Indicate your First Name \n":"");
		mensaje+=((document.getElementById("t_apellido").value.trim()=="")?"> Indicate your Last Name \n":"");
		mensaje+=((document.getElementById("t_ciudad").value.trim()=="")?"> Indicate the City \n":"");
		mensaje+=((document.getElementById("t_pais").value.trim()=="")?"> Indicate the Country \n":"");
		mensaje+=((document.getElementById("t_mail").value.trim()=="")?"> Indicate the e-mail \n":"");
		mensaje+=((document.getElementById("t_zona").value.trim()=="")?"> Indicate the Zone of Interest \n":"");
		mensaje+=((document.getElementById("t_mensaje").value.trim()=="")?"> Indicate the Message \n":"");
		mensaje+=((mail(document.getElementById("t_mail").value.trim()))?"":"> Invalid format e-mail \n");
		if (mensaje!="The following mistakes happened:\n") alert(mensaje);
		return (mensaje=="The following mistakes happened:\n");
	}
}

function comprobarlong(obj,tipo){
	var maxchars=500;
	var res=true;
	if (obj.value.length>=maxchars) res=false;
	if (tipo==0)
		document.getElementById("nchars").innerHTML="Quedan "+(maxchars-obj.value.length).toString()+" caracteres";
	else
		document.getElementById("nchars").innerHTML=(maxchars-obj.value.length).toString()+" characters left";
	if (!res){
		obj.value=obj.value.substring(0,maxchars);
	}
}