function ValidateEmail(valor) 
{
    if (/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(valor))
	    return true;
    else
	    return false;
}  

function ValidatePhone(source, arguments)
{
    var ValidChars = "0123456789.()- ";
    var IsCorrect=true;
    var Char;
    var IsValid=false;
    incoming= document.getElementById(source.controltovalidate).value;
    for (cont = 0; cont < incoming.length && IsCorrect == true; cont++) 
    { 
        Char = incoming.charAt(cont); 
        if (ValidChars.indexOf(Char) == -1) {
             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.';
    	   
	        arguments.IsValid=false;
	        return;
        }
        else
        {
        if(!ValidateEmail(Email.value))
	        {
		        source.errormessage = "Please check the emails address.";
    		 
		        arguments.IsValid=false;
		        return;
	        }
        }
        arguments.IsValid=true;

    }    
}


function ValidateComments(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 ValidateFirstName(source, arguments)
{

    var FirstName = getElementContact(source.controltovalidate);
    if (FirstName.value == "")
    {
	    source.errormessage = 'Please, enter your first name.';
	   //FirstName.focus();
	    arguments.IsValid=false;
	    return;
    }		
    arguments.IsValid=true;
}

function ValidateLastName(source, arguments)
{

    var LastName = getElementContact(source.controltovalidate);
    if (LastName.value == "")
    {
	    source.errormessage = 'Please, enter your last name.';
	    //LastName.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;
                }
            }
        }
       
    }    
}