
var focus=false;
function CustomValidateConfEmail(source, arguments)
{
    if(arguments)
    {
        var ConfEmail = getElementContact(source.controltovalidate);
        if (ConfEmail.value == "")
	    {
		    source.errormessage = 'Please, confirm your email.';
		    //ConfEmail.focus();
		    arguments.IsValid=false;
		    return;
	    }
	    else
	    {
	        if(!ValidateEmail(ConfEmail.value))
		    {
			    source.errormessage = "Please, check the email for confirmation.";
			    //ConfEmail.focus();
			    arguments.IsValid=false;
			    return;
		    }
	    }
	    
	    var Email = getElementContact("txtEmail");
	    if(ConfEmail.value != Email.value)
	    {
		    source.errormessage = "The confirm email is not the same that the email.";
		    //ConfEmail.focus();
		    arguments.IsValid=false;
		    return;
	    }
	    
        arguments.IsValid=true;
    }  
}

function CustomValidateEmail(source, arguments)
{
    if(arguments)
    {
        var Email = getElementContact(source.controltovalidate);
        if (Email.value == "")
	    {
		    source.errormessage = 'Please, enter your Email.';
		    //Email.focus();
		    arguments.IsValid=false;
		    return;
	    }
	    else
	    {
	        if(!ValidateEmail(Email.value))
		    {
			    source.errormessage = "Please, check your Email.";
			    //Email.focus();
			    arguments.IsValid=false;
			    return;
		    }
	    }
        arguments.IsValid=true;
    }    
}

function ValidateEmail(valor) 
{
    if (/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(valor))
	    return true;
    else
	    return false;
}

function CustomValidateComments(source, arguments)
{
    var Comment = getElementContact(source.controltovalidate);
    if (Comment.value == "")
	{
		source.errormessage = 'Please, enter your Comments.';
		//Comment.focus();
		arguments.IsValid=false;
		return;
	}		
    arguments.IsValid=true;
}

function getElementContact(name)
{
    var object = null;
    var tbSmallContact=document.getElementById('tbContact'); 
    for (var i=0; i<tbSmallContact.rows.length; i++)
    {
        for (var j=0; j<tbSmallContact.rows[i].cells.length; j++)
        {
            for (var k=0; k<tbSmallContact.rows[i].cells[j].childNodes.length; k++)
            {                
                if(tbSmallContact.rows[i].cells[j].childNodes[k].id == name)
                {
                   object = tbSmallContact.rows[i].cells[j].childNodes[k];
                   return object;
                }
            }
        }
    }    
}