// Fecha creacion: 24/03/2011
// Proyecto: Medios Externos SL.


// FUNCION PARA ENVIAR LOS EMAILS.
function EmailHTML(usuario,dominio,clase){
var HTMLContent="";
 if(usuario!=undefined && dominio!=undefined){
  HTMLContent+="<a href=mailto:"+usuario+"@"+dominio; 
  HTMLContent+= (clase!=undefined) ? " class="+clase+">" : ">";
  HTMLContent+= usuario+"@"+dominio;
  HTMLContent+="</a>";
  document.write(HTMLContent);
 }
}

// FUNCION QUE VERIFICA EL CAMPO EMAIL
function EmailCorrecto(email) {
	caracNoValidos = " /:,;";
	if(email=="") return false;
	for(i=0;i<caracNoValidos.length; i++) {
		caracMal = caracNoValidos.charAt(i);
		if(email.indexOf(caracMal,0) > -1){ 		
			return false;}
	}
	posArroba = email.indexOf("@",1);
	if(posArroba==-1) {return false;}
	if (email.indexOf("@",posArroba+1)!= -1){return false;}
	posPunto = email.indexOf(".",posArroba);
	if(posPunto == -1){return false;}
	if (posPunto+3 > email.length){return false;}
	return true;		
}

// FUNCIONES NUMERICAS. VERIFICACION DEL TELEFONO DEL FORMULARIO DE CONTACTO EN CASO DE RELLENARLO.
function isDigit(theDigit){ 
var digitArray = new Array('0','1','2','3','4','5','6','7','8','9'),j; 
for (j = 0; j < digitArray.length; j++)
		{if (theDigit == digitArray[j]) return true}
return false 
} 

function isPositiveInteger(theString){ 
	var theData = new String(theString) 

	if (!isDigit(theData.charAt(0))) 
		if (!(theData.charAt(0)== '+')) 
			return false 
	for (var i = 1; i < theData.length; i++) 
		if (!isDigit(theData.charAt(i))) return false 
	return true 
}


// FUNCION PARA VALIDAR EL FORMULARIO DE CONTACTO.
function validarFormularioContacto(elform) {
var todok = true;
var msgerror='Por favor, corrige los siguientes datos obligatorios:\n\n';
	if (elform.empresa.value == "") {msgerror+=' - Su nombre o empresa\n'; todok=false;}
	if (elform.mensaje.value == "") {msgerror+=' - Escriba su comentario\n'; todok=false;}
	if ( (elform.email.value == "") && (elform.telefono.value == "") ) {msgerror+=' - Necesitamos un m\xE9todo de contacto: e-mail y/o tel\xE9fono\n'; todok=false;}
	if (elform.telefono.value != "")
		if (!isPositiveInteger(elform.telefono.value)) {msgerror+=' - Su tel\xE9fono no parece correcto'; todok=false;}
	if (elform.email.value != "")
		if (!EmailCorrecto(elform.email.value)){msgerror+=' - Tu direcci\xF3n de correo electr\xF3nico no parece correcta';todok=false;}
	if (!todok) {alert(msgerror);return(false); } else return (true);
}

function validarFormularioPresupuesto(elform) {
var todok = true;
var msgerror='Por favor, corrige los siguientes datos obligatorios:\n\n';
	if (elform.nombre.value == "") {msgerror+=' - Su nombre\n'; todok=false;}
	if (elform.apellidos.value == "") {msgerror+=' - Sus apellidos\n'; todok=false;}
	if (elform.empresa.value == "") {msgerror+=' - El nombre de su empresa\n'; todok=false;}
	if ( (elform.email.value == "") && (elform.telefono.value == "") ) {msgerror+=' - Necesitamos un m\xE9todo de contacto: e-mail y/o tel\xE9fono\n'; todok=false;}
	if (elform.telefono.value != "")
		if (!isPositiveInteger(elform.telefono.value)) {msgerror+=' - Su tel\xE9fono no parece correcto'; todok=false;}
	if (elform.email.value != "")
		if (!EmailCorrecto(elform.email.value)){msgerror+=' - Tu direcci\xF3n de correo electr\xF3nico no parece correcta';todok=false;}
	if (!todok) {alert(msgerror);return(false); } else return (true);
}
