function getCookie(c_name)
{
if (document.cookie.length>0)
	{
	c_start=document.cookie.indexOf(c_name + "=")
	if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1 
		c_end=document.cookie.indexOf(";",c_start)
		if (c_end==-1) c_end=document.cookie.length
		return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
return null
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate)
}

function carAlfa(cadena)
{
	validos="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	for (i=0;i<cadena.length;i++)
	{
	if (validos.indexOf(cadena.charAt(i))==-1) return true;
	if (cadena.charAt(i)==".")
	if ((i!=cadena.length-1) && (cadena.charAt(i+1)=="."))
	return true;
	}
return false;
}

function validarDepartamento(s_name)
{
var hayerror;
hayerror = false;
if (s_name.id.value != "1" && s_name.id.value != "2")
        {
        alert('El campo Departamento es obligatorio.');
        s_name.id.focus();
        hayerror = true;
        }
if (hayerror == false) { return true; }
else { return false; }
}

function validarNombre(s_name)
{
var hayerror;
hayerror = false;
if (s_name.nombreapellidos.value.length < 1)
	{
	alert('El campo Nombre y apellidos es obligatorio.');
	s_name.nombreapellidos.focus();
	hayerror = true;
	}
if (s_name.nombreapellidos.value.length > 40 && hayerror == false)
	{
	alert('El campo Nombre y apellidos no puede superar los 40 carácteres.');
	s_name.nombreapellidos.focus();
	hayerror = true;
	}
if (hayerror == false) { return true; }
else { return false; }
}

function validarCorreo(s_name)
{
var hayerror;
hayerror = false;
regx = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
if (s_name.correoelectronico.value.length < 1)
	{
	alert('El campo Correo electrónico es obligatorio.');
	s_name.correoelectronico.focus();
	hayerror = true;
	}
if (s_name.correoelectronico.value.length < 7 && hayerror == false)
	{
	alert('El campo Correo electrónico debe superar los 6 carácteres.');
	s_name.correoelectronico.focus();
	hayerror = true;
	}
if (s_name.correoelectronico.value.length > 40 && hayerror == false)
	{
	alert('El campo Correo electrónico no puede superar los 40 carácteres.');
	s_name.correoelectronico.focus();
	hayerror = true;
	}
if (regx.test(s_name.correoelectronico.value) == false && hayerror == false)
	{
	alert('El campo Correo electrónico no es correcto.');
	s_name.correoelectronico.focus();
	hayerror = true;
	}
if (hayerror == false) { return true; }
else { return false; }
}

function validarTelefono(s_name)
{
var hayerror;
hayerror = false;
if (s_name.telefono.value.length < 9)
	{
	alert('El campo Teléfono debe ser superior a 8 carácteres.');
	s_name.telefono.focus();
	hayerror = true;
	}
if (s_name.telefono.value.length > 20 && hayerror == false)
	{
	alert('El campo Teléfono no puede superar los 20 carácteres.');
	s_name.telefono.focus();
	hayerror = true;
	}
if (hayerror == false) { return true; }
else { return false; }
}

function validarDominio(s_name)
{
var hayerror;
hayerror = false;
if (s_name.dominio.value.length < 1)
	{
	alert('El campo Dominio es obligatorio.');
	s_name.dominio.focus();
	hayerror = true;
	}
if (s_name.dominio.value.length > 40 && hayerror == false)
	{
	alert('El campo Dominio no puede superar los 40 carácteres.');
	s_name.dominio.focus();
	hayerror = true;
	}
if (hayerror == false) { return true; }
else { return false; }
}

function validarMensaje(s_name)
{
var hayerror;
hayerror = false;
if (s_name.mensaje.value.length < 1)
	{
	alert('El campo Mensaje es obligatorio.');
	s_name.mensaje.focus();
	hayerror = true;
	}
if (s_name.mensaje.value.length > 2000 && hayerror == false)
	{
	alert('El campo Mensaje no puede superar los 2.000 carácteres.');
	s_name.mensaje.focus();
	hayerror = true;
	}
if (hayerror == false) { return true; }
else { return false; }
}

function validarImagen(s_name)
{
var hayerror;
hayerror = false;
if (s_name.security_code.value.length < 1)
	{
	alert('El campo Imagen es obligatorio.');
	s_name.security_code.focus();
	hayerror = true;
	}
if (s_name.security_code.value.length != 6 && hayerror == false)
	{
	alert('El campo Imagen debe ser de 6 carácteres.');
	s_name.security_code.focus();
	hayerror = true;
	}
if (carAlfa(s_name.security_code.value) && hayerror == false)
        {
        alert('El campo Imagen debe ser alfanumérico.');
        s_name.security_code.focus();
        hayerror = true;
        }
if (hayerror == false) { return true; }
else { return false; }
}

function validarFormulario(s_name)
{
var test_departamento;
var test_nombre;
var test_correo;
var test_telefono;
var test_mensaje;
var test_imagen;
test_departamento=validarDepartamento(s_name);
if (test_departamento == true)
	{
	test_nombre=validarNombre(s_name);
	}
if (test_departamento == true && test_nombre == true)
	{
	test_correo=validarCorreo(s_name);
	}
if (test_departamento == true && test_nombre == true && test_correo == true)
        {
        test_telefono=validarTelefono(s_name);
        }
if (test_departamento == true && test_nombre == true && test_correo == true && test_telefono == true)
        {
        test_dominio=validarDominio(s_name);
        }
if (test_departamento == true && test_nombre == true && test_correo == true && test_telefono == true && test_dominio == true)
        {
        test_mensaje=validarMensaje(s_name);
        }
if (test_departamento == true && test_nombre == true && test_correo == true && test_telefono == true && test_dominio == true && test_mensaje == true)
        {
	test_imagen=validarImagen(s_name);
        }
if (test_departamento == true && test_nombre == true && test_correo == true && test_telefono == true && test_dominio == true && test_mensaje == true && test_imagen == true)
        {
	return true;
        }
return false;
}
