function BorrarFormulario()
{
	window.frmIncidenciaTelecentro.reset();
}

function ValidarFormulario()
{
	
	if( document.getElementById('ddlSelectTelecentro').value== '0' ) {
		alert("Seleccione o seu telecentro");
		document.frmIncidenciaTelecentro.ddlSelectTelecentro.focus();
		return;
	}

	if( document.getElementById('ddlSelectTipoIncidencia').value== '0' ) {
		alert("Seleccione o tipo de incidencia");
		document.frmIncidenciaTelecentro.ddlSelectTipoIncidencia.focus();
		return;
	}
	
	if( trim( document.frmIncidenciaTelecentro.txtIncidencia.value ) == "" )
	{
		alert("Engada o detalle da súa incidencia");
		document.frmIncidenciaTelecentro.txtIncidencia.focus();
		return;
	}
	
	if( trim( document.frmIncidenciaTelecentro.txtNome.value ) == "" )
	{
		alert("Engada o seu nome e apelidos");
		document.frmIncidenciaTelecentro.txtNome.focus();
		return;
	}
	
	if( ValidaEmail( document.frmIncidenciaTelecentro.txtEmail ) == false )
	{
	    document.frmIncidenciaTelecentro.txtEmail.focus();
	    return;
	}

    	if( ( document.frmIncidenciaTelecentro.txtTelefono.value.length >= 0 ) && ( document.frmIncidenciaTelecentro.txtTelefono.value.length < 9 ) ) {
		alert("O número de teléfono non é válido");
		document.frmIncidenciaTelecentro.txtTelefono.focus();
		return;
	}

	if( trim( document.frmIncidenciaTelecentro.txtVerificacion.value ) == "" )
	{
		alert("Introduza os datos de verificación do formulario");
		document.frmIncidenciaTelecentro.txtVerificacion.focus();
		return;
	}	

	
	document.frmIncidenciaTelecentro.submit();	
	
}

function ValidaEmail(obj)
{
    var sEmail= new Object;
   	sEmail=trim(obj.value);
	if (sEmail=="")
	{
		alert("Introduza o enderezo electrónico") 
		obj.focus(); 
		obj.select();
		return false;
	}
			
	if (sEmail.length > 0)
	{
		if (sEmail.indexOf ('@',0) == -1 || sEmail.indexOf ('.',0) == -1)
	  	{
	    	alert("O enderezo electrónico non ten un formato válido")
			obj.focus(); 
			obj.select();
			return false;
		}
		sEmail = trim(sEmail)
		if(ChequeaEmail(sEmail))
			return true;
		else
			return false;
	}
	return true;	
}

function ChequeaEmail(lemailStr)
{
	if (lemailStr =='')
    	return '';

	var Mesg = "Introduza un enderezo electrónico válido"
	var lemailPat=/^(.+)@(.+)$/
	var lspecialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var lvalidChars="\[^\\s" + lspecialChars + "\]"
	var lfirstChars=lvalidChars
	var lquotedUser="(\"[^\"]*\")"
	var lipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var latom="(" + lfirstChars + lvalidChars + "*" + ")"
	var lword="(" + latom + "|" + lquotedUser + ")"
	var luserPat=new RegExp("^" + lword + "(\\." + lword + ")*$")
	var ldomainPat=new RegExp("^" + latom + "(\\." + latom +")*$")
	var lmatchArray=lemailStr.match(lemailPat)
	
	if (lmatchArray==null) 
	{
		alert (Mesg);
		return false;
	}
	
	var luser=lmatchArray[1]
	var ldomain=lmatchArray[2]

	if (luser.match(luserPat)==null) 
	{
		alert (Mesg);
		document.frmIncidenciaTelecentro.txtEmail.focus();
		document.frmIncidenciaTelecentro.txtEmail.select()
		return false;
    }
	  
	var lIPArray=ldomain.match(lipDomainPat)

	if (lIPArray!=null) 
	{
	  	for (var li=1;li<=4;li++) 
	  	{
	    	if (lIPArray[li]>255) 
			{
				alert (Mesg);
				document.frmIncidenciaTelecentro.txtEmail.focus();
				document.frmIncidenciaTelecentro.txtEmail.select()
				return false;
	    	}
    	}  
	}

	var ldomainArray=ldomain.match(ldomainPat)
	
	if (ldomainArray==null)
 	{
		alert (Mesg);
		document.frmIncidenciaTelecentro.txtEmail.focus();
		document.frmIncidenciaTelecentro.txtEmail.select()
		return false;
	}
		
	var latomPat=new RegExp(latom,"g")
	var ldomArr=ldomain.match(latomPat)
	var llen=ldomArr.length
	
	if (ldomArr[ldomArr.length-1].length<1 || 
    	ldomArr[ldomArr.length-1].length>255) 
    {
			alert (Mesg);
			document.frmIncidenciaTelecentro.txtEmail.focus();
			document.frmIncidenciaTelecentro.txtEmail.select()
			return false;
	}
	if (((ldomArr[ldomArr.length-1].length>=1) && (ldomArr[ldomArr.length-1].length<=255)) && (llen<2)) 
	{
		alert (Mesg);
		document.frmIncidenciaTelecentro.txtEmail.focus();
		document.frmIncidenciaTelecentro.txtEmail.select()
    	return  false;
	}	
	return true;
}
			
function validarLongitudIncidencia(obj,eventKeyCode,limit)
{
    var isNN = ( navigator.appName.indexOf("Netscape") != -1 );
    var keyCode = (isNN) ? eventKeyCode.which : eventKeyCode.keyCode; 	
    if((obj.value.length>limit)&&(keyCode!=8))
    {
        alert("Excede a máxima lonxitude permitida");
        return false;
    }
    else
    {
        return true;
    }
}

function isNumeric(e)
{
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	var keyCode = (isNN) ? e.which : e.keyCode; 
		
	if (isNN)
	{
		if (keyCode == 0)
			return true;
	}
	
	if((keyCode>47&&keyCode<58)||(keyCode==8)||(keyCode==9)||(keyCode==46)||(keyCode==189))  
	{
		return true;
	}	
	else	
		return false;		
}

function trim( cadena )
{
    if(cadena.indexOf(' ')>-1)
    {
        var value='';
        var arrSplit=cadena.split(' ');
        for(i=0;i<arrSplit.length;i++)
        {
            if(arrSplit[i].length > 1)
            {
                value=value + arrSplit[i]+' '; 
            }
        }    
        return value.substring(0,value.length-1);
    }
    else
        return cadena;
}

function mostrarAno( idAno ) {	
	this.idAno = document.getElementById( idAno );
	this.actualizaAno()
}

mostrarAno.prototype.actualizaAno = function()
{
	var thisobj = this
	var thedate = new Date();
	this.idAno.innerHTML = thedate.getFullYear();
}


